任意文本的名称引用?

任意文本的名称引用?

在我的 TeX 文件中,有类似这样的内容:

\newcommand{\head}[2]{
\textbf{#1 \imp:} \textit{#2}\\
}

\newcommand{\definition}[1]{
\head{Definition}{#1}
}

\newcommand{\lemma}[1]{
\head{Lemma}{#1}
}

当我写引理和定义时,很难跟踪它们。所以我想使用标签。然后我很想写一些类似的东西

According to Lemma 3 we know that ....

引理 3 是即时填写的nameref,所以我只需要写这个

According to \nameref{lemma_cook} we know that .....

我尝试使用标签和引用,但它们只适用于可枚举的部分、图形和内容。有没有办法调整我的新命令来实现这一点(将它们放在可枚举环境中、使用虚拟计数器、使用hyperref包等)?

答案1

不要手动操作,而是使用\newtheorem命令;该amsthm包使用“当前样式”的概念扩展了命令:

\documentclass{article}
\usepackage{amsthm}

%\theoremstyle{plain} % implicit
\newtheorem{thm}{Theorem}[section] % theorems are numbered by section
\newtheorem{lem}[thm]{Lemma}       % lemmas share the numbering

\theoremstyle{definition} % body font is upright
\newtheorem{defn}[thm]{Definition} % definitions share the numbering

\newtheorem*{rem}{Remark} % unnumbered

\begin{document}

\section{Basics}

\begin{lem}\label{lem:easy}
$1+1=2$.
\end{lem}

\begin{thm}\label{thm:add}
$1+1+1=3$.
\end{thm}
\begin{proof}
The proof is easy when one recalls Lemma~\ref{lem:easy}.
\end{proof}

\begin{defn}
A natural number is \emph{nice} when it has good properties.
\end{defn}

\begin{thm}\label{thm:main}
Every natural number is nice.
\end{thm}
\begin{proof}
Easy induction, the inductive step is provided by Theorem~\ref{thm:add}.
\end{proof}

\begin{rem}
All of the above extends to real numbers, but this paper is too
short for showing the proof.
\end{rem}

\end{document}

在此处输入图片描述

相关内容