How can I use \ref
inside lstlisting
.
I create two lstlisting
s, e.g. listing1
and listing2
. Now, in the third lstlisting
, I want to give a reference to them. But when I do, I do not get the reference of listing1
and listing2
.
Here is the code I am using.
\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}
Example
"Listing 1": \ref={listing1},
"Listing 2": \ref{listing2}
\end{lstlisting}
\end{document}
listing1
and listing2
are the labels I defined in other listings and they work fine when I reference them within the section.
Here is the output I am getting:
escapeinside
option in the listings manual.