Open LuckeyBertl28 opened 4 months ago
Unfortunately, I think we cannot support the listings: true
option in crossreferenceable Quarto listings (those that have ids lst-*
). Specifically, the issue is that Quarto uses its own float environment and crossref counters. listings: true
is a pandoc option that enables the listings
LaTeX package. However, the listings
documentation doesn't seem to show any way to change which float environment is used by listings
, nor does it seem to support sublistings.
I've noticed that the error doesn't seem to be associated with the listings: true
option, as a different error occurs when listings: false
is set.
To elaborate, when I include the following include-in-header
in the configuration:
format:
pdf:
listings: true
include-in-header:
- text: |
\newenvironment{codelisting}{\begin{figure}}{\end{figure}}
the document renders correctly. The listings are captioned as Figure because that’s how I’ve defined them. However, I propose replacing the figure
environment in the code snippet above with the environment that Quarto typically uses for listings.
In the generated TeX file sublistings_issue.tex.txt, you’ll notice that the listings are encapsulated within the codelisting
environment (see lines 150, 184). This issue isn’t related to the listings
package since the codelisting
environment isn’t predefined, leading to the error. Once I manually define the environment, the rendering works as intended. However, I’m unsure how to configure the codelisting
environment to match the one Quarto typically utilizes for listings.
However, I propose replacing the figure environment in the code snippet above with the environment that Quarto typically uses for listings.
That won't work. We already use a float environment defined by newfloat
, using the float
package. The bug here is that it seems that the float
package simply doesn't support subfloats (in the way expected by \subcaption
). Replacing codelisting
with figure
works because figure
is defined by a different environment that does support subfloat counters for \subcaption
.
Unfortunately, there isn't much we can do here in the short term.
Bug description
Issue: Sublistings Failing to Render in PDF Output
When attempting to render a Quarto document to PDF, sublistings are not being supported. The error varies depending on whether the
listings
option is enabled or disabled.I have expected to work the same way as figures.
It works as expected for the HTML output.
Possible Solution
When
listings: true
: Define thecodelisting
environment within the LaTeX preamble to mimic the behavior of figures, allowing for the inclusion of captions and references for code listings.When
listings: false
: Add initialization of the `subcodelisting' counter to the default TeX template/preamble.Additional Notes
The expected functionality was assumed to be analogous to that of figures within the document. However, due to my limited knowledge in Quarto, LaTeX, and Lua, I am not able to provide a more comprehensive solution.
Steps to reproduce
Foo :::
::: {#lst-bar}
Bar :::
::::
Referencing listing group @lst-multiple-listings.
Referencing sublistings @lst-foo, @lst-bar.
When
listings: false
sublistings_issue_listings_false.log
Rendering to HTML
Rendering to HTML works without errors, output looks as expected.
Your environment
Quarto check output