Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tcolorbox 5.1.1 is incompatible with lineno package #183

Closed
FrankMittelbach opened this issue Jun 28, 2022 · 10 comments
Closed

tcolorbox 5.1.1 is incompatible with lineno package #183

FrankMittelbach opened this issue Jun 28, 2022 · 10 comments

Comments

@FrankMittelbach
Copy link

The recent change (fixing #182) breaks if linenumbers are used. Re-enabling autoparskip fixes that, in other words the balanced parskip somehow interferes with lineno and everything breaks if there is a tcolorbox and linenumbers are active. This is a pity because up to now lineno and tcolorbox worked well together (and I made good use of that during copy-editing of TLC).

Here is an example from TLC cut down to show the problem:

\documentclass{article}

\usepackage{lineno,kantlipsum,tcolorbox}

\tcbuselibrary{breakable,skins}

%define all colors as cmyk (gray) or spot:
\definecolor{utf8-bordercolor}{cmyk}{0,0,0,0.12}
\definecolor{utf8-backgroundcolor}{cmyk}{0,0,0,0.07}


\newenvironment{unicodeengine}
               {%
                 \begin{tcolorbox}[beamer,breakable,colback=utf8-backgroundcolor,%
                     colframe=utf8-bordercolor,%
                     parbox=false,top=3pt,bottom=1pt,%
                     colbacktitle=utf8-backgroundcolor,%
                     coltitle=black,%
                     boxed title style = {boxrule=0mm,titlerule=.3mm,toptitle=0.2mm,%
                                          arc=1mm,fonttitle=\mdseries,frame hidden},
                     detach title,
                     title={\tiny\sffamily Unicode engines},
                     attach boxed title to top right={xshift=-5mm,yshift=-1.5mm}%
                   ]%
                 \ignorespaces
               }
               {\par
                \end{tcolorbox}%
               }

\linenumbers

\tcbset{autoparskip}     % was set in v5.1.0, it is removed in v5.1.1 and that kills the document
                         % i.e., the new default breaks lineno

\begin{document}

\kant[1]

\begin{unicodeengine}
some bla bla
\end{unicodeengine}

\kant

\end{document}

All is fine as long as one sets autoparskip. If commented out the first page ends at line 11, the second overprints. (in case of the Companion sources it was worse and looped producing empty pages after pages)

@muzimuzhi
Copy link
Contributor

muzimuzhi commented Jun 28, 2022

A simplified example. It seems the culprits are breakable and \nointerlineskip (set by before skip balanced). Testing with Overleaf shows the problem is reproducible since texlive 2014.

\documentclass{article}
\usepackage{lineno,tcolorbox}
\tcbuselibrary{breakable}

\linenumbers

\begin{document}
before text

\par\nointerlineskip % simulate `before skip balanced`
\begin{tcolorbox}[breakable, nobeforeafter]
  content
\end{tcolorbox}

after text
\end{document}

Update: A further simplified example which is only relevant to lineno:

\documentclass{article}
\usepackage{lineno}

\linenumbers

\begin{document}
before text

% excerpted from `before skip balanced`
\par\nointerlineskip
% excerpted from \tcb@prepare@break@operation
\noindent% applies parskip
\vskip\lineskip
content

after text
\end{document}

Expected: three lines on first page
Actual: first page ends after first line "before text", with lineno 1

@muzimuzhi
Copy link
Contributor

muzimuzhi commented Jun 29, 2022

A random and incomplete1 patch to lineno:

\documentclass{article}
\usepackage{lineno, tcolorbox}
\tcbuselibrary{breakable}

\makeatletter
\def\@LN@depthbox{% 
  % \@tempdima is set to \prevdepth before
  \ifdim\@tempdima>-1000pt\relax
    \dp\@tempboxa=\@tempdima
  \fi
  \nointerlineskip
  \ifdim\@tempdima>-1000pt\relax
    \kern-\@tempdima
  % \else % is this needed?
  %   \kern-\dp\@tempboxa
  \fi
  \box\@tempboxa}
\makeatother

\linenumbers

\begin{document}
before text

\par\nointerlineskip
\noindent
\vskip\lineskip
content

middle text

\begin{tcolorbox}[breakable]
  content
\end{tcolorbox}

after text
\end{document}

image

Footnotes

  1. It's incomplete because value of \prevdepth is used in other places like \internallinenumberpar and bframe env.

@T-F-S
Copy link
Owner

T-F-S commented Jun 29, 2022

Update: A further simplified example which is only relevant to lineno:

\documentclass{article}
\usepackage{lineno}

\linenumbers

\begin{document}
before text

% excerpted from `before skip balanced`
\par\nointerlineskip
% excerpted from \tcb@prepare@break@operation
\noindent% applies parskip
\vskip\lineskip
content

after text
\end{document}

@muzimuzhi Thanks to your analysis this seems to be a lineno problem with \prevdepth resp. \nointerlineskip which sets \prevdepth=-1000pt. As far as I can see, lineno should be corrected in a way as you already proposed in your patch. \nointerlineskip is used at several spots by tcolorbox and presumably by many other packages.

@T-F-S
Copy link
Owner

T-F-S commented Jun 29, 2022

I reported this at latex-lineno/lineno#3, but I am not sure if Karl Wette is able to do the repairs to lineno since the original package authors are deceased or inactive.

@muzimuzhi
Copy link
Contributor

muzimuzhi commented Jun 29, 2022

I reported this at latex-lineno/lineno#3, but I am not sure if Karl Wette is able to do the repairs to lineno since the original package authors are deceased or inactive.

Karl Wette has been a/the new maintainer of lineno since 2021, perhaps shortly after he/she uploaded a new package linenoamsmath to CTAN. See latex3/latex2e#684 (comment). Thus I suppose he/she is active.

@FrankMittelbach
Copy link
Author

guarding against \prevdepth=-1000pt is probably just

\makeatletter
\def\@LN@depthbox{%
  \ifdim\@tempdima = -1000pt
  % \nointerlineskip is already set so we don't need set it again (and we shouldn't back up)
  \else
    \dp\@tempboxa=\@tempdima
    \nointerlineskip \kern-\@tempdima 
  \fi
  \box\@tempboxa
  } 
\makeatother

but I have not looked very hard into the lineno so I may be wrong.

But I think tcolorbox needs looking at as well. If I see, for example, this:

  parskip/.style={before={\ifnum\lastnodetype=-1\relax\else\par%
      \ifvmode\edef\tcb@prevdepth{\the\glueexpr\prevdepth+\lineskip+\parskip}%
      \def\tcb@undo@before{\addvspace{-\glueexpr\tcb@prevdepth}}%
      \pagebreak[0]\fi\fi\noindent},

then \tcb@prevdepthis set unconditionally, even if there was a \nointerlineskip and \prevdepth has its signalling value. Maybe there is some provision that prevdepth can't be -1000pt at this point but if not one can probably construct an example where tcolorbox fails here.

@T-F-S
Copy link
Owner

T-F-S commented Jun 30, 2022

then \tcb@prevdepthis set unconditionally, even if there was a \nointerlineskip and \prevdepth has its signalling value. Maybe there is some provision that prevdepth can't be -1000pt at this point but if not one can probably construct an example where tcolorbox fails here.

Thank you for hinting me to that. I looked into it and I think it is applied only where it cannot not hurt (end of a page with no further content on that page). But I will keep that possible source of problems in mind.

@T-F-S
Copy link
Owner

T-F-S commented Feb 10, 2023

then \tcb@prevdepthis set unconditionally, even if there was a \nointerlineskip and \prevdepth has its signalling value. Maybe there is some provision that prevdepth can't be -1000pt at this point but if not one can probably construct an example where tcolorbox fails here.

Thank you for hinting me to that. I looked into it and I think it is applied only where it cannot not hurt (end of a page with no further content on that page). But I will keep that possible source of problems in mind.

With https://github.com/T-F-S/tcolorbox/releases/tag/v6.0.0 the \prevdepth code was removed, because it created other problems: #200

@T-F-S T-F-S closed this as completed Feb 10, 2023
@muzimuzhi
Copy link
Contributor

The problem persists for breakable tcolorboxes:

\documentclass{article}
\usepackage{lineno}
\usepackage{tcolorbox}
\tcbuselibrary{breakable}

\linenumbers

\begin{document}
text before
\begin{tcolorbox}[breakable]
  content
\end{tcolorbox}
text after
\end{document}

That's because the same pattern is found as shown in the second example in #183 (comment). Applying Frank's patch in #183 (comment) solves the problem, hence it would be resolved by a new lineno release containing the fix for latex-lineno/lineno#3.

@muzimuzhi
Copy link
Contributor

Applying Frank's patch in #183 (comment) solves the problem, hence it would be resolved by a new lineno release containing the fix for latex-lineno/lineno#3.

Should be fixed with lineno v5.3 (2023-05-20), CTAN announcement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants