[R] OT: Adding verbatim R code text into LaTeX documents: texttt; verb or url?

Mark Wardle mark at wardle.org
Wed Jan 28 08:46:59 CET 2009


2009/1/28 Peter Dunn <PDunn2 at usc.edu.au>:
> Hi all
>
> I use Sweave extensively to mix R and LaTeX, and often have R code appearing in my LaTeX document.
>
> Just a quick question then: What is the best way to add example of R commands into LaTeX in-line?  (That is, not using Sweave.)  For example, suppose I wish to place in my document this instruction:
> [...] *snip*

Try this:

\usepackage{listings}

\lstset{%
	basicstyle=\scriptsize,
	breaklines=true,
	frame=single,
	literate=
		{<-}{$\leftarrow$}{2}
}

\renewcommand\lstlistlistingname{List of listings}


Have a look at the listings package... You can see I'm making the font
size smaller, giving all code a frame, and converting <- into a proper
left arrow (just for R!)

listings is very capable.

http://www.ctan.org/tex-archive/macros/latex/contrib/listings/
http://www.ctan.org/get/macros/latex/contrib/listings/listings.pdf

bw

Mark
-- 
Dr. Mark Wardle
Specialist registrar, Neurology
Cardiff, UK




More information about the R-help mailing list