I have sometimes been warned against using cleveref
because it makes very fundamental changes of some of the basic LaTeX commands, like \label
. Is this concern justified, and what are the issues of loading it? Are there good reasons not to use it?
[Tex/LaTex] Is cleveref safe to use
cleveref
Related Solutions
Option (1) Use \captionsetup[figure]{...}
to get back the right format.
\documentclass[prl,twocolumn]{revtex4-2}
\usepackage{subcaption}
\usepackage{graphicx}
\usepackage{cleveref}
\captionsetup[figure]{textfont=normalfont,singlelinecheck=off,justification=raggedright}% added <<<
\usepackage{kantlipsum}
\begin{document}
\maketitle
See \cref{fig:1a}
\begin{figure}[ht]
\begin{subfigure}{\textwidth} % this 'subfigure' env. has no visible content
\refstepcounter{subfigure}\label{fig:1a}
\refstepcounter{subfigure}\label{fig:1b}
\end{subfigure}%
\centering
\includegraphics[width=\linewidth]{example-image}% use linewidth <<<
%\caption{(a) First sub caption. (b) Second sub caption. And some more text}
\caption{ (\protect\subref{fig:1a}) First sub caption. (\protect\subref{fig:1b}) Second sub caption. And some more text}
\label{fig:1}
\end{figure}
\kant[1-7]
\end{document}
or (2) Instead of subcaption
it can be used subfig
. (See the use of \subref{..}
in the example)
\documentclass[prl,twocolumn]{revtex4-2}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{caption}
\usepackage{cleveref}
\usepackage{kantlipsum}
\captionsetup[figure]{textfont=normalfont,singlelinecheck=off,justification=raggedright}
\begin{document}
\maketitle
See \cref{fig:1a} and subfigure~\subref{fig:1b}.
\begin{figure}[ht!]
\subfloat{\label{fig:1a}}
\subfloat{\label{fig:1b}}
\centering
\includegraphics[width=\linewidth]{FigureOne.pdf}
\caption{ \protect\subref{fig:1a} First sub caption. \protect\subref{fig:1b} Second sub caption. And some more text}
\label{fig:1}
\end{figure}
\kant[1-7]
\end{document}
The FigureOne.pdf
was generated by this file.
%%file FigureOne.tex
\documentclass[preview, border=5pt]{standalone}
\usepackage{geometry}
\usepackage{subfig}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\centering
\subfloat[][]{\includegraphics[width=0.5\textwidth]{example-image-a}}\enspace
\subfloat[][]{\includegraphics[width=0.5\textwidth]{example-image-b}}
\end{figure}
\end{document}
The underlying problem has little to do with cleveref
in this case. What happens is that calling \frontmatter
in aucklandthesis.cls
messes up memoir
's setup for secnumdepth
and, hence, all of your sectioning commands are unnumbered. Therefore, in the MWE at least, \refstepcounter
is never called, and your labels miss the information cleveref
complains about. If you remove the calls to \cref
your document compiles, but with all chapters unnumbered.
The documentclass appears to assume \frontmatter
is not to be used at all, since it calls \mainmatter
straight from de definition of \maketitle
...
It is true that aucklandthesis.cls
does not redefine \frontmatter
, but it does redefine \mainmatter
and, in so doing, leaves out important things of the memoir original. As far as I can tell, you can get things working doing by hand what the class does not do:
\mainmatter
\makeatletter
\@mainmattertrue
\makeatother
\setcounter{secnumdepth}{\value{maxsecnumdepth}}
\pagenumbering{arabic}
But, in this case, it appears this documentclass is not really official to your institution, which means you are not required to use it. In which case you might be better off simply starting from one of the standard classes, memoir itself, or KOMA-Script.
Unfortunately, the original author of the class seems to be long gone from my institution, so I can't ask them about it, and there doesn't seem to be anyone else responsible for maintaining it these days.
Formally, it is a package published on CTAN. Whether its maintainer is still on the institution or not does not change their role wrt to CTAN. Well, that in theory, in practice things might be different... And I did check the documentation and it seems there is no contact information for you to attempt to report this. If you really think sticking to the document class is worth it, you might want to try some contact through CTAN itself. Or, if your institution does advertise this document class as something "official", even if not "required" but just "recommended", you probably should report this to someone at the University.
Best Answer
How cleveref works
Cleveref augments the
\label
command so that it writes some additional information into the.aux
file. This part is not particularly invasive at all as it keeps the original implementation of\label
intact and all standard functions that rely on it will still work (e.g. the normal\ref
command). The second command that is augmented is\refstepcounter
- again, the original functionality is being preserved and this should cause no issues.Almost all functionality enhancing packages redefine the standard commands in some way (e.g. modifying lists, sections, equations...). All further functionality (i.e. the
\cref
command) is being handled in entirely separate functions.Potential issues
Almost all issues come from the use of the
\refstepcounter
command - or rather the lack of its usage. All packages that do use it will work with cleveref out of the box. For those that do not, there are two options:\cref{label}
will produce incorrect output (incorrect meaning a missing label and potentially incorrect number). It will cause warnings but will still compile. You've now got two options:\ref
command. This will always work.If you want to get a feel for the issues that people have with cleveref, just browse https://tex.stackexchange.com/questions/tagged/cleveref!
Cleveref and breqn packages don't play nice together and Making refcheck work with cleveref are some typical issues that you may encounter.
Lastly, the documentation of cleveref has a section on
poor mans cleveref
- when you need to send your LaTeX source code to someone else, and they don't have cleveref installed. I think this may have been an issue in the early days of this package, but it has been a standard package for all the major tex distributions for probably 5 years now - so this is unlikely to be an issue.Why you should use cleveref
Because it is clever and really simplifies your cross-referencing. I would like to point you to Difference between ref, varioref and cleveref. Decision for a thesis, Cross-reference packages: which to use, which conflict? and How to get more complete references.