R代码中的Knitr转义乳胶特殊字符(例如〜,$) [英] Knitr escape latex special characters (e.g., ~, $) in R code
本文介绍了R代码中的Knitr转义乳胶特殊字符(例如〜,$)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在此knitr文档的输出上运行LaTeX时会崩溃,因为LaTeX特殊字符未正确转义.任何提示如何解决此问题?
LaTeX crashes when I run it on the output of this knitr document because the LaTeX special characters aren't properly escaped. Any hints 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}
推荐答案
如果您的框架包含带有特殊乳胶字符的编织块,则需要添加[fragile]
选项:
You need to add [fragile]
option if your frame contains a knitr chunk with special latex characters:
\begin{frame}[fragile]
来源:编织器网页.
这篇关于R代码中的Knitr转义乳胶特殊字符(例如〜,$)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文