pandoc-crossref
pandoc-crossref copied to clipboard
LaTeX Error: Environment pandoccrossrefsubfigures undefined
I'm trying to render a Markdown document as PDF using pandoc. It includes subfigures and cross-references. When producing the PDF, I get this error message:
! LaTeX Error: Environment pandoccrossrefsubfigures undefined.
Is there any way to avoid this error?
In the meantime, I found a temporary solution that consists on creating a new, known environment to replace the missing one:
\newenvironment{pandoccrossrefsubfigures}
{
\begin{figure}
}
{
\end{figure}
}
I hope this is helpful.
I'm using macOS Catalina 10.15.7, pandoc 2.14.1, and pandoc-crossref. I've installed both using homebrew. As a result, pandoc version is 2.14.1, although pandoc-crossref was compiled with pandoc 2.14.0.2. As a result, I get this warning every time I render my documents:
WARNING: pandoc-crossref was compiled with pandoc 2.14.0.2 but is being run through 2.14.1. This is not supported. Strange things may (and likely will) happen silently.
Is there any way to avoid this error?
Pretty sure this is explained in the manual under caveats. Tl;dr is pandoc-crossref uses header-includes to inject some LaTeX commands. If your custom pandoc template doesn't use header-includes, it won't work.
Add
$for(header-includes)$
$header-includes$
$endfor$
into the preamble in the template. Or see https://github.com/lierdakil/pandoc-crossref/blob/master/lib-internal/Text/Pandoc/CrossRef/Util/ModifyMeta.hs for what exactly is injected and when and replicate that.
As a result, I get this warning every time I render my documents
That is a homebrew issue, they don't rebuild pandoc-crossref when pandoc updates. I don't use or actually have access to macOS, so I don't know much about homebrew. Someone with a working knowledge of how homebrew triggers rebuilds could probably fix this.
Thank you for the response. I haven't been able to successfully include:
$for(header-includes)$
$header-includes$
$endfor$
in the template's preamble, but I will keep trying. In the meantime, I will try to replicate what I need from the HS file you provided.
I stumbled upon the link in the manual you include, but I didn't understand it.
Thanks again.
Hold on. Sorry, apparently I misread the issue report. Your input format is Markdown? What command are you using to convert to PDF?
It's something like this:
pandoc \
--standalone \
--metadata-file metadata.yaml \
--filter pandoc-crossref \
--citeproc \
--number-sections \
--include-in-header header.tex \
--output output.pdf \
format.yaml \
input.md
Ah. So the issue is --include-in-header, not a custom template. The simplest options are either move header.tex into metadata.yaml (as header-includes), or actually use a custom template based on the default one (see https://pandoc.org/MANUAL.html#templates). Either way, it avoids --include-in-header option.
Or, if you prefer to keep --include-in-header for some reason, make a file latex.template with contents
$for(header-includes)$
$header-includes$
$endfor$
and run
echo | pandoc --metadata-file metadata.yaml -F pandoc-crossref --template latex.template -t latex -s
to dump whatever pandoc-crossref intends to add to the header (this will depend on some settings in metadata.yaml as you might expect). You can add this output to header.tex.
Thanks so much for the information. For now I will try the second alternative, dumping the directives pandoc-crossref needs into my header.tex. Unfortunately, I'm using more than one --include-in-header directives when rendering the PDF file.