title: Change Heading Level based on whether knitting to pdf or docx in RMarkdown
body: <p>I have a large project which contains several chapters (or children) which I can knit successfully as a pdf or docx.</p>
  
  <p>Here is the <code>master.Rmd</code> which knits the children <code>chapterOne.Rmd</code></p>
  
  <pre><code>---
  title: Title of My Project
  author: "My Name"
  csl: G:/My Drive/ZoteroRPlugin/styles-master/spectroscopy-letters.csl
  output:
    pdf_document:
      includes:
        in_header: styles/preamble.tex #not relevant to the question
      keep_tex: yes
      latex_engine: xelatex
      number_sections: yes
    word_document:
      fig_caption: yes
      toc: yes
      reference_docx: styles/word-styles-reference_05.docx
  link-citations: yes
  documentclass: styles/thesis-umich3
  bibliography: G:/My Drive/ZoteroRPlugin/Report_references.bib
  ---
  
  ```{r global_options, include=FALSE}
  library(knitr)
  knitr::opts_chunk$set(fig.align='center')
  use_betterbiblatex = TRUE
  ```
  
  \chapter{Introduction}
  &lt;!--# Introduction --&gt;
  ```{r child = 'chapterOne.Rmd'}
  ```
  \pagebreak
  
  \chapter{Literature Review}
  ```{r child = 'chapterTwo.Rmd'}
  ```
  \pagebreak
  </code></pre>
  
  <p>And here is the code for one of the children files <code>chapterOne.Rmd</code>.</p>
  
  <pre><code>---
  output: pdf_document
  ---
  
  ```{r chapter1_options, include=FALSE}
  library(knitr)
  knitr::opts_chunk$set(fig.align='center')
  use_betterbiblatex = TRUE
  ```
  
  ## Level 1 Heading
  
  Insert Text Here
  
  ### Level 2 Heading
  </code></pre>
  
  <p>But in order for the headings to be done correctly I need to increase the heading level when knitting to docx (this is due to the csl file I need to use). Since the command <code>\chapter{Introduction}</code> is not recognized (which is fine).</p>
  
  <p>Here is a screenshot when uploading to <code>docx</code> which gives me the proper headings
  <img src="https://i.imgur.com/Sr2Geco.png" alt="img"></p>
  
  <p>However this causes the <code>pdf</code> to be incorrectly leveled. </p>
  
  <p>I realize that I could <code>Ctrl+H</code> and to a <code>Find/Replace</code> for <code>##</code> to <code>#</code> but this is not optimal to do everytime I have to switch between knitting to pdf vs docx. 
  <img src="https://i.imgur.com/xGRnNEu.png" alt="img"></p>
  
  <p>Does anyone have any ideas on a work-around??</p>