Skip to content

Commit 25ddc1f

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. # Conflicts: # news/changelog-1.9.md # tests/docs/smoke-all/2024/08/30/10291/latex-hyphen-lang-es-no-install.qmd
1 parent 34c2625 commit 25ddc1f

File tree

5 files changed

+79
-3
lines changed

5 files changed

+79
-3
lines changed

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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@ format: pdf
44
lang: es
55
latex-auto-install: false
66
_quarto:
7+
tests-on-ci: false
78
tests:
8-
pdf: default
9+
pdf:
10+
shouldError: true
11+
printsMessage:
12+
level: INFO
13+
regex: "Unknown option 'spanish'"
914
---
1015

16+
** This test is to be run manually as we don't want to uninstall and reinstall package in CI**
17+
1118
```{r}
1219
#| include: false
1320

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

@@ -42,6 +42,9 @@ unitTest("Detect missing files with `findMissingFontsAndPackages`", async () =>
4242
(babel) If it’s the main language, try adding \`provide=*'
4343
(babel) to the babel package options.`, "ngerman.ldf")
4444
assertFound("! Package babel Error: Unknown option 'english'.", "english.ldf");
45+
assertFound(`! Package babel Error: Unknown option 'ngerman'.
46+
(babel) Suggested actions:
47+
(babel) * Make sure you haven't misspelled it`, "ngerman.ldf");
4548
assertFound("!pdfTeX error: pdflatex (file 8r.enc): cannot open encoding file for reading", "8r.enc");
4649
assertFound("! CTeX fontset `fandol' is unavailable in current mode", "fandol");
4750
assertFound('Package widetext error: Install the flushend package which is a part of sttools', "flushend.sty");
@@ -51,4 +54,61 @@ unitTest("Detect missing files with `findMissingFontsAndPackages`", async () =>
5154
assertFound("luaotfload-features.lua:835: module 'lua-uni-normalize' not found:", "lua-uni-algos.lua");
5255
},{
5356
cwd: () => "unit/latexmk/"
57+
})
58+
59+
unitTest("Detect missing hyphenation with babel warnings", async () => {
60+
// Test backtick-quote format (old format)
61+
const logWithBacktick = `Package babel Warning: No hyphenation patterns were preloaded for
62+
(babel) the language \`Spanish' into the format.
63+
(babel) Please, configure your TeX system to add them and
64+
(babel) rebuild the format. Now I will use the patterns
65+
(babel) preloaded for \\language=0 instead on input line 51.`;
66+
assert(
67+
findMissingHyphenationFiles(logWithBacktick) === "hyphen-spanish",
68+
"Should detect hyphen-spanish from backtick-quote format"
69+
);
70+
71+
// Test straight-quote format (new format - the bug we're fixing)
72+
const logWithStraightQuotes = `Package babel Warning: No hyphenation patterns were preloaded for
73+
(babel) the language 'Spanish' into the format.
74+
(babel) Please, configure your TeX system to add them and
75+
(babel) rebuild the format. Now I will use the patterns
76+
(babel) preloaded for \\language=0 instead on input line 51.`;
77+
assert(
78+
findMissingHyphenationFiles(logWithStraightQuotes) === "hyphen-spanish",
79+
"Should detect hyphen-spanish from straight-quote format"
80+
);
81+
82+
// Test ngerman special case (should return hyphen-german, not hyphen-ngerman)
83+
const logGerman = `Package babel Warning: No hyphenation patterns were preloaded for
84+
(babel) the language 'ngerman' into the format.`;
85+
assert(
86+
findMissingHyphenationFiles(logGerman) === "hyphen-german",
87+
"Should map ngerman to hyphen-german"
88+
);
89+
90+
// Test Chinese - no hyphen package exists
91+
const logChinese = `Package babel Warning: No hyphenation patterns were preloaded for
92+
(babel) the language 'chinese' into the format.`;
93+
assert(
94+
findMissingHyphenationFiles(logChinese) === undefined,
95+
"Should return undefined for Chinese (no hyphen package)"
96+
);
97+
98+
// Test alternative Info pattern (issue #10291)
99+
const logInfoChinese = `Package babel Info: Hyphen rules for 'chinese-hans' set to \\l@nil
100+
(babel) (\\language10). Reported on input line 143.`;
101+
assert(
102+
findMissingHyphenationFiles(logInfoChinese) === undefined,
103+
"Should return undefined for chinese-hans via Info pattern"
104+
);
105+
106+
// Test no warning present
107+
const logNoWarning = "Some other log text without babel warnings";
108+
assert(
109+
findMissingHyphenationFiles(logNoWarning) === undefined,
110+
"Should return undefined when no babel warning present"
111+
);
112+
}, {
113+
cwd: () => "unit/latexmk/"
54114
})

0 commit comments

Comments
 (0)