minted icon indicating copy to clipboard operation
minted copied to clipboard

Overflows page vertically when linebreak is used

Open rugk opened this issue 4 years ago • 16 comments

If you use linebreaks, and have a long line that coincidentally is printed at the end of the page, it overflows the vertical end of the page/the visual background box/color, at least.

See: image

This should not happen.

Relevant code:

\usepackage{minted}
\usemintedstyle{default}

\setminted{
	bgcolor=lightGrey,
	% Zeilennummern
	% xleftmargin=25pt, % required to show line numbers
	% linenos,
	% Zeilenumbruch
	breaklines,
	breakanywhere,
	% tabs
	obeytabs,
	tabsize=4,
	% showtabs,
	highlightcolor=Goldenrod,
}

% […]

\newenvironment{multipageListing}{
	\setstretch{1.0}
	\captionsetup{type=listing}
}{}

rugk avatar Aug 17 '20 14:08 rugk

Can you provide a complete (also compilable) example? This saves time for any one who wants to reproduce the problem before digging into the issue.

Edit: Also, why \newenvironment{multipageListing} is relevant?

muzimuzhi avatar Aug 17 '20 15:08 muzimuzhi

As expected, the tcblisting environment from tcolorbox package (with library minted loaded) does not have the same issue. But as restricted by fvextra package, one of dependencies of minted, the page break point is inserted only between input lines, not between broken lines.

\documentclass{article}
\usepackage[papersize={8cm, 6cm}, showframe]{geometry} % just for test
\usepackage{tcolorbox}
\tcbuselibrary{breakable, minted}
\usepackage{xcolor}

\begin{document}
\begin{minted}[breaklines,bgcolor=gray]{text}
  content content content content content content content content content content content content
  content content content content content content content content content content content content
  content content content content content content content content content content content content
\end{minted}

\newpage

\begin{tcblisting}{size=minimal, breakable, listing only}
  content content content content content content content content content content content content
  content content content content content content content content content content content content
  content content content content content content content content content content content content
\end{tcblisting}
\end{document}

image

muzimuzhi avatar Aug 17 '20 16:08 muzimuzhi

Well… do you know a workaround?

BTW in draft mode respectively without a background color, the page breaks works without problems.

rugk avatar Aug 29 '20 14:08 rugk

Does the above tcolorbox example count for a workaround?

muzimuzhi avatar Aug 29 '20 14:08 muzimuzhi

Oh, awesome. I've tried it and it works.

I've just added this to the preabmle:

% minted fix color
% https://github.com/gpoore/minted/issues/278
\usepackage{tcolorbox}
\tcbuselibrary{breakable, minted}

I hope this does not have any other negative side-effects, but for now, I don't see any of these? So if that works, why not just switch to this (in your dependencies)?

For everyone having the same issue, pay attention: Load xcolor before tcolorbox.

rugk avatar Aug 29 '20 17:08 rugk

FYI, tcolorbox is already mentioned in documentation of minted, unnumbered section Framing alternatives.

muzimuzhi avatar Aug 29 '20 19:08 muzimuzhi

Okay, but uhm… note that I actually just added the preamble thing. I did not switch to tcblisting and it still fixes this problem :thinking:

I use \inputminted.

rugk avatar Aug 29 '20 23:08 rugk

For everyone having the same issue, pay attention: Load xcolor before tcolorbox.

tcolorbox loads pgf, and pgf loads xcolor without any package options. So yes, if you need to pass options to package xcolor, either load it before tcolorbox, or add \PassOptionsToPackage{svgnames}{xcolor} before tcolorbox is loaded.

Okay, but uhm… note that I actually just added the preamble thing. I did not switch to tcblisting and it still fixes this problem 🤔

I use \inputminted.

I'm afraid tcolorbox doesn't have this utility. Taking the following code using \inputminted as an example, its output is the same as that of minted env in https://github.com/gpoore/minted/issues/278#issuecomment-674966728:

\begin{filecontents}[noheader, force]{long-line.txt}
  content content content content content content content content content content content content
  content content content content content content content content content content content content
  content content content content content content content content content content content content
\end{filecontents}

\documentclass{article}
\usepackage[papersize={8cm, 6cm}, showframe]{geometry} % just for test
\usepackage{tcolorbox}
\tcbuselibrary{breakable, minted}

\begin{document}
\inputminted[breaklines,bgcolor=gray]{text}{long-line.txt}
\end{document}

muzimuzhi avatar Aug 30 '20 00:08 muzimuzhi

Any solution to this problem?

I'm writing my tesis with LaTeX and I use quite a lot minted blocks, sometimes alone, sometimes within listing environments to add captions. And I have also faced the overflow problem.

Adding \tcbuselibrary{breakable, minted} doesn't make any difference.

I can try to break lines manually and simulate the arrows with $\hookrightarrow$.

skanskan avatar Oct 06 '20 18:10 skanskan

Adding \tcbuselibrary{breakable, minted} doesn't make any difference.

@skanskan You need to use \begin{tcblisting}{size=minimal, breakable, listing only} instead of \begin{minted}, see the example in https://github.com/gpoore/minted/issues/278#issuecomment-674966728.

muzimuzhi avatar Oct 06 '20 19:10 muzimuzhi

\begin{tcblisting}{size=minimal, breakable, listing only}

In my code I was using this options:

\begin{minted}[breaklines, fontsize=\footnotesize, baselinestretch=1.3,tabsize=3, bgcolor=bg]{R}

But now they don't work. How can I achieve the same results with tcblisting?

\begin{tcblisting}{size=minimal, breakable, listing only, fontsize=\footnotesize, baselinestretch=1.3, tabsize=3, bgcolor=bg}

skanskan avatar Oct 06 '20 23:10 skanskan

@skanskan Try

\begin{tcblisting}{
  size=minimal, breakable, listing only,
  minted language=R, minted style={breaklines, fontsize=\footnotesize, ...}}
... ...

See tcolorbox's package manual, sec. 16.5 _Option Keys of the minted library.

muzimuzhi avatar Oct 07 '20 12:10 muzimuzhi

\begin{tcblisting}{
  size=minimal, breakable, listing only,
  minted language=R, minted style={breaklines, fontsize=\footnotesize, ...}}

Now it says: Error: TeX capacity exceeded, sorry [input stack size=5000]. \end{tcblisting}

skanskan avatar Oct 07 '20 14:10 skanskan

@skanskan Sorry, I made a mistake. The option name should be minted options, not minted style. The latter one is for specifying a known pygments highlighting style.

muzimuzhi avatar Oct 07 '20 16:10 muzimuzhi

Now it doesn't produce any error message but the output is shifted downwards half page, and if I embed the code inside a \begin{lstlisting} to add a caption it overlaps with the code.

Anway, don't worry, I'm fine using escapeinside=@@ and @\scalebox{0.8}{$\hookrightarrow$}@.

skanskan avatar Oct 07 '20 17:10 skanskan

@skanskan To further help you, I'm afraid a complete example is required. To get more replies more active/in time, it's recommended to post it on tex.stackexchange.com.

muzimuzhi avatar Oct 07 '20 18:10 muzimuzhi