Dear Colleagues:
In an attempt to have things like # See page \pageref{this} inside
comments in R code chunks I have modified Sweave.sty as below. I have
followed fancyvrb's manual with regard to the use of the commandchars
argument. But when compiling with LaTeX (using attached test file) I
get a LaTeX error
(/usr/share/texmf-texlive/tex/latex/ae/t1aett.fd)
! Missing \endcsname inserted.
<to be read again>
\global
l.25 } else y <- 4
The line in question is
\DefineVerbatimEnvironment{Sinput}{Verbatim}{formatcom=\lstset{fancyvrb=true},commandchars=\\\{\}}
Can anyone give me a pointer to how to properly change Sweave.sty to
allow it to use fancyvrb in this way? I am following the model in
SweaveListingUtils for having Sweave use the listings package to do
pretty-printing.
Thanks very much
Frank
Sweavel.sty:
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{Sweavel}{}
\RequirePackage{listings,ifthen,graphicx,fancyvrb,relsize}
\RequirePackage{ifthen}
\newboolean{swe...@gin}
\setboolean{swe...@gin}{true}
\newboolean{swe...@ae}
\setboolean{swe...@ae}{true}
\declareoption{nogin}{\setboolean{swe...@gin}{false}}
\declareoption{noae}{\setboolean{swe...@ae}{false}}
\ProcessOptions
\IfFileExists{upquote.sty}{\RequirePackage{upquote}}{}
\ifthenelse{\boolean{swe...@gin}}{\setkeys{gin}{width=0.8\textwidth}}{}%
\ifthenelse{\boolean{swe...@ae}}{%
\RequirePackage[T1]{fontenc}
\RequirePackage{ae}
}{}%
%\DefineVerbatimEnvironment{Sinput}{Verbatim}{fontshape=sl}
\DefineVerbatimEnvironment{Sinput}{Verbatim}{formatcom=\lstset{fancyvrb=true},commandchars=\\\{\}}
\DefineVerbatimEnvironment{Soutput}{Verbatim}{}
\DefineVerbatimEnvironment{Scode}{Verbatim}{fontshape=sl}
\newenvironment{Schunk}{}{}
\newcommand{\Sconcordance}[1]{%
\ifx\pdfoutput\undefined%
\csname newcount\endcsname\pdfoutput\fi%
\ifcase\pdfoutput\special{#1}%
\else\immediate\pdfobj{#1}\fi}
--
Frank E Harrell Jr Professor and Chair School of Medicine
Department of Biostatistics Vanderbilt University
\documentclass{article}
\usepackage[nogin]{Sweavel}
\begin{document}
\lstloadlanguages{R}
\lstset{language=R,fancyvrb=true,escapechar=`,%
basicstyle=\smaller,commentstyle=\ttfamily\itshape\smaller,%
keywordstyle=\bf,%
showstringspaces=false,%
xleftmargin=4ex,literate={<-}{{$\leftarrow$}}2{<<-}{{$\twoheadleftarrow$}}2 {~}{{$\sim$}}1 {<=}{{$\leq$}}2 {>=}{{$\geq$}}2 {^}{{$^\wedge$}}1,%
alsoother={$},alsoletter={.<-},%
otherkeywords={!,!=,~,$,*,\&,\%/\%,\%*\%,\%\%,<-,<<-,/}}%
This is page \pageref{this}.\label{this}
\begin{Schunk}
\begin{Sinput}
b <- 4
a <- b # this is a test line
i <- 2
if(i==3) { # another line, for y^2 \pageref{this}
y <- 3^3
z <- 'this string'
qqcat <- y ~ pol(x,2)
} else y <- 4
\end{Sinput}
\end{Schunk}
\end{document}
______________________________________________
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.