TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Some spaces seem ignored by the \halign primitive. For instance,

\setbox0=\vbox{\halign{ # \cr \space b \cr}}

indicates that there is no glue before b, but that there are two spaces after. It seems that spaces in the preamble are lost as soon as it is read, but I can't be sure.

Which spaces (implicit spaces, funny spaces, macros expanding to spaces, other spaces) are lost where in \halign?

share|improve this question

I don't know about implicit spaces, but after & or \cr, tokens are expanded (looking for \omit or \noalign) until an unexpandable token is found. Spaces are ignored in both cases.

share|improve this answer
but spaces are also ignored within the preamble? – Bruno Le Floch Apr 20 '11 at 15:34
@Bruno: No. It looks like the space after the { is ignored, but the space following the # is certainly there. A preamble of ` a # \cr` inserts a space before and after the b. – TH. Apr 20 '11 at 15:43
right. So spaces would only be ignored at the beginning of the u part of the template, perhaps. – Bruno Le Floch Apr 20 '11 at 15:48
@Bruno: That would be consistent with ignoring spaces after &. – TH. Apr 20 '11 at 15:50
up vote 5 down vote accepted

When reading the "u"-part of the preamble for each column of an \halign, namely the part which will be inserted before the cell contents, TeX ignores any leading "spacer". In this context, a "spacer" is defined as any implicit or explicit character token with category code 10. See @<Scan the template \<u_j>...@>= in tex.web for those who understand Pascal code.

At the start of each cell, i.e., just after each & or \cr (or \crcr), TeX fully expands tokens and ignores "spacers". This is done by calling @<Get the next non-blank non-call token@> before any call to init_col.

A test to show that indeed arbitrary implicit space tokens are ignored:

% Define \sp as an implicit space token "q".
\lccode` =`q\def\\{\let\sp= }\lowercase{\\ }

% Store an \halign in a box. The \sp in the u-part
% preamble is completely ignored, directly when TeX
% stores the preamble.  To prove this, we redefine
% \sp globally, and see that it doesn't appear at
% the next line.
  \sp x # \cr
  \sp \space A\gdef\sp{!} \cr
  \space B \cr
% Show the box.  Leading spaces have all been ignored.
% Not trailing spaces.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.