Knitr emits special latex characters (e.g. ~, $) in R code

LaTeX crashes when I run it on the output of this knitr document, because LaTeX special characters are not properly escaped. Any clues on how to fix this?

\documentclass{beamer} \begin{document} \begin{frame}{Unescaped dollar signs and tildes} In this example, neither the tilde nor the dollar sign will appear in the pdf document, and the dollar sign will cause a \LaTeX error. <<xtable, results="asis">>= n <- 100 x <- rnorm(n) y <- 2*x + rnorm(n) out <- lm(y ~ x) library(xtable) xtable(summary(out)$coef, digits=c(0, 2, 2, 1, 2)) @ \end{frame} \end{document} 
+5
source share
1 answer

You need to add the [fragile] option if your frame contains a piece of the outfit with special latex characters:

 \begin{frame}[fragile] 

Source: knitr user webpage .

+3
source

Source: https://habr.com/ru/post/1202398/


All Articles