1

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.

4
  • 1
  • @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, 2016 at 5:05
  • 1
    @AustinA.: See this paste for a solution to your problem (which still uses flalign).
    – Werner
    Dec 2, 2016 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. Dec 2, 2016 at 11:40

1 Answer 1

2

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:

enter image description here

\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]{%
  \begin{equation}
    \makebox[0pt]{$\displaystyle \BODY$}% Set equation
    \makebox[0pt][r]{\makebox[.5\linewidth][l]{#1}}% Set custom text (argument)
  \end{equation}
}

\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).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .