上面的代码其实cleverref
会报警告:
LaTeX Warning: Reference `lem' on page 1 undefined on input line 18.
LaTeX Warning: Reference `lem' on page 1 undefined on input line 18.
此事在下面的几个链接里都有记载:
- https://tex.stackexchange.com/a/730164/322482
- https://tex.stackexchange.com/a/735502/322482
- https://tex.stackexchange.com/questions/747380/cleveref-not-referring-correctly-to-a-theorem#comment1863469_747380
目前来看的最佳实践似乎是:
\documentclass{article}
\usepackage{amsthm}
\usepackage{cleveref}
\newtheorem{thm}{Theorem}[section]
\newtheorem{lem}[thm]{Lemma}
\AddToHook{env/lem/begin}{\crefalias{thm}{lem}}
\crefname{lem}{lemma}{lemmas}
\Crefname{lem}{Lemma}{Lemmas}
\begin{document}
\begin{thm}\label{thm}
foo
\end{thm}
\begin{lem}\label{lem}
foo
\end{lem}
\noindent
\cref{lem}, \Cref{lem}
\end{document}
似乎在firstaid
中已经修了...但我不太懂这个...
最后补充一下「我本地TL2025会出问题」的内核和宏包版本(\listfiles
):
*File List*
article.cls 2025/01/22 v1.4n Standard LaTeX document class
size10.clo 2025/01/22 v1.4n Standard LaTeX file (size option)
amsthm.sty 2020/05/29 v2.20.6
cleveref.sty 2018/03/27 v0.21.4 Intelligent cross-referencing
l3backend-pdftex.def 2025-04-14 L3 backend support: PDF output (pdfTeX)
问 `cleveref` 引用名称不正确