title: How to use LaTeX Code in R Chunk in R-Markdown?
body: <p>I am currently writing on a report with rmarkdown and therefore I want to create sections inside a r code chunk. I figured out that this is possible with the help of cat() and results="asis". My problem with this solution is, that my R code results and code isn't properly displayed as usual.</p>
  
  <p>For example</p>
  
  <pre><code>---
  title: "test"
  output: pdf_document
  ---
  
  ```{r, results='asis'}
  for (i in 1:10) {
    cat("\\section{Part:", i, "}")
    summary(X)
    $\alpha = `r X[1,i]`$  
  }
  ```
  </code></pre>
  
  <p>pretty much does the trick, but here there are still two problems:</p>
  
  <ul>
  <li>the R output for summary() is displayed very strange because I guess it`s interpreted as LaTeX code</li>
  <li>I can't use LaTeX formulas in this enviroment, so if I want every section to end with a equation, which also might use a R variable, this is not possible</li>
  </ul>
  
  <p>Does somebody know a solution for some of these problems, or is there even a workaround to create sections within a loop and to have R code, R output and LaTeX formulas in this section? Or maybe at least one of those things?</p>
  
  <p>I am very thankful for every kind of advice</p>