Несколько форматов \the... для одного счетчика?

Несколько форматов \the... для одного счетчика?

Допустим, у меня есть определение ( \arabic), которое включает небольшой список подопределений ( \alph). Иногда мне нужно использовать полные перекрестные ссылки (2.3а,2.3б, ...). Но иногда, когда основное определение ясно из контекста, я хочу использовать короткие перекрестные ссылки (а,б, ..).

Но я могу определить только один \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.

введите описание изображения здесь

Связанный контент