6

This is a piece of my LaTeX code:

\documentclass[a4paper,oneside]
\usepackage{minted}
\usepackage{tcolorbox}
\tcbuselibrary{breakable,skins}
\usepackage{etoolbox}
\usepackage{fancyvrb}

\begin{document}
\begin{tcolorbox}[breakable=true]
\centering
\RecustomVerbatimEnvironment{Verbatim}{BVerbatim}{}
\inputminted{gnuplot}{script.txt}
\end{tcolorbox}  
\end{document}

This is the script.txt file:

This is how the output looks like:

The tcolorbox spans across pages, but the minted code is not 'inside' it

I am trying to fit the minted code in the tcolorbox, such that the code also spans across pages. Can someone guide me in the right way?

4
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Jun 16, 2015 at 11:26
  • Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. Jun 16, 2015 at 13:07
  • @ThomasF.Sturm Sure, I will try my best to. It's not tedious to me, but I am using a template for my document and am building it up slowly by looking into the posts on TeX.SX, as I am a complete beginner in LaTeX.
    – progammer
    Jun 16, 2015 at 14:57
  • @jsp99 but we have no access to script.txt, so we cannot reproduce the problem. Either provide the file or provide some dummy replacement contents allowing us to reproduce the proble. Also, your code is missing the document class that you are using. Jun 16, 2015 at 15:53

1 Answer 1

8

I think I found the cause of the problem. Your use of \RecustomVerbatimEnvironment seems to make the minted code unbreakable. If you omit this (and thereby also omit centering), your code is breakable:

\begin{filecontents*}{script.txt}
Bla bla bla bla bla.
Blub blub blub.
Bla bla bla bla bla.
Blub blub blub.
Bla bla bla bla bla.
Blub blub blub.
Bla bla bla bla bla.
Blub blub blub.
Bla bla bla bla bla.
Blub blub blub.
Bla bla bla bla bla.
Blub blub blub.
Bla bla bla bla bla.
Blub blub blub.
Bla bla bla bla bla.
Blub blub blub.
Bla bla bla bla bla.
Blub blub blub.
Bla bla bla bla bla.
Blub blub blub.
\end{filecontents*}

\documentclass[a4paper,oneside]{report}
\usepackage{minted}
\usepackage{tcolorbox}
\tcbuselibrary{breakable,skins}
\usepackage{etoolbox}
\usepackage{fancyvrb}

\begin{document}

\rule{1pt}{14cm}

\begin{tcolorbox}[breakable,enhanced]
%\centering
%\RecustomVerbatimEnvironment{Verbatim}{BVerbatim}{}
\inputminted{gnuplot}{script.txt}
\end{tcolorbox}
\end{document}

enter image description here

Update:

You get the same result, if you use the minted library of tcolorbox and its \tcbinputlisting command instead of putting \inputminted into a tcolorbox.

With your provided script.txt plus setting minted options={breaklines} for line breaking, this gives:

\documentclass[a4paper,oneside]{report}
\usepackage{minted}
\usepackage{tcolorbox}
\tcbuselibrary{breakable,skins,minted}
\usepackage{etoolbox}
\usepackage{fancyvrb}

\begin{document}

\tcbinputlisting{
  listing file=script.txt,
  minted language=gnuplot,
  minted options={breaklines},% <-- put other minted options inside the brackets
  breakable,enhanced,% <-- put other tcolorbox options here
  listing only
}

\end{document}

enter image description here

If you have many gnuplot inputs, you can wrap all settings into a new macro using \newcommand or \newtcbinputlisting (from tcolorbox).

For example, create a new macro \gnuplotinput like the following:

\documentclass[a4paper,oneside]{report}
\usepackage{tcolorbox}
\tcbuselibrary{breakable,skins,minted}

\newtcbinputlisting{\gnuplotinput}[2][]{%
  listing file={#2},
  minted language=gnuplot,
  minted options={breaklines},% <-- put other minted options inside the brackets
  breakable,enhanced,% <-- put other tcolorbox options here
  listing only,#1
}

\begin{document}

\gnuplotinput{script.txt}

\end{document}
2
  • that almost solved the problem. But my code lines are long (I updated my question with the script.txt file) and they don't wrap at the right boundary of tcolorbox. Can you suggest a solution for that as well?
    – progammer
    Jun 16, 2015 at 16:27
  • 1
    @jsp99 Yes, the recent version of minted supports line breaks. I have updated my answer in this way. Jun 16, 2015 at 16:38

You must log in to answer this question.

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