# LaTeX locally change equation numbering

I want my document to look like this:

Normal document text.

equation (1)

Definition Definition text.

equation (D1)

More definition text.

Normal document text.

equation (2)

More document text.

So the numbering changes inside the definition, and remains unaltered outside the definition.

If you only want a temporary change, use the \tag command, loaded by the amsmath package. Here's the code:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

Equation the first, normally numbered.
$$a=b+c$$

A special equation.
$$\tag{D1} d=e+f$$

A second, normally numbered equation.
$$g=h+i$$

\end{document}


If you use \label to reference the equations later, \tag doesn't have to have the same argument as \label. This is the result:

You can define a new environment.

\newcounter{defcounter}
\setcounter{defcounter}{0}

.
.
.

\newenvironment{myequation}{%
\refstepcounter{defcounter}
\renewcommand\theequation{D\thedefcounter}
$$} {$$}


And use it like

\begin{myequation}\label{myeq:one}
a = b
\end{myequation}


You can use it any where and you get D1, D2 etc as the equation number.

Full code:

\documentclass{article}
\newcounter{defcounter}
\setcounter{defcounter}{0}

\usepackage{amsthm}
\newtheorem{defn}{Definition}

\newenvironment{myequation}{%
\refstepcounter{defcounter}
\renewcommand\theequation{D\thedefcounter}
$$} {$$}
%
\begin{document}
Bbla bla
$$x = y$$
\begin{defn}
bla bla
\begin{myequation}\label{myeq:one}
a = b
\end{myequation}
\begin{myequation}
a = b
\end{myequation}
\end{defn}
bla bla
$$\label{eq:one} x = yz$$
\begin{myequation}
a = b
\end{myequation}

From equation~\ref{myeq:one} and~\ref{eq:one}...
\end{document}


I'm not really sure if one would want to do this, but with the following implementation it will be easy to revert to a unique numbering scheme. The equation counter is changed inside the defn environment, so there's no need to change the coding style.

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}

\usepackage{hyperref} % just to show it works also with it

\theoremstyle{definition}
\newtheorem{defninn}{Definition}

\newcounter{defcounter}

\makeatletter
\newenvironment{defn}
{\global\chardef\dc@currentequation=\value{equation}%
\let\c@equation\c@defcounter
\renewcommand{\theequation}{D\arabic{equation}}%
% comment the following line if you don't use hyperref
\renewcommand{\theHequation}{D\arabic{equation}}%
\defninn}
{\enddefninn
\setcounter{equation}{\dc@currentequation}}
\makeatother

\begin{document}

Bla bla
$$x = y$$

\begin{defn}
bla bla
$$\label{eq:one} a = b$$
\end{defn}

Bla bla
$$a = b \label{eq:two}$$

\begin{defn}
bla bla
\begin{gather}
x = yz \label{eq:ga} \\
a = b \label{eq:gb}
\end{gather}
\end{defn}

Bla bla
$$1=1$$

From equations \eqref{eq:one}~and~\eqref{eq:two} or
from equation~\eqref{eq:ga}, we deduce something.

\end{document}