Removing Minted Indentation – Correct LaTeX Indentation Techniques

indentationmintedsource

When writing with minted code snippets I dislike to remove indentation in latex source, so correct results are generated. Is there a way to substract latex indentation-level from minted indentation? I hope this mwe makes it clear:

\documentclass{beamer}
\usepackage{minted}
\begin{document}
\begin{frame}[fragile,t]
  \begin{itemize}
    \item readable Latex source

      \begin{minted}{python}
        l = 1
      \end{minted}

      not so nice Latex source but, correct indentation

      \begin{minted}{python}
l = 1        
      \end{minted}

      So how to subtract the indentation level from latex source?

  \end{itemize}
\end{frame}
\end{document}

producing this output:
enter image description here

BTW: Please consider that code listings may have a line lengths up to 80 characters, where this additional indent will cause overlapping source, or linebreaks.

Best Answer

There's an option called autogobble which does exactly what you want.

autogobble

% arara: pdflatex: {shell: 1}
\documentclass{beamer}
\usepackage{minted}
\begin{document}
\begin{frame}[fragile,t]
  \begin{itemize}
    \item readable Latex source

      \begin{minted}[autogobble]{python}
        l = 1
      \end{minted}

      not so nice Latex source but, correct indentation

      \begin{minted}{python}
l = 1        
      \end{minted}

      So how to subtract the indentation level from latex source?

  \end{itemize}
\end{frame}
\end{document}
Related Question