Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command for adding a LaTeX template to pandoc on R

I am trying to use Pandoc to convert a .md file to PDF. In doing this, I would like to add a LaTeX template into it. Is there a way to do this? If so, what is the command for doing it in RStudio?

The command I am currently using is the following

```{r}
pandoc("foo.md", format="latex")
```

Thank you in advance.

like image 623
Pablo O Avatar asked Nov 12 '22 21:11

Pablo O


1 Answers

One way to do it is to use the function system and run pandoc directly, adding a Latex header.

For example:

system("pandoc -f markdown -t latex -o foo.pdf -H template.tex -V papersize:\"a4paper\" -V geometry:\"top=2cm, bottom=3cm, left=2cm, right=2cm\" foo.md ")

-f inicates the origin language, though I mix MarkDown and Latex and it works fine.

-t is the result language, though it really compiles the created latex and what you get is a .pdf document

-o the name of the file you want to create

-H a header to add. There is where you can put your template

-V many variables that you can set. Here I set the paper size and margins

at the end you write the name of your MarkDown file

template.tex is a tex file with the header I want in the Latex document. I use it to add packages, headers and some other parameters. For example:

\usepackage{booktabs}

\usepackage[spanish, es-tabla]{babel}

\usepackage{colortbl}

\usepackage{float}

\usepackage{fancyhdr}

\usepackage[singlelinecheck=false]{caption}

\setlength{\headheight}{40pt}

\pagestyle{fancy}

\lhead{My Title}

\rhead{\includegraphics[height=50pt]{MyGraph.png}}

like image 177
Rufo Avatar answered Nov 15 '22 06:11

Rufo