4

I am working on a tutorial for the knitr package using the beamer class. I was able to display latex code and knitr chunks inside my presentation without evaluation but I additionally want to add inline code, namely \Sexpr{} without evaluation. So the three dots (...) should be replaced by \Sexpr{pi}. Any suggestions?

\documentclass{beamer}
\usepackage[english]{babel}
\usepackage{listings}
\lstset
{
language=[LaTeX]TeX,
breaklines=true,
basicstyle=\tt\scriptsize,
keywordstyle=\color{blue},
identifierstyle=\color{black},
}
\usepackage[utf8]{inputenc}
\usetheme{Madrid}

\title{}

\begin{document}

<<setup,echo=FALSE,include=FALSE>>=
render_listings()
@


\begin{frame}[fragile]{}{}

\begin{lstlisting}
\documentclass{article}
\begin{document}
The value of $\pi$ is ...


\Sexpr{''}<<label>>=
print("knitr!")
@

\end{document}
\end{lstlisting}



\end{frame}

\end{document}

1 Answer 1

5

You can use escapechar:

\begin{lstlisting}[escapechar=|]
\documentclass{article}
\begin{document}
The value of $\pi$ is \Sex||pr{pi}


||<<label>>=
print("knitr!")
@

\end{document}
\end{lstlisting}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.