# Multiple \the… formats for a single counter?

Say I have a definition (\arabic) that includes a small list of sub-definitions (\alph). Sometimes I want to use full cross-references (2.3a, 2.3b, ...). But sometimes, when the main definition is clear from context, I want to use short cross-references (a, b, ..).

But I can only define one \thesubdefinition macro. So my question is: is there a recommended way to tie more than one formatting to a single counter (i.e., one \label)? In the 'user code' I imagine using \ref for the full reference and \shortref for the short one:

\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


I could probably hack something, but maybe there's a package for this?

• I'd say to look at the zref package. – egreg Dec 23 '13 at 18:26
• There's also the cleveref package and its \creflabelformat command. One might imagine two different ways to format the label. – Bernard Dec 24 '13 at 1:03
• @Bernard: The cleveref package cannot tinker with the internals of the label (i.e., the \thecounter macro). All it allows you to do is surround it with parentheses and such. It would have been handy if cleveref had the solution, since I'm already using it. :-) – mhelvens Dec 24 '13 at 13:45

You can use zref:

\documentclass{article}
\usepackage{amsthm}
\usepackage[user]{zref}

\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]
\newcounter{subdefinition}[definition]

\makeatletter
\zref@newprop{subdef}{}
\zref@newprop{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}


Note that you need to use \zlabel for setting a label for \subdef.

• Thanks! A perfectly valid answer to my question. It's just a shame that a whole set of new commands is required to make this work. In particular, it means that I can't use cleveref anymore, which I left out of the original question for simplicity's sake. :-) Anyway, if I have to use a different \label command on the document level anyway, I might as well use two counters in the background, which is what I've now done. – mhelvens Dec 24 '13 at 13:44