Skip to content

Commit

Permalink
Merge pull request #10614 from quarto-dev/latex/auto-install-opt-out
Browse files Browse the repository at this point in the history
Quarto LaTeX engine improvement on missing package detection
  • Loading branch information
cderv authored Aug 30, 2024
2 parents 0008520 + ab5ccec commit 81a2834
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 9 deletions.
9 changes: 8 additions & 1 deletion news/changelog-1.6.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All changes included in 1.6:
- ([#10039](https://github.com/quarto-dev/quarto-cli/issues/10039)): `quarto inspect` properly handles `!expr` tag in metadata.
- ([#10188](https://github.com/quarto-dev/quarto-cli/issues/10188)): `quarto inspect` properly resolves includes across subdirectory boundaries.

## Lua filters
## Lua Filters

- ([#10004](https://github.com/quarto-dev/quarto-cli/issues/10004)): Resolve callout titles, theorem names, and `code-summary` content through `quarto_ast_pipeline()` and `process_shortcodes()`.
- ([#10196](https://github.com/quarto-dev/quarto-cli/issues/10196)): Protect against nil values in `float.caption_long`.
Expand All @@ -23,6 +23,13 @@ All changes included in 1.6:
- ([#10217](https://github.com/quarto-dev/quarto-cli/issues/10217)): Explicitly compute units for image dimensions in `typst` format when they're not given.
- ([#10212](https://github.com/quarto-dev/quarto-cli/issues/10212)): Moves Pandoc variables to the function declaration for the default template.

## `latex` and `pdf` Format

- ([#10291](https://github.com/quarto-dev/quarto-cli/issues/10291)): Several improvement regarding Quarto LaTeX engine behavior for missing hyphenation log message:
- `latex-auto-install: false` now correctly opt out any missing hyphenation packages detection and installation. Only a warning will be thrown if any detected in the log.
- For default behavior (`latex-auto-install: true`), detection is still happening and missing packages are installed automatically. If it fails, Quarto does not fail anymore as PDF rendering as succeeded already. Only a warning will be thrown to log the installation failure.
- Log message about hyphenation package missing for `chinese` or `chinese-hans` languages are now ignored.

## Projects

- ([#10268](https://github.com/quarto-dev/quarto-cli/issues/10268)]): `quarto create` supports opening project in Positron, in addition to VS Code and RStudio IDE.
Expand Down
8 changes: 8 additions & 0 deletions src/command/render/latexmk/parse-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ const resolvingMatchers = [
export function findMissingHyphenationFiles(logText: string) {
//ngerman gets special cased
const filterLang = (lang: string) => {
// It seems some languages have no hyphenation files, so we just filter them out
// e.g. `lang: zh` has no hyphenation files
// https://github.com/quarto-dev/quarto-cli/issues/10291
const noHyphen = ["chinese-hans", "chinese"];
if (noHyphen.includes(lang)) {
return;
}

// NOTE Although the names of the corresponding lfd files match those in this list,
// there are some exceptions, particularly in German and Serbian. So, ngerman is
// called here german, which is the name in the CLDR and, actually, the most logical.
Expand Down
22 changes: 14 additions & 8 deletions src/command/render/latexmk/pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,21 @@ async function initialCompileLatex(
const logText = Deno.readTextFileSync(response.log);
const missingHyphenationFile = findMissingHyphenationFiles(logText);
if (missingHyphenationFile) {
if (await pkgMgr.installPackages([missingHyphenationFile])) {
// We installed hyphenation files, retry
continue;
} else {
writeError("missing hyphenation file", "", response.log);
return Promise.reject();
// try to install it, unless auto install is opted out
if (pkgMgr.autoInstall) {
logProgress("Installing missing hyphenation file...");
if (await pkgMgr.installPackages([missingHyphenationFile])) {
// We installed hyphenation files, retry
continue;
} else {
logProgress("Installing missing hyphenation file failed.");
}
}
// Let's just through a warning, but it may not be fatal for the compilation
// and we can end normally
warning(
`Possibly missing hyphenation file: '${missingHyphenationFile}'. See more in logfile (by setting 'latex-clean: false').\n`,
);
}
} else if (pkgMgr.autoInstall) {
// try autoinstalling
Expand All @@ -205,8 +213,6 @@ async function initialCompileLatex(
packagesUpdated = true;
}

const logText = Deno.readTextFileSync(response.log);

// Try to find and install packages
const packagesInstalled = await findAndInstallPackages(
pkgMgr,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
format: pdf
lang: es
latex-auto-install: false
_quarto:
tests:
pdf:
noErrors: true
printsMessage:
- WARN
- 'missing hyphenation.*hyphen-spanish'
---

```{r}
#| include: false
# Remove the hyphen package for spanish so that the test is meaningful
if (tinytex::check_installed("hyphen-spanish")) {
message("Removing 'hyphen-spanish' package for the render")
tinytex::tlmgr_remove("hyphen-spanish")
}
```

# Hola !

automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente
21 changes: 21 additions & 0 deletions tests/docs/smoke-all/2024/08/30/10291/latex-hyphen-lang-es.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
format: pdf
lang: es
_quarto:
tests:
pdf: null
---

```{r}
#| include: false
# Remove the hyphen package for spanish
if (tinytex::check_installed("hyphen-spanish")) {
message("Removing 'hyphen-spanish' package for the render")
tinytex::tlmgr_remove("hyphen-spanish")
}
```

# Hola !

automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente automáticamente
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
format: pdf
lang: zh
_quarto:
tests:
pdf: null
---

# 范叶亮

0 comments on commit 81a2834

Please sign in to comment.