Suppose there is


Each \newcount uses \alloc@ and that has \wlog{\string#5=\string#2\the\allocationnumber}. Thus to determine which register mycountera uses I can look into the .log file for the (e.g.) \c@mycountera=\count123.

But how can I determine the number of the used register inside of LaTeX automatically? (Something like \registernumber{\c@mycountera} expanding to 123.) After \newcount\c@mycountera it is \the\allocationnumber, but when there is an unknown number of counts created between \newcount\c@mycountera and the time when I need the information this does not help. (I cannot use \xdef\myallocationnumber{\the\allocationnumber} immediatly after \newcount\c@mycountera, because it is defined inside of a package.)

(I suspect that the answer is usable with e.g. \dimen, \box,... too.)

  • 1
    @Stephen Out of curiosity where are you using this? – Yiannis Lazarides Feb 23 '12 at 15:51
  • as for example \cl@@ckpt stores all the counters in a list, you could check by inspecting the list as well. – Yiannis Lazarides Feb 23 '12 at 17:11
  • @Sure, although one could extract those as well. Please see my answer, I think you will end up with issues in any case. – Yiannis Lazarides Feb 23 '12 at 18:12
  • @Stephen Now that the problem is clearer, perhaps it's better to change the question's title. – egreg Feb 23 '12 at 20:31
  • @egreg I asked a separate question for that: tex.stackexchange.com/questions/45651/… . Sorry for the mess I created her. – Stephen Feb 24 '12 at 17:15

You can use the fact that \meaning will print something like \countXXX for a register:


I've used a simple loop to remove the type of register from the front of the number here. There are perhaps better ways to do that, but if proves the principal. The loop uses the fact that \char48 is 0 and \char57 is 9, so anything outside of this range is not a number.

  • Quite similar to mine. I'd use `0 and `9 instead of 48 and 57, just not to look at the ASCII table. However, it fails for box registers. – egreg Feb 23 '12 at 15:23
  • +1 After gobbling six preceding \relax (from \count) in the result your answer exactly solves my problem. Thanks! (I'll wait until tomorrow before accepting it, just in the unlikely case there would be another answer.) – Stephen Feb 23 '12 at 15:46
  • 1
    @Joseph a simpler (but devious) test for digits is \ifnum1<1#1 digit\else non-digit\fi. – Bruno Le Floch Feb 23 '12 at 19:24
  • @BrunoLeFloch I was sure there shortcut, but couldn't be bothered to work it out! – Joseph Wright Feb 23 '12 at 19:52

Here is one that works also for box registers:

       \ifnum`#1<`0 \else \ifnum`#1>`9 \else #1\fi\fi

\def\showcounter#1{\expandafter\showregister\csname c@#1\endcsname}





\showcounter{AAE} % or \expandafter\showregister\csname c@AAE\endcsname

Box register numbers will be in hexadecimal form, preceded by "

The output should be (if starting without any package)


(Moved additional code to this other answer)

Here's a LaTeX3 version:

\DeclareExpandableDocumentCommand{\showcounter} { m }
  { \exp_args:Nc \showregister { c@#1 } }
\DeclareExpandableDocumentCommand{\showregister} { m }
   \tl_map_function:fN { \cs_meaning:N #1 } \showreg_scan:n
\cs_generate_variant:Nn \tl_map_function:nN { f }
\cs_new:Npn \showreg_scan:n #1
      (  \int_compare_p:n { `#1 >= `0 } && \int_compare_p:n { `#1 <= `9 } )
      \int_compare_p:n { `#1 = `" }
      ( \int_compare_p:n { `#1 >= `A } && \int_compare_p:n { `#1 <= `F } )
     { #1 }

\def\test#1{\edef\x{\showregister#1}\message{\x\space = \meaning#1}}




The output on the terminal will be

36 = \dimen36
"23 = \char"23
  • @egreg: nitpicking, once more, but variables normally (i.e., in the LaTeX3 naming convention) start with \l_ or \g_ or \c_ depending on whether they are to be modified locally, globally, or not at all (constants). – Bruno Le Floch Feb 23 '12 at 19:26
  • @BrunoLeFloch You're right, of course – egreg Feb 23 '12 at 20:22

This is too long for a comment. As per the OP the counter number is to be used for checking the order of packages loaded. This is highly unlikely that it can be a full proof technique.

LaTeX2e, stores all the counters allocated in an \@elt list called \cl@@ckpt.

The following MWE will display all counters allocated and the name of the counter i.e., the part after c@. As you will observe by running the example, hyperTexies like Heiko will fiddle the system. Mostly though, it will predict order of loading:

% See all the counters in LaTeX2e
% and their allocation numbers
       \csname c@##1\endcsname
       \space = ##1,\par
All counter in article class plus one!
Expand list.


\ifcsname c@section@level\endcsname 
   hyperef package has been loaded
   not loaded
%\expandafter\let\csname c@section@level\endcsname\undefined 



A better way to check for file order is to check the @filelist.

% Just to see files
 \next, \par
% Command factory
      \expandafter\edef\csname @\next\endcsname{\thectr}

% Define macro to check order
   \edef\X{\csname @#1\endcsname}
    \edef\Y{\csname @#2\endcsname}
      Yes loaded earlier \X, \Y
      No loaded later \X, \Y


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.