Skip to content

Commit 499be6b

Browse files
committed
Fix babel hyphenation warning detection with straight quotes (#10291)
Updated regex to accept both backtick-quote (`Spanish') and straight-quote ('Spanish') formats for detecting missing hyphenation packages. Added unit tests and modified smoke-all tests to skip package removal on CI.
1 parent c92ec40 commit 499be6b

File tree

6 files changed

+78
-5
lines changed

6 files changed

+78
-5
lines changed

news/changelog-1.9.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ All changes included in 1.9:
3737

3838
### `pdf`
3939

40+
- ([#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.
4041
- ([#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.
4142
- ([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.
4243

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

Lines changed: 1 addition & 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]);

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ format: pdf
33
lang: es
44
latex-auto-install: false
55
_quarto:
6+
tests-on-ci: false
67
tests:
78
pdf:
8-
noErrors: true
9+
shouldError: true
910
printsMessage:
10-
- WARN
11-
- 'missing hyphenation.*hyphen-spanish'
11+
level: INFO
12+
regex: "Unknown option 'spanish'"
1213
---
1314

15+
** This test is to be run manually as we don't want to uninstall and reinstall package in CI**
16+
1417
```{r}
1518
#| include: false
1619

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 !

tests/docs/smoke-all/2025/11/04/13633.qmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ _quarto:
88
---
99

1010
```{r}
11+
#| eval: !expr isFALSE(as.logical(Sys.getenv("CI", "false")))
1112
#| include: false
13+
#| messages: "NA"
1214
1315
# Remove babel-english package to test auto-installation
1416
if (tinytex::check_installed("babel-english")) {

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

Lines changed: 61 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

@@ -43,6 +43,9 @@ unitTest("Detect missing files with `findMissingFontsAndPackages`", async () =>
4343
(babel) If it’s the main language, try adding \`provide=*'
4444
(babel) to the babel package options.`, "ngerman.ldf")
4545
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");
4649
assertFound("!pdfTeX error: pdflatex (file 8r.enc): cannot open encoding file for reading", "8r.enc");
4750
assertFound("! CTeX fontset `fandol' is unavailable in current mode", "fandol");
4851
assertFound("! CTeX fontset 'fandol' is unavailable in current mode", "fandol");
@@ -71,4 +74,61 @@ unitTest("Detect missing files with `findMissingFontsAndPackages`", async () =>
7174
assertFound("No file LGRcmr.fd. ! LaTeX Error: This NFSS system isn't set up properly.", "lgrcmr.fd");
7275
},{
7376
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/"
74134
})

0 commit comments

Comments
 (0)