# R Markdown, Pandoc, MikTex

#1

Hi

I recently upgraded my (Windows) version of RStudio and R, and installed miktex and pandoc for html/pdf file conversion as I understood this was the right thing to do. My standard r scripts still work fine, but now markdown will only generate Word output. Knitting to html generates a blank window or a 404 error, while knitting to pdf generates the following error:

‘!Latex error: missing \begin {document} error: failed to compile...execution halted’

I'm new to working with R Markdown and I probably misunderstood the relationship between markdown, pandoc and latex. Perhaps I didn't need latex in the first place. I don't want to code in latex (if I'm right in saying that's a different markup language), I just want to write markdown in the .Rmd file and generate html and pdf output.

My IT department have not been able to help, but they are not really familiar with R themselves.

I understand RStudio comes with R markdown and Pandoc built in - is this then everything I need for the workflow I have outlined or are there other system requirements?

I'd be very grateful if anyone could point me in the right direction?

Thanks
Oli

#2

Can you install tinytex and try knitting to PDF again?

If it still doesn't work, please post a sample of your *.Rmd file you're working on and full error message from the terminal

#3

The Installation chapter of R Markdown: the Definitive Guide might be helpful to you:

LaTeX is indeed another type of markup language, but when using R Markdown you don't have to interact with LaTeX directly (unless you want to!). It's just the under-the-hood tool that allows generation of PDF documents — LaTeX's native rendered format is PDF.

The R Markdown technology stack can be a lot to wrap your head around at first. This diagram (from the R Markdown getting started guide) summarizes what's going on:

1. You write a plain text R Markdown file (.Rmd) which combines YAML metadata, Markdown text, and code chunks
2. The knitr package renders that file into pure Markdown (.md). Along the way, it runs all the code chunks and adds their output to the file.
3. The Markdown file is passed to Pandoc, which converts it into any of a long list of output formats (HTML, PDF, Word, etc etc). For PDF output, Pandoc first converts the Markdown file to LaTeX, then lets the LaTeX engine do the PDF rendering.