假设我有一个定义 ( \arabic
),其中包含一小串子定义 ( \alph
)。有时我想使用完整的交叉引用 (2.3a,2.3b,...)。但有时,当主要定义从上下文中清晰可见时,我想使用简短的交叉引用(A,b,..)。
但我只能定义一个\thesubdefinition
宏。所以我的问题是:有没有推荐的方法将多种格式绑定到一个计数器(即一个\label
)?在“用户代码”中,我想象使用\ref
完整引用和\shortref
简短引用:
\newcounter{subdefinition}[definition]
\def\subdef#1{\refstepcounter{subdefinition}(\alph{subdefinition}) #1}
...
\begin{definition} \label{def}
Bla bla technical stuff:
\subdef{simple axiom}\label{simple},
\subdef{complex axiom}\label{complex}.
Note that axiom~\shortref{complex} is more complex than axiom~\shortref{simple}.
\end{definition}
We will focus mostly on axiom~\shortref{complex}). % axiom b
...
Recall that axiom~\ref{complex} is very complex. % axiom 2.3b
我可能会破解某些东西,但也许有一个可以解决这一问题的包?
答案1
您可以使用zref
:
\documentclass{article}
\usepackage{amsthm}
\usepackage[user]{zref}
\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]
\newcounter{subdefinition}[definition]
\makeatletter
\zref@newprop{subdef}{}
\zref@newprop{fulldef}{}
\zref@addprop{main}{subdef}
\zref@addprop{main}{fulldef}
\newcommand\subdef[1]{%
\refstepcounter{subdefinition}%
\zref@setcurrent{subdef}{\alph{subdefinition}}%
\zref@setcurrent{fulldef}{\thedefinition\alph{subdefinition}}%
(\alph{subdefinition})~#1%
}
\newcommand{\shortref}[1]{\zref[subdef]{#1}}
\newcommand{\fullref}[1]{\zref[fulldef]{#1}}
\makeatother
\begin{document}
\section{A definition}
\begin{definition} \label{def}
Bla bla technical stuff:
\subdef{simple axiom}\zlabel{simple},
\subdef{complex axiom}\zlabel{complex}.
Note that axiom~\shortref{complex} is more complex than axiom~\shortref{simple}.
\end{definition}
\section{A reference}
We will focus mostly on axiom~\fullref{complex}.
\end{document}
请注意,您需要使用\zlabel
来设置标签\subdef
。