Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interplay of header-includes, extra_dependencies, and in_header in pdf_document() #1359

Closed
crsh opened this issue May 28, 2018 · 6 comments
Closed

Comments

@crsh
Copy link
Contributor

crsh commented May 28, 2018

Hi,

I've noticed some unexpected interplay between the different methods of customizing the document preamble in PDF documents. header-includes and includes: in_header both work individually, but when I use both header-includes appears to be ignored:

---
title: "Untitled"
output: 
  pdf_document:
    keep_tex: true
    includes:
      in_header: preamble.tex

header-includes:
  - \usepackage{booktabs}
---

preamble.tex could for example simply contain

\usepackage{tabulary}

However, once I include the additional extra_dependencies everything is included.

---
title: "Untitled"
output: 
  pdf_document:
    keep_tex: true
    extra_dependencies:
      - tabularx
    includes:
      in_header: preamble.tex

header-includes:
  - \usepackage{booktabs}
---

Is this intended behavior? To me it would be useful and less confusing if these three approaches could be used independently of one another.

@crsh
Copy link
Contributor Author

crsh commented Jun 12, 2018

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.

@rich-iannone rich-iannone added bug an unexpected problem or unintended behavior Difficulty: Intermediate labels Jun 19, 2018
@rich-iannone rich-iannone removed the bug an unexpected problem or unintended behavior label Jul 17, 2018
@mnazarov
Copy link
Contributor

mnazarov commented Dec 3, 2018

This is actually an issue upstream in pandoc - see jgm/pandoc#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...

@dmurdoch
Copy link

dmurdoch commented Feb 18, 2019

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.

@pauljohn32
Copy link

pauljohn32 commented Oct 4, 2019

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.

@yihui yihui closed this as completed in 5499ec6 Nov 26, 2019
@yihui
Copy link
Member

yihui commented Nov 26, 2019

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!

@github-actions
Copy link

github-actions bot commented Nov 3, 2020

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants