minted icon indicating copy to clipboard operation
minted copied to clipboard

Different behaviour in `breakafter`

Open miticollo opened this issue 2 years ago • 12 comments

To explain me I created two examples.

\documentclass{article}

\usepackage{minted}

\begin{document}

\begin{minted}[breaklines, breakafter=\#, showspaces, space=~]{text}
 ==== q1 ====
        Utilization of Srv        [0.1453 ± 0.0043 (2.9895% | 20)# 0.0144 ± 0.0004 (2.9798% | 151)]
\end{minted}

\end{document}

Correctly this produces. immagine But if I change \# with {,} it doesn't work anymore.

\documentclass{article}

\usepackage{minted}

\begin{document}

\begin{minted}[breaklines, breakafter={,}, showspaces, space=~]{text}
 ==== q1 ====
        Utilization of Srv        [0.1453 ± 0.0043 (2.9895% | 20), 0.0144 ± 0.0004 (2.9798% | 151)]
\end{minted}

\end{document}

immagine

miticollo avatar Jul 05 '22 15:07 miticollo

I'm getting the same result for both of your examples, which is no line break.

breaklines is really designed to work with spaces, or spaces plus breakbefore or breakafter. By redefining the space to ~, you are telling LaTeX not to break lines before spaces, so you get no line breaks. You can get around this by redefining an fvextra internal macro that governs line breaking. You can add this in your preamble:

\makeatletter
\def\FV@FVSpaceToken{ }
\makeatother

This may have undesired effects elsewhere if you are using features like tab expansion.

gpoore avatar Jul 05 '22 19:07 gpoore

I'm getting the same result for both of your examples, which is no line break.

I'm confused about why I get two different results. Anyway if I add

\makeatletter
\def\FV@FVSpaceToken{ }
\makeatother

both examples work. But there is a wrong indentation compared to before. immagine

miticollo avatar Jul 05 '22 19:07 miticollo

It looks like redefining \FV@FVSpaceToken{ } already broke things. You could try this instead:

\makeatletter
\def\FV@Break@AfterTokenBreak#1{%
  \let\FV@LastToken=#1%
  \@ifnextchar\FV@Undefined%
   {}%
   {\ifthenelse{\boolean{FV@BreakAfterGroup}}%
     {\ifx\@let@token#1\relax
        \g@addto@macro{\FV@TmpLine}{#1}%
        \let\FV@Break@Next\FV@Break@Scan
      \else
        \ifx\@let@token\bgroup\relax
          \g@addto@macro{\FV@TmpLine}{#1}%
          \let\FV@Break@Next\FV@Break@AfterTokenBreak@Group
        \else
          \g@addto@macro{\FV@TmpLine}{#1\FancyVerbBreakAfterBreak}%
          \let\FV@Break@Next\FV@Break@Scan
        \fi
      \fi}%
     {\g@addto@macro{\FV@TmpLine}{#1\FancyVerbBreakAfterBreak}%
      \let\FV@Break@Next\FV@Break@Scan}%
    \FV@Break@Next}%
}
\makeatother

gpoore avatar Jul 05 '22 20:07 gpoore

It works. Thanks!

But why with my first two examples I have two different results and you don't? Can it depend on my TeXLive installation?

miticollo avatar Jul 05 '22 21:07 miticollo

I don't know why you would get different results. I would expect both to be the same given how the typesetting code works, and that is what happens on my computer. I'm using TeX Live 2022.

gpoore avatar Jul 05 '22 21:07 gpoore

I'm using TeX Live 2022.

Me too.

Can you try with these two examples?

\documentclass{article}

\usepackage{minted}

\begin{document}

\begin{minted}[breaklines, breakafter={;}, showspaces, space=~]{text}
        Utilization of Srv [0.1453 ± 0.0043 (2.9895% | 20); 0.0144 ± 0.0004 (2.9798% | 151)]
\end{minted}

\end{document}

immagine

\documentclass{article}

\usepackage{minted}

\begin{document}

\begin{minted}[breaklines, breakafter={?}, showspaces, space=~]{text}
        Utilization of Srv [0.1453 ± 0.0043 (2.9895% | 20)? 0.0144 ± 0.0004 (2.9798% | 151)]
\end{minted}

\end{document}

immagine I didn't say but I always compiled with

latexmk -interaction=nonstopmode -shell-escape -synctex=1 -lualatex foo.tex

miticollo avatar Jul 05 '22 22:07 miticollo

@lorenzoferron98 I get no-line-break result for all your four examples, either compiled with pdflatex or lualatex, either on my computer running a latest texlive 2022 or on Overleaf.com's texlive 2021, 2020, and even 2019 containers.

Can you add \listfiles to preamble, recompile, find package version info near the end of log file, and paste it here?

muzimuzhi avatar Jul 06 '22 01:07 muzimuzhi

@muzimuzhi

Can you add \listfiles to preamble, recompile, find package version info near the end of log file, and paste it here?

This is LuaHBTeX, Version 1.15.0 (TeX Live 2022)  (format=lualatex 2022.7.6)  6 JUL 2022 09:17
[...]
*File List*
 article.cls    2021/10/04 v1.4n Standard LaTeX document class
  size10.clo    2021/10/04 v1.4n Standard LaTeX file (size option)
  minted.sty    2021/12/24 v2.6 Yet another Pygments shim for LaTeX
  keyval.sty    2022/05/29 v1.15 key=value parser (DPC)
kvoptions.sty    2022-06-15 v3.15 Key value format for package options (HO)
 ltxcmds.sty    2020-05-10 v1.25 LaTeX kernel commands for general use (HO)
kvsetkeys.sty    2019/12/15 v1.18 Key value parser (HO)
 fvextra.sty    2019/02/04 v1.4 fvextra - extensions and patches for fancyvrb
  ifthen.sty    2022/04/13 v1.1d Standard LaTeX ifthen package (DPC)
etoolbox.sty    2020/10/05 v2.5k e-TeX tools for LaTeX (JAW)
fancyvrb.sty    2022/06/06 4.5 verbatim text (tvz,hv)
 upquote.sty    2012/04/19 v1.3 upright-quote and grave-accent glyphs in verbat
im
textcomp.sty    2020/02/02 v2.0n Standard LaTeX package
  lineno.sty    2005/11/02 line numbers on paragraphs v4.41
    calc.sty    2017/05/25 v4.3 Infix arithmetic (KKT,FJ)
shellesc.sty    2019/11/08 v1.0c unified shell escape interface for LaTeX
ifplatform.sty    2017/10/13 v0.4a Testing for the operating system
pdftexcmds.sty    2020-06-27 v0.33 Utility functions of pdfTeX for LuaTeX (HO)
infwarerr.sty    2019/12/03 v1.5 Providing info/warning/error messages (HO)
   iftex.sty    2022/02/03 v1.0f TeX engine tests
catchfile.sty    2019/12/09 v1.8 Catch the contents of a file (HO)
etexcmds.sty    2019/12/15 v1.7 Avoid name clashes with e-TeX commands (HO)
ifluatex.sty    2019/10/25 v1.5 ifluatex legacy package. Use iftex instead.
    "foo.w18"
 xstring.sty    2021/07/21 v1.84 String manipulations (CT)
  framed.sty    2011/10/22 v 0.96: framed or shaded text with page breaks
   float.sty    2001/11/08 v1.3d Float enhancements (AL)
  xcolor.sty    2022/06/12 v2.14 LaTeX color extensions (UK)
   color.cfg    2016/01/02 v1.6 sample color configuration
  luatex.def    2021/06/01 v1.2c Graphics/color driver for luatex
mathcolor.ltx
l3backend-luatex.def    2022-07-01 L3 backend support: PDF output (LuaTeX)
  ts1cmr.fd    2019/12/16 v2.5j Standard LaTeX font definitions
supp-pdf.mkii
"_minted-foo/default.pygstyle"
_minted-foo/1B1A7A6EA3FF9ABB76AC61E181E436BB2DD7C3DB66FF1642B442757AA646C8DB.py
gtex
 ***********

miticollo avatar Jul 06 '22 07:07 miticollo

No difference.

Does the problem reproducible with other engine on your side, for example pdflatex and xelatex? An other guess is there might be invisible character(s) in your local test file, which can be checked by some unicode conversion tool, for example https://r12a.github.io/app-conversion/.

muzimuzhi avatar Jul 06 '22 07:07 muzimuzhi

It seems that I can break line if I use particular chars:

Special characters given to breakafter should be backslash-escaped (usually #, {,}, %, [, ]; the backslash \ may be obtained via \)

Because if I use d for example

\documentclass{article}

\usepackage{minted}

\begin{document}

\begin{minted}[breaklines, breakafter=d, showspaces, space=~]{text}
 ==== q1 ====
        Utilization of Srv        [0.1453 ± 0.0043 (2.9895% | 20)d 0.0144 ± 0.0004 (2.9798% | 151)]
\end{minted}

\end{document}

No break line is produced. Anyway there is a difference in pygtex file when use \# and {,}

\begin{Verbatim}[commandchars=\\\{\}]
        ==== q1 ====
        Utilization of Srv        [0.1453 ± 0.0043 (2.9895\PYGZpc{} | 20)\PYGZsh{} 0.0144 ± 0.0004 (2.9798\PYGZpc{} | 151)]
\end{Verbatim}

where

\def\PYGZsh{\char`\#}
\begin{Verbatim}[commandchars=\\\{\}]
        ==== q1 ====
        Utilization of Srv        [0.1453 ± 0.0043 (2.9895\PYGZpc{} | 20), 0.0144 ± 0.0004 (2.9798\PYGZpc{} | 151)]
\end{Verbatim}

I don't know if this difference in pygtex is correct.

Moreover I use this version of pygmentize installed on Manjaro

Pygments version 2.12.0, (c) 2006-2022 by Georg Brandl, Matthäus Chajdas and contributors.

miticollo avatar Jul 06 '22 08:07 miticollo

I don't know if this difference in pygtex is correct.

Yes I think the difference is expected. The problem still is, none of Geoffrey, Overleaf.com and I can reproduce your problem.

BTW, what do you get from example below?

\documentclass{article}
\usepackage{fvextra}

\begin{document}

\begin{Verbatim}[breaklines, breakafter={\#}]
        Utilization of Srv [0.1453 ± 0.0043 (2.9895% | 20)# 0.0144 ± 0.0004 (2.9798% | 151)]
\end{Verbatim}

\begin{Verbatim}[breaklines, breakafter={,}]
        Utilization of Srv [0.1453 ± 0.0043 (2.9895% | 20), 0.0144 ± 0.0004 (2.9798% | 151)]
\end{Verbatim}

\begin{Verbatim}[breaklines, breakafter={\#}, showspaces]
        Utilization of Srv [0.1453 ± 0.0043 (2.9895% | 20)# 0.0144 ± 0.0004 (2.9798% | 151)]
\end{Verbatim}

\begin{Verbatim}[breaklines, breakafter={,}, showspaces]
        Utilization of Srv [0.1453 ± 0.0043 (2.9895% | 20), 0.0144 ± 0.0004 (2.9798% | 151)]
\end{Verbatim}

\begin{Verbatim}[breaklines, breakafter={\#}, showspaces, space=~]
        Utilization of Srv [0.1453 ± 0.0043 (2.9895% | 20)# 0.0144 ± 0.0004 (2.9798% | 151)]
\end{Verbatim}

\begin{Verbatim}[breaklines, breakafter={,}, showspaces, space=~]
        Utilization of Srv [0.1453 ± 0.0043 (2.9895% | 20), 0.0144 ± 0.0004 (2.9798% | 151)]
\end{Verbatim}

\end{document}

my result with lualatex image

muzimuzhi avatar Jul 06 '22 11:07 muzimuzhi

latexmk -interaction=nonstopmode -shell-escape -synctex=1 -lualatex ./foo.tex

immagine The same!

miticollo avatar Jul 06 '22 11:07 miticollo