I am using the solution for nested subequations with alignment (“The subequations environment & the parentequation counter”). I would like to use cleveref package references with groups of subequations defined by \nextParentEquation command, but then I end up with “??” instead of “eq.” prefix.
Does anyone know how could this problem be solved?
MWE and image are below.
\documentclass[a4paper,12pt,abstracton]{scrartcl}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsmath}
\usepackage[hidelinks]{hyperref}
\usepackage{etoolbox}
\let\theparentequation\theequation % let \theparentequation use the same definition as equation
\patchcmd{\theparentequation}{equation}{parentequation}{}{} % change every occurence of "equation" to "parentequation"
\renewenvironment{subequations}[1][]{% optional argument: label-name for (first) parent equation
\refstepcounter{equation}%
% \def\theparentequation{\arabic{parentequation}}% we patched it already
\setcounter{parentequation}{\value{equation}}% parentequation = equation
\setcounter{equation}{0}% (sub)equation = 0
\def\theequation{\theparentequation\alph{equation}}%
\let\parentlabel\label% Evade sanitation performed by amsmath
\ifx\\#1\\\relax\else\label{#1}\fi% #1 given: \label{#1}, otherwise: nothing
\ignorespaces
}{%
\setcounter{equation}{\value{parentequation}}% equation = subequation
\ignorespacesafterend
}
\newcommand*{\nextParentEquation}[1][]{% optional argument: label-name for (first) parent equation
\refstepcounter{parentequation}% parentequation++
\setcounter{equation}{0}% equation = 0
\ifx\\#1\\\relax\else\parentlabel{#1}\fi% #1 given: \label{#1}, otherwise: nothing
}
\usepackage{cleveref}
\setlength\parindent{0pt}
\begin{document}
\section*{Equations:}
\begin{subequations} \label{eq:1}%
Below are two main equations divided into three sub-equations:\\
first:
\begin{align}
0+1 &= 1\text{,} \tag{\ref*{eq:1}} \\
\intertext{second:} \nextParentEquation[eq:2]
100+100 &= 200\text{,} \label{eq:2a} \\
\intertext{and third:}
10000+20000 &= 30000\text{.} \label{eq:2b}
\end{align}
\end{subequations}
\section*{References to equations:}
\texttt{cref}: \cref{eq:1} vs \texttt{ref}: eq.~(\ref{eq:1}).\\
\textbf{\texttt{cref}: \cref{eq:2}} vs \texttt{ref}: eq.~(\ref{eq:2}).\\
\texttt{cref}: \cref{eq:2a} vs \texttt{ref}: eq.~(\ref{eq:2a}).\\
\texttt{cref}: \cref{eq:2b} vs \texttt{ref}: eq.~(\ref{eq:2b}).
\end{document}
