Article View: comp.text.tex
Article #11069Re: Own Counters with Labels/Ref --- Solution
From: Ivo Welch
Date: Fri, 08 Jan 1993 16:32
Date: Fri, 08 Jan 1993 16:32
64 lines
2733 bytes
2733 bytes
Thanks to Alexander Durner, who came up with a solution:
1) You should use the `\label' command instead of `\newlabel' to
force writing to the aux file. `\newlabel' just defines the label
for the rest of the document.
2) To make LaTeX `know' which counter it should use for the label,
(locally) redefine `\@currentlabel'.
While this sounds easy, there is still some work to be done:
1) the `\@currentlabel' contains an @ (at sign) which normally has
`category code' 12 (= other) and thus can't be used in a
command name. With LaTeX, the two commands
\makeatletter
and
\makeatother
are available to change this catcode.
2) the \label command is written to the aux file at the same time
when the `completed page' is shipped to the dvi file (this is
necessary to keep page-number references right). Thus, the
\@currentlabel should be set to the counter's value, not to
the counter's name. (I think that expansion is done during LaTeX's
processing of \label, but to make things clearer I've used
\edef instead of \def or \newcommand.)
3) any changes to \@currentlabel should be kept local (otherwise,
it could mess up the references to theorems etc.)
I suggest you define a private macro as follows
\makeatletter
\def\mycounterlabel#1#2{% #1=label, #2=counter
\begingroup % to keep change to \@currentlabel local
\edef\@currentlabel{\arabic{#2}}% label := the value of #2
\label{#1}%
\endgroup}
\makeatother
Then you could say, e.g.,
\mycounterlabel{mylabel}{my}
to get the desired effect in your sample text.
LaTeX defines \theCOUNTER to print COUNTER's value (default: arabic)
and \p@COUNTER to print a `prefix' for it (e.g., section number;
default: empty).
The LaTeX def. of \@currentlabel inside a theorem-like environment
is done by \refstepcounter, and looks like
\edef\@currentlabel{\csname p@#2\endcsname\csname the#2\endcsname}%
where #2 is the COUNTER name.
If you don't want to hardwire the `arabic' into your
\mycounterlabel macro, you might replace the \edef line (and
\renewcommand the \theCOUNTER macro as you like).
A.D.
Technical Details
Message-ID:
<1993Jan8.083232.13913@mic.ucla.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!sdd.hp.com!network.ucsd.edu!news.service.uci.edu!ucivax!ucla-cs!ucla-mic!agsm!iwelchReferences:
<1992Dec31.185751.28407@mic.ucla.edu>Show Full Headers
Complete Article Headers
Newsgroups: comp.text.tex Path: arc1-ca.pugleaf.net!sparky!uunet!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!sdd.hp.com!network.ucsd.edu!news.service.uci.edu!ucivax!ucla-cs!ucla-mic!agsm!iwelch From: iwelch@agsm.ucla.edu (Ivo Welch) Subject: Re: Own Counters with Labels/Ref --- Solution Message-ID: <1993Jan8.083232.13913@mic.ucla.edu> Nntp-Posting-Host: risc.agsm.ucla.edu Organization: UCLA, Anderson Graduate School Of Management References: <1992Dec31.185751.28407@mic.ucla.edu> Date: 8 Jan 93 08:32:32 PST Lines: 64