I want to cite LaTeX code into my document but how do I embed the keywords “\begin{lstlisting}” and “\end{lstlisting}” correctly?
CODE BELOW DOES NOT WORK (obviously):
\lstset{language=TeX, basicstyle=\footnotesize, numbers=left, numberstyle=\tiny, frame=single}
\begin{lstlisting}
\begin{lstlisting} % this is code
place your source code here % this is code
\end{lstlisting} % this is code
\end{lstlisting}
Do you have
\usepackage{listings}in your preamble? If so, it should work.TeXis a supported language.Here’s a minimal example:
which compiles to
EDIT
To quote commands from the listings package (actually, only for
\end{lstlisting}), escape to latex to print the\character and you’re all set. In the following, I’ve defined@as the escape character and everything within two@symbols is typeset in LaTeX. So here, I’ve input the\using LaTeX and the rest withinlstlistingand the\end{...}sequence is not interpreted as a closing the environment.The output is