LaTeX offers a verbatim environment. \begin{verbatim} This is maintained verbatim, Latex commands and environments are typeset as written without any processing. \end{verbatim}
Be sure to use the package verbatim. ---Joe "Peter Dunn" <pdu...@usc.edu.au> Sent by: r-help-boun...@r-project.org 01/28/2009 01:41 AM To "R Help" <r-help@r-project.org> cc Subject [R] OT: Adding verbatim R code text into LaTeX documents: texttt; verb or url? 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: ...is done in R using the command \verb|lm( y ~ var.one + var.two )| as follows: I used \verb above, but I see three options: \verb, \url (package url), or \texttt; there are probably others. Here are my comments on these three: - Using \texttt is OK, but it disappears my tildes and can hyphenate - Using \verb is good, but it can hyphenate. - Using \url is very good, but it: * disappears my spaces; so for the above example, the spaces added for clarity are gone. * Minor: I like my verbatim text a little smaller (\small size), and change the font size for verbatim using \def\verba...@font{\small\ttfamily} but \url seems to ignore this and appears larger than if I used \text or \verb. Also, using \url often adds line-breaks mid-variable at the dots (for example, splitting var.one to have "var." on one line, and "one" on the next). I'm not sure this is a problem or not; here it is just an observation. Ideally, one would want a LaTeX function, say \rcode{}, that displayed in-text using non-proportional font, kept tildes, kept spacing, uses my verb-font changes, and broke at sensible places for R. (I don't want much, do I?) So two questions: * What do other people do? Maybe there is a solution I have over-looked. * Is there an easy solution? I suppose writing such a command in LaTeX is possible, but there is strong evidence to reject the hypothesis that I would be able to write one. Maybe one of the above choices are easily adopted. If no easy solutions exist or emerge, I'm happy to run with \url. Thanks again. P. Peter Dunn Biostatistician School of Health and Sport Science Faculty of Science, Health and Education University of the Sunshine Coast Tel: +61 7 5456 5085 Fax: +61 7 5430 2896 Email: pdu...@usc.edu.au www.usc.edu.au CRICOS Provider Number: 01595D This communication is intended for the recipient only and should not be forwarded, distributed or otherwise read by others without express permission. The views expressed in this email are not necessarily those of the University of the Sunshine Coast. -- This message has been scanned for viruses and\ dangerous...{{dropped:15}} ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.