11

minted works well when the code snippet is short, or fit into one page. The problem occurs when I pasted a code snippet with several hundred lines. Sometimes it processed but the output was truncated; other times it produced a bunch of errors. And if I break it into pages, the amount of characters in each page matter, i.e. it could yield a blank page after the \end{minted}. For example:

....
\begin{minted}[bgcolor=bg,mathescape]{c++}
code here
\end{minted}
... -> a blank page sometimes appear
\begin{minted}[bgcolor=bg,mathescape]{c++}
code here
\end{minted}
....

Has anyone encountered this awkward behavior with minted package? Any idea or suggestion would be greatly appreciated. Thanks.

6
  • FYI, this behaviour is known, it’s a bug, and I have no idea how to fix it. Oct 9, 2011 at 16:11
  • @KonradRudolph: Please turn your comment into an answer.
    – lockstep
    Dec 3, 2011 at 22:14
  • 1
    I have recently converted a lot of source files to pdf using minted package with no problems and errors, each resulting pdf files several pages long. For each source file, a .tex file was generated, and the source code was inserted with \inputminted[opts...]{c++}{file}.
    – guillem
    Nov 26, 2012 at 9:59
  • 1
    I find that the problem is not in \inputminted or \begin{minted} per se, but in the \begin{listing}. If I have a long listing inserted only using \inputminted then it works fine.
    – fikovnik
    Mar 9, 2015 at 23:12
  • See also the comparison of minted to the verbments package, written by the minted maintainer: tex.stackexchange.com/a/103471/8666
    – 0 _
    May 29, 2016 at 3:15

2 Answers 2

10

Unfortunately, this behaviour is due to a known bug. Worse, I have no idea how to fix it.

In the long run, I plan to get rid of the fancyvrb package altogether since strictly speaking minted doesn’t need the verbatim capabilities – LaTeX sequences get escaped anyway. This would lead to a lot more flexibility.

For now, though, this is unfortunately not a trivial change. If you want to get your hands dirty you can try \letting \Verbatim and \endVerbatim to \relax, and then tinkering a bit to get the rendering right again. Disclaimer: I haven’t tried this.

10

The bad behaviour of the minted package in truncating code can be prevented through the mdframed package. Example:

\begin{mdframed}[linecolor=black, topline=true, bottomline=true,
  leftline=false, rightline=false, backgroundcolor=yellow!20!white]
    \begin{minted}[mathescape]{c++}
        int main()
            {
                bla bla...
            }
    \end{minted}
\end{mdframed}

Obviously you should have package mdframed loaded in your preamble, simply by \usepackage{mdframed} and eventually with global options. Even better, without pasting:

\begin{mdframed}[linecolor=black, topline=true, bottomline=true,
  leftline=false, rightline=false, backgroundcolor=yellow!20!white]
    \inputminted[fontsize=\scriptsize, linenos, frame=lines]{c++}{path/to/your/code.cpp}
\end{mdframed}

You must log in to answer this question.

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