2

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:

enter image description here

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

Thank you all in advance for your time!

5

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}
\patchcmd\subequations{\theparentequation\alph{equation}}{\theparentequation\thechildequation}{}{\error} % Must come before loading cleverref
\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} 
| improve this answer | |
  • 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
  • 1
    +1, but you should say \newcommand{\thechildequation}{\Alph{equation}} (or, even better according to my taste, \newcommand*{\thechildequation}{\Alph{equation}}. – GuM Jan 9 '18 at 23:44
  • 1
    Okay, I edited it just for you @GuM. – Hood Chatham Jan 9 '18 at 23:54
3

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.

| improve this answer | |
  • 2
    Make sure that you do this before loading cleverref though! – Hood Chatham Jan 9 '18 at 22:56
  • 1
    Updated my answer. Thanks! But why? – Phelype Oleinik Jan 9 '18 at 22:58
  • 2
    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
3

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} 

enter image description here

| improve this answer | |
  • 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
  • 1
    It's worth noting that this approach will not be compatible with cleverref without modification. – Hood Chatham Jan 9 '18 at 22:58
  • 1
    @HoodChatham: ??? It seems to work, just look at the result. – Bernard Jan 9 '18 at 23:25
  • 1
    @Héctor: I've added a third possibility. – Bernard Jan 9 '18 at 23:26
  • 1
    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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.