Skip to content

Commit 43fdcd7

Browse files
authored
Install missing BibTeX style files instead of crashing on Windows (#15377)
When bibtex could not open its style file, the bibliography step matched `open style file ([^ ]+)` against the whole .blg text. The character class also matched the newline, so the captured name ran into the next log line ("agsm.bst\n---line"). That name was then passed to findAndInstallPackages() as its log file argument: on Windows, existsSync() throws os error 123 for the invalid name and the render ends with a raw stack trace; elsewhere the lookup finds no such file and nothing is installed. The .bst auto-install has not worked since the latexmk emulation was first written. That code was ported from TinyTeX's latexmk emulation, which at the time read the .blg with readLines(), applied the same regex per line, and passed the extracted names to parse_packages(files = ...), which searches each name with tlmgr. The port matched against a single string instead of lines, and had no equivalent of the `files =` entry point, so the name ended up used as a log path. TinyTeX later moved the pattern into regex_errors() and switched to parse_packages(text = x) (rstudio/tinytex@256465d). Do the same here: add the pattern to packageMatchers next to the other missing-file patterns ported from regex_errors(), with \S so it stops at the end of the line, and pass the .blg path to findAndInstallPackages() so the file is searched with tlmgr like any other missing file. The style-file check stays in front of the call: without it, any bibtex failure with nothing to install would now abort the render. A missing .bst that tlmgr cannot provide now ends with "no matching packages" and the .blg path, like a missing .sty. Fixes #15376
1 parent 4856b1f commit 43fdcd7

4 files changed

Lines changed: 21 additions & 5 deletions

File tree

‎news/changelog-1.12.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ All changes included in 1.12:
5050
- ([#15320](https://github.com/quarto-dev/quarto-cli/pull/15320)): Update to Pandoc's LaTeX template following Pandoc 3.13 support:
5151
- Table captions are set with the `caption` package, with a 6pt gap to the table.
5252
- Footnotes in long tables are placed after the table by Pandoc, and no longer rely on `footnotehyper`.
53+
- ([#15376](https://github.com/quarto-dev/quarto-cli/issues/15376)): Fix a missing BibTeX style file (`.bst`) not being installed automatically with `cite-method: natbib`, and the render crashing on Windows instead of reporting the error.
5354

5455
### `revealjs`
5556

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,8 @@ const packageMatchers = [
488488
},
489489
},
490490
{ regex: /.* \\(file ([^)]+)\\): cannot open .*/g },
491+
// bibtex .blg log; \S keeps the match off the next log line
492+
{ regex: /.* open style file (\S+).*/g },
491493
{ regex: /.*file [`']([^']+)' .*is missing.*/g },
492494
{ regex: /.*! CTeX fontset [`']([^']+)' is unavailable.*/g },
493495
{ regex: /.*: ([^:]+): command not found.*/g },

‎src/command/render/latexmk/pdf.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,14 +431,11 @@ async function makeBibliographyIntermediates(
431431

432432
if (existsSync(log)) {
433433
const logOutput = Deno.readTextFileSync(log);
434-
const match = logOutput.match(/.* open style file ([^ ]+).*/);
435-
436-
if (match) {
437-
const file = match[1];
434+
if (logOutput.match(/ open style file /)) {
438435
if (
439436
await findAndInstallPackages(
440437
pkgMgr,
441-
file,
438+
log,
442439
response.result.stderr,
443440
quiet,
444441
)

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,22 @@ unitTest("Detect missing files with `findMissingFontsAndPackages`", async () =>
8383
})
8484

8585
// deno-lint-ignore require-await
86+
// https://github.com/quarto-dev/quarto-cli/issues/15376
87+
unitTest("Detect missing BibTeX style file in the .blg log", async () => {
88+
// bibtex writes the next log line right after the style file name
89+
const blg = `This is BibTeX, Version 0.99e (TeX Live 2026)
90+
The top-level auxiliary file: doc.aux
91+
I couldn't open style file agsm.bst
92+
---line 7 of file doc.aux
93+
: \\bibstyle{agsm
94+
: }
95+
I'm skipping whatever remains of this command
96+
I found no style file---while reading file doc.aux
97+
(There were 2 error messages)
98+
`;
99+
assertEquals(findMissingFontsAndPackages(blg, "."), ["agsm.bst"]);
100+
});
101+
86102
unitTest("Detect luaotfload font fallback crash and surface an actionable hint", async () => {
87103
// The luaotfload font-fallback resolver crashes on recent TeX Live when a
88104
// fallback font is set (mainfontfallback/monofontfallback): define_font of the

0 commit comments

Comments
 (0)