title: Accessing YAML parameters as macros within external LaTeX files
body: <p>I'm looking for ways to add variables (or LaTeX macros) to the YAML header or soon after such that they can be used in external <code>.tex</code> files that are a part of my (modularised) report.</p>
  
  <p><strong>My <code>.rmd</code> file</strong></p>
  
  <pre><code>---
  output:
    pdf_document:
      latex_engine: xelatex
      includes:
        before_body: some.tex
  params:
    cat: "Felix"
    numb: 14
  ---
  
  # chapter
  Oh my \textbf{`r params$cat`}. 
  $x = `r 2*params$numb`^2$
  
  &lt;!-- Trying again to get the parameter --&gt;
  \input{some.tex}
  </code></pre>
  
  <p><strong>My <code>some.tex</code> file:</strong></p>
  
  <pre><code>`r params\$cat`
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <p><a href="https://i.stack.imgur.com/j72Y3.png" rel="noreferrer"><img src="https://i.stack.imgur.com/j72Y3.png" alt="enter image description here"></a></p>
  
  <p><strong>Hoped-for output</strong></p>
  
  <p>I want to be able to somehow pass the variables from the YAML header (or even just below it) to be used by LaTeX so that all important and regularly updated parameters can be viewed and changed in one place.</p>