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 %?

有帮助吗?

解决方案

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}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top