title: How to convert Rmarkdown file to working latex file
body: <p>I have written a manuscript I would like to submit to a journal in Rmarkdown. The journal accepts word and latex files, so I am looking for a way to generate a working <code>.tex</code> file out of my <code>.Rmd</code> file.</p>
  <p>I have read some posts that allude to this being possible (e.g., <a href="https://stackoverflow.com/questions/42876148/how-to-generate-latex-file-without-preamble-in-r-markdown">How to generate LaTeX file without preamble in R markdown?</a>) and this is getting me some of the way, but I am still having problems.</p>
  <p>For example, using the method mentioned in the post above, I can convert a test <code>.Rmd</code> into something with a <code>.tex</code> filetype. This is the test Rmarkdown (just the usual template for new files):</p>
  <pre><code>---
  title: &quot;Test document&quot;
  author: &quot;Me&quot;
  date: &quot;23 7 2020&quot;
  output: pdf_document
  ---
  
  ```{r setup, include=FALSE}
  knitr::opts_chunk$set(echo = TRUE)
  ```
  
  ## R Markdown
  
  This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see &lt;http://rmarkdown.rstudio.com&gt;.
  
  When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
  
  ```{r cars}
  summary(cars)
  ```
  
  ## Including Plots
  
  You can also embed plots, for example:
  
  ```{r pressure, echo=FALSE}
  plot(pressure)
  ```
  
  Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
  </code></pre>
  <p>This compiles fine to PDF as it should. Then, in the console I run:</p>
  <pre><code>knitr::knit(&quot;test.Rmd&quot;)
  </code></pre>
  <p>to get a markdown file <code>test.md</code> in my working directory, and then I can apparently convert this <code>.md</code> file to <code>.tex</code> with</p>
  <pre><code>rmarkdown::pandoc_convert(&quot;test.md&quot;, to = &quot;latex&quot;, output = &quot;test.tex&quot;)
  </code></pre>
  <p>This produces a <code>.tex</code> file that, when I double click on it, pops up a PDF view of the file that looks fine. Taking a look at the file though, it is incomplete or at least unfamiliar to me:</p>
  <pre><code>\hypertarget{r-markdown}{%
  \subsection{R Markdown}\label{r-markdown}}
  
  This is an R Markdown document. Markdown is a simple formatting syntax
  for authoring HTML, PDF, and MS Word documents. For more details on
  using R Markdown see \url{http://rmarkdown.rstudio.com}.
  
  When you click the \textbf{Knit} button a document will be generated
  that includes both content as well as the output of any embedded R code
  chunks within the document. You can embed an R code chunk like this:
  
  \begin{Shaded}
  \begin{Highlighting}[]
  \KeywordTok{summary}\NormalTok{(cars)}
  \end{Highlighting}
  \end{Shaded}
  
  \begin{verbatim}
  ##      speed           dist       
  ##  Min.   : 4.0   Min.   :  2.00  
  ##  1st Qu.:12.0   1st Qu.: 26.00  
  ##  Median :15.0   Median : 36.00  
  ##  Mean   :15.4   Mean   : 42.98  
  ##  3rd Qu.:19.0   3rd Qu.: 56.00  
  ##  Max.   :25.0   Max.   :120.00
  \end{verbatim}
  
  \hypertarget{including-plots}{%
  \subsection{Including Plots}\label{including-plots}}
  
  You can also embed plots, for example:
  
  \begin{figure}
  \centering
  \includegraphics{figure/pressure-1.png}
  \caption{plot of chunk pressure}
  \end{figure}
  
  Note that the \texttt{echo\ =\ FALSE} parameter was added to the code
  chunk to prevent printing of the R code that generated the plot.
  </code></pre>
  <p>As far as I can tell, it is missing the preamble, <code>\begin{document}</code>, <code>\end{document}</code>, and I have no idea what is going on with <code>hypertarget</code> bit of the section headers. Unsurprisingly, it does not &quot;re-compile&quot; when I hit run in MiKTeX. The <code>verbatim</code> bits for the code chunks look to be what I'm after, though.</p>
  <p>So, is there a way to generate a <code>.tex</code> file that compiles out of an <code>.Rmd</code> file? Or will I have to manually write the preamble and all that? If the answer to my problem is &quot;read up pandoc&quot;, then fair enough, I will have to bite the bullet and finally have a look at it. But I find it hard to imagine that there is no good (easy) way to prepare submittable manuscripts in Rmarkdown.</p>