# Subsections separated in different sections with same main numbering

The problem is I want to place a set of equations in different section in the article, and label them with same main number in \subequations environments.

As I found in relevant questions, I can put the text in \intertext block in math mode to get a subequations separated by text labeled with the same main number.

But if I have an equations, for example

a=b (2a)
b=c (2b)
c=d (2c)
d=e (2d)


I write (2a), (2b) in one section. And then I write some other equations with label like (3), (4). And finaly I put the (2c), (2d) in the next section. So what can I do to make sure c=d and d=e in the next section with main numbering (2) and subequation numbering (2c), (2d) instead of (5a) and (5b)?

\section{A}
Text Text
\begin{subequations}
\begin{align)
a &= b \\ % want to labeled by (2a)
b &= c \\ % want to labeled by (2c)
\end{align}
\end{subequations}

Text Text
$$3=3 % labeled by (3)$$

Text Text
$$4=4 % labeled by (4)$$

Text Text

\section{B}
Text Text
\begin{subequations}
\begin{align}
c &= d \\ % want to labeled by (2c)
d &= e \\ % want to labeled by (2d)
\end{align}
\end{subequations}


Or if there is other solution than subequations ?

Here's a solution involving a new environment. Whenever you plan to have split subequation numbering, use longsubequation with an argument that can be

label=<string>


or

continue=<string>


The syntax should be obvious. The <string> can also be used in \ref or \eqref in order to refer to the global equation number.

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentEnvironment{longsubequations}{m}
{
\keys_set:nn { wutuku/subeqn } { #1 }
\bool_if:NT \l__wutuku_subeqn_continue_bool
{
\tl_gset:Nx \g__wutuku_subeqn_save_tl { \the\value{equation} }
\setcounter{equation}{ \tl_use:c { g__wutuku_subeqn_eqn_ \l__wutuku_subeqn_label_tl _tl } }
}
\begin{subequations}
\bool_if:NTF \l__wutuku_subeqn_continue_bool
{
\setcounter{equation}{ \tl_use:c { g__wutuku_subeqn_subeqn_ \l__wutuku_subeqn_label_tl _tl } }
}
{
\label{ \l__wutuku_subeqn_label_tl }
}
}
{
\tl_gset:cx { g__wutuku_subeqn_subeqn_ \l__wutuku_subeqn_label_tl _tl } { \the\value{equation} }
\end{subequations}
\bool_if:NTF \l__wutuku_subeqn_continue_bool
{
\setcounter{equation}{ \tl_use:N \g__wutuku_subeqn_save_tl }
}
{
\tl_gset:cx { g__wutuku_subeqn_eqn_ \l__wutuku_subeqn_label_tl _tl } { \the\value{equation} }
}
}

\keys_define:nn { wutuku/subeqn }
{
label .code:n =
{
\tl_set:Nn \l__wutuku_subeqn_label_tl { #1 }
\tl_new:c { g__wutuku_subeqn_eqn_#1_tl }
\tl_new:c { g__wutuku_subeqn_subeqn_#1_tl }
},
continue .code:n =
{
\tl_set:Nn \l__wutuku_subeqn_label_tl { #1 }
\bool_set_true:N \l__wutuku_subeqn_continue_bool
},
}
\bool_new:N \l__wutuku_subeqn_continue_bool
\tl_new:N \g__wutuku_subeqn_save_tl
\ExplSyntaxOff

\begin{document}

\section{A}
Text Text
$$1=1 \label{eq:1}$$

Text Text
\begin{longsubequations}{label=foo}
\begin{align}
a &= b \label{eq:2a} \\
b &= c \label{eq:2b}
\end{align}
\end{longsubequations}

Text Text
$$3=3 \label{eq:3}$$

Text Text
$$4=4 \label{eq:4}$$

Text Text

\section{B}
Text Text
\begin{longsubequations}{continue=foo}
\begin{align}
c &= d \label{eq:2c} \\
d &= e \label{eq:2d}
\end{align}
\end{longsubequations}

Text Text
$$5=5 \label{5}$$

Text Text
\begin{longsubequations}{continue=foo}
\begin{align}
c &= d \label{eq:2e} \\
d &= e \label{eq:2f}
\end{align}
\end{longsubequations}

Text Text
$$6=6 \label{6}$$

\eqref{foo} should be 2

\eqref{eq:1} \eqref{eq:2a} \eqref{eq:2e}

\clearpage

\section{C}
Text Text
$$1=1$$

Text Text
\begin{longsubequations}{label=baz}
\begin{align}
a &= b \\
b &= c
\end{align}
\end{longsubequations}

Text Text
$$3=3$$

Text Text
$$4=4$$

Text Text

\section{D}
Text Text
\begin{longsubequations}{continue=baz}
\begin{align}
c &= d \\
d &= e
\end{align}
\end{longsubequations}

Text Text
$$5=5$$

Text Text
\begin{longsubequations}{continue=foo}
\begin{align}
c &= d \\
d &= e
\end{align}
\end{longsubequations}

Text Text
$$6=6$$

\end{document}


As you see from the example, longsubequations can even be intertwined.

If you want to change the automatic equation numbering you can manually set the equation and subequation counters. The subequations environment internally copies the current equation number into a variable and uses the main counter as subcounter. Therefore, changing the main counter outside a subequations environment changes the equation number, and changing the main counter inside the environment changes the subequation number. The environment will increase both counters, so set to the number you want minus 1.

Note that you should reset the counter afterwards to resume numbering in the document. In the MWE below the previous value is stored in a temporary counter, therefore it does not matter how many equations are in between.

EDIT In line with @egreg's answer a bit more automation, where the counters that need to be continued are stored as well, so you don't have to set the number manually. Note that for this approach you can only save a single set of counters - however you can introduce additional counters if you want to continue different sets of equations.

MWE:

\documentclass{article}
\usepackage{amsmath}
\newcounter{tmpcount} % temporary counters
\newcounter{continuemain}
\newcounter{continuesub}

\begin{document}
$$1=1 % labeled by (1)$$

\setcounter{continuemain}{\value{equation}}
\begin{subequations}
\begin{align}
a &= b \\ % want to labeled by (2a)
b &= c % want to labeled by (2c)
\end{align}
\setcounter{continuesub}{\value{equation}}
\end{subequations}
$$3=3 % labeled by (3)$$
$$4=4 % labeled by (4)$$

% store current equation counter
\setcounter{tmpcount}{\value{equation}}
% set main equation counter
\setcounter{equation}{\value{continuemain}}
\begin{subequations}
% set subequation counter
\setcounter{equation}{\value{continuesub}}
\begin{align}
c &= d \\ % want to labeled by (2c)
d &= e % want to labeled by (2d)
\end{align}
% update sub-counter for continuation in next set of subequations
\setcounter{continuesub}{\value{equation}}
\end{subequations}
% reset equation counter to previous value
\setcounter{equation}{\value{tmpcount}}
$$5=5 % labeled by (5)$$
\end{document}


Result: