
· Vikram Aruchamy · LaTeX
How to Insert Code in LaTeX with Indentation (listings, minted)
To insert code with its indentation preserved, load the listings package and put the code in an lstlisting environment, for example \begin{lstlisting}[language=Python, tabsize=4]. Spaces and tabs are kept as typed. For richer highlighting use minted with \begin{minted}{python}, and for plain unformatted text the built-in verbatim environment is enough.