5

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.

0

2 Answers 2

7

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}
0

This has been long answered but I wanted to further add that the command \noindent works perfectly well within normal text. I'm not sure if it does within your code but it's worth keeping the idea in mind anyway.

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    May 25, 2022 at 8:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .