Re: [R] How to format R code in LaTex documents
I often produce program listings in my LaTeX documents. I use the verbatim environment but use commands such as \addtolength{\oddsidemargin}{-0.95in} \addtolength{\evensidemargin}{-0.95in} to widen the printed page so that I do not have to resort to line continuation characters. This method is simple and you can experiment with values other than 0.95in to find the value most appropriate to you John On 15/01/07, Benjamin Dickgiesser [EMAIL PROTECTED] wrote: Hi, I am planning on putting some R script in an appendix of a LaTex document. Can anyone recommend me a way of how to format it? Is there a way to keep all line breaks without having to insert \\ in every single line? Thank you! Benjamin __ R-help@stat.math.ethz.ch 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. -- John C Frain Trinity College Dublin Dublin 2 Ireland www.tcd.ie/Economics/staff/frainj/home.html mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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.
Re: [R] How to format R code in LaTex documents
At 14:12 15/01/2007, Frank E Harrell Jr wrote: Benjamin Dickgiesser wrote: Hi, I am planning on putting some R script in an appendix of a LaTex document. Can anyone recommend me a way of how to format it? Is there a way to keep all line breaks without having to insert \\ in every single line? Thank you! Benjamin Here's one way and I would appreciate anyone's improvements. I've also included solutions from two others. Please let me know what you decide to use. -Frank Some interesting ideas below so just to add that I find I often have to use the linewidth parameter to avoid lines wrapping. This is valuable if you are also going to include bits of R output as well (you can control the width of your own code fragments of course). \usepackage{listings,relsize} \lstloadlanguages{R} \lstset{language=R,basicstyle=\smaller[2],commentstyle=\rmfamily\smaller, showstringspaces=false,% xleftmargin=4ex,literate={-}{{$\leftarrow$}}1 {~}{{$\sim$}}1} \lstset{escapeinside={(*}{*)}} % for (*\ref{ }*) inside lstlistings (S code) . . . \begin{lstlisting} . . . S code . . . \end{lstlisting} The following code was provided by Vincent Goulet: listings is a great package to highlight R keywords and comments and --- that was my main use of the package --- index those keywords. I found that I had to slightly redefine the list of keywords included in listings. I still did not take the time to submit a patch to the author, though... In any case, here's what I use, if it can be of any help to anyone: \lstloadlanguages{R} \lstdefinelanguage{Renhanced}[]{R}{% morekeywords={acf,ar,arima,arima.sim,colMeans,colSums,is.na,is.null,% mapply,ms,na.rm,nlmin,replicate,row.names,rowMeans,rowSums,seasonal,% sys.time,system.time,ts.plot,which.max,which.min}, deletekeywords={c}, alsoletter={.\%},% alsoother={:_\$}} \lstset{language=Renhanced,extendedchars=true, basicstyle=\small\ttfamily, commentstyle=\textsl, keywordstyle=\mdseries, showstringspaces=false, index=[1][keywords], indexstyle=\indexfonction} with [EMAIL PROTECTED] -- Vincent Goulet, Associate Professor École d'actuariat Université Laval, Québec [EMAIL PROTECTED] http://vgoulet.act.ulaval.ca Anupam Tyagi provided the following: \documentclass{report} \usepackage{listings} \begin{document} Somethings . \lstset{% general command to set parameter(s) basicstyle=\small, % print whole in small stringstyle=\ttfamily, % typewriter type for strings numbers=left, % numbers on the left numberstyle=\tiny, % Tiny numbers stepnumber=2, % number every second line of code numbersep=5pt, % 5pt seperation between numbering and code listing language=R } \lstinputlisting{text1.R} \end{document} Michael Dewey http://www.aghmed.fsnet.co.uk __ R-help@stat.math.ethz.ch 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.
[R] How to format R code in LaTex documents
Hi, I am planning on putting some R script in an appendix of a LaTex document. Can anyone recommend me a way of how to format it? Is there a way to keep all line breaks without having to insert \\ in every single line? Thank you! Benjamin __ R-help@stat.math.ethz.ch 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.
Re: [R] How to format R code in LaTex documents
Benjamin Dickgiesser wrote: Hi, I am planning on putting some R script in an appendix of a LaTex document. Can anyone recommend me a way of how to format it? Is there a way to keep all line breaks without having to insert \\ in every single line? Thank you! Benjamin Here's one way and I would appreciate anyone's improvements. I've also included solutions from two others. Please let me know what you decide to use. -Frank \usepackage{listings,relsize} \lstloadlanguages{R} \lstset{language=R,basicstyle=\smaller[2],commentstyle=\rmfamily\smaller, showstringspaces=false,% xleftmargin=4ex,literate={-}{{$\leftarrow$}}1 {~}{{$\sim$}}1} \lstset{escapeinside={(*}{*)}} % for (*\ref{ }*) inside lstlistings (S code) . . . \begin{lstlisting} . . . S code . . . \end{lstlisting} The following code was provided by Vincent Goulet: listings is a great package to highlight R keywords and comments and --- that was my main use of the package --- index those keywords. I found that I had to slightly redefine the list of keywords included in listings. I still did not take the time to submit a patch to the author, though... In any case, here's what I use, if it can be of any help to anyone: \lstloadlanguages{R} \lstdefinelanguage{Renhanced}[]{R}{% morekeywords={acf,ar,arima,arima.sim,colMeans,colSums,is.na,is.null,% mapply,ms,na.rm,nlmin,replicate,row.names,rowMeans,rowSums,seasonal,% sys.time,system.time,ts.plot,which.max,which.min}, deletekeywords={c}, alsoletter={.\%},% alsoother={:_\$}} \lstset{language=Renhanced,extendedchars=true, basicstyle=\small\ttfamily, commentstyle=\textsl, keywordstyle=\mdseries, showstringspaces=false, index=[1][keywords], indexstyle=\indexfonction} with [EMAIL PROTECTED] -- Vincent Goulet, Associate Professor École d'actuariat Université Laval, Québec [EMAIL PROTECTED] http://vgoulet.act.ulaval.ca Anupam Tyagi provided the following: \documentclass{report} \usepackage{listings} \begin{document} Somethings . \lstset{% general command to set parameter(s) basicstyle=\small, % print whole in small stringstyle=\ttfamily, % typewriter type for strings numbers=left, % numbers on the left numberstyle=\tiny, % Tiny numbers stepnumber=2, % number every second line of code numbersep=5pt, % 5pt seperation between numbering and code listing language=R } \lstinputlisting{text1.R} \end{document} __ R-help@stat.math.ethz.ch 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.
Re: [R] How to format R code in LaTex documents
On Jan 15, 2007, at 8:42 AM, Benjamin Dickgiesser wrote: Hi, I am planning on putting some R script in an appendix of a LaTex document. Can anyone recommend me a way of how to format it? Is there a way to keep all line breaks without having to insert \\ in every single line? I think the LaTeX environments lstlisting and/or verbatim might do what you want. Thank you! Benjamin Haris __ R-help@stat.math.ethz.ch 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.
Re: [R] How to format R code in LaTex documents
Consider using the fancyvrb package if you need additional customization. On 1/16/07, Benjamin Dickgiesser [EMAIL PROTECTED] wrote: Hi, I am planning on putting some R script in an appendix of a LaTex document. Can anyone recommend me a way of how to format it? Is there a way to keep all line breaks without having to insert \\ in every single line? Thank you! Benjamin __ R-help@stat.math.ethz.ch 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. -- Tim Calkins 0406 753 997 __ R-help@stat.math.ethz.ch 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.
Re: [R] How to format R code in LaTex documents
Another alternative is to simply use LyX (www.lyx.org), which is a WYSIWYG (graphical) front-end for LaTeX. There's an code environment where you can paste everything right in, and it'll show in your PDF output exactly as it appears while editing. Also, not an answer to your question, but you might also want to check out xtable (http://cran.r-project.org/src/contrib/Descriptions/xtable.html), which allows R to output LaTeX that can be pasted into your .tex file. On 1/15/07, Tim Calkins [EMAIL PROTECTED] wrote: Consider using the fancyvrb package if you need additional customization. On 1/16/07, Benjamin Dickgiesser [EMAIL PROTECTED] wrote: Hi, I am planning on putting some R script in an appendix of a LaTex document. Can anyone recommend me a way of how to format it? Is there a way to keep all line breaks without having to insert \\ in every single line? Thank you! Benjamin __ R-help@stat.math.ethz.ch 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. -- Tim Calkins 0406 753 997 __ R-help@stat.math.ethz.ch 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. -- Ubuntu Linux 6.06 (Dapper Drake) [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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.