How do I keep Sweave from compiling things in a verbatim environment? For example:
\documentclass{article}
\begin{document}
\begin{verbatim}
<<>>=
1+1
@
\end{verbatim}
\end{document}
Results for me in a pdf with:
\begin{Schunk}
\begin{Sinput}
> 1+1
\end{Sinput}
\begin{Soutput}
[1] 2
\end{Soutput}
\end{Schunk}
But I just wanted the input commands.
To be more clear, I want the output in this pdf file to be exactly:
<<>>=
1+1
@
Best Answer
If you're willing to add a single space before the
<<>>
and the@
, that'll do the trick. (The Sweave driver only interprets as chunks blocks of text beginning with<<>>=
at the beginning of a line -- no spaces allowed!)Your input file will now look like this:
And your output file will look like this, possibly indented, but without leading spaces:
ADDED LATER
Alternatively, you can use a chunk of R code that, when Sweave'd, uses
cat()
to output the desired tex code. This solution is probably formally better (in some sense), and also works as desired: