I have a listing that I want to restate at some later point. How can I do this, without creating a new index for the restated listing?
My best approach so far has been to put the listing twice, which creates a new index for the second occurrence. If the label of the two duplicated listing is not changed, this in addition lead to a naming conflict.
\documentclass{article}
\usepackage{listings}
\begin{document}
\section{One}
\begin{lstlisting}[caption=Code,label=lst:code]
x:=1;
\end{lstlisting}
Here, we introduce Listing~\ref{lst:code}.
\section{Two}
For convenience, we restate Listing~\ref{lst:code} here.
\begin{lstlisting}[caption=Code,label=lst:code]
x:=1;
\end{lstlisting}
\end{document}
How do I avoid this?
Ideally, I would like to restate the listing without having to repeat its contents explicitly (this is possible for e.g. Lemmas using thm-restate). Essentially, I would like to obtain the same result as in this question, but for listings.


\lstinputlistingcould help to avoid the duplication of the content. – Daniel Oct 18 '17 at 14:12title=instead ofcaption=for the second occurrence should prevent the additional label and index entry. Alternatively, try thenololoption to prevent inclusion of the second listing into the list of listings. – Daniel Oct 18 '17 at 14:14