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)
3 Answers
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.
- 757,742
-
5I 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
-
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. – David Carlisle May 11 '12 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
expl3we still use a lot of count registers: there is an impact. – Joseph Wright May 11 '12 at 13:52 -
1To the reader wondering "what's an
emacsbuffer?" I would suggest keepingsource2e.pdfhandy. It's in most TeX distributions. – Matthew Leingang May 11 '12 at 15:01 -
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:-) – David Carlisle May 11 '12 at 15:33
-
@JosephWright, this still doesn't explain why registers are used rather than constants. =] Is it purely historical or are there modern-day performance implications? – Alex Hirzel May 11 '12 at 19:07
-
@AlexHirzel I don't understand what you mean by 'constants': in TeX, apart from a few primitives, a constant is just a macro or register that we don't change by convention. In
expl3, we still use registers for these integer 'constant-by-conventions' as there is a performance gain. – Joseph Wright May 11 '12 at 19:12 -
(Actually, it's a bit more complex as we do use
\chardefand\mathchardefto create smaller positive integer constants.) – Joseph Wright May 11 '12 at 19:14 -
2
-
So in a typical Latex class file, if I were to rewrite all measurements in the more readable form, e.g. "0pt" can I assume there would not be a noticeable difference on a fast modern computer? – Kaveh1000 Jul 16 '14 at 09:22
-
@user42645 unless the length setting is in a macro to be used thousands of times it will be hard to measure the difference let alone notice it. But beware of the need for trailing space or \relax – David Carlisle Jul 16 '14 at 09:27
-
It would be nice to add similar with usage within
\numexpr(I compared\count@=\numexpr\z@+\z@+\z@\relaxwith0+0+0). There isn't as much a difference as in your test but still it shows. – Apr 27 '18 at 17:41
\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.
- 1,779
I had to look it up at the index of the TeXbook
\z@is used quite often to stand for either0ptor0
p. 348, Appendix B
- 3,848
latex z: http://www-sop.inria.fr/marelle/tralics/doc-z.html – Jake May 11 '12 at 12:58\p@mean in some code? – Werner May 11 '12 at 14:37LaTeX \z@led me right to this page – CoffeeTableEspresso Mar 27 '19 at 02:24