This is a followup to an old thread

hfill in math mode

I'm starting a new one because it's hard to write all this in a comment. In the original thread, @egreg proposed the following commands


as a way to obtain the effect of \hfill within an align environment. The first pushes text to the right, the second to the left, of the line.

I've been trying to modify these command, and am getting inconsistent results. To avoid &\pushright{\text{foo}} I would like to put the text and the atsign in the macro, then just say, for example, \rightPush{foo}. I've succeeded to construct \rightPush, but for some baffling reason, the analog \leftPush doesn't work. Here are my two macros.

\def\rightPush#1{& \ifmeasuring@#1\else\omit\hfill$\displaystyle\text{#1}$\fi\ignorespaces}
\def\leftPush#1{\ifmeasuring@#1\else\omit$\displaystyle\text{#1}$\hfill & \fi\ignorespaces}

I'd be happy to leave the & out of the macro, but that doesn't help: the \text in the \leftPush is what generates the errors (though not in the \rightPush). As a followup question, if somebody could explain what the \ifmeasuring@ and omit are doing in this macro, I'd really appreciate it.

Thanks very much for any advice

  • Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. Otherwise it is difficult to figure out how precisely you are using \leftPush and \rightPush.
    – jarauh
    Oct 28 '15 at 15:34

No test file is provided but at the very least

\def\leftPush#1{\ifmeasuring@#1\else\omit$\displaystyle\text{#1}$\hfill & \fi\ignorespaces}

should be

\def\leftPush#1{\ifmeasuring@#1\else\omit$\displaystyle\text{#1}$\hfill \fi&\ignorespaces}

so that as for \rightPush you get a & whether \ifmeasuring@ is true or false.

AMS alignments are always executed twice, the first "measuring" pass does not typeset anything but just measures the size of the cell entries which determines some parameters that are set before the second typesetting pass. \ifmeasuring@ is true just on the first execution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.