Closed maxdrohde closed 10 months ago
Thanks for the report. I'm not sure what you expect Quarto to do here. In general, not every latex package is compatible with other LaTeX package. You probably need to make changes to the template to accommodate your use case.
Thanks @cscheid, it was just surprising to me that the Quarto code block background option for PDFs wasn't compatible with a common LaTeX package. I see your point though -- maybe this is more of an issue with the tcolorbox
package. If there was a way to change the Quarto implementation so that they don't conflict, that would be helpful to me, but I realize that might be challenging. I was just stumped for a while figuring out where the error was coming from.
If there was a way to change the Quarto implementation, that would be helpful so that they don't conflict.
We don't change the Pandoc format templates unless it's absolutely necessary, because the additional confusion from the inconsistency tends to cause more problems than it solves.
I see your point though -- maybe this is more of an issue with the tcolorbox package.
It's likely that this package is not compatible with some other package used in the latex template. I recommend you use keep-tex: true
(or quarto render file.qmd --to latex
), inspect the generated source, and debug it from there. That will tell you how to change the templates as necessary.
Quarto uses the tcolorbox
package to implement code cell shading, so you should be able to just omit the \usepackage{tcolorbox}
in this case...
So the issue is probably that the include means that the packages are included in the wrong order, and that's the error message that LaTeX emits... yikes. 👀 Typst cannot win soon enough!
I believe the issue is because Quarto is loading some packages with options
\@ifpackageloaded{tcolorbox}{}{\usepackage[skins,breakable]{tcolorbox}}
But with ifpackageloaded
, we do that only when package is not already loaded. When \usepackage{tcolorbox}
is used in YAML, it is loaded before our call.
This means options are not added.... but we need them for the background it seems. This leads to the error.
Doing this don't have issue.
include-in-header:
text: |
\usepackage[skins,breakable]{tcolorbox}
If we wanted to be really clean with the option we need, the usual way is to use \PassOptionsToPackages
at the top of the document. This will define some option to set when the package is loaded. We could then load tcolorbox
if not already loaded.
This is explain in https://tex.stackexchange.com/a/124052/209358 a bit, and this is what Pandoc is doing in its template
https://github.com/quarto-dev/quarto-cli/blob/aadb1908193ec91ef48448e3a89eba3efe0bcf20/src/resources/formats/pdf/pandoc/latex.template#L1-L9
Anyhow, another LaTeX weirdness. Not loading a package already loaded in template is usually a good approach.
Bug description
When I import the
tcolorbox
LaTeX package into Quarto, I get an error if I am also using the code block background color YAML argument (code-block-bg
). Please see the minimal example below.Steps to reproduce
Minimal document showing the error
pandoc to: latex output-file: bug_test.tex standalone: true pdf-engine: xelatex variables: graphics: true tables: true default-image-extension: pdf
metadata documentclass: scrartcl classoption:
running xelatex - 1 This is XeTeX, Version 3.141592653-2.6-0.999995 (TeX Live 2023) (preloaded format=xelatex) restricted \write18 enabled. entering extended mode
updating tlmgr
updating existing packages
compilation failed- error Package pgfkeys Error: I do not know the key '/tcb/frame hidden' and I am goi ng to ignore it. Perhaps you misspelled it.
See the pgfkeys package documentation for explanation. Type H for immediate help.
...
l.200 \begin{Shaded}
see bug_test.log for more information.