| 1 |
% Source: http://biostat.mc.vanderbilt.edu/wiki/pub/Main/SweaveTemplate/Sweavel.sty |
| 2 |
% Author: Frank Harrell (with slight tweaks by Yihui Xie) |
| 3 |
% Usage: \usepackage{Sweavel} |
| 4 |
% To change size of R code and output, use e.g.: \def\Sweavesize{\normalsize} |
| 5 |
% To change just the size of output, use e.g.: \def\Routsize{\smaller[2]} |
| 6 |
% To change colors of R code, output, and commands, use e.g.: |
| 7 |
% \def\Rcolor{\color{black}} |
| 8 |
% \def\Routcolor{\color{green}} |
| 9 |
% \def\Rcommentcolor{\color{red}} |
| 10 |
% To change background color or R code and/or output, use e.g.: |
| 11 |
% \def\Rbackground{\color{white}} |
| 12 |
% \def\Routbackground{\color{white}} |
| 13 |
% To use rgb specifications use \color[rgb]{ , , } |
| 14 |
% To use gray scale use e.g. \color[gray]{0.5} |
| 15 |
% If you change any of these after the first chunk is produced, the |
| 16 |
% changes will have effect only for the next chunk. |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
\NeedsTeXFormat{LaTeX2e} |
| 21 |
\ProvidesPackage{Sweavel}{} % substitute for Sweave.sty using |
| 22 |
% listings package with relsize |
| 23 |
\RequirePackage{listings,fancyvrb,color,relsize} |
| 24 |
|
| 25 |
\providecommand{\Sweavesize}{\smaller} |
| 26 |
\providecommand{\Routsize}{\Sweavesize} |
| 27 |
|
| 28 |
\providecommand{\Rcolor}{\color[rgb]{0, 0.5, 0.5}} |
| 29 |
\providecommand{\Routcolor}{\color[rgb]{0.461, 0.039, 0.102}} |
| 30 |
\providecommand{\Rcommentcolor}{\color[rgb]{0.101, 0.043, 0.432}} |
| 31 |
|
| 32 |
\providecommand{\Rbackground}{\color[gray]{0.91}} |
| 33 |
\providecommand{\Routbackground}{\color[gray]{0.935}} |
| 34 |
% Can specify \color[gray]{1} for white background or just \color{white} |
| 35 |
|
| 36 |
\lstdefinestyle{Rstyle}{fancyvrb=false,escapechar=`,language=R,% |
| 37 |
basicstyle={\Rcolor\Sweavesize},% some want \ttfamily too |
| 38 |
backgroundcolor=\Rbackground,% |
| 39 |
showstringspaces=false,% |
| 40 |
keywordstyle=\Rcolor,% |
| 41 |
commentstyle={\Rcommentcolor\ttfamily\itshape},% |
| 42 |
literate={<-}{{$\leftarrow$}}2{<<-}{{$\twoheadleftarrow$}}2{~}{{$\sim$}}1{<=}{{$\leq$}}2{>=}{{$\geq$}}2{^}{{$^{\scriptstyle\wedge}$}}1,% |
| 43 |
alsoother={$},% |
| 44 |
alsoletter={.<-},% |
| 45 |
otherkeywords={!,!=,~,$,*,\&,\%/\%,\%*\%,\%\%,<-,<<-,/},% |
| 46 |
escapeinside={(*}{*)}}% |
| 47 |
% Other options of interest: |
| 48 |
% frame=single,framerule=0.1pt,framesep=1pt,rulecolor=\color{blue}, |
| 49 |
% numbers=left,numberstyle=\tiny,stepnumber=1,numbersep=7pt, |
| 50 |
% keywordstyle={\bf\Rcolor} |
| 51 |
|
| 52 |
\lstdefinestyle{Routstyle}{fancyvrb=false,literate={~}{{$\sim$}}1{R^2}{{$R^{2}$}}2{^}{{$^{\scriptstyle\wedge}$}}1{R-squared}{{$R^{2}$}}2,% |
| 53 |
frame=single,framerule=0.2pt,framesep=1pt,basicstyle=\Routcolor\Routsize\ttfamily,% |
| 54 |
backgroundcolor=\Routbackground} |
| 55 |
|
| 56 |
\newenvironment{Schunk}{}{} |
| 57 |
\lstnewenvironment{Sinput}{\lstset{style=Rstyle}}{} |
| 58 |
\lstnewenvironment{Scode}{\lstset{style=Rstyle}}{} |
| 59 |
\lstnewenvironment{Soutput}{\lstset{style=Routstyle}}{} |
| 60 |
|