1

I'm using minted for displaying C++ code. If there is a long line at the bottom of the page, the line breaks as expected. Unfortunately there is also a gray arrow to indicate the line break.output

How can I prevent this?

Edit: Here's a MWE to reproduce the problem:

\documentclass[a4paper,12pt]{report}
\usepackage{minted}
\usepackage{xcolor}
\definecolor{bg}{rgb}{0.95,0.95,0.95}
\setminted[c++]{breaklines,bgcolor=bg}
\begin{document}
\begin{minted}{c++}
#include <iostream>

int main() {
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
std::cout << "Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World" std::endl;
}
\end{minted}
\end{document}

The output looks like this: enter image description here

2
  • Could you show a MWE to reproduce this problem.
    – Tom
    May 24, 2022 at 21:14
  • @Tom I added a MWE, sorry I didn't do that in the first place.
    – RaphBilder
    May 25, 2022 at 7:07

1 Answer 1

1

minted package bgcolor scheme was not robust at page break. See manual page. 22.

Be aware that if bgcolor is used with breaklines=true, and a line break occurs just before a page break, then text may extend below the colored background in some instances. It is best to use a more advanced framing package in those cases

I recommend you use tcolorbox package which even provides a built-in framing environment with minted support. An example as follow:

\documentclass[a4paper,12pt]{report}
\begin{filecontents*}{test.h}
#include <iostream>

int main() {

std::cout << "Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World" std::endl;
}
\end{filecontents*}
%\usepackage{minted}
\usepackage{tcolorbox}
\tcbuselibrary{minted,breakable}
\usepackage{xcolor}
\definecolor{bg}{rgb}{0.95,0.95,0.95}
%\setminted[c++]{breaklines,bgcolor=bg}
\begin{document}
%\begin{minted}{c++}
\begin{tcblisting}{
colback=bg,
breakable,
listing only,
minted language=c++,
minted options={breaklines}}
#include <iostream>

int main() {
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
std::cout << "Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World" std::endl;
}
\end{tcblisting}
%\end{minted}
\tcbinputlisting{
colback=bg,
breakable,
listing only,
listing file={test.h},
minted language=c++,
minted options={breaklines}}
\end{document}

enter image description here enter image description here

2
  • Thank you very much for your answer. Is it also possible to add a whole file, like you would with the \inputminted command?
    – RaphBilder
    May 25, 2022 at 8:57
  • @RaphBilder Yes. You could use \tcbinputlisting{⟨options⟩}. More info you can check tcolorbox manual mirror.its.dal.ca/ctan/macros/latex/contrib/tcolorbox/… . I will add an example in the answer.
    – Tom
    May 25, 2022 at 9:13

You must log in to answer this question.

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