cleveref -- using both abbreviated and full form references?
Here is another approach requiring less delving in to the innards of cleveref
. The idea is to change the name locally using \crefname
.
\documentclass{scrartcl}
\usepackage[demo]{graphicx}
\usepackage[noabbrev]{cleveref}
\DeclareRobustCommand{\abbrevcrefs}{%
\crefname{figure}{fig.}{figs.}%
\crefname{equation}{eqn.}{eqns.}%
}
\DeclareRobustCommand{\cshref}[1]{{\abbrevcrefs\cref{#1}}}
\begin{document}
\section{Geometric abstraction}
\begin{equation}
\label{eq:x}
x = 1.
\end{equation}
\Cref{myfig} shows a black square. For a black square, please refer to
\cref{myfig,eq:x}. Squares can be black (cf.\ \cshref{myfig,eq:x}).
Back to \cref{myfig,eq:x}.
\begin{figure}
\centering
\includegraphics[width=6cm,height=6cm]{fig1.pdf}
\caption[asd]{Kazimir Malevich. \textit{Black Square.} 1915. Oil on canvas. State Russian Museum, St Petersburg.}
\label{myfig}
\end{figure}
\end{document}
We load the cleveref
package with the noabbrev
option to get all the full name versions. We provide a list of abbreviated forms encapsulated in a command \abbrevcrefs
and then define a new command \cshref
for abbreviated references that calls \cref
proceeded by \abbrevcrefs
and enclosed in a group to make the effect local.
The same general approach could be used to make modified versions of other commands from the cleveref
package.
I had hoped to be able just use the internal \@cref@abbrevtrue
locally to turn on abbreviations, but it turns out that cleveref
only uses this switch when initially defining the label names, not when typesetting them. The label defining process is hooked in to \AtBeginDocument
code, and can not be easily reevaluated to extract the abbreviated versions, hence the need to set up the abbreviations oneself.