Convert Markdown files into PDF via LaTeX using Pandoc

| category RStudy  | tag LaTeX  kintr 

1. R Markdown

R Markdown “is a format that enables easy authoring of reproducible web reports from R. It combines the core syntax of Markdown (an easy-to-write plain text format for web content) with embedded R code chunks that are run so their output can be included in the final document.”

2. Using R Markdown with RStudio

RStudio IDE is a powerful and productive user interface for R. An overview of how to use R Markdown within RStudio is available here

3. Convert R Markdown to Markdown

knitr can convert R Markdown (.Rmd) files into plain markdown (.md) files. With Rstudio, you only need to click the ‘Knit HTML’ button.

You can also use the following command:


4. Convert Markdown files into PDF via LaTeX using Pandoc

4.1 Install Pandoc and MiKTeX

We need to install the following tools first.

Pandoc can convert files from one markup format into another, see the webpage for more details.

MiKTeX is an up-to-date implementation of TeX/LaTeX and related programs for Windows.

4.2 Convert Markdown files into PDF

pandoc -o test.pdf

Run Pandoc from Rstudio directly:

system("pandoc -o test.pdf")

Note: you may need to add the path of ‘pandoc’ to your Environment Variables. How?

4.3 When Markdown files include Chinese

Run Pandoc from Rstudio directly:

system("pandoc -o test.pdf  --latex-engine=xelatex --template=pm-template-felix.latex")

Note: MiKTeX need to install several packages when you run this command at the first time, this may need several minutes.

Note: You need to put pm-template-felix.latex under the same dir with .md files. ‘pm-template-felix.latex’ is a revised version of pm-template.latex

Note: 该模板默认字体为宋体(SimSun),若需要其他字体只需替换SimSun即可。更多字体

Previous     Next