# What does \z@ do?

in parcolumns it has \z@ all over the space. I don't see it define it anywhere so I assume it is some internal command or something? I can't really make heads or tails of it though and I can't really search google for it(doesn't return anything useful)

-
First Google hit for latex z: www-sop.inria.fr/marelle/tralics/doc-z.html – Jake May 11 '12 at 12:58
@Jake Unfortunately the title of the page Tralics: a LaTeX to XML translator (Z) is very deceiving. Good site reference though as it clued me in to a lot of macros I couldn't find in some others references. – Uiy May 11 '12 at 13:54
– Joseph Wright May 11 '12 at 13:57
– Werner May 11 '12 at 14:37

\z@ is a LaTeX “constant” that's defined to be zero. Package developers can use it to assign or test against the value 0 and it can also replace a length of 0pt. Similar constants are \@ne (one) \tw@ (two) and so on. Due to the @ they can only be used in packages or between \makeatletter and \makeatother.

-

latex.ltx says

\newdimen\z@ \z@=0pt % can be used both for 0pt and 0


so as it says it is short (and efficient) way of getting 0.

You should always have a copy of the latex source file latex.ltx in a text editor window while reading package code:-), or perhaps, if you prefer, the typeset version of that, without the comments being removed, source2e.pdf, this is available in most distributions, or may be typeset from the sources.

Note that \count@=\z@ is more efficient than \count@=0 as \z@ is a register so terminates the scan for a number. But 0 might be the first token in 0123 so TeX has to read ahead to find the next token, if it is a space, discard it, if it is anything else it needs to put the token back into its input stream to be read after the assignment.

A Test file:

\catcode@=11
%\def\a{\dimen@=\z@}
\def\a{\dimen@=0pt\relax}
\def\b{\a\a\a\a\a\a\a\a\a\a}
\def\c{\b\b\b\b\b\b\b\b\b\b}
\def\d{\c\c\c\c\c\c\c\c\c\c}
\def\e{\d\d\d\d\d\d\d\d\d\d}
\def\f{\e\e\e\e\e\e\e\e\e\e}
\def\g{\f\f\f\f\f\f\f\f\f\f}
\def\h{\g\g\g\g\g\g\g\g\g\g}

\h

\bye


Doing a few runs of each to and taking a typical timing, with 0pt as above:

$time tex zat This is TeX, Version 3.1415926 (TeX Live 2011/Cygwin) (./zat.tex ) No pages of output. Transcript written on zat.log. real 0m3.822s user 0m3.774s sys 0m0.015s  With the % moved a line so it uses \z@: $ time tex zat
This is TeX, Version 3.1415926 (TeX Live 2011/Cygwin)
(./zat.tex )
No pages of output.
Transcript written on zat.log.

real    0m1.080s
user    0m1.029s
sys     0m0.030s


This is an easily observable difference, even without using the time command. 10^7 is quite a few assignments but probably not impossibly many.

-
I understand that parsing a macro is more efficient in principle. Just wondering: Does that have a noticable effect in practice? – ilpssun May 11 '12 at 13:07
@ilpssun I think you have that backwards, \z@ is more efficient because it is not a macro, but a register. It was certainly noticeable in the 1980's when the definition was made (as in the difference between only having time for a coffee and having time to go for lunch) To actually notice (rather than measure) the difference now you probably have to have a very big document doing an awful lot of assignments. – David Carlisle May 11 '12 at 13:16
@DavidCarlisle It still shows up to some extent, certainly in the more general case of 'integer constants as registers rather than numerals'. See the fact that in expl3 we still use a lot of count registers: there is an impact. – Joseph Wright May 11 '12 at 13:52
To the reader wondering "what's an emacs buffer?" I would suggest keeping source2e.pdf` handy. It's in most TeX distributions. – Matthew Leingang May 11 '12 at 15:01
@MatthewLeingang, hard as it is to imagine someone not using emacs, you make a good point I should keep my editor bias out of the question, I'll reword:-) – David Carlisle May 11 '12 at 15:33