[R] Off-Topic: LaTeX package listings

Marc Schwartz MSchwartz at MedAnalytics.com
Mon Oct 4 05:37:32 CEST 2004


On Sun, 2004-10-03 at 21:26, Kjetil Brinchmann Halvorsen wrote:
> Hola!
> 
> I ask here since I learnt from this list that the LaTeX package listings 
> should be good
> for typesetting R code. I encountered one problem:
> \begin{lstlisting}
>       X %*% V
> \end{lstlisting}
> 
> in the output the * in %*% disappears! same with %/%, etc, the /
> disappears.
> 
> Any ideas?
> 
> Kjetil


That's because the "%" is a comment character in LaTeX. Thus, anything
after it will be ignored.

For program code, you generally want to use the 'verbatim' or
'smallverbatim' environment:

\begin{verbatim}
  X %*% V
\end{verbatim}

In the verbatim environment, all characters are treated literally,
rather than interpreted by any special meaning.

Outside of that, say in a regular LaTeX document, you can escape the
"%":

\%

HTH,

Marc Schwartz




More information about the R-help mailing list