So I've created a new equation-style environment with an associated counter to track a certain set of definitions I introduce in my document:
\newcounter{defcounter}
\newenvironment{defeq}{%
\refstepcounter{defcounter}
\renewcommand\theequation{D.\thedefcounter}
\begin{equation}}
{\end{equation}}
This produces the desired result: a new environment defeq just like equation, but with its own counter and its own label format (e.g., (D.1)).
But occasionally I'll have several definitions in a row and want to use a gather environment to avoid the ugly vertical spacing that results from consecutive equation environments. A slight modification of the above kind of works:
\newenvironment{defgather}{%
\refstepcounter{defcounter}
\renewcommand\theequation{D.\thedefcounter}
\gather}
{\endgather}
However, linebreaking with \\ doesn't seem to step the newly created counter. The following MWE illustrates the issue:
\documentclass{article}
\usepackage{amsmath}
\newcounter{defcounter}
\newenvironment{defeq}{%
\refstepcounter{defcounter}
\renewcommand\theequation{D.\thedefcounter}
\begin{equation}}
{\end{equation}}
\newenvironment{defgather}{%
\refstepcounter{defcounter}
\renewcommand\theequation{D.\thedefcounter}
\gather}
{\endgather}
\begin{document}
\begin{defeq}
1
\end{defeq}
Text text text text.
\begin{defgather}
2 \\
3
\end{defgather}
\end{document}
The lines containing "1" and "2" are appropriately labelled -- (D.1) and (D.2). However, the line containing "3" is labelled (D.2) indicating that the \\ hasn't stepped defcounter as the default gather does with the equation counter.
How can I fix my new gather environment so that \\ steps the new counter?

equationcounter is stepped with everydefeqas well. Is this the expected behaviour? That is, if you put anequationbefore and after everything, you'll have a numbering 1, D.1, D.2, D.2, 5. – Werner Jul 24 '15 at 05:11