【问题标题】:How to insert LaTeX math expressions in the comments of R chunks in Sweave?如何在 Sweave 的 R 块的注释中插入 LaTeX 数学表达式?
【发布时间】:2017-09-23 05:53:07
【问题描述】:

以下代码用于Sweave/Latex beamer:

\begin{frame}[fragile]
\frametitle{Function Basics}
\begin{block}{Elementary Functions}
<<>>=
pi       # \texttt{pi} is a predefined const.
sin(pi)  # \texttt{sin(pi)}$\neq$0, due to computing error.
sinpi(1) # Instead, we use \texttt{sinpi(x=1)} to get around.
exp(1)
log(10)
@
\end{block}
\end{frame}

我的问题:

上述三个#cmets中,经过Sweave编译后,\texttt{}、$\neq$仍然存在。 Sweave 无法识别 R 块中的 Latex 代码。

另一方面,Latex 似乎也无法识别 R 块中的任何代码(R 或 Latex)。

那么,在这种情况下,如何以 Latex 数学格式显示 \texttt{}、$\neq$?提前谢谢!

【问题讨论】:

  • Tex stackexchange 管理员说这似乎是一个纯粹的问题。建议发到R论坛。

标签: r latex sweave


【解决方案1】:

这是预期的行为。我会建议一个解决方法:

\begin{frame}
\begin{tabular}{ll}
  > pi&\# \texttt{pi} is a predefined const.\\
  \Sexpr{pi}&\\
  > sin(pi)&\# \texttt{sin(pi)}$\neq$0, due to computing error.\\
  \Sexpr{sin(pi)}&\\
  > sinpi(1)&\# Instead, we use \texttt{sinpi(x=1)} to get around.\\
  \Sexpr{sinpi(1)}&\\
\end{tabular}
\end{frame}

产量

【讨论】:

  • 非常感谢!使用 {tabular} 和 \Sexpr{} 是非常好的策略!
猜你喜欢
  • 2018-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-20
  • 2023-03-25
  • 2018-12-08
相关资源
最近更新 更多