10

The words chapter, part, appendix, table, figure, and the like are lowercased and spelled out in text (though sometimes abbreviated in parenthetical references).

(Chicago Manual of Style, 16th ed., section 8.178)

MWE:

\documentclass{scrartcl}
\usepackage[demo]{graphicx}
\usepackage{cleveref}
\begin{document}

\section{Geometric abstraction}
\Cref{myfig} shows a black square. For a black square, please refer to \cref{myfig}. Squares can be black (cf.\ \cref{myfig}).

\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}

MWE produces: enter image description here

What I am looking for: enter image description here

Is there a clever (sorry) way to achieve this with cleveref? I know that \Cref{} will always produce the full form, capitalized reference, so that is a good start. But how would I handle the non-parenthetical reference in mid-sentence?

2 Answers 2

13

Here is another approach requiring less delving in to the innards of cleveref. The idea is to change the name locally using \crefname.

Sample output

\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.

1

Okay, I think I found a solution -- but it is neither elegant nor clever ;-)

I defined a new command lcCref, which will always give a lowercase, full form reference and will also handle plural references correctly:

\usepackage{xstring}
\def\lcCref#1{%
    \StrCount{#1}{,}[\n]%
    \ifnum\n>0\relax%
        \StrBefore[1]{#1}{,}[\myFirst]%
        \lcnamecrefs{\myFirst}~\labelcref{#1}%
    \else%
        \lcnamecref{#1}~\labelcref{#1}%
    \fi%
}

First, the number of arguments are counted. If a single label is referenced, the outputs of lcnamecref and labelcref are combined (see cleveref doc). If there are multiple references, lcnamecrefs is used instead of lcnamecref. The StrBefore construct is needed because lcnamecrefs only accepts a single label as an argument.

\lcCref{myfig} will result in figure 1, whereas \lcCref{myfig,anotherfig} will result in figures 1 and 2.

I have the feeling that this might be overly complicated. But it seems to works ...

1
  • Well ... this doesn't really work in all situations. \lcCref{mytable,myfig}, for example, will not work. Also, my hack really takes away from the flexibility of cleveref, as the things cannot be overridden by a global option.
    – plxc
    Jul 12, 2014 at 10:27

You must log in to answer this question.

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