Do YAML parameters get passed to includes tex files?

Hi,

If you define some YAML parameters, such as:

---
output: pdf_document
title: "This is my title"
---

The title text gets passed to the $title$ variable in the TeX template.

So if I am writing additional TeX to include when rendering my document, there are a couple options. You can write TeX that should be in the header (in_header), before the body (before_body), or after the body (after_body).

I am wondering if the YAML parameters are also passed to the additional TeX files. Currently, it doesn't seem that they do. For example, I have a preamble.tex file containing the following code:

% add a header
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\rhead{$title$}

And my R Markdown looks like:

---
title: "My amazing title"
output:
  pdf_document:
    includes:
      in_header: preamble.tex
---

The rendered PDF has a header line, but the right-aligned text is literally title, not the actual title defined in the YAML meta-data.

1 Like

Yes. You can set that up. Travis Gerke describes how in the post below (and there'd be a heckuva a lot of copying and pasting were I to include the entire section), but it starts with

Here’s a bonus I learned along the way. You can send custom arguments to your .tex doc by simply defining new variables in the YAML header (relevant info in the pandoc docs here).

I'm not very LaTeX experienced, but I believe you have to setup the option to do this in your TeX template.

1 Like

Hi @mara

Thanks for the response! I did actually read Travis' post when you shared it on Twitter the other day. It was a good read.

I'm actually pretty comfortable defining custom YAML parameters in a R Markdown file and passing them to the TeX template. I used this approach to adapt my university's TeX template for writing my dissertation.

However, what I seem to be stuck on is whether those same YAML parameters get passed to the "other" TeX files that may be part of the rendering process. The YAML parameters definitely get passed to the TeX template, but it seems like they may not get used by in_header TeX files (and also by before_body and after_body); or I'm just doing something wrong.

Using the example YAML below, the parameters definitely get passed to the template.tex file, but perhaps not to the other *.tex files that eventually get combined with the template file to form the complete file TeX, which then is rendered to PDF by pandoc.

---
output:
  pdf_document:
    template: template.tex
    includes:
      in_header: preamble.tex
      before_body: before.tex
---
2 Likes

Oh! OK. I understand what you're saying, and, unfortunately, I don't know the answer. If you're on Twitter, you might try to ping Travis, as I'm guessing he might know!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.