Royun Royun - 5 months ago 29
LaTeX Question

How to insert LaTeX math expressions in the comments of R chunks in Sweave?

The following codes are for the Sweave/Latex beamer´╝Ü

\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.

My question:

in the above three # comments, after Sweave compiling, \texttt{}, $\neq$ still exist. Sweave does not recognize Latex code in the R chunk.

On the other hand, it seems that Latex does not identify any codes (R or Latex) in the R chunk as well.

So, how to show \texttt{}, $\neq$ in Latex math format in this circumstance? Thank you in advance!

Answer Source

This is expected behaviour. I would suggest a workaround:

  > 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.\\


enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download