如何透過 thmtools 使用 smartef 名稱作為定理名稱

如何透過 thmtools 使用 smartef 名稱作為定理名稱

我正在嘗試使用 來設定一些類似定理的環境thmtools,使其能夠工作,cleverer同時嘗試與不同語言保持相容。

如果我加載cleveref後,thmtools它似乎可以很好地處理來自\cref命令的翻譯交叉引用。似乎組合babel已經cleveref知道如何將「定理」、「引理」和「定義」翻譯成我的語言(誰提供翻譯以及如何提供翻譯?)。

然而,環境卻並非如此名字,所以我必須以某種方式為name=的選項提供翻譯後的字串\declaretheorem。我在手冊中發現cleveref有一些巨集提供了套件使用的名稱,例如\cref@theorem@name,我正在嘗試使用它們。當我使用時,一切都運行良好amsthm,但如果我加載,thmtools我會收到一條莫名其妙的錯誤訊息。

下面的最小範例應該可以說明問題:

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

在此輸入影像描述

如果你想讓它相容,你必須在符號名稱前面\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}

在此輸入影像描述

相關內容