minted icon indicating copy to clipboard operation
minted copied to clipboard

Autogobble with file input with line ranges

Open AntonC9018 opened this issue 2 years ago • 4 comments

How is autogobble supposed to work with file input? Is it supposed to do nothing, detect the indent from the entire file, or detect it from the given range? I'd assume it's one of the first two, because the last one is not how it in fact behaves. Any workaround besides preprocessing files manually?

AntonC9018 avatar Apr 02 '22 12:04 AntonC9018

autogobble should dedent the part of the inputted file that is displayed, whether that is the whole file or only a range. This works for me. Can you provide an example?

gpoore avatar Apr 02 '22 14:04 gpoore

test.tex

\documentclass{report}

% Code blocks
\usepackage{minted}
\usepackage{color}
\setminted{%
  autogobble=true,
  codetagify=true,
  linenos=true,
  breaklines=true,
  baselinestretch=0.72,
  % https://www.giss.nasa.gov/tools/latex/ltx-178.html
  fontsize=\footnotesize
}

\begin{document}

Test \ref{test}.

\section{Test}\label{test}
\inputminted[firstline=2, lastline=4]{cs}{test.txt}

\end{document}

test.txt (windows line endings, spaces for indentation)

{
    {   
        Hello
        World
    }
}

Compile with (Windows, MikTeX):

latexmk --shell-escape -pdf test.tex

Result:

image

Importing the whole file, for reference:

image

AntonC9018 avatar Apr 02 '22 15:04 AntonC9018

There was a bug that affected output when a line after lastline had less indentation than the selected range. It should be fixed in the last commit. Until there is a new release of minted on CTAN, you can download the minted.sty from the last commit and either put that in the same directory as your document, or replace your existing minted.sty.

gpoore avatar Apr 02 '22 18:04 gpoore

Thanks, awesome

AntonC9018 avatar Apr 02 '22 18:04 AntonC9018