Closed crsh closed 5 years ago
Hi, sorry to bother again. In case this is not intended behavior, I'd be willing to contribute a pull request to fix this. Any pointers as to where this could originate would be appreciated.
This is actually an issue upstream in pandoc
- see https://github.com/jgm/pandoc/issues/3139 and links from there. In short, in_header
(which is transformed into command line option) overwrites YAML's header-includes
, since command line options have 'higher precedence' (since they provide a way to overwrite YAML metadata), but the discussion is ongoing...
One other observation: if you include extra_dependencies
in the pdf_document
call, then inline R code in the header-includes:
field is not executed. For example, this works:
---
output:
pdf_document:
keep_tex: true
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- '`r paste0("\\fancyhead[CO,CE]{", params$figureno, "}")`'
params:
figureno: "Fig. 1-1"
---
but this doesn't:
---
output:
pdf_document:
keep_tex: true
extra_dependencies: fancyhdr
header-includes:
- \pagestyle{fancy}
- '`r paste0("\\fancyhead[CO,CE]{", params$figureno, "}")`'
params:
figureno: "Fig. 1-1"
---
If you look at the generated .tex
file in the second one, you can see that the R code was never executed, and the literal string including it was inserted into the header.
Problem still exists in pandoc-2.7. My document which has a template and an includes statement:
output:
pdf_document:
citation_package: natbib
fig_caption: true
highlight: haddock
keep_tex: true
latex_engine: pdflatex
pandoc_args: [--listings]
template: "theme/report-template.tex"
includes:
in_header: "theme/guidePreambleKnitr.tex"
was failing to run the "header-includes: " section. I solve problem in short term by following your fix to add an extra_dependencies flag.
This is a bad bug for me and I was having a hard time figuring it out until I found this post. Thanks very much to the original poster. I've grown frustrated with relying on pandoc because of problems like this.
As @mnazarov pointed out, this was by design of Pandoc. I agree it is confusing, so I just pushed a fix to always include the code from the header-includes
field in the LaTeX preamble. Thanks for the report!
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.
Hi,
I've noticed some unexpected interplay between the different methods of customizing the document preamble in PDF documents.
header-includes
andincludes: in_header
both work individually, but when I use bothheader-includes
appears to be ignored:preamble.tex
could for example simply containHowever, once I include the additional
extra_dependencies
everything is included.Is this intended behavior? To me it would be useful and less confusing if these three approaches could be used independently of one another.