latex-lineno / lineno

lineno – Line numbers on paragraphs
Other
11 stars 2 forks source link

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

Closed T-F-S closed 1 year ago

T-F-S commented 2 years ago

In https://github.com/T-F-S/tcolorbox/issues/183 a problem in interaction between tcolorbox and lineno was reported.

The problem is nailed down to a \prevdepth problem with lineno in https://github.com/T-F-S/tcolorbox/issues/183#issuecomment-1169385556:

\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 https://github.com/T-F-S/tcolorbox/issues/183#issuecomment-1169406409

kwwette commented 1 year ago

@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 commented 1 year ago

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

muzimuzhi commented 1 year ago

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
https://github.com/T-F-S/tcolorbox/issues/183#issuecomment-1169406409
Frank's patch
https://github.com/T-F-S/tcolorbox/issues/183#issuecomment-1169682868
image image image image
Full example

```tex \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 commented 1 year ago

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 commented 1 year ago

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

```tex \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 commented 1 year ago

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 commented 1 year ago

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

muzimuzhi commented 1 year ago

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.