# Step-by-step in report

I am trying to explain a program code step-by-step, but I would like to show what we have atm in each example, without retyping.

\documentclass{report}
\usepackage{listings}

\begin{document}

\begin{lstlisting}
#!/bin/sh
export A=2
\end{lstlisting}

We have
\begin{example}
$$A =2$$
\end{example}

\begin{lstlisting}
export B=2
\end{lstlisting}

And we have now
\begin{example}
$$A = 2$$
$$B = 2$$
\end{example}

\end{document}


Is there an environment, which stores these? Or is there a better style in doing this, while still showing all variables already declared?

• How about you check this. You can escape some text in listings environment. – M. Al Jumaily Aug 28 '19 at 21:23
• This is technically very nice, but doesn't solve my problem, as the real code uses lstinputlistings and is written by somebody else – 927589452 Aug 28 '19 at 22:02
• Not really, I should pobably remove the listings tag, as the problem is more with the example-pseudoenvironment – 927589452 Aug 29 '19 at 7:36