# \linegoal: its use in the second column of the two column document doesn't work correctly

This is the following-up question to interesting @Bernard answer. For some reason I test his interesting solution, how it works if i repeat the same equation four times:

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

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
\lipsum[1]
\begin{aligned} NUP_S & =1- \rlap{\parbox[t]{\linegoal}{probability of successfully finishing an SU service}}\\[0.5ex] & = 1 - \frac{\lambda_S(1-P^{BL}_S)(1-P^{FT}_S)}{\lambda_S}\\ & = P^{BL}_S + P^{FT}_S + P^{BL}_S P^{FT}_S\\ NUP_S & = P^{BL}_S + P^{FT}_S - P^{BL}_S P^{FT}_S \end{aligned}
\lipsum[2]
\begin{aligned} NUP_S & =1- \rlap{\parbox[t]{\linegoal}{probability of successfully finishing an SU service}}\\[0.5ex] & = 1 - \frac{\lambda_S(1-P^{BL}_S)(1-P^{FT}_S)}{\lambda_S}\\ & = P^{BL}_S + P^{FT}_S + P^{BL}_S P^{FT}_S\\ NUP_S & = P^{BL}_S + P^{FT}_S - P^{BL}_S P^{FT}_S \end{aligned}
\lipsum[3]
\begin{aligned} NUP_S & =1- \rlap{\parbox[t]{\linegoal}{probability of successfully finishing an SU service}}\\[0.5ex] & = 1 - \frac{\lambda_S(1-P^{BL}_S)(1-P^{FT}_S)}{\lambda_S}\\ & = P^{BL}_S + P^{FT}_S + P^{BL}_S P^{FT}_S\\ NUP_S & = P^{BL}_S + P^{FT}_S - P^{BL}_S P^{FT}_S \end{aligned}
\lipsum[4-5]
\begin{aligned} NUP_S & =1- \rlap{\parbox[t]{\linegoal}{probability of successfully finishing an SU service}}\\[0.5ex] & = 1 - \frac{\lambda_S(1-P^{BL}_S)(1-P^{FT}_S)}{\lambda_S}\\ & = P^{BL}_S + P^{FT}_S + P^{BL}_S P^{FT}_S\\ NUP_S & = P^{BL}_S + P^{FT}_S - P^{BL}_S P^{FT}_S \end{aligned}
\lipsum[6]
\end{document}


Edited:

To my surprise, the results of equation code (after two compilation) are not the same as expected. Each equation in the second column on the page has different formatted text:

I wonder, do I overlooked something in my test or the reasons is in some difference in used LaTeX installation. I use 64-bit MikTeX, upgraded yesterday.

• The fact that the equation is doubled is irrelevant. The problem seems to be in that the second equation is in the right column. If I remove the first display and substitute it with a \lipsum paragraph, the output is similar to yours. – egreg Apr 9 '19 at 22:49
• I tested it also with multicol instead of twocolumn and the problem is the same. – egreg Apr 9 '19 at 22:55
• @egreg, you are right. do i change question title in mwe accordingly (that they will better describe the problem)? – Zarko Apr 10 '19 at 4:25
• I think you should. – egreg Apr 10 '19 at 8:44
• In the meantime, I added a \the to the code that simplifies what's written in the .aux file. – egreg Apr 10 '19 at 8:54

The code

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

\begin{document}

aaaa\the\linegoal

\vfill\pagebreak

aaaa\the\linegoal

\end{document}


outputs aaaa147.27754pt in the first column and aaaa-90.55577pt in the second one. The problem is that the position is computed in the same way for both columns.

A patch that works for your case (but that's admittedly not fully general): if the linegoal turns out to be negative, we add \columnwidth+\columnsep.

In the case above I get aaaa147.27754pt in both cases. With your example

\documentclass[twocolumn]{article}
\usepackage{amsmath}
\usepackage{linegoal}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}

\makeatletter
\let\Z@E@linegoal\relax % undefine the property
\zref@newprop*{linegoal}[\linewidth]{%
\the\dimexpr
\ifdim\dimexpr
\linewidth -\the\pdflastxpos sp
+\ifodd\zref@extractdefault{linegoal/posx.\the\LNGL@unique}{page}\c@page
\oddsidemargin
\else\evensidemargin
\fi
+1in+\hoffset\relax<0pt
\columnwidth+\columnsep+\fi
\linewidth -\the\pdflastxpos sp
+\ifodd\zref@extractdefault{linegoal/posx.\the\LNGL@unique}{page}\c@page
\oddsidemargin
\else\evensidemargin
\fi
+1in+\hoffset
\relax
}% linegoal zref-property
\makeatother

\begin{document}
\lipsum[1]
\begin{aligned} NUP_S & =1- \rlap{\parbox[t]{\linegoal}{probability of successfully finishing an SU service}}\\[1ex] & = 1 - \frac{\lambda_S(1-P^{BL}_S)(1-P^{FT}_S)}{\lambda_S}\\ & = P^{BL}_S + P^{FT}_S + P^{BL}_S P^{FT}_S\\ NUP_S & = P^{BL}_S + P^{FT}_S - P^{BL}_S P^{FT}_S \end{aligned}
\lipsum[2-3]
\begin{aligned} NUP_S & =1- \rlap{\parbox[t]{\linegoal}{probability of successfully finishing an SU service}}\\[1ex] & = 1 - \frac{\lambda_S(1-P^{BL}_S)(1-P^{FT}_S)}{\lambda_S}\\ & = P^{BL}_S + P^{FT}_S + P^{BL}_S P^{FT}_S\\ NUP_S & = P^{BL}_S + P^{FT}_S - P^{BL}_S P^{FT}_S \end{aligned}
\lipsum[4-5]
\end{document}


we get