R代码中的特殊字符(例如,~,$)

R代码中的特殊字符(例如,~,$),r,latex,knitr,beamer,R,Latex,Knitr,Beamer,当我在knitr文档的输出上运行它时,LaTeX崩溃,因为LaTeX特殊字符没有正确转义。有什么提示可以解决这个问题吗 \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 dol

当我在knitr文档的输出上运行它时,LaTeX崩溃,因为LaTeX特殊字符没有正确转义。有什么提示可以解决这个问题吗

\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}
\documentclass{beamer}
\开始{document}
\开始{frame}{Unescaped dollar signs and tildes}
在本例中,瓷砖和美元符号
将显示在pdf文档中,并显示美元符号
将导致\LaTeX错误。
=

n如果您的框架包含带有特殊乳胶字符的knitr块,则需要添加
[fragile]
选项:

\begin{frame}[fragile]
来源: