# How to change the sub-tags of Equations and the cross-references accordingly?

I am trying to modify the following labels for the letters to be capital letters. I also need the cross-references (using cleverref) to match the newly defined style. There are several related questions, but I couldn't mix up all the knowledge out there to come up with what I need. There goes a MWE:

\documentclass{article}
\usepackage{mathtools, amsthm, amssymb} % MATH PACKAGES
\usepackage{cleveref} % FOR FANCY REFERENCES

\begin{document}
Look what a fancy optimisation problem in \cref{p} subject to \cref{c1,c2}, folks!
\begin{subequations}
\begin{alignat}{2}\label{p}
& \max_{L,\mathbf{x}} & & v(L) - \sum_{i \in L} \delta \cdot x_i\\\label{c1}
& \text{subject to} &\quad & \mathbf{x} \in \mathfrak{C}(\mathfrak{L},v)\\\label{c2}
& & & x_i \geqslant \delta \cdot x_i^{*} \forall \text{ Players }i\in N \text{ such that } \omega_i < \omega_j
\end{alignat}
\end{subequations}

\end{document}


There goes the current output:

What I need are letters A, B and C in capital form everywhere.

I think this does what you want. The {subequations} environment hardcodes the behavior that says that subequations should be written as lowercase letters \alph{equation}. This uses \patchcmd from the etoolbox package to replace \alph{equation} with a handle \thechildequation which you can define as you like.

This patching must be done before loading the cleverref package because cleverref defines it's own wrapper around the original {subequations} environment so it can add its own handling (it moves the original \subequations into \cref@old@subequations).

\documentclass{article}
\usepackage{mathtools, amsthm, amssymb} % MATH PACKAGES
\usepackage{etoolbox}
\usepackage{cleveref} % FOR FANCY REFERENCES
\newcommand*{\thechildequation}{\Alph{equation}}
\begin{document}
Look what a fancy optimisation problem in \cref{p} subject to \cref{c1,c2}, folks!
\begin{subequations}
\begin{alignat}{2}\label{p}
& \max_{L,\mathbf{x}} & & v(L) - \sum_{i \in L} \delta \cdot x_i\\\label{c1}
& \text{subject to} &\quad & \mathbf{x} \in \mathfrak{C}(\mathfrak{L},v)\\\label{c2}
& & & x_i \geqslant \delta \cdot x_i^{*} \forall \text{ Players }i\in N \text{ such that } \omega_i < \omega_j
\end{alignat}
\end{subequations}

\end{document}

• Three different great answers appeared within seconds. I accept yours just because you were the first one! Thank you. – Héctor Jan 9 '18 at 22:55
• Okay, I edited it just for you @GuM. – Hood Chatham Jan 9 '18 at 23:54

You can redefine the subequations environment. Just put this in your preamble after loading amsmath and before cleverref:

\makeatletter
\renewenvironment{subequations}{%
\refstepcounter{equation}%
\protected@edef\theparentequation{\theequation}%
\setcounter{parentequation}{\value{equation}}%
\setcounter{equation}{0}%           VVVV - Changed to "Alph"
\def\theequation{\theparentequation\Alph{equation}}%
\ignorespaces
}{%
\setcounter{equation}{\value{parentequation}}%
\ignorespacesafterend
}
\makeatother


The redefinition is necessary because the \theequation is defined each time the environment is called, so it is not possible (as far as I know) to define just the label.

• Make sure that you do this before loading cleverref though! – Hood Chatham Jan 9 '18 at 22:56
• Updated my answer. Thanks! But why? – Phelype Oleinik Jan 9 '18 at 22:58
• cleverref changes the definition of \subequations to add some wrapper code and then call the original version of \subequations which it saves in \cref@old@subequations. If you do this after loading cleverref, it deletes cleverref's wrapper code. – Hood Chatham Jan 9 '18 at 22:59

Here's a solution: defining a Subequations environment (\renewwenvironment{subequations} would also work). I corrected some spacing problems, and propose another alignment, which looks nicer, in my opinion:

 \documentclass{article}
\usepackage{mathtools, amsthm, amssymb} % MATH PACKAGES
\usepackage{cleveref} % FOR FANCY REFERENCES

\makeatletter
\newenvironment{Subequations}{%
\refstepcounter{equation}%
\protected@edef\theparentequation{\theequation}%
\setcounter{parentequation}{\value{equation}}%
\setcounter{equation}{0}%
\def\theequation{\theparentequation\Alph{equation}}%
\ignorespaces
}{%
\setcounter{equation}{\value{parentequation}}%
\ignorespacesafterend
}
\makeatother

\begin{document}

Look what a fancy optimisation problem in \cref{p} subject to \cref{c1,c2}, folks!
\begin{Subequations}
\begin{alignat}{2}\label{p}
& \max_{L,\mathbf{x}} & & v(L) - \sum_{i \in L} \delta \cdot x_i\\\label{c1}
& \text{subject to} &\quad & \mathbf{x} \in \mathfrak{C}(\mathfrak{L},v)\\\label{c2}
& & & x_i \geqslant \delta \cdot x_i^{*}\quad \forall \text{ Players }i\in N \text{ such that } \omega_i < \omega_j
\end{alignat}
\end{Subequations}

\begin{Subequations}
\begin{alignat}{2}\label{q}
\max_{L,\mathbf{x}} & & & v(L) - \sum_{i \in L} \delta \cdot x_i\\\label{d1}
\text{subject to} & &\quad & \mathbf{x} \in \mathfrak{C}(\mathfrak{L},v)\\\label{d2}
& & & x_i \geqslant \delta \cdot x_i^{*} \quad \forall \text{ Players }i\in N \text{ such that } \omega_i < \omega_j
\end{alignat}
\end{Subequations}

\begin{Subequations}
\begin{alignat}{2} %\label{r}
& \max_{L,\mathbf{x}} \quad \mathrlap{v(L) - \sum_{i \in L} \delta \cdot x_i} \\[0.5ex] \label{e1}
& \text{subject to} & \quad \smash{\rule[-4.5ex]{0.5pt}{6.5ex}\;}& \mathbf{x} \in \mathfrak{C}(\mathfrak{L},v) \\\label{e2}
& & & x_i \geqslant \delta \cdot x_i^{*} \quad \forall \text{ Players }i\in N \text{ such that } \omega_i < \omega_j
\end{alignat}
\end{Subequations}

\end{document}


• I really appreciate the alternative alignment. I accepted another equally useful answer that appeared first. Thank you! – Héctor Jan 9 '18 at 22:55
• It's worth noting that this approach will not be compatible with cleverref without modification. – Hood Chatham Jan 9 '18 at 22:58
• @HoodChatham: ??? It seems to work, just look at the result. – Bernard Jan 9 '18 at 23:25
• @Héctor: I've added a third possibility. – Bernard Jan 9 '18 at 23:26
• To be honest, I'm not really sure. If you \show\subequations after loading cleverref, you'll see that cleverref has redefined it to be a wrapper. This is presumably in order to get some cleverref feature to work correctly -- I'm not sure what. There's a description on line 6527 of cleverref.dtx here: tug.ctan.org/tex-archive/macros/latex/contrib/cleveref/… – Hood Chatham Jan 9 '18 at 23:39