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.


enter image description here


enter image description here





\def\@wasblank{\PYG {err}{BLANK}}
\def\ffoo{\goodbreak}% or \clearpage or whatever


\noindent x1\\x2\\x3\\x4\\x5\\x6\\x7\\x8\\x9\\x10\\x11\\x12

\interlinepenalty10000 %
    "type": "Room"
    "type1": "Room"
    "typesad": "Room"
    "typde": "Room"
    "tydpe": "Room"


  "2aaaaa" ,


  • Is there any way I can use this in conjunction with breaklines? – Charlie Harding Mar 18 '16 at 10:52
  • @CharlieHarding I'd expect so, did you try? – David Carlisle Mar 18 '16 at 11:09
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.