# Equation environment with text at left and right

edit: Is there a way to accomplish the below without using the flalign environment? As I mentioned in my question, I know that it is possible to achieve what I'm asking using the flalign environment. This environment however, cannot be wrapped in a newenvironment and so the solution can't be automated. Does anyone know of another solution method?

My question is simple. I'm trying to create an equation environment that will tag an equation with both custom text and an equation number. The text should be flush left and the equation number flush right. It should look like the following.

(customTxt)                      1 + 1 = 2                                 (1)


The custom text is generated by a complicated command that does some arithmetic with counters. The equation number is just \theequation as usual.

I can certainly accomplish this using e.g. flalign:

\begin{flalign}
\mycommand && 1 + 1 = 2 &&
\end{flalign}


However, I can't seem to wrap this into a newenvironment. This appears to be a known issue about align cf this question or this question. I'm working on a very long document and every equation needs to be marked like this. I'd really like to have some sort of custom equation environment that sets this up for me:

\begin{myEqn}{\mycommand}
1 + 1 = 2
\end{myEqn}


Can anyone offer suggestions? edit How do I define a shortcut or command to do this succinctly? Every time I use this command, the parts

\mycommand && ... &&


will always be the same. Is there any way to automate this? The trouble is that the solution given in the referred-to questions will not work in a \newenvironment command.

• – Steven B. Segletes Dec 2 '16 at 4:59
• @StevenB.Segletes does your stackEngine solution work with equation labels? I want the right equation number to be referred to in e.g. Equation \ref{mylabel} – Austin A. Dec 2 '16 at 5:05
• @AustinA.: See this paste for a solution to your problem (which still uses flalign). – Werner Dec 2 '16 at 8:19
• It should work in the normal way with labels, since it uses the equation environment. Of course, the caveat here is that what is stacked is the text identifier to the left of the equation. If you instead stack multiple equations with the package in an equation environment, you will still only get one equation number per equation environment. – Steven B. Segletes Dec 2 '16 at 11:40

Actually, it is possible to wrap flalign inside a different environment. Below I capture the environment's contents using environ and process it like a macro in two different ways:

\documentclass{article}

\usepackage{amsmath,environ}

\NewEnviron{myEqnA}[1]{%
\begin{flalign}
#1 && \BODY &&
\end{flalign}
}

\newcommand{\mycommand}{%
\text{mycom}% ...or a complicated macro
}

\NewEnviron{myEqnB}[1]{%
$$\makebox[0pt]{\displaystyle \BODY}% Set equation \makebox[0pt][r]{\makebox[.5\linewidth][l]{#1}}% Set custom text (argument)$$
}

\begin{document}

\begin{myEqnA}{\mycommand}
1 + 1 = 2
\end{myEqnA}

\begin{myEqnB}{\mycommand}
1 + 1 = 2
\end{myEqnB}

\end{document}


The differences in horizontal alignment stem from the differences in how the equations are set up. In myEqnB, both the equation and the custom text (argument) are set in zero-width boxes (for ease of alignment).