考虑以下情况
假设我有多个环境,每个环境都有一个标题。为了清楚起见,假设我有以下环境:
\newtheorem{theorem}{Theorem} \newtheorem{lemma}[theorem]{Lemma} \newtheorem{proposition}[theorem]{Proposition}
现在我使用了以下方法之一
\begin{theorem} My theorem is a world shaking result like P = NP (just for fun :) ). \begin{itemize} \item part one \item part two \end{itemize} \end{theorem} \begin{proof} As for the the first part of this theorem, I will do the second... \end{proof}
theorem
现在,假设我已将环境类型更改为lemma
,那么在该proof
环境中,我希望术语theorem
自动更改为lemma
。
不幸的是,我找不到任何特定的技巧来实现自动化。但是,我知道这是可能的,因为我用它cleveref
来引用标签,它会相应地改变。但它是如何做到的,我不知道!
包含一个最小工作示例,如下所示:
\documentclass{article}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem} %[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\begin{document}
\begin{theorem}
My theorem is a world shaking result like P = NP (just for fun :) ).
\begin{itemize}
\item part one
\item part two
\end{itemize}
\end{theorem}
\begin{proof}
As for the the first part of this theorem, I will do the second...
\end{proof}
\end{document}
问候。
答案1
由于您已经在使用cleveref
,它提供了命令\namecref
。
按照以下示例使用它:
\documentclass{article}
\usepackage{amsthm}
\usepackage{cleveref}
\newtheorem{theorem}{Theorem} %[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\begin{document}
\begin{theorem}\label{any}
My theorem is a world shaking result like P = NP (just for fun :) ).
\begin{itemize}
\item part one
\item part two
\end{itemize}
\end{theorem}
\begin{proof}
As for the the first part of this \namecref{any}, I will do the second...
\end{proof}
\end{document}
输出:
现在,将示例中的theorem
改为,您将得到lemma