# How to use cleveref names as theorem names with thmtools

I'm trying to setup a few theorem-like environments with thmtools, making it work with cleverer while trying to stay compatible with different languages.

If I load cleveref after thmtools it seems to work very well with translated cross-references coming out from the \cref command. It seems that a combination of babel and cleveref already knows how to translate "theorem", "lemma", and "definition" to my language (who is providing the translation and how?).

However, the same is not true with the environment names, so I have to somehow provide a translated string to the name= option of \declaretheorem. I've found in the cleveref manual that there are some macros that provide the names used by the package, such as \cref@theorem@name, and I'm trying to use them. It all worked well when I was using amsthm, but if I load thmtools I get an inexplicable error message.

The following minimal example should show the problem:

\documentclass[italian]{article}

\usepackage{amsthm}
\usepackage{thmtools} % Comment this line and it works
\usepackage[capitalise]{cleveref}
\usepackage{babel}

\makeatletter
\newtheorem{theorem}{\cref@theorem@name}
\makeatother

\begin{document}

\begin{theorem}
Let ABC be a triangle. If it hits your head it will hurt\ldots
\end{theorem}

\end{document}


Compiling the code above I get the error:

./mwe.tex:10: Undefined control sequence. [\makeatother]


Note, in the code above I'm using \newtheorem only to make the example work if you comment the \usepackage{thmtools} line. The same problem happens if I use \declaretheorem (which of course is not available without thmtools).

What is happening here?

P.S: I'm not just writing "Teorema" as the theorem name because I'm writing a class file and I want to stay compatible with multiple languages.

Chicken or egg? ;-)

\cref@theorem@name is not yet defined when \newtheorem is issued. Solution: use \noexpand.

\documentclass[italian]{article}
\usepackage[T1]{fontenc}

\usepackage{amsthm}
\usepackage{thmtools} % Comment this line and it works
\usepackage[capitalise]{cleveref}
\usepackage{babel}

\makeatletter
\newtheorem{theorem}{\noexpand\cref@theorem@name}
\makeatother

\begin{document}

\begin{theorem}\label{test}
Let ABC be a triangle. If it hits your head it will hurt\ldots
\end{theorem}

\cref{test}

\end{document}


If you want to make this compatible with \declaretheorem you have to add a couple of \noexpand's in front of the symbolic name.

Here's a less heavy way:

\documentclass[italian]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}

\usepackage{amsthm}
\usepackage{thmtools} % Comment this line and it works
\usepackage[capitalise]{cleveref}

\newcommand{\dtname}[1]{%
\expandafter\noexpand
\expandafter\noexpand
\expandafter\noexpand
\csname cref@#1@name\endcsname
}
\newcommand{\ntname}[1]{%
\expandafter\noexpand
\csname cref@#1@name\endcsname
}

\newtheorem{theorem}{\ntname{theorem}}

\declaretheorem[name=\dtname{lemma}]{lemma}

\begin{document}

\begin{lemma}\label{tl}
$0\ne 1$
\end{lemma}

\begin{theorem}\label{test}
Sia $ABC$ un triangolo. Se ti piglia in testa ti farà male.
\end{theorem}

Il \cref{test} e il \cref{tl} sono importanti.

\end{document}


• I'm sorry but the solution works for \newtheorem but not for \declaretheorem. I've tried \declaretheorem[name=\noexpand\cref@theorem@name]{theorem} and it doesn't work with the same error message. Any idea? – gigabytes Feb 15 '16 at 8:20
• @gigabytes You have to suppress two expansions: \noexpand\noexpand\noexpand\cref@theorem@name – egreg Feb 15 '16 at 8:45