For a project, I am printing a large amount of source code using Minted. Certain blocks, such as CSS blocks, are fairly short, but are split across pages, which means they are not as readable. Is it possible to get Minted to only insert a page break where there is a double line break in the code?
-
What if there isn't a double line break, but the page space is not enough? – Alenanno Feb 21 '16 at 11:48
-
@Alenanno Then breaking anywhere would be acceptable, but almost all my code has fairly regular double line breaks. – Charlie Harding Feb 21 '16 at 11:53
The plan here is first set interlinepenalty to 10000 so no linebreaking happens normally and then modify the underlying fancyverb to detect a blank line and if so encourage a page break.
The example uses a very small page, just to show the effect.
Before:
After:
\documentclass{article}
\usepackage{minted}
\setlength\topskip{\baselineskip}
\setlength\textheight{12\baselineskip}
\makeatletter
%\showoutput
\def\@wasblank{\PYG {err}{BLANK}}
\def\foo{\aftergroup\ffoo}
\def\ffoo{\goodbreak}% or \clearpage or whatever
\let\zzzz\FV@PreProcessLine
\def\FV@PreProcessLine{%
\ifx\FV@Line\@empty
\def\FV@Line{BLANK}%
\fi
\ifx\FV@Line\@wasblank
\def\FV@Line{\aftergroup\aftergroup\aftergroup\foo}%
\fi
\zzzz}
\begin{document}
%\showoutput
\noindent x1\\x2\\x3\\x4\\x5\\x6\\x7\\x8\\x9\\x10\\x11\\x12
%\tracingall
{
\interlinepenalty10000 %
\begin{minted}{json}
[
{
"type": "Room"
"type1": "Room"
"typesad": "Room"
"typde": "Room"
"tydpe": "Room"
},
1111,
"aaaaa",
"aaaasda",
"aaaaa",
2222,
"2aaaaa" ,
333,
"zzzz"
]
\end{minted}
}
\end{document}
-
Is there any way I can use this in conjunction with breaklines? – Charlie Harding Mar 18 '16 at 10:52
-
-
I tried enabling the [breaklines] option of minted in the MWE, and it stopped page breaking the code at all. – Charlie Harding Mar 19 '16 at 11:44