quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.55k stars 293 forks source link

Lua filter not applied to bibliography in HTML output for multi-page books #10180

Open TomBener opened 4 days ago

TomBener commented 4 days ago

Bug description

When rendering a Quarto book project to HTML, I've encountered an issue where a Lua filter (citation-backlinks.lua) is not applied to the bibliography if the bibliography is rendered in a separate references.qmd file as follows:

# References {.unnumbered}

::: {#refs}
:::

This behavior is observed when the project includes a references.qmd file, which moves the bibliography list from the index.html to references.html. The Lua filter is intended to add citation backlinks to the bibliography entries.

This issue does not occur when rendering the book to PDF or DOCX formats, which suggests that the problem might be related to how Quarto processes and applies Lua filters in the context of generating multi-page HTML outputs. In PDF and DOCX formats, the output is self-contained, and the Lua filter is applied successfully to the bibliography.

Steps to reproduce

  1. Create a Quarto book project with the following structure in _quarto.yml:
project:
  type: book
  output-dir: _book
book:
  title: Lua Filter Test in Quarto
  chapters:
    - index.qmd
    - references.qmd
bibliography: bib.bib
csl: gb-author-date.csl
format:
  html: default
  docx: default
  pdf: default
  1. Use the command quarto render --to html -L _extensions/citation-backlinks/citation-backlinks.lua to render the project to HTML.
  2. Observe that the Lua filter is not applied to the bibliography in references.html.

You can also view the full demo project here.

Expected behavior

The Lua filter should be applied to the bibliography in all output formats, including when the bibliography is rendered in a separate HTML file (references.html) for multi-page book projects.

Actual behavior

The Lua filter is applied successfully in PDF and DOCX outputs but not in the HTML output when the bibliography is rendered in references.html.

Your environment

Quarto check output

$ quarto check

Quarto 1.5.52
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.2.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.41.0: OK
      Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.5.52
      Path: /Applications/quarto/bin

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

[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /Users/user/Library/TinyTeX/bin/universal-darwin
      Version: 2024

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

[✓] Checking Python 3 installation....OK
      Version: 3.10.10
      Path: /Users/user/.pyenv/versions/3.10.10/bin/python3
      Jupyter: 5.7.2
      Kernels: python3

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

[✓] Checking R installation...........OK
      Version: 4.4.1
      Path: /opt/homebrew/Cellar/r/4.4.1/lib/R
      LibPaths:
        - /Users/user/.R/packages
        - /opt/homebrew/lib/R/4.4/site-library
        - /opt/homebrew/Cellar/r/4.4.1/lib/R/library
      knitr: 1.47
      rmarkdown: 2.27

[✓] Checking Knitr engine render......OK
cderv commented 4 days ago

I did not look in detail, but a reminder that currently settings up Lua filters to run after --citeproc by Pandoc is not possible

Using -L at command for quarto render is a 'hack' for Quarto as the filter is not inserted into the filter chain like with filters: in configuration. It is even probably an oversight that we do not catch this -L at command line to do the right thing for Quarto.

We discussed this already in

and my comment still applies

Using quarto render -L as you did works because in this case the filters is independently added to the list of filters to run. It could work for some filters, but would not for other more tied to Lua API for example. Those need to be in the filter chain.

Probably for HTML books this is required to be in the filter chain.

This type of usage probably needs to wait for #7888 to be solved.

TomBener commented 4 days ago

@cderv Thanks for your response. I also suspect the issue may be related to citeproc, but the weird thing is that it only happens when rendering multi-page HTML, while PDF and DOCX work well. This is the reason why I submitted the issue.

cderv commented 4 days ago

but the weird thing is that it only happens when rendering multi-page HTML, while PDF and DOCX work well.

The chain of processing is different. as you suspect PDF and DOCX are single processed doc, where for HTML book each .qmd is resolved independently and then some processing creates the book websites. So the problem may lie there.

I'll keep this one open and not a full duplicate of #7888 so that we can investigate more