gpoore / minted

minted is a LaTeX package that provides syntax highlighting using the Pygments library. Highlighted source code can be customized using fancyvrb.
1.73k stars 125 forks source link

Overfull hbox with `mintinline` and `breakanywhere` in enumerate environment #387

Open janstarke opened 3 months ago

janstarke commented 3 months ago

Dear all,

we observe overfull hbox messages when we're using mintline in an enumerate environment. We use this situation when when enumerate a set of file paths, which can be really long and can contain where long parts (e.g. hashes or UUIDs), which is why we don't want to break only at token boundaries, but anywhere.

I was trying to add some glue at the end of the line as a mitigation, but without success. Does anyone have a solution for this problem?

Minimal working example:

Code

\documentclass{article}
\usepackage{minted}

\begin{document}

\begin{itemize}
    \item \mintinline[breaklines,breakanywhere]{output}{This_is_very_very_very_very_very_very_very_very_very_long_verbatim_text}
\end{itemize}

\end{document}

Observed result

The output of LaTeX contains the following warning:

Overfull \hbox (0.61113pt too wide) in paragraph at lines 2--9
[][][]\TU/lmtt/m/n/10 T[]h[]i[]s[]_[]i[]s[]_[]v[]e[]r[]y[]_[]v[]e[]r[]y[]_[]v[]
e[]r[]y[]_[]v[]e[]r[]y[]_[]v[]e[]r[]y[]_[]v[]e[]r[]y[]_[]v[]e[]r[]y[]_[]v[]e[]r
[]y[]_[]v[]e[]r[]y[]_[]l[]o[]n[]g[]_[]v[]e[]

The warning does not occur when mintinline is not used inside an enumerate environment

Expected result

No warnings

muzimuzhi commented 3 months ago

I would suggest to just live with such a small amount of overfull hbox (0.61113pt).

The warning does not occur when mintinline is not used inside an enumerate environment

Given the same left margin, the overfull hbox is reproducible outside of an itemize environment.

\documentclass{article}
\usepackage{minted}

\begin{document}

\begin{itemize}
    \item \mintinline[breaklines,breakanywhere]{output}{This_is_very_very_very_very_very_very_very_very_very_long_verbatim_text}
\end{itemize}

% emulate left margin of \item in first level itemize
% see anatomy of list dimensions in https://latexref.xyz/list.html
\noindent\hskip\dimexpr\leftmargin+\itemindent\relax
\mintinline[breaklines,breakanywhere]{output}{This_is_very_very_very_very_very_very_very_very_very_long_verbatim_text}

\end{document}

As a non-solution workaround, you can enlarge \hfuzz inside such list environments. For example setting \hfuzz=1pt. Initially LateX sets \hfuzz=0.1pt.

From TeX by Topic, sec. 19.1.1 Badness,

Overfull horizontal and vertical boxes are passed unnoticed if their excess width or height is less than \hfuzz or \vfuzz respectively.