12

Using the Cleveref package (v0.19) i have a problem with missing parentheses when referencing to subequations, using the \labelcref command. Here is a MWE:

\documentclass{article}
\usepackage{parskip}
\usepackage{amsmath}
\usepackage{cleveref}

% Change so that the parentheses for equations are part of the hyperlink
\creflabelformat{equation}{#2(#1)#3}
\crefrangelabelformat{equation}{#3(#1)#4 to #5(#2)#6}

% This does not work:
\creflabelformat{subequations}{#2(#1)#3}
\crefrangelabelformat{subequations}{#3(#1)#4 to #5(#2)#6}

\begin{document}
\textbf{Writing three subequations:}
\begin{subequations}\label{eqn:abc}
    \begin{align}
        A&=B\label{eqn:abc1}\\
        B&=C\label{eqn:abc2}\\
        C&=A\label{eqn:abc3}
    \end{align}
\end{subequations}
Referencing using \texttt{$\backslash$cref}: \cref{eqn:abc}, \cref{eqn:abc1}, \cref{eqn:abc2}, \cref{eqn:abc3}.

Referencing using \texttt{$\backslash$labelcref}: \labelcref{eqn:abc}, \labelcref{eqn:abc1}, \labelcref{eqn:abc2}, \labelcref{eqn:abc3}. $\leftarrow$ Parenthesis are missing for subequations!\\[2ex]

\textbf{Writing two separate single equations:}
\begin{equation}\label{eqn:singlexy}
    x=y
\end{equation}
and
\begin{equation}\label{eqn:singleyx}
    y=x
\end{equation}
Referencing using \texttt{$\backslash$cref}: \cref{eqn:singlexy}, \cref{eqn:singleyx}.

Referencing using \texttt{$\backslash$labelcref}: \labelcref{eqn:singlexy}, \labelcref{eqn:singleyx}. $\leftarrow$ Parenthesis are \emph{not} missing for normal equations!
\end{document}

The output is as follows:

Output of MWE above

As can be seen, the \labelcref command omits the parentheses when referencing to the subequations (1a, 1b and 1c), as well as to their parent equation (1). As mentioned in the code above, the following lines of code do not solve the problem:

\creflabelformat{subequations}{#2(#1)#3}
\crefrangelabelformat{subequations}{#3(#1)#4 to #5(#2)#6}

I'm quite certain it worked in an earlier version of Cleveref (without adding the above two lines).

Any ideas would be greatly appreciated!

2
  • cross-referencing isn't a faulty tag for your question. It's the more general complement to cleveref and may be helpful in attracting more potential answerers.
    – lockstep
    Jan 28, 2014 at 14:40
  • @lockstep Yes, I guess you are right. I also added an amsmath tag, since the align environment used above is part of it.
    – MLC
    Jan 28, 2014 at 15:12

4 Answers 4

6

You are right, in version 0.18.9 the parenthesis were there.

In the latest version, additional support for subequations has been added. So says the documentation:

Added separate subequation cross-reference type

First of all, you have to use subequation instead of subequations and, for them, \labelcrefformat instead of \creflabelformat and \labelcrefrangeformat instead of \crefrangelabelformat, that is

\labelcrefformat{subequation}{#2(#1)#3}
\labelcrefrangeformat{subequation}{#3(#1)#4 to #5(#2)#6}

instead of

\creflabelformat{subequations}{#2(#1)#3}
\crefrangelabelformat{subequations}{#3(#1)#4 to #5(#2)#6}

MWE:

\documentclass{article}
\usepackage{parskip}
\usepackage{amsmath}
\usepackage[colorlinks]{hyperref}
\usepackage{cleveref}

% Change so that the parentheses for equations are part of the hyperlink
\creflabelformat{equation}{#2(#1)#3}
\crefrangelabelformat{equation}{#3(#1)#4 to #5(#2)#6}

% This does work:
\labelcrefformat{subequation}{#2(#1)#3}
\labelcrefrangeformat{subequation}{#3(#1)#4 to #5(#2)#6}

\begin{document}
\textbf{Writing three subequations:}
\begin{subequations}\label{eqn:abc}
    \begin{align}
        A&=B\label{eqn:abc1}\\
        B&=C\label{eqn:abc2}\\
        C&=A\label{eqn:abc3}
    \end{align}
\end{subequations}
Referencing using \texttt{$\backslash$cref}: \cref{eqn:abc}, \cref{eqn:abc1}, \cref{eqn:abc2}, \cref{eqn:abc3}.

Referencing using \texttt{$\backslash$labelcref}: \labelcref{eqn:abc}, \labelcref{eqn:abc1}, \labelcref{eqn:abc2}, \labelcref{eqn:abc3}. $\leftarrow$ Parenthesis are \emph{NOT} missing for subequations!\\[2ex]

\textbf{Writing two separate single equations:}
\begin{equation}\label{eqn:singlexy}
    x=y
\end{equation}
and
\begin{equation}\label{eqn:singleyx}
    y=x
\end{equation}
Referencing using \texttt{$\backslash$cref}: \cref{eqn:singlexy}, \cref{eqn:singleyx}.

Referencing using \texttt{$\backslash$labelcref}: \labelcref{eqn:singlexy}, \labelcref{eqn:singleyx}. $\leftarrow$ Parenthesis are \emph{not} missing for normal equations!
\end{document} 

Output:

enter image description here

Strangely enough, for equations you have to use \creflabelformat and \crefrangelabelformat.

1
  • Thank you very much! This answered my question perfectly!
    – MLC
    Jan 28, 2014 at 15:46
3

In my case

\crefalias{subequation}{equation}

in the preamble was the best solution for this problem. (I got this idea from this answer to the same question asked by somebody else.)

The great advantage of this solution is, that

\labelcref{equation1,subequation2a)
\labelcref{eqn:singlexy,eqn:abc2} %in your example

works too. (In the accepted solution this would not work.) Other advantages of this solution are:

  • Only one line in the preamble has to be added.
  • You don't have to think about different languages
  • You don't have to think about modifications like \newcommand{\crefrangeconjunction}{--}

Are there any disadvantages of this (\crefalias{subequation}{equation}) solution?

1

I found that the \namecref command didn't work either, giving ?? as output, so i added the following line to the preamble:

\crefname{subequation}{eq.}{eqs.}

However, then the parenthesis around subequations and their parent equation dissapeared, when using the \cref command... So, it turns out one also has to add the following two lines:

\creflabelformat{subequation}{#2(#1)#3}
\crefrangelabelformat{subequation}{#3(#1)#4 to #5(#2)#6}

Thus, the complete code is then as follows:

\documentclass{article}
\usepackage{parskip}
\usepackage{amsmath}
\usepackage[colorlinks]{hyperref}
\usepackage[all]{hypcap}
\usepackage{cleveref}
%
% Change so that the parentheses for equations are part of the hyperlink
\creflabelformat{equation}{#2(#1)#3}
\crefrangelabelformat{equation}{#3(#1)#4 to #5(#2)#6}
%
% Make \cref, \labelcref and \namecref work as intended with subequations
\labelcrefformat{subequation}{#2(#1)#3}
\labelcrefrangeformat{subequation}{#3(#1)#4 to #5(#2)#6}
\crefname{subequation}{eq.}{eqs.}
\creflabelformat{subequation}{#2(#1)#3}
\crefrangelabelformat{subequation}{#3(#1)#4 to #5(#2)#6}
%
\begin{document}
\textbf{Writing three subequations:}
\begin{subequations}\label{eqn:abc}
    \begin{align}
        A&=B\label{eqn:abc1}\\
        B&=C\label{eqn:abc2}\\
        C&=A\label{eqn:abc3}
    \end{align}
\end{subequations}
Referencing using \texttt{$\backslash$cref}: \cref{eqn:abc}, \cref{eqn:abc1}, \cref{eqn:abc2}, \cref{eqn:abc3}.

Referencing using \texttt{$\backslash$labelcref}: \labelcref{eqn:abc}, \labelcref{eqn:abc1}, \labelcref{eqn:abc2}, \labelcref{eqn:abc3}.

Referencing using \texttt{$\backslash$namecref}: \namecref{eqn:abc}, \namecref{eqn:abc1}, \namecref{eqn:abc2}, \namecref{eqn:abc3}.\\[2ex]

\textbf{Writing two separate single equations:}
\begin{equation}\label{eqn:singlexy}
    x=y
\end{equation}
and
\begin{equation}\label{eqn:singleyx}
    y=x
\end{equation}
Referencing using \texttt{$\backslash$cref}: \cref{eqn:singlexy}, \cref{eqn:singleyx}.

Referencing using \texttt{$\backslash$labelcref}: \labelcref{eqn:singlexy}, \labelcref{eqn:singleyx}.

Referencing using \texttt{$\backslash$namecref}: \namecref{eqn:singlexy}, \namecref{eqn:singleyx}.
\end{document}

This yields the following output:

New \cref output

3
  • This wasn't stated in your question, so unaccepting my answer seems a bit unfair to me... Feb 2, 2014 at 18:10
  • @karlkoeller I'm sorry! I didn't realize klicking the checkmark on my own question removed it from yours. :-/ I'm quite new to this forum, so I should have checked this more carefully. Anyway, I re-clicked the checkmark on your answer, since you did a great job answering my initial question. Thank you!
    – MLC
    Feb 2, 2014 at 22:11
  • It's OK. +1 for answering your own question with your complete solution :-) Feb 3, 2014 at 5:52
1

\labelcref, \namecref etc. seem to work correctly with subequations in the latest pre-release version (0.21) available from my web site: http://www.dr-qubit.org/latex.html

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .