gpoore / minted

minted is a LaTeX package that provides syntax highlighting using the Pygments library. Highlighted source code can be customized using fancyvrb.
1.74k stars 126 forks source link

[Feature Request] Allow arbitrary or tagged line ranges #355

Closed useredsa closed 1 year ago

useredsa commented 1 year ago

The listings package allows the user to select which lines of the input file to include based on some markers that appear in the code. This is listed in their documentation as "arbitrary linerange markers''.

For example, here, it would only show the second loop.

\lstset{rangeprefix=\{\ ,% curly left brace plus space
rangesuffix=\ \}}% space plus curly right brace

\begin{lstlisting}[linerange=loop\ 2-end]
{ loop 2 }
for
i :=maxint to 0 do
begin
{ do
nothing }
end ;
{ end }
\begin{lstlisting}%
[linerange=loop\ 2-end]
{ loop 1 }
for i:=maxint to 0 do
begin
{ do nothing }
end;
{ end }
{ loop 2 }
for i:=maxint to 0 do
begin
{ do nothing }
end;
{ end }
\end{lstlisting}

This is extremely useful when referencing existing codebases, where extra code can be added or deleted, since that messes up the line numbers and the documentation does not render well anymore. This post is the request to include a feature with similar behavior in minted.

Thank you very much.

gpoore commented 1 year ago

minted version 3.0 is now under development, thanks to a grant from the TeX Users Group. It will include support for including snippets of external files based on regular expressions/literal delimiters. Progress on including snippets will be tracked in #373 . Initial beta releases of minted version 3.0 are expected by early 2024.