93

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)

5

3 Answers 3

74

\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.

102
+200

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.

13
  • 5
    I understand that parsing a macro is more efficient in principle. Just wondering: Does that have a noticable effect in practice?
    – ilpssun
    May 11, 2012 at 13:07
  • 14
    @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. May 11, 2012 at 13:16
  • 4
    @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, 2012 at 13:52
  • 2
    @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:-) May 11, 2012 at 15:33
  • 2
    I'll add some figures to my answer May 11, 2012 at 19:17
0

I had to look it up at the index of the TeXbook

\z@ is used quite often to stand for either 0pt or 0

p. 348, Appendix B

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .