Skip to content

Commit 81a2834

Browse files
authored
Merge pull request #10614 from quarto-dev/latex/auto-install-opt-out
Quarto LaTeX engine improvement on missing package detection
2 parents 0008520 + ab5ccec commit 81a2834

File tree

6 files changed

+86
-9
lines changed

6 files changed

+86
-9
lines changed

news/changelog-1.6.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ All changes included in 1.6:
55
- ([#10039](https://github.com/quarto-dev/quarto-cli/issues/10039)): `quarto inspect` properly handles `!expr` tag in metadata.
66
- ([#10188](https://github.com/quarto-dev/quarto-cli/issues/10188)): `quarto inspect` properly resolves includes across subdirectory boundaries.
77

8-
## Lua filters
8+
## Lua Filters
99

1010
- ([#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()`.
1111
- ([#10196](https://github.com/quarto-dev/quarto-cli/issues/10196)): Protect against nil values in `float.caption_long`.
@@ -23,6 +23,13 @@ All changes included in 1.6:
2323
- ([#10217](https://github.com/quarto-dev/quarto-cli/issues/10217)): Explicitly compute units for image dimensions in `typst` format when they're not given.
2424
- ([#10212](https://github.com/quarto-dev/quarto-cli/issues/10212)): Moves Pandoc variables to the function declaration for the default template.
2525

26+
## `latex` and `pdf` Format
27+
28+
- ([#10291](https://github.com/quarto-dev/quarto-cli/issues/10291)): Several improvement regarding Quarto LaTeX engine behavior for missing hyphenation log message:
29+
- `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.
30+
- 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.
31+
- Log message about hyphenation package missing for `chinese` or `chinese-hans` languages are now ignored.
32+
2633
## Projects
2734

2835
- ([#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.

src/command/render/latexmk/parse-error.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ const resolvingMatchers = [
111111
export function findMissingHyphenationFiles(logText: string) {
112112
//ngerman gets special cased
113113
const filterLang = (lang: string) => {
114+
// It seems some languages have no hyphenation files, so we just filter them out
115+
// e.g. `lang: zh` has no hyphenation files
116+
// https://github.com/quarto-dev/quarto-cli/issues/10291
117+
const noHyphen = ["chinese-hans", "chinese"];
118+
if (noHyphen.includes(lang)) {
119+
return;
120+
}
121+
114122
// NOTE Although the names of the corresponding lfd files match those in this list,
115123
// there are some exceptions, particularly in German and Serbian. So, ngerman is
116124
// called here german, which is the name in the CLDR and, actually, the most logical.

src/command/render/latexmk/pdf.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,21 @@ async function initialCompileLatex(
180180
const logText = Deno.readTextFileSync(response.log);
181181
const missingHyphenationFile = findMissingHyphenationFiles(logText);
182182
if (missingHyphenationFile) {
183-
if (await pkgMgr.installPackages([missingHyphenationFile])) {
184-
// We installed hyphenation files, retry
185-
continue;
186-
} else {
187-
writeError("missing hyphenation file", "", response.log);
188-
return Promise.reject();
183+
// try to install it, unless auto install is opted out
184+
if (pkgMgr.autoInstall) {
185+
logProgress("Installing missing hyphenation file...");
186+
if (await pkgMgr.installPackages([missingHyphenationFile])) {
187+
// We installed hyphenation files, retry
188+
continue;
189+
} else {
190+
logProgress("Installing missing hyphenation file failed.");
191+
}
189192
}
193+
// Let's just through a warning, but it may not be fatal for the compilation
194+
// and we can end normally
195+
warning(
196+
`Possibly missing hyphenation file: '${missingHyphenationFile}'. See more in logfile (by setting 'latex-clean: false').\n`,
197+
);
190198
}
191199
} else if (pkgMgr.autoInstall) {
192200
// try autoinstalling
@@ -205,8 +213,6 @@ async function initialCompileLatex(
205213
packagesUpdated = true;
206214
}
207215

208-
const logText = Deno.readTextFileSync(response.log);
209-
210216
// Try to find and install packages
211217
const packagesInstalled = await findAndInstallPackages(
212218
pkgMgr,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
format: pdf
3+
lang: es
4+
latex-auto-install: false
5+
_quarto:
6+
tests:
7+
pdf:
8+
noErrors: true
9+
printsMessage:
10+
- WARN
11+
- 'missing hyphenation.*hyphen-spanish'
12+
---
13+
14+
```{r}
15+
#| include: false
16+
17+
# Remove the hyphen package for spanish so that the test is meaningful
18+
if (tinytex::check_installed("hyphen-spanish")) {
19+
message("Removing 'hyphen-spanish' package for the render")
20+
tinytex::tlmgr_remove("hyphen-spanish")
21+
}
22+
```
23+
24+
# Hola !
25+
26+
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
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
format: pdf
3+
lang: es
4+
_quarto:
5+
tests:
6+
pdf: null
7+
---
8+
9+
```{r}
10+
#| include: false
11+
12+
# Remove the hyphen package for spanish
13+
if (tinytex::check_installed("hyphen-spanish")) {
14+
message("Removing 'hyphen-spanish' package for the render")
15+
tinytex::tlmgr_remove("hyphen-spanish")
16+
}
17+
```
18+
19+
# Hola !
20+
21+
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
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
format: pdf
3+
lang: zh
4+
_quarto:
5+
tests:
6+
pdf: null
7+
---
8+
9+
# 范叶亮

0 commit comments

Comments
 (0)