Cómo utilizar nombres de Cleveref como nombres de teoremas con thmtools

Cómo utilizar nombres de Cleveref como nombres de teoremas con thmtools

Estoy intentando configurar algunos entornos similares a teoremas con thmtools, haciéndolo funcionar cleverermientras intento seguir siendo compatible con diferentes idiomas.

Si lo cargo cleverefdespués thmtools, parece funcionar muy bien con las referencias cruzadas traducidas que salen del \crefcomando. Parece que una combinación de babely cleverefya sabe cómo traducir "teorema", "lema" y "definición" a mi idioma (¿quién proporciona la traducción y cómo?).

Sin embargo, no ocurre lo mismo con el medio ambiente.nombres, así que de alguna manera tengo que proporcionar una cadena traducida a la name=opción de \declaretheorem. Descubrí en el cleverefmanual que hay algunas macros que proporcionan los nombres utilizados por el paquete, como \cref@theorem@name, y estoy intentando usarlas. Todo funcionó bien cuando estaba usando amsthm, pero si lo cargo, thmtoolsaparece un mensaje de error inexplicable.

El siguiente ejemplo mínimo debería mostrar el problema:

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

Al compilar el código anterior aparece el error:

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

Tenga en cuenta que en el código anterior lo estoy usando \newtheoremsolo para que el ejemplo funcione si comenta la \usepackage{thmtools}línea. El mismo problema ocurre si uso \declaretheorem(que por supuesto no está disponible sin thmtools).

¿Que está sucediendo aquí?

PD: No escribo simplemente "Teorema" como nombre del teorema porque estoy escribiendo un archivo de clase y quiero seguir siendo compatible con varios idiomas.

Respuesta1

¿Pollo o huevo?;-)

\cref@theorem@nameAún no está definido cuándo \newtheoremse emitirá. Solución: utilizar \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}

ingrese la descripción de la imagen aquí

Si desea que esto sea compatible, \declaretheoremdebe agregar un par de \noexpand' delante del nombre simbólico.

Aquí hay una forma menos pesada:

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

ingrese la descripción de la imagen aquí

información relacionada