minted
minted copied to clipboard
Overflows page vertically when linebreak is used
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:
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}
}{}
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?
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}
Well… do you know a workaround?
BTW in draft
mode respectively without a background color, the page breaks works without problems.
Does the above tcolorbox
example count for a workaround?
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.
FYI, tcolorbox
is already mentioned in documentation of minted
, unnumbered section Framing alternatives.
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
.
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}
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$.
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.
\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 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.
\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 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.
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 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.