Skip to content

Infer bib engine from file contents - #19

Merged
yihui merged 4 commits into
rstudio:mainfrom
HughParsonage:infer-biber
Sep 9, 2026
Merged

yihui merged 4 commits into
rstudio:mainfrom
HughParsonage:infer-biber

Conversation

@HughParsonage

Copy link
Copy Markdown
Contributor

Since biber typically uses biblatex, we can infer bibtex/biber by examining the contents of file.

The pull requests adds some tests, notably running install_tinytex. I wasn't sure whether this was appropriate or not.

@CLAassistant

CLAassistant commented Sep 22, 2020

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

yihui and others added 2 commits June 17, 2026 19:45
Single test file means `CI=true Rscript tests/*.R` works directly
without a for loop.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
The `bib_engine` argument of `latexmk()` defaulted to `bibtex`, so the
bibliography of a biblatex + biber document was silently not built (bibtex
requires \bibdata/\bibstyle in the .aux file, which biblatex + biber does not
produce). Users had to manually set `bib_engine = 'biber'`.

Default `bib_engine` to NULL and infer the engine from the auxiliary files
generated during compilation: if a .bcf file exists (produced by biblatex with
the biber backend), use biber; otherwise use bibtex. The explicit argument and
the global option `tinytex.bib_engine` still take precedence.

This reworks rstudio#19 to infer from the generated aux files rather than parsing the
.tex source with regexes, which is more robust (handles multi-line
\usepackage, \RequirePackage, etc.).

Co-authored-by: HughParsonage <hugh.parsonage@gmail.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yihui

yihui commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this, @HughParsonage — the core idea (stop defaulting to bibtex so biblatex+biber docs get their bibliography built) is a good one, and it's still a real gap today.

I've rebased the PR onto current main and reworked the implementation. Summary of what changed from the original:

  • Inference source. The original parsed the .tex source with regexes (\addbibresource, backend=bibtex, …). That's fragile — it misses multi-line \usepackage, \RequirePackage, \ExecuteBibliographyOptions, etc. Instead I infer from the generated aux files: biblatex+biber emits a .bcf, so bib_engine defaults to biber when <base>.bcf exists after the LaTeX run, and bibtex otherwise. Detection happens after the engine has already run, so no source parsing is needed.
  • Default. bib_engine now defaults to NULL (inferred). An explicit argument and the global option tinytex.bib_engine still take precedence.
  • Tests. Kept a focused test (tests/test-ci/) that compiles a biblatex+biber document and checks the bibliography is actually built. Dropped the install_tinytex() call and the binary-PDF / pdftotext comparison from the original, since those are brittle in CI.
  • Doc + NEWS updated.

Let me know if you'd rather keep the source-parsing approach for any case I've missed.

@HughParsonage

Copy link
Copy Markdown
Contributor Author

No I think your approach is better. Happy to help!

@yihui
yihui merged commit ccf2c89 into rstudio:main Sep 9, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants