Skip to content

Cite Method: biblatex cannot handle underscores in filename of .bib file #10027

Open

Description

@Mavoort

Bug description

If you write an article that contains citations and use the biblatex engine instead of the default one (citeproc), Quarto cannot handle underscores in the filename of the .bib file.

Steps to reproduce

Content of documend.qmd:

---
format:
  pdf:
    cite-method: biblatex
    keep-latex: true
bibliography: quarto_references.bib
---

Quarto [@Allaire_Quarto_2024] is really awesome!

Content of quarto_references.bib:

@software{Allaire_Quarto_2024,
        author = {Allaire, J.J. and Teague, Charles and Scheidegger, Carlos and Xie, Yihui and Dervieux, Christophe},
        doi = {10.5281/zenodo.5960048},
        month = feb,
        title = {{Quarto}},
        url = {https://github.com/quarto-dev/quarto-cli},
        version = {1.4},
        year = {2024}
}

Expected behavior

Quarto should render the document to a pdf-file and use biber to create correct citations:

2024-06-15-173450_1501x356_scrot

Actual behavior

Quarto apparently runs biber on quarto\_references.bib (notice the backslash), which doesn't exist. This causes biber to fail with an error message:

generating bibliography
  INFO - This is Biber 2.19
  INFO - Logfile is 'document.blg'
  INFO - Reading 'document.bcf'
  INFO - Found 1 citekeys in bib section 0
  INFO - Processing section 0
  INFO - Looking for bibtex file 'quarto\_references.bib' for section 0
  ERROR - Cannot find 'quarto\_references.bib'!
  INFO - ERRORS: 1

Your environment

  • OS: Ubuntu 23.10 mantic

Quarto check output

Quarto 1.4.554
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.11: OK
      Dart Sass version 1.69.5: OK
      Deno version 1.37.2: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.4.554
      Path: /opt/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: (not installed)
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: Installation From Path
      Path: /usr/bin
      Version: 2023

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.11.6
      Path: /usr/bin/python3
      Jupyter: 5.3.1
      Kernels: julia-1.10, python3, sagemath

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........OK
      Version: 4.3.1
      Path: /usr/lib/R
      LibPaths:
        - /home/marcel/R/x86_64-pc-linux-gnu-library/4.3
        - /usr/local/lib/R/site-library
        - /usr/lib/R/site-library
        - /usr/lib/R/library
      knitr: 1.43
      rmarkdown: 2.23

[✓] Checking Knitr engine render......OK

Activity

  1. added
    bug
    on Jun 15, 2024
  2. Mavoort commented on Jun 15, 2024

    @Mavoort
    Author

    If you look at the generated LaTeX-file document.tex, the problem is in line 127:

    126 \usepackage[]{biblatex}
    127 \addbibresource{quarto\_references.bib}

    If you remove the underscore there and then run xelatex+biber+xelatex again

    xelatex --interaction=nonstopmode document.tex
    biber document

    everything works fine.

  3. mcanouil commented on Jun 15, 2024

    @mcanouil
    Collaborator

    That's a LaTeX limitation I'm afraid. LaTeX "does not like" underscores and needs to escape them which in some situations leads to crash or weird side effects.
    I'm not sure there is anything that can be done here.

    Note that keep-latex does not exist, the correct option is keep-tex.

  4. Mavoort commented on Jun 16, 2024

    @Mavoort
    Author

    Hm, the option keep-latex works fine for me.

    Thanks for you answer.
    However, I still think this has nothing to do with LaTeX.

    LaTeX "doesn't like" underscores because it uses them to typeset subscript: H_2 O --> H₂O . That's why Quarto has to escape them in normal text, meaning it converts text with _ underscore in the .qmd file to text with \_ underscore in the generated LaTeX file.

    But there are exceptions to this, which are filenames. For example, Quarto converts

    ![description](image_with_underscore.png)

    to

    \includegraphics{image_with_underscore.png}

    in the generated .tex file (notice: no backslashes). Otherwise, it would not be possible to include images with an underscore in the filename. The same is true for hyperlinks with \href.

    This means Quarto must have an internal filter somewhere: Escape all underscores with a backslash, except in filenames of hyperlinks and images.

    What I am suggesting is to add bibtex files to that exception. That way, everything would work. You can see this the following way:

    1. run quarto render document.qmd --> generates a LaTeX-file, document.tex
    2. edit document.tex manually to remove the backslash at
    \addbibresource{quarto\_references.bib}
    1. run XeLaTeX: xelatex --interaction=nonstopmode document.tex
    2. run biber: biber document
    3. run XeLaTeX again

    This works without problems, generating a pdf-file with the desired citations. There are no error messages in XeLaTeX or biber. For this reason I think the problem lies with Quarto and not with LaTeX.

  5. mcanouil commented on Jun 16, 2024

    @mcanouil
    Collaborator

    Hm, the option keep-latex works fine for me.

    Try with a document that does not crash.
    It can't work because that option does not exist in the codebase.


    The issue is Pandoc. Quarto does not handle citations, Pandoc does.

    quarto pandoc -s --bibliography=refer_ences.bib --biblatex -o index.tex index.md
    

    Will lead to \addbibresource{refer\_ences.bib}.

    It's a problem with LaTeX not handling _ everywhere the same way. In some places, they need to be escaped and in others, they don't. Here Pandoc escaped it while it should not.

    This needs to be reported upstream (https://github.com/jgm/pandoc).

    FYI, I did not see a report for bibliography file but another one for another part:

  6. added
    upstream
    latex
    on Jun 16, 2024
  7. Mavoort commented on Jun 16, 2024

    @Mavoort
    Author

    I think you're right. I did not consider that the problem might be with Pandoc. I'll open an issue there.

  8. cderv commented on Jun 17, 2024

    @cderv
    Member

    Related discussion

    and historically Pandoc has this issue reported, but it seems it was not a Pandoc issue directly 🤔

    It is possible they missed something and that \addbibresource does not allow escaped underscore, which is what Pandoc templating system is adding.

  9. njbart commented on Jun 22, 2024

    @njbart

    bibliography: '`quarto_references.bib`{=latex}' (i.e., specifying that the string is raw latex, based on a suggestion made in jgm/pandoc#9262 (comment)) seems to work for the example given in the OP.

  10. cderv commented on Jun 24, 2024

    @cderv
    Member

    That is a good solution !

    • bibliography is not a format specific field
    • The underscore in bibliography is really a LaTeX with biblatex problem.

    So I would say solutions should be

    • Don't use underscore in bibliography filename
    • Or escape using raw LaTeX as you shared !

    Thanks

  11. added this to the Future milestone on Jun 24, 2024
  12. julesbouton commented on Oct 19, 2025

    @julesbouton

    Hi,
    I might be wrong, but it seems that this issue has been solved upstream in pandoc 3.8.1:

    jgm/pandoc#11152

    I'm not a user of quarto, but of Zettlr, which had the same problem, and underscores are not escaped anymore in bibliography paths since I updated pandoc to 3.8.2 (latest).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bibliographybuglatexpandocupstream

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions