I am trying to use thmtools
and cleveref
and I am getting a quite peculiar error. Here's a minimal example.
\documentclass{article}
\usepackage{thmtools}
\usepackage{cleveref}
\declaretheorem[name=Lemma,Refname={Lemma,Lemmas}]{lem}
\declaretheorem[name=Proposition,Refname={Proposition,Proposition}]{prop}
\declaretheorem[name=Theorem,Refname={Theorem,Theorems}]{thr}
\begin{document}
\begin{lem}\label{lem1}
A lemma.
\end{lem}
\begin{prop}\label{prop1}
A proposition.
\end{prop}
\begin{thr}\label{thr1}
A theorem.
\end{thr}
\Cref{lem1}, \Cref{prop1} and \Cref{thr1}.
\end{document}
When I run pdflatex
(using a fresh default installation of TeXLive 2011) I receive a message:
LaTeX Warning: Cref reference format for label type `prop' undefined on input line 24.
and the final sentence is rendered in the pdf file as "Lemma 1, ?? 1 and Theorem 1." The weird thing is that if I use only two \declaretheorem
definitions, then everything is fine. If I change the order of definitions, then it is always the second one that yields a warning.
Any ideas about what is happening here and how to fix it?
Best Answer
There is a bug in
thm-autoref.sty
. Part of the set-up forcleveref
s magic is left to the start of the document. Socleveref
maintains a list of all the label types that it has been told about so that when it gets to the\begin{document}
hook, it can iterate through them and finish the necessary configuration.Examining this list for your document (well, my slightly extended version) reveals that it is:
That doesn't look right!
\thmt@envname
is getting processed four times here. In my code, then\thmt@envname
isprop
which happens to be the last one in my list of\declaretheorem
s (for your code it would bethr
- I experimented with permutations a bit). So something isn't being expanded when it should. After playing a bit of Ultimate Code Frisbee (chasing definitions from one place to another), I tracked it down to a definition inthm-autoref.sty
, specifically the definition of\thmt@refnamewithcomma
. It reads:Clearly, we need to expand the
\thmt@envname
. One way to do this is with two\expandafter
s:So if you put that at the top of your document (within
\makeatletter ... \makeatother
) it will fix this problem. Warning The same command is used forautoref
, I don't know if this will break that (though it really aught not to do so).Here's a full example:
Result:
(Oh - something doesn't like
standalone
. Oh dear, back to more traditional tools.)