5

I know that \eqref exactly matches the style of the reference to the style of the equation label. However, I prefer to use \cref from the cleveref package because (1) it allows me to place the word Equation before the number and because (2) it allows me type \cref{eq1,eq2} quite comfortably. Further, following this question, I'm redefining the style of the equation number delimiters. Unluckily, such a change is not captured by the cleveref package.

Here goes a MWE:

\documentclass{article}
\usepackage{amsmath}
\usepackage[capitalise,noabbrev,]{cleveref}

\makeatletter
\def\tagform@#1{\maketag@@@{[\ignorespaces#1\unskip\@@italiccorr]}}
\makeatother

\begin{document}
    \cref{eq1} is fancy
    \begin{equation}\label{eq1}
        a = b
    \end{equation}  
\end{document}

This produces:

enter image description here

Then, my question is: how can I get the round parentheses to become square brackets?

Thank you all for your time.

3
  • 1
    See the mathtools package for its \newtagform macro as well in order to simplify such styles of equation tags
    – user31729
    Nov 9, 2017 at 12:13
  • 1
    Do you mean that mathtools provides easier ways to do what I'm doing?
    – EoDmnFOr3q
    Nov 9, 2017 at 12:14
  • 1
    Regarding the style of tags mathtools is helping you definitely, but I think the \cref issue still persists, however. mathtools loads amsmath (and extends it) so you will be able to use everything you already applied from amsmath
    – user31729
    Nov 9, 2017 at 12:15

2 Answers 2

5

In my point of view the easiest (though not most elegant, perhaps) way is to change \creflabelformat for the equation counter as well, applying the \tagform@ macro explicitly for this.

\creflabelformat{equation}{#2\tagform@{#1}#3}

The #2 and #3 are reserved for hyperref targets.

Here's the full code.

\documentclass{article}
\usepackage{amsmath}

\usepackage[capitalise,noabbrev,]{cleveref}


\makeatletter
\def\tagform@#1{\maketag@@@{[\ignorespaces#1\unskip\@@italiccorr]}}

\creflabelformat{equation}{#2\tagform@{#1}#3}

\makeatother





\begin{document}
    \cref{eq1} is fancy
    \begin{equation}\label{eq1}
        a = b
    \end{equation}  
\end{document}

enter image description here

0
4

The following solution uses the \newtagform and \usetagform macros of the mathtools package and the \creflabelformat macro of the cleveref package to achieve your formatting objective.

\documentclass{article}

\usepackage{mathtools} % for "\newtagform" macro
\newtagform{brackets}{[}{]}
\usetagform{brackets} % employ square brackets as delimiters around eq. numbers

\usepackage[capitalise,noabbrev]{cleveref}
\creflabelformat{equation}{#2{\upshape[#1]}#3}

\begin{document}
\cref{eq1} is fancy.
\begin{equation}\label{eq1}
        a = b
\end{equation}
\end{document}
2
  • 1
    I wonder whether the second occurrence of #2 should instead be #3 (viz., in \creflabelformat{equation}{#2{\upshape[#1]}#2})? From the cleveref documentation, §8.1.2: The <format> argument “should contain the three arguments #1, #2 and #3, the first being the formatted version of the label counter, the others determining the beginning and end of the portion that becomes a hyperlink when the hyperref package is loaded…. #2 and #3 must appear in that order." Feb 26, 2019 at 6:41
  • @JimRatliff - Many thanks for contacting me and for pointing out the error. I've fixed the code. Best, Mico
    – Mico
    Feb 26, 2019 at 8:45

You must log in to answer this question.

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