What does \z@ do?
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 two 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.
\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
.