Skip to content

Commit c1375a3

Browse files
authored
Merge pull request #13643 from quarto-dev/fix/tinytex/babel-error
2 parents 537a0f9 + b1e3e16 commit c1375a3

File tree

6 files changed

+109
-5
lines changed

6 files changed

+109
-5
lines changed

news/changelog-1.9.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ All changes included in 1.9:
66
- ([#13441](https://github.com/quarto-dev/quarto-cli/pull/13441)): Catch `undefined` exceptions in Pandoc failure to avoid spurious error message.
77
- ([#13046](https://github.com/quarto-dev/quarto-cli/issues/13046)): Use new url for multiplex socket.io server <https://multiplex.up.railway.app/> as default for `format: revealjs` and `revealjs.multiplex: true`.
88
- ([#13506](https://github.com/quarto-dev/quarto-cli/issues/13506)): Fix navbar active state detection when sidebar has no logo configured. Prevents empty logo links from interfering with navigation highlighting.
9+
- ([#13633](https://github.com/quarto-dev/quarto-cli/issues/13633)): Fix detection and auto-installation of babel language packages from newer error format that doesn't explicitly mention `.ldf` filename.
910

1011
## Dependencies
1112

@@ -37,6 +38,7 @@ All changes included in 1.9:
3738

3839
### `pdf`
3940

41+
- ([#10291](https://github.com/quarto-dev/quarto-cli/issues/10291)): Fix detection of babel hyphenation warnings with straight-quote format instead of backtick-quote format.
4042
- ([rstudio/tinytex-releases#49](https://github.com/rstudio/tinytex-releases/issues/49)): Fix detection of LuaTeX-ja missing file errors by matching both "File" and "file" in error messages.
4143

4244
## Projects

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export function findMissingHyphenationFiles(logText: string) {
133133
const babelWarningRegex = /^Package babel Warning:/m;
134134
const hasWarning = logText.match(babelWarningRegex);
135135
if (hasWarning) {
136-
const languageRegex = /^\(babel\).* language `(\S+)'.*$/m;
136+
const languageRegex = /^\(babel\).* language [`'](\S+)[`'].*$/m;
137137
const languageMatch = logText.match(languageRegex);
138138
if (languageMatch) {
139139
return filterLang(languageMatch[1]);
@@ -283,6 +283,12 @@ const packageMatchers = [
283283
{ regex: /.*! LaTeX Error: File [`']([^']+)' not found.*/g },
284284
{ regex: /.* [fF]ile ['`]?([^' ]+)'? not found.*/g },
285285
{ regex: /.*the language definition file ([^\s]*).*/g },
286+
{
287+
regex: /.*! Package babel Error: Unknown option [`']([^'`]+)'[.].*/g,
288+
filter: (match: string, _text: string) => {
289+
return `${match}.ldf`;
290+
},
291+
},
286292
{ regex: /.* \\(file ([^)]+)\\): cannot open .*/g },
287293
{ regex: /.*file [`']([^']+)' .*is missing.*/g },
288294
{ regex: /.*! CTeX fontset [`']([^']+)' is unavailable.*/g },

tests/docs/smoke-all/2024/08/30/10291/latex-hyphen-lang-es-no-install.qmd

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
---
22
format: pdf
3-
# new babel support in Pandoc 3.6.3 solves missing package when specific lang is used.
43
lang: es
54
latex-auto-install: false
65
_quarto:
6+
tests-on-ci: false
77
tests:
8-
pdf: default
8+
pdf:
9+
noErrors: true
10+
printsMessage:
11+
level: WARN
12+
regex: "Possibly missing hyphenation"
913
---
1014

15+
** This test is to be run manually as we don't want to uninstall and reinstall package in CI**
16+
1117
```{r}
1218
#| include: false
13-
19+
#| messages: 'NA'
1420
# Remove the hyphen package for spanish so that the test is meaningful
1521
if (tinytex::check_installed("hyphen-spanish")) {
1622
message("Removing 'hyphen-spanish' package for the render")

tests/docs/smoke-all/2024/08/30/10291/latex-hyphen-lang-es.qmd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,21 @@ _quarto:
66
pdf: null
77
---
88

9+
**Only remove package on CI**
910
```{r}
11+
#| eval: !expr isFALSE(as.logical(Sys.getenv("CI", "false")))
1012
#| include: false
13+
#| messages: "NA"
1114
1215
# Remove the hyphen package for spanish
1316
if (tinytex::check_installed("hyphen-spanish")) {
1417
message("Removing 'hyphen-spanish' package for the render")
1518
tinytex::tlmgr_remove("hyphen-spanish")
1619
}
20+
if (tinytex::check_installed("babel-spanish")) {
21+
message("Removing 'babel-spanish' package for the render")
22+
tinytex::tlmgr_remove("babel-spanish")
23+
}
1724
```
1825

1926
# Hola !
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
title: "Babel English Auto-Install (#13633)"
3+
format: pdf
4+
lang: en
5+
_quarto:
6+
tests:
7+
pdf: null
8+
---
9+
10+
```{r}
11+
#| eval: !expr isFALSE(as.logical(Sys.getenv("CI", "false")))
12+
#| include: false
13+
#| messages: "NA"
14+
15+
# Remove babel-english package to test auto-installation
16+
if (tinytex::check_installed("babel-english")) {
17+
message("Removing 'babel-english' package for the render")
18+
tinytex::tlmgr_remove("babel-english")
19+
}
20+
```
21+
22+
This document tests that Quarto correctly detects and auto-installs babel-english when rendering with `lang: en`.

tests/unit/latexmk/parse-error.test.ts

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
*/
77

8-
import { findMissingFontsAndPackages } from "../../../src/command/render/latexmk/parse-error.ts"
8+
import { findMissingFontsAndPackages, findMissingHyphenationFiles } from "../../../src/command/render/latexmk/parse-error.ts"
99
import { unitTest } from "../../test.ts";
1010
import { assert } from "testing/asserts";
1111

@@ -42,6 +42,10 @@ unitTest("Detect missing files with `findMissingFontsAndPackages`", async () =>
4242
(babel) There is a locale ini file for this language.
4343
(babel) If it’s the main language, try adding \`provide=*'
4444
(babel) to the babel package options.`, "ngerman.ldf")
45+
assertFound("! Package babel Error: Unknown option 'english'.", "english.ldf");
46+
assertFound(`! Package babel Error: Unknown option 'ngerman'.
47+
(babel) Suggested actions:
48+
(babel) * Make sure you haven't misspelled it`, "ngerman.ldf");
4549
assertFound("!pdfTeX error: pdflatex (file 8r.enc): cannot open encoding file for reading", "8r.enc");
4650
assertFound("! CTeX fontset `fandol' is unavailable in current mode", "fandol");
4751
assertFound("! CTeX fontset 'fandol' is unavailable in current mode", "fandol");
@@ -70,4 +74,61 @@ unitTest("Detect missing files with `findMissingFontsAndPackages`", async () =>
7074
assertFound("No file LGRcmr.fd. ! LaTeX Error: This NFSS system isn't set up properly.", "lgrcmr.fd");
7175
},{
7276
cwd: () => "unit/latexmk/"
77+
})
78+
79+
unitTest("Detect missing hyphenation with babel warnings", async () => {
80+
// Test backtick-quote format (old format)
81+
const logWithBacktick = `Package babel Warning: No hyphenation patterns were preloaded for
82+
(babel) the language \`Spanish' into the format.
83+
(babel) Please, configure your TeX system to add them and
84+
(babel) rebuild the format. Now I will use the patterns
85+
(babel) preloaded for \\language=0 instead on input line 51.`;
86+
assert(
87+
findMissingHyphenationFiles(logWithBacktick) === "hyphen-spanish",
88+
"Should detect hyphen-spanish from backtick-quote format"
89+
);
90+
91+
// Test straight-quote format (new format - the bug we're fixing)
92+
const logWithStraightQuotes = `Package babel Warning: No hyphenation patterns were preloaded for
93+
(babel) the language 'Spanish' into the format.
94+
(babel) Please, configure your TeX system to add them and
95+
(babel) rebuild the format. Now I will use the patterns
96+
(babel) preloaded for \\language=0 instead on input line 51.`;
97+
assert(
98+
findMissingHyphenationFiles(logWithStraightQuotes) === "hyphen-spanish",
99+
"Should detect hyphen-spanish from straight-quote format"
100+
);
101+
102+
// Test ngerman special case (should return hyphen-german, not hyphen-ngerman)
103+
const logGerman = `Package babel Warning: No hyphenation patterns were preloaded for
104+
(babel) the language 'ngerman' into the format.`;
105+
assert(
106+
findMissingHyphenationFiles(logGerman) === "hyphen-german",
107+
"Should map ngerman to hyphen-german"
108+
);
109+
110+
// Test Chinese - no hyphen package exists
111+
const logChinese = `Package babel Warning: No hyphenation patterns were preloaded for
112+
(babel) the language 'chinese' into the format.`;
113+
assert(
114+
findMissingHyphenationFiles(logChinese) === undefined,
115+
"Should return undefined for Chinese (no hyphen package)"
116+
);
117+
118+
// Test alternative Info pattern (issue #10291)
119+
const logInfoChinese = `Package babel Info: Hyphen rules for 'chinese-hans' set to \\l@nil
120+
(babel) (\\language10). Reported on input line 143.`;
121+
assert(
122+
findMissingHyphenationFiles(logInfoChinese) === undefined,
123+
"Should return undefined for chinese-hans via Info pattern"
124+
);
125+
126+
// Test no warning present
127+
const logNoWarning = "Some other log text without babel warnings";
128+
assert(
129+
findMissingHyphenationFiles(logNoWarning) === undefined,
130+
"Should return undefined when no babel warning present"
131+
);
132+
}, {
133+
cwd: () => "unit/latexmk/"
73134
})

0 commit comments

Comments
 (0)