10

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?

  • 3
    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
5

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}{}
\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}

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

enter image description here

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.