\hfill in math mode
You can do it, but not with \hfill
, because of how align
works. Here's a way:
\documentclass{article}
\usepackage{amsmath}
\makeatletter
\newcommand{\pushright}[1]{\ifmeasuring@#1\else\omit\hfill$\displaystyle#1$\fi\ignorespaces}
\newcommand{\pushleft}[1]{\ifmeasuring@#1\else\omit$\displaystyle#1$\hfill\fi\ignorespaces}
\makeatother
\begin{document}
\begin{align*}
a + b + c &= a + b + c + d + e + f + g + h + i \\
& \pushright{\text{(foo)}}
\end{align*}
\begin{align*}
a + b + c + d + e + f + g + h + i &= a + b + c \\
\pushleft{\text{(foo)}} &
\end{align*}
\end{document}
A slightly different implementation allows you to use \hfill
where you want:
\documentclass{article}
\usepackage{amsmath}
\makeatletter
\newcommand{\specialcell}[1]{\ifmeasuring@#1\else\omit$\displaystyle#1$\ignorespaces\fi}
\makeatother
\begin{document}
\begin{align*}
a + b + c &= a + b + c + d + e + f + g + h + i \\
& \specialcell{\hfill\text{(foo)}}
\end{align*}
\begin{align*}
a + b + c + d + e + f + g + h + i &= a + b + c \\
\specialcell{\text{(foo)}\hfill} \\
\specialcell{\hfill\text{(foo)}\hfill}
\end{align*}
\end{document}
I'd recommend against using the simple \omit
.
In align you can use \omit
at the start of cells:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
a + b + c &= a + b + c + d + e + f + g + h + i \\
&\omit\hfill foo\\
a&=b\\
\omit text & =c \\
\omit\hfill text&=d
\end{align*}
\end{document}
The most obvious answer is \hfill
as demonstrated by this plain TeX file
$a\hfill b$
\bye