thmtools で cleveref 名を定理名として使用する方法

thmtools で cleveref 名を定理名として使用する方法

私は、 でいくつかの定理のような環境を設定し、さまざまな言語との互換性を保ちながらthmtoolsで動作するようにしようとしています。cleverer

ロードしたcleveref後で、thmtoolsコマンドから出力される翻訳された相互参照で非常にうまく機能するようです。と\crefの組み合わせは、すでに「定理」、「補題」、および「定義」を自分の言語に翻訳する方法を知っているようです (誰がどのように翻訳を提供しているのでしょうか)。babelcleveref

しかし、環境に関しては同じことが当てはまらない。名前name=なので、のオプションに何らかの方法で翻訳された文字列を提供する必要があります。マニュアルには、 など、パッケージで使用される名前を提供するマクロがいくつかあることが\declaretheoremわかったので、それらを使用しようとしています。 を使用しているときはすべて正常に動作していましたが、 をロードすると不可解なエラー メッセージが表示されます。cleveref\cref@theorem@nameamsthmthmtools

次の最小限の例で問題がわかるはずです。

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

上記のコードをコンパイルすると、次のエラーが発生します:

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

上記のコードでは、\newtheoremの行をコメントアウトした場合にのみ例が機能するように を使用しています\usepackage{thmtools}。 を使用した場合も同じ問題が発生します\declaretheorem(もちろん なしでは使用できませんthmtools)。

ここで何が起きてるの?

PS: クラス ファイルを作成し、複数の言語との互換性を維持したいため、定理名として「Teorema」とだけ書いているわけではありません。

答え1

鶏が先か、卵が先か?;-)

\cref@theorem@nameが発行されるとき、 はまだ定義されていません\newtheorem。 解決策: を使用します\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}

ここに画像の説明を入力してください

これを と互換性を持たせたい場合は、シンボリック名の前に 's を\declaretheoremいくつか追加する必要があります。\noexpand

より簡単なやり方は次のとおりです:

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

ここに画像の説明を入力してください

関連情報