3

I am using cleveref for cross-referencing in my thesis. For equations, it typically looks like this:

As can be seen in Eq. (5), the numbers don't add up.

However, sometimes I only want to reference an equation without structuring my sentence around it, i.e. I just want to put it in brackets. In this case, I don't want brackets around the number:

This can be done with the previously shown formula (Eq. 5).

However, when writing (\cref{eq5}) it naturally keeps the brackets, and it looks like this:

This can be done with the previously shown formula (Eq. (5)).

Is there a way to get my desired result with cleveref, so that I don't have to manually change all the instances where I run into this problem?

I know that I could write it as (Eq.~\ref{eq5}), but I would prefer to have a single command that handles all references, if possible. That's why I'm using cleveref in the first place.

I'd also appreciate suggestions how to better handle this situation in general. Perhaps there is a standard way of doing this that I'm not aware of. It seems weird to me that the default choice of \cref{} for equations is one that is different than the one for figures and tables, and leads to specific problems that do not appear for those. So maybe I'm misusing the package somehow.

Note that this is not (and never has been) a feature request for cleveref. I am simply asking how to use it properly and whether I could add a line of code to my Latex file that can solve the problem I have.

2
  • 1
    You wrote, "t seems weird to me that the default choice of \cref{} for equations is one that is different than the one for figures and tables". IMNSHO, this isn't weird at all. Instead, it merely implements a very common typographic convention with regard to equation numbers, viz., to encase the equation numbers in parentheses. If cleveref didn't implement this convention, there would probably be lots and lots of complaints from users that this common convention was being disregarded...
    – Mico
    Jun 18, 2019 at 13:27
  • Considering the point you make about how difficult it is to implement what I'm asking for, it is probably not that weird. I just expected that cleveref would consider this specific situation and adapt to it, if it goes to the trouble of making a special rule.
    – PoorYorick
    Jun 18, 2019 at 13:42

1 Answer 1

4

I suppose you could achieve your desired output simply by writing (Eq.~\ref{eq5}), right?

Before I delve into alternative suggestions, I would like provide an excerpt from the user guide of the cleveref package (cf p. 4, fn. 2). In a related context, Toby Cubitt (the author and maintainer of the cleveref package) writes that

Trying to determine the appropriate case automatically would be tantamount to solving the full natural-language processing problem in cleveref. Check back in a century or so for this feature.

I quote this passage because your request -- for LaTeX and/or cleveref to detect automatically that an instance of \cref occurs by itself, surrounded by parentheses, and to change the output of \cref based on this condition -- comes very close to asking for a solution to a natural-language processing issue.

Recall also that \cref is designed to take and process multiple arguments. What exactly is supposed to happen if a \cref instruction takes multiple arguments (which may or may not be labels to equation objects...) but is also surrounded by a pair of parentheses?

Rather than try to solve your feature request head-on, then, I would like to make three suggestions for alternative solutions to your typesetting objective:

  • write (Eq.~\ref{eq5}) -- it's not that hard, is it?

  • use a single comma rather than a pair of parentheses to offset the cross-reference visually, and keep using \cref

  • use \labelcref instead of \cref, in effective making "formula" the noun that's associated with the equation number. Speaking for myself, I like this method best because it avoids typesetting two nouns -- "formula" and "Eq." -- when one is enough.

(The following code loads the hyperref package and loads the cleveref package with the option nameinlink to make it obvious, visually speaking, what's produced by \cref, \labelcref, and \ref.)

enter image description here

\documentclass{article}
\usepackage[colorlinks,allcolors=blue]{hyperref} % optional
\usepackage[capitalize,nameinlink]{cleveref}
\setlength{\textwidth}{3.5in} % just for this example
\begin{document}
\setcounter{equation}{4} % just for this example


\begin{equation} \label{eq5} 1+4=5 \end{equation}
%As can be seen in \cref{eq5}, the numbers don't add up.

\noindent
\begin{tabular}{@{}ll@{}}
\dots\ the previously shown formula (\cref{eq5}). & bad\\

\dots\ the previously shown formula (Eq.~\ref{eq5}). & good \\

\dots\ the previously shown formula,  \cref{eq5}. & better? \\

\dots\ the previously shown formula~\labelcref{eq5}. & best?
\end{tabular}
\end{document}

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.