[Tex/LaTex] Multiple line verbatim environment

verbatim

I want to achieve the output shown below using multiple line verbatim

enter image description here

My attempt so far is

\documentclass[a5paper]{article}
\usepackage{listings}
\begin{document}

\begin{lstlisting}
123
$\times$ 456
=============
738(this is $123 \times 6$)
\end{lstlisting}

\end{document}

This is definitely not what I need and so I didn't write the code further.Can someone help me with the multiplication symbol and the desired result

Best Answer

Here's one option, but are you sure you want this formatting?

\documentclass[a5paper]{article}
\usepackage{listings}

\lstset{
  columns=flexible,
  basicstyle=\small\ttfamily,
  mathescape=true,
  escapeinside=||
}

\begin{document}

\begin{lstlisting}
    123
 $\times$ 456
  ======
    738       (this is $123 \times 6$)
   615        (this is $123 \times 5$, shifted one position to the left)
 +492         (this is $123 \times 4$, shifted two positions to the left)
========
  56088
\end{lstlisting}

\end{document}

enter image description here

Related Question