thmtools - Theorem does not change the title when I change the command that defines it

A complement to Schrödinger's cat fine answer.

Try and comment out the definition of \testTitle. When you run LaTeX over the example, you'll receive

! Undefined control sequence.
\thmt@thmname ->\testTitle

l.8 \declaretheorem[title = \testTitle]{thm}

Oh, weird, isn't it? If you try the same with just amsthm features, with

\documentclass[11pt, a4paper]{article}

\usepackage{amsthm}

\newtheorem{thm}{\testTitle}
\newcommand\testTitle{Theorem}

\renewcommand\testTitle{The theorem}

\begin{document}
    \begin{thm}
        This is a theorem.
    \end{thm}
\end{document}

you'll see no problem. Note that the position of \newcommand{\testTitle}{...} is irrelevant.

What's the difference? With amsthm (or the default \newtheorem of the LaTeX kernel), no expansion is performed. On the contrary, \declaretheorem performs expansion on the value given to title (or its alias name).

It would happen similarly with ntheorem, by the way.

How do you solve the issue? Use \protect in front of the “symbolic name”. And no, a single \noexpand will not suffice. Since thmtools uses \protected@edef for doing its job, this \protect will be changed into an “infinite \noexpand”; however, when typesetting the text, \protect is the same as \relax, so it does no harm.


Welcome! A quick (and dirty, maybe) way of achieving what you want is to \protect the title from being expanded before you want this to happen. (I also use the name key but it works with title, too. According to the manual, name seems to a bit more versatile.)

\documentclass[11pt, a4paper]{article}
\usepackage[utf8]{inputenc}

\usepackage{amsthm}
\usepackage{thmtools}

\newcommand\testTitle{Theorem}

\declaretheorem[name=\protect\testTitle]{thm}


\renewcommand\testTitle{The theorem}

\begin{document}
    \begin{thm}
        This is a theorem.
    \end{thm}
\end{document}

enter image description here

Why does your code not give you what you want? Because the value of title gets expanded when you say

\declaretheorem[title = \testTitle]{thm}

With \protect, i.e.

 \declaretheorem[title =\protect\testTitle]{thm}

you prevent this from happening.