Compute remaining horizontal space in align environment
takes a couple of runs:
\documentclass{article}
\usepackage{showframe}
\usepackage[fleqn]{amsmath}
\newcommand*{\RubbishText}{This was obvious once it was determind that the earlier versions $E = mc$ and $E = mc^3$ were not quite accurate.}%
\makeatletter
\newcount\zzz
\def\foo{%
\global\advance\zzz\@ne
\ifmeasuring@
\else
\expandafter\ifx\csname zz\romannumeral\zzz\endcsname\relax
\else
\edef\RemainingSpace{\the\dimexpr 30000000sp -
\csname zz\romannumeral\zzz\endcsname sp\relax}%
\typeout{\the\zzz: \RemainingSpace}%
\fi
\pdfsavepos
\edef\tmp{\write\@auxout{%
\gdef\noexpand\noexpand\expandafter\noexpand
\csname zz\romannumeral\zzz\endcsname{\noexpand\the\pdflastxpos}}}
\tmp
\fi
}
\makeatother
\newcommand*{\RemainingSpace}{9.0cm}%
\begin{document}\noindent
First using \verb|align*| with a \verb|\quad| for spacing:
\begin{align*}
E &= mc^2 \quad\foo\parbox[t]{\RemainingSpace}{\RubbishText}\\
F &= ma + \sin^2 x + cos^2 x - 1.
\end{align*}
Or could use \verb|&&| for spacing (but less important than the above version):
\begin{align*}
E &= mc^2 &&\foo\parbox[t]{\RemainingSpace}{\RubbishText}\\
F &= ma + \sin^2 x + cos^2 x - 1
\end{align*}
Or, using \verb|alignat*|
\begin{alignat*}{2}
E &= mc^2 \quad\foo\parbox[t]{\RemainingSpace}{\RubbishText}\\
F &= ma + \sin^2 x + cos^2 x - 1
\end{alignat*}
\end{document}
The package linegoal
and its \linegoal
macro produce —after two compilations—the correct output. But they throws errors and warnings, probably due to how amsmath
’s environments process their contents.
egreg saved me from going through answers and code and provided the \ifmeasuring@
conditional from amsmath
.
I have defined a \Note
macro that hides the text from the measuring.
Sadly, this does not work for the &&
version of align*
as amsmath
needs to know the width to align the columns correctly.
I have therefore provided a starred version of \Note
that does the same as before, still producing warnings and errors.
Note that I have included the \quad
in the un-starred version of \Note
.
Code
\documentclass{article}
\usepackage{showframe}
\usepackage{linegoal}
\usepackage[fleqn]{amsmath}
\newcommand*{\RubbishText}{This was obvious once it was determind that the earlier versions $E = mc$ and $E = mc^3$ were not quite accurate.}%
\makeatletter
\newcommand*{\Note}{\@ifstar\s@Note\@Note}
\newcommand*{\@Note}[1]{\ifmeasuring@\else\quad\parbox[t]{\linegoal}{#1}\fi}
\newcommand*{\s@Note}[1]{\parbox[t]{\linegoal}{#1}}
\makeatother
\begin{document}\noindent
First using \verb|align*| with a \verb|\quad| for spacing:
\begin{align*}
E &= mc^2 \Note{\RubbishText} \\
F &= ma + \sin^2 x + cos^2 x - 1.
\end{align*}
Or could use \verb|&&| for spacing (but less important than the above version):
\begin{align*}
E &= mc^2 & \Note*{\RubbishText}\\
F &= ma + \sin^2 x + cos^2 x - 1
\end{align*}
Or, using \verb|alignat*|
\begin{alignat*}{2}
E &= mc^2 \Note{\RubbishText} \\
F &= ma + \sin^2 x + cos^2 x - 1
\end{alignat*}
\end{document}