2

So, whenever you begin a document by giving it some class (article, memoir, etc), there are many default lengths and heights being used. What I am looking for is a way to see these without explicitly needing to dig through the documentation or even the source code.

I understand that you can use \the\<some_name> in the body to display the value of \<some_name> in the document. But the problem is, what if you aren't sure what a variable is named?

Ideally, I am looking for something just like the \layout{} command from the layout package, but more general.

  • If you're looking only for registers, i.e. commands defined by \newcount, \newdimen etc., you can look through the log file, as all allocations are logged there in the form \<some_name>=\<type_of_register><number>. There's no way to display the definitions of all commands in scope, AFAIK – siracusa Aug 17 '18 at 22:45
  • Interesting. I tried some things, and \the\<type_of_register><number> works as well as \the\<some_name>. This will work as a sort of manual solution to my problem, thanks! – user8384493 Aug 17 '18 at 23:00
4

You can, yes, scroll through the .log. But where is the fun in that? :)

Also, with the number you cannot know the name of the allocated register, so it's not of much use to know only what it contains.

Here's a LaTeX solution (it won't work in plain TeX). This exploits LaTeX's \e@alloc macro, which is used through the kernel to allocate registers. I added something to the definition of \e@alloc to make it save the allocated register names. Add this to your document:

\makeatletter
\def \countlist{\@gobble}% @gobble to remove the first comma
\def \dimenlist{\@gobble}%
\def  \skiplist{\@gobble}%
\def\muskiplist{\@gobble}%
\def   \boxlist{\@gobble}%
\def  \tokslist{\@gobble}%
\def  \readlist{\@gobble}%
\def \writelist{\@gobble}%
\def\e@alloc#1#2#3#4#5#6{%
  \global\advance#3\@ne
  \e@ch@ck{#3}{#4}{#5}#1%
  \allocationnumber#3\relax
  \global#2#6\allocationnumber
  \wlog{\string#6=\string#1\the\allocationnumber}%
  % Until here it's unchanged
  % Now we define a \reserved@a macro that will hold the name of the \<type>list
  \edef\reserved@a{%
    \expandafter\noexpand
    \csname\expandafter\@gobble\string#1list\endcsname}%
  % Now we add #6 (the allocated register) to the list
  \expandafter\xdef\reserved@a{\reserved@a,#6}%
  }%
\makeatother

This will "record" the allocated registers in the \<type>list macro. Its will only have effect after you inserted it, so if you want to see the registers allocated by the document class you need to add this before.

Because it only affects what is allocated after the redefinition, you cant see the LaTeX kernels registers, like these:

\newcount\@tempcnta
\newcount\@tempcntb
\newif\if@tempswa
\newdimen\@tempdima
\newdimen\@tempdimb
\newdimen\@tempdimc
\newbox\@tempboxa
\newskip\@tempskipa
\newskip\@tempskipb
\newtoks\@temptokena
\newskip\@flushglue

Now it's up to you what you'll do with that list. For example, you can print a table with the register name on the left and its value to the right:

\makeatletter
\def \countlist{\@gobble}% @gobble to remove the first comma
\def \dimenlist{\@gobble}%
\def  \skiplist{\@gobble}%
\def\muskiplist{\@gobble}%
\def   \boxlist{\@gobble}%
\def  \tokslist{\@gobble}%
\def  \readlist{\@gobble}%
\def \writelist{\@gobble}%
\def\e@alloc#1#2#3#4#5#6{%
  \global\advance#3\@ne
  \e@ch@ck{#3}{#4}{#5}#1%
  \allocationnumber#3\relax
  \global#2#6\allocationnumber
  \wlog{\string#6=\string#1\the\allocationnumber}%
  \edef\reserved@a{%
    \expandafter\noexpand
    \csname\expandafter\@gobble\string#1list\endcsname}%
  \expandafter\xdef\reserved@a{\reserved@a,#6}%
  }%
\makeatother
\documentclass{memoir}% Many allocations :)
\usepackage[T1]{fontenc}
\usepackage{etoolbox}% For the csvlist thingy
\usepackage{longtable}% To allow page breaks

\begin{document}

% Create an empty list
\newcommand\reglist{}
% Define a command \do which adds a table row to the list
\def\do#1{\appto\reglist{%
% the allocated register  its value
  \expandafter\string#1 & \the#1 \\}}%
% Process the \skiplist            VVVVVVVVV
\expandafter\docsvlist\expandafter{\skiplist}

% Print the list
\begin{longtable}{@{\ttfamily}l@{ = }l}
  \reglist
\end{longtable}

\end{document}

\@firstoffour pages:

enter image description here


Plain TeX solution:

Basically the same as for LaTeX2e, except that the macro is called \@alloc and it's a little different:

\catcode`@=11
\def\@gobble#1{}% plain doesn't have \@gobble
\def \countlist{\@gobble}% @gobble to remove the first comma
\def \dimenlist{\@gobble}%
\def  \skiplist{\@gobble}%
\def\muskiplist{\@gobble}%
\def   \boxlist{\@gobble}%
\def  \tokslist{\@gobble}%
\def  \readlist{\@gobble}%
\def \writelist{\@gobble}%
\def\alloc@#1#2#3#4#5{\global\advance\count1#1by\@ne
  \ch@ck#1#4#2% make sure there's still room
  \allocationnumber=\count1#1%
  \global#3#5=\allocationnumber
  \wlog{\string#5=\string#2\the\allocationnumber}%
  \edef\reserved@a{%
    \expandafter\noexpand
    \csname\expandafter\@gobble\string#2list\endcsname}%
  \expandafter\xdef\reserved@a{\reserved@a,#5}%
  }
\catcode`@=12

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.