Skip to content
Back to formatted view

Raw Message

Message-ID: <48D41416.3040006@vanderbilt.edu>
Date: 2008-09-19T21:05:26Z
From: Frank E Harrell Jr
Subject: [R-gui] Tinn-R/Latex output
In-Reply-To: <dd08d4lk47fj4pd9m8tnfg2rffvm9hlvid@4ax.com>

Mike Prager wrote:
> "David Carslaw" <D.C.Carslaw at its.leeds.ac.uk> wrote:
> 
>> I find Tinn-R to be an excellent editor for R, but I have one question I
>> have not been able to answer.
>>  
>> I wish to include some R code in Latex.  Using the Edit/Copy formatted
>> (to export)/TeX does provide Latex-type output.  However, there are lots
>> of commands such as \RAIdentifier and \RAOperator etc. that would appear
>> to need either a Latex package to interpret or a list of new commands
>> that describe font attributes etc.
>>
>> My question is whether such a package exists, or is the user expected to
>> define their own commands to interpret them?
> 
> 
> David,
> 
> I also find Tinn-R an excellent editor for R.
> 
> When I include R code in Latex, I use the Latex "listings"
> package. It has a wide variety of settings for pretty-printing R
> code and can be customized by the user.  I think that would be
> more satisfactory in the long run than inserting Latex codes (or
> having an editor insert Latex codes) to mark R language
> elements.
> 
> HTH
> 
> Mike P.
> 

The following is how I set up the listings package usage for R.  If you 
have improvements to this please pass them along. -Frank

\usepackage{listings,relsize}
%Setup for listings package
\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)

-- 
Frank E Harrell Jr   Professor and Chair           School of Medicine
                      Department of Biostatistics   Vanderbilt University