The tag for the custom environment housing an equation is not placing the tag flush right. I may not have the right search terms because I am not finding the solution for this issue. Here is my MWE:
\documentclass{article}
\usepackage{mathtools}
% PRB: Tag placement on a line does not position flush right.
\newcounter{derivativeFormula}
\renewcommand*{\thederivativeFormula}{\textsc{df}\arabic{derivativeFormula}}
\usepackage{zref-savepos}
\makeatletter
\newenvironment{DerivativeFormula}{ %
\def\equation{$$\refstepcounter{derivativeFormula}} % order
\def\@eqnnum{{\normalfont \normalcolor \thederivativeFormula}}% is
\equation % important!
}{ %
\@gobble %
\print@eqnum{(\thederivativeFormula)} %
\endequation %
}
\makeatother
\begin{document}
A regular equation which should be reference (1).
\begin{equation}\label{eqn:testA}
\frac{dx}{dx} = 1
\end{equation}
A regular equation which should be reference (2).
\begin{equation}\label{eqn:testB}
\frac{d(u+v)}{dx} = \frac{du}{dx}+\frac{dv}{dx}
\end{equation}
This is the \texttt{DerivativeFormula} environment. I want the tag
to be flush right. It should read (DF1) but way that way -->.
\begin{DerivativeFormula}\label{eqn:testC}
\frac{d(uv)}{dx} = u\frac{du}{dx} + v\frac{du}{dx}
\end{DerivativeFormula}
Another plain equation to check numbering and reference (3).
\begin{equation}\label{eqn:testD}
\frac{du^n}{dx} = nu^{n-1}\frac{du}{dx}
\end{equation}
The values of the references are, in order,
\eqref{eqn:testA}, \eqref{eqn:testB}, \eqref{eqn:testC}, \eqref{eqn:testD}.
\end{document}


mathtoolsloadsamsmath, there is no reason that\tagcannot be used; if you find otherwise, it's a bug and should be reported as such. – barbara beeton Mar 15 '18 at 17:26