including r code in a latex file
On Mon, 1 May 2000, Faheem Mitha wrote:
Dear R people,
The header practically says it all. I was wanting to include r code in a
Latex file. Since R code using{ and }, which are interpreted by Latex as
control characters, I would expect it to get upset.
While you could use verbatim, as others have suggested, the lgrind
definitions that I posted here the other day has been written with that in
mind to produce nice R-code program listings for inclusion in LaTeX
documents.
lgrind is a pretty standard program, you may find it on you system. I
haven't myself been able to make it work, for some unknown reason, but if
you take the following code:
R:\
:pb=^\d?\p\d<-\dfunction\(\a\):\
:bb={:be=}:cb=\d#:ce=$sb=":se=\e":lb=':le=\e':id=.:\
:zb=@:ze=@:tb=%%:te=%%:mb=%\$:me=\$%:vb=%\|:ve=\|%:\
:kw=while for in repeat if else switch break next\
return stop warning function:
save it to a file you call e.g. ~/tex/lgrindefs
then running
lgrind -i -d ~/tex/lgrindefs mycode.R > mycode.tex
should produce a nice LaTeXed file. I think... You need to include the
lgrind style file in you document, as well as use a macro to include it.
See the lgrind(1) man page for details
Best,
Kjetil
Kjetil Kjernsmo Graduate astronomy-student Problems worthy of attack University of Oslo, Norway Prove their worth by hitting back E-mail: kjetikj at astro.uio.no - Piet Hein Homepage <URL:http://www.astro.uio.no/~kjetikj/> Webmaster at skepsis.no -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._