5

I'm thinking about migrating several large documents from cleveref to zref-clever. I have read Migration from cleveref to zref-clever as well as the manual, but several questions remain.

One of them is: How I can control whether references to equations include "equation" or "equations" before the label(s), independently of whether references to figures and tables include "figure" and "table"? (The reasoning is that equations are numbered with parentheses whereas figures and tables are numbered without parentheses. Thus, it is clear that "see (1)" means equation (1) whereas "see 1" would be ambiguous because it could mean either Figure 1 or Table 1.)

My understanding is that I need to use the option noname when referring to each equation. To avoid having to type the option in each reference, I could define a new command:

\documentclass{article}

\usepackage{zref-clever}
\newcommand{\zcrefeq}[1]{\zcref[noname]{#1}}

\begin{document}

\begin{equation}\label{eq:1}
  a = b
\end{equation}

\begin{figure}[h]
  \caption{Some figure.}
  \label{fig:1}
\end{figure}

We have \zcrefeq{eq:1} and \zcref{fig:1}. 
\zcref[S]{eq:1} is the first equation. 
 
\end{document}

Is there a more elegant way of doing this by setting an overall option or a reference format option?

2 Answers 2

2

You can add the following to your preamble:

\zcRefTypeSetup{equation}{
  Name-sg =,
  name-sg =,
  Name-pl =,
  name-pl =,
  Name-sg-ab =,
  name-sg-ab =,
  Name-pl-ab =,
  name-pl-ab =,
}

Obviously, this means you no longer have the option to add the type name back for individual references unless you do something like

\zcref[refbounds={,Equation (,),}]{label}

or

\zcref[refbounds={Equation (,,,)}]{label}

The former includes the word "Equation" and the parentheses into the hyperlink if hyperref is loaded, whereas the latter doesn't.


EDIT

a more elegant solution would be to only redefine the abbreviated type names to be empty and use abbrev option with \zcRefTypeSetup:

\documentclass{article}

\usepackage{zref-clever}
\zcRefTypeSetup{equation}{
  Name-sg-ab =,
  name-sg-ab =,
  Name-pl-ab =,
  name-pl-ab =,
  abbrev,
}

\begin{document}

\begin{equation}\label{eq:1}
  a = b
\end{equation}

\begin{figure}[h]
  \caption{Some figure.}
  \label{fig:1}
\end{figure}

We have \zcref{eq:1} and \zcref{fig:1}. 
\zcref[S]{eq:1} is the first equation. 

\end{document}

Since the S option is equivalent to noabbrevfirst=true, capfirst=true, the reference \zcref[S]{eq:1} will use the type name Name-sg, which is set to "Equation" by default.

1
  • Thanks, your edit is precisely the kind of elegant solution I was looking for. Commented Jan 4 at 6:39
5

You could maybe redefine \zcref to check whether the reference contains eq:, and sets noname in this case

\NewCommandCopy\originalzcref\zcref
\RenewDocumentCommand{\zcref}{ s O{} m }{%
  \begingroup%
  \UseName{str_if_in:nnT} {#3} {eq:} {%
    \zcsetup{noname}%
  }%
  \IfBooleanTF{#1}{\originalzcref*[#2]{#3}}{\originalzcref[#2]{#3}}%
  \endgroup%
}

But you need also to redefine the S key to restore the name, when used

\DeclareKeys [zref-clever/reference]{
  S .meta:n =
     { capfirst = {#1} , noabbrevfirst = {#1}, typeset=both },
}

(instead of only capfirst = {#1} , noabbrevfirst = {#1})

Example:

\documentclass{article}

\usepackage{zref-clever}

\NewCommandCopy\originalzcref\zcref
\RenewDocumentCommand{\zcref}{ s O{} m }{%
  \begingroup%
  \UseName{str_if_in:nnT} {#3} {eq:} {%
    \zcsetup{noname}%
  }%
  \IfBooleanTF{#1}{\originalzcref*[#2]{#3}}{\originalzcref[#2]{#3}}%
  \endgroup%
}

\DeclareKeys [zref-clever/reference]{
  S .meta:n =
     { capfirst = {#1} , noabbrevfirst = {#1}, typeset=both },
}

\begin{document}

\begin{equation}\label{eq:1}
  a = b
\end{equation}

\begin{figure}[h]
  \caption{Some figure.}
  \label{fig:1}
\end{figure}

We have \zcref{eq:1} and \zcref{fig:1}.
\zcref[S]{eq:1} is the first equation.

\end{document}

Example

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.