Stéphane Laurent
Stéphane Laurent

Reputation: 84519

Rmarkdown with pdf output and plain LaTeX code block

How to do a plain code block with rmarkdown when this code block contains some tex code and one wants the pdf output ?

For example, this does not work:

---
title: "Untitled"
output:
  pdf_document:
    keep_tex: yes
---

Hello !

```
\begin{verbatim}
This is verbatim text
\end{verbatim}
```

This generated this error: ! LaTeX Error: \begin{document} ended by \end{verbatim}.

Of course, I can do:

```{r, eval=FALSE}
\begin{verbatim}
This is verbatim text
\end{verbatim}
```

But the problem when doing that, is that the code block in the output can be highlighted by the R highlighting colors (not for the example above, but this could occur in some cases).

Upvotes: 2

Views: 3513

Answers (1)

scoa
scoa

Reputation: 19867

You could use pandoc's verbatim fenced code block syntax:

~~~latex
\begin{verbatim}
This is verbatim text
\end{verbatim}
~~~

Or also:

```latex
\begin{verbatim}
This is verbatim text
\end{verbatim}
```

Upvotes: 3

Related Questions