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

Lineno breaks/hides content, if \nointerlineskip is used. #3

Closed
T-F-S opened this issue Jun 29, 2022 · 8 comments
Closed

Lineno breaks/hides content, if \nointerlineskip is used. #3

T-F-S opened this issue Jun 29, 2022 · 8 comments

Comments

@T-F-S
Copy link

T-F-S commented Jun 29, 2022

In T-F-S/tcolorbox#183 a problem in interaction between tcolorbox and lineno was reported.

The problem is nailed down to a \prevdepth problem with lineno in T-F-S/tcolorbox#183 (comment):

\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}

Also, an incomplete patch for lineno is provided in T-F-S/tcolorbox#183 (comment)

@kwwette
Copy link
Contributor

kwwette commented Nov 29, 2022

@T-F-S Thanks for reporting this. I don't understand the lineno code well enough to know how to fix this, but I'd be happy to accept a complete patch if you have one.

@kwwette
Copy link
Contributor

kwwette commented May 18, 2023

Closing this issue as I believe this has been resolved by T-F-S/tcolorbox#183; if that's not correct please let me know.

@kwwette kwwette closed this as completed May 18, 2023
@muzimuzhi
Copy link
Contributor

This is issue is reproducible without tcolorbox. It's really about handling a special value of \prevdepth (-1000pt) set by \nointerlineskip.

Default Using \linenumbers My attempt
T-F-S/tcolorbox#183 (comment)
Frank's patch
T-F-S/tcolorbox#183 (comment)
image image image image
Full example

\documentclass{article}
\usepackage{lineno}
\usepackage{multicol}

\makeatletter
\def\muzimuzhiPATCH{%
  \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}}

\def\FrankPATCH{%
  \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


\begin{document}

\def\testWithPrevdepth#1{{%
  \noindent\texttt{\UseName{str_if_empty:nTF}{#1}{default}{\detokenize{#1}}}\par
  before text\par
  #1%
  \noindent\vskip0pt % any vskip triggers the problem
  content\par
  after text\par}\medskip}

\def\tests#1{{#1%
  \testWithPrevdepth{}
  \testWithPrevdepth{\prevdepth=10pt}
  \testWithPrevdepth{\prevdepth=-10pt}
  \testWithPrevdepth{\prevdepth=-100pt}
  \testWithPrevdepth{\prevdepth=-1000pt}
  \newpage
}}

\tests{}
\tests{\linenumbers}
\tests{\linenumbers\muzimuzhiPATCH}
\tests{\linenumbers\FrankPATCH}

\end{document}

kwwette added a commit that referenced this issue May 19, 2023
@kwwette kwwette reopened this May 19, 2023
@kwwette
Copy link
Contributor

kwwette commented May 19, 2023

Thanks @muzimuzhi for the examples. I've applied Frank's patch to lineno.sty. Could you please confirm that this version of lineno.sty fixes the issue and behaves as you expect?

@muzimuzhi
Copy link
Contributor

Just one concern: the inter-line skip is actually altered by \linenumbers. Is this OK?
image

If that's OK, then here's a similar patch for \internallinenumberpar (used by user command \internallinenumbers) and bframe env:

diff --git a/lineno.sty b/lineno.sty
index 9fb0be8..1107b4c 100644
--- a/lineno.sty
+++ b/lineno.sty
@@ -2725,10 +2725,14 @@ Macro file lineno.sty for LaTeX: attach line numbers, refer to them.
      \begingroup
         \c@internallinenumbers\prevgraf
         \setbox\@tempboxa\hbox{\vbox{\makeinternalLinenumbers}}%
-        \dp\@tempboxa\prevdepth
         \ht\@tempboxa\z@
-        \nobreak\vskip-\prevdepth
-        \nointerlineskip\box\@tempboxa
+        \ifdim\prevdepth=-1000pt
+        \else
+          \dp\@tempboxa\prevdepth
+          \nobreak\vskip-\prevdepth
+          \nointerlineskip
+        \fi
+        \box\@tempboxa
      \endgroup
      \fi\fi
      }
@@ -2866,7 +2870,9 @@ Macro file lineno.sty for LaTeX: attach line numbers, refer to them.
    \def\makeLineNumber{\copy\bframebox\hss}%
   }
   {\par
-   \kern-\prevdepth
+   \ifdim\prevdepth=-1000pt \else
+     \kern-\prevdepth
+   \fi
    \kern\bframesep
    \nointerlineskip
    \@tempdima\textwidth
Default Using \linenumbers
+ Frank's patch extended
image
On next column/page
image
On third column/page
image
image
Full example, v2

\documentclass[twocolumn]{article}
\usepackage{lineno}

\makeatletter
\def\FrankPATCH{%
  \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}%
  \renewcommand\internallinenumberpar{%
    \ifvmode\@@@par\else\ifinner\@@@par\else\@@@par
    \begingroup
    \c@internallinenumbers\prevgraf
    \setbox\@tempboxa\hbox{\vbox{\makeinternalLinenumbers}}%
    \ht\@tempboxa\z@
    \ifdim\prevdepth=-1000pt
    \else
      \dp\@tempboxa\prevdepth
      \nobreak\vskip-\prevdepth
      \nointerlineskip
    \fi
    \box\@tempboxa
    \endgroup
    \fi\fi
  }
  \renewcommand\endbframe{%
    \par
    \ifdim\prevdepth=-1000pt \else
      \kern-\prevdepth
    \fi
    \kern\bframesep
    \nointerlineskip
    % \textwidth is proposed to be replaced with \columnwidth in
    %   https://github.com/latex-lineno/lineno/pull/8
    \@tempdima\textwidth
    \advance\@tempdima 2\bframesep
    \hbox{\hskip-\bframesep
         \vrule\@width\@tempdima\@height\bframerule\@depth\z@}%
  }
}
\makeatother

% just tweak
% see full fix in https://github.com/latex-lineno/lineno/pull/8
\AtBeginDocument{%
  \textwidth=\dimexpr\columnwidth-10pt
}

\raggedbottom

\begin{document}

\def\testWithPrevdepth#1{{%
  \noindent\texttt{\UseName{str_if_empty:nTF}{#1}{default}{\detokenize{#1}}}\par

  before text\par
  #1%
  \noindent\vskip0pt % any vskip triggers the problem
  content\par
  after text\par}}

\def\tests#1{{#1%
  \testWithPrevdepth{}
%  \testWithPrevdepth{\prevdepth=10pt}
  \testWithPrevdepth{\prevdepth=-10pt}
%  \testWithPrevdepth{\prevdepth=-100pt}
  \testWithPrevdepth{\prevdepth=-1000pt}
  \begin{center}
    \UseName{tl_if_in:nnT}{#1}{\linenumbers}{\internallinenumbers}%
    \testWithPrevdepth{}
  \end{center}
  \begin{center}
    \UseName{tl_if_in:nnT}{#1}{\linenumbers}{\internallinenumbers}%
    \testWithPrevdepth{\prevdepth=-10pt}
  \end{center}
  \begin{center}
    \UseName{tl_if_in:nnT}{#1}{\linenumbers}{\internallinenumbers}%
    \testWithPrevdepth{\prevdepth=-1000pt}
  \end{center}
  \begin{bframe}
    foo\par
    \nointerlineskip
  \end{bframe}
  \begin{bframe}
    \testWithPrevdepth{\prevdepth=-1000pt}
  \end{bframe}
  \newpage
}}

\tests{\linenumbers\FrankPATCH}
\tests{}

\end{document}

kwwette added a commit that referenced this issue May 19, 2023
@kwwette
Copy link
Contributor

kwwette commented May 19, 2023

Thanks again @muzimuzhi I've applied the additional patches. Can you please check the latest version of lineno.sty is working correctly?

I couldn't work out how to remove the extra inter-line skip. It's probably fine as is, so I may leave it for now.

@kwwette
Copy link
Contributor

kwwette commented May 20, 2023

I've submitted a new release of linono (v5.3) to CTAN with these changes.

@kwwette kwwette closed this as completed May 20, 2023
@muzimuzhi
Copy link
Contributor

Ignoring the restored inter-line skip, I can confirm lineno v5.3 works correctly. Thank you for this update and sorry for my late response.

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