1

The cleveref manual states (page 7):

The \namecrefs and \nameCrefs commands produce the plural forms. The \lcnamecref and \lcnamecrefs commands force the reference name to lowercase, for use when the capitalise option is enabled. [...] Note that all these commands can only be passed a single reference name; they do not accept multi-references like \cref. (Passing multiple references to these commands would make little sense if the references had different types, and is redundant if they have the same type.)

I am interested in the last part stating that it's "redundant": does that mean there already is a command that does that? Or do they mean one can simply use \lcnamecrefs instead of \lcnamecref to produce the plural form?

I'm asking because of the answer suggested here: I'm trying to use \newcommand{\lccref}[1]{\lcnamecref{#1}~\labelcref{#1}} to automate lowercase referencing but it breaks everytime I have multiple references (obviously, seeing the above bit from the manual, this is a "feature").

How can I change my command to work with both single and multiple references?




MWE:

enter image description here

\documentclass{scrreprt}
\usepackage{cleveref}
\newcommand{\lccref}[1]{\lcnamecref{#1}~\labelcref{#1}}
\begin{document}
\begin{equation}
    E=mc^2\label{eq:foo}
\end{equation}
\begin{equation}
    E/m=c^2\label{eq:bar}
\end{equation}

First \lccref{eq:foo}, then \lccref{eq:bar}. But don't try \lccref{eq:foo,eq:bar}.
\end{document}
3

You can create a new command \lccrefs which passes only the first parameter to \lcnamecrefs:

\documentclass{scrreprt}
\usepackage{cleveref}
  \newcommand{\lccref}[1]{\lcnamecref{#1}~\labelcref{#1}}
  \makeatletter
      \def\lcfirstnamecrefs#1,#2\@nil{\lcnamecrefs{#1}}
      \newcommand{\lcfirstnamecref}[1]{\lcfirstnamecrefs #1,\@nil}
  \makeatother
  \newcommand{\lccrefs}[1]{\lcfirstnamecref{#1}~\labelcref{#1}}
\begin{document}
\begin{equation}
    E=mc^2\label{eq:foo}
\end{equation}
\begin{equation}
  E/m=c^2\label{eq:bar}
\end{equation}
\begin{equation}
  E = \frac{1}{2}mv^2 \label{eq:baz}
\end{equation}

    First \lccrefs{eq:foo}, then \lccref{eq:bar}. 
    But don't try \lccrefs{eq:foo,eq:bar} or 
    \lccrefs{eq:foo,eq:bar,eq:baz}.

\end{document}

enter image description here

  • Correct me if I'm wrong, but then the first \newcommand{\lccref}[1]{\lcnamecref{#1}~\labelcref{#1}} is no longer needed? – Superuser27 Mar 25 at 13:03
  • 1
    You need it for the singular, e.g. \lccref will print the singular 'equation' and \lccrefs the plural 'equations' – DG' Mar 25 at 13:05
  • Right, thanks! Is there a way to auto switch within a single command? i.e. \lccref outputs figure xy if it receives a single parameter, figures xy and yz if it receives multiple? – Superuser27 Mar 25 at 13:07
  • Also it doesn't work with more than 2 references :( – Superuser27 Mar 25 at 13:16
  • 1
    I have no problems with more than two references. Maybe you could elaborate a bit on what is wrong – DG' Mar 25 at 13:56
3

Instead of using lcnameref, you can also locally (i.e., within a \begingroup/\endgroup pair) change the label names with \crefname. You need to specify the names for each type of reference separately.

MWE:

\documentclass{article}
\usepackage{cleveref}
\usepackage{graphicx}

\newcommand{\smallCref}[1]{%
\begingroup%
\crefname{figure}{figure}{figures}%
\crefname{equation}{equation}{equations}%
\cref{#1}%
\endgroup%
}

\begin{document}
\begin{figure}
    \centering
    \includegraphics[width=0.5\linewidth]{example-image-a}
    \caption{Foo\label{fig:foo}}
\end{figure}

\begin{equation}
    E=mc^2\label{eq:foo}
\end{equation}
\begin{equation}
    E/m=c^2\label{eq:bar}
\end{equation}


\Cref{fig:foo} shows a correct usage of \verb|\Cref{}| at the beginning of the sentence. Whereas we can see how to use \verb|\cref{}| at the end of a sentence (\cref{fig:foo}).
\par Sometimes though, one may want to reference \Cref{fig:foo} with the complete label ``figure'', but having it capitalized in the middle of a sentence is weird. How can I have that single reference in smallcaps, leaving all other references in the document in the original capitalization?

In lower case: \smallCref{fig:foo}. Abbreviated: \cref{fig:foo}.

First \smallCref{eq:foo}, then \smallCref{eq:bar}. But don't try \smallCref{eq:foo,eq:bar}.

\end{document}

Result:

enter image description here

  • 1
    The answer if perfectly valid, but @DG's answer doesn't require to redefine the name for each environment one wants to reference (figure/table/section/chapter/equation/...), although yours is more straight forward, his is more flexible in my opinion, so I'm going to "accept" his. But still thank you very much for your answer! – Superuser27 Mar 25 at 13:05
  • @Superuser27 I see you changed your mind? Note that, if you don't want the abbreviated labels at all in your document, it is much easier to use \usepackage[noabbrev]{cleveref} (but I assume you knew that already). – Marijn Mar 25 at 13:42

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.