Incorporating a literal code chunk is knitr
FAQ 8. For this case, use
\documentclass{article}
\begin{document}
<<setup, include=FALSE>>=
render_listings()
@
\begin{lstlisting}
\Sexpr{''}<<>>=
1+1
@
\end{lstlisting}
\end{document}
Question
I want to let the chunk itself be displayed as text inside the listings environment. If I enter the chunk inside listings as below it is getting evaluated.
\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}
<<>>=
1+1
@
\end{lstlisting}
\end{document}
Is there a way that does not include to comment <<>>=
and @
out with %
?
Solution
Incorporating a literal code chunk is knitr
FAQ 8. For this case, use
\documentclass{article}
\begin{document}
<<setup, include=FALSE>>=
render_listings()
@
\begin{lstlisting}
\Sexpr{''}<<>>=
1+1
@
\end{lstlisting}
\end{document}