單一計數器有多種格式?

單一計數器有多種格式?

假設我有一個定義 ( \arabic),其中包含一小部分子定義 (\alph )。有時我想使用完整的交叉引用(2.3a,2.3b,...)。但有時,當主要定義從上下文中很清楚時,我想使用簡短的交叉引用(A,,..)。

但我只能定義一個\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

在此輸入影像描述

相關內容