I want to show LaTeX code inside a Beamer presentation.
If I try the following MWE as an article, it works flawlessly:
\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\lstset
{
language=[LaTeX]TeX,
breaklines=true,
basicstyle=\tt\scriptsize,
keywordstyle=\color{blue},
identifierstyle=\color{magenta},
}
\begin{document}
\begin{lstlisting}
\documentclass{article}
\begin{document}
Hello World
\end{document}
\end{lstlisting}
\end{document}
However, the moment I want to use that code into a Beamer presentation like in the MWE below:
\documentclass{beamer}
\usepackage{lmodern}
\usepackage{listings}
\lstset
{
language=[LaTeX]TeX,
breaklines=true,
basicstyle=\tt\scriptsize,
keywordstyle=\color{blue},
identifierstyle=\color{magenta},
}
\title{A Tiny Example}
\author{John Doe}
\date{\today}
\begin{document}
\maketitle
\begin{frame}
\frametitle{First Slide}
\begin{lstlisting}
\documentclass{article}
\begin{document}
Hello World
\end{document}
\end{lstlisting}
\end{frame}
\end{document}
I get the following errors:
! Missing \endcsname inserted.
! LaTeX Error: Can be used only in preamble.