Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I understand what \@gobble, \@gobbletwo etc. do, but I don't understand why \@gobble allows for an argument.

I believe that the definition of the macro is \long\def\@gobble#1{}. Why is this argument needed?

In this answer for instance David Carlisle defines \global\advance\rowc\@ne\@gobble{##}&&%. Does it mean that only ## are gobbled?

share|improve this question
The purpose of \@gobble is precisely to gobble one argument. –  egreg Dec 6 '12 at 15:11
Davids answer is within table constructions, they are a very special beast. In general, see egregs answer –  daleif Dec 6 '12 at 15:13
the meaning of ## is strange, not the command \@gobble. –  tohecz Dec 6 '12 at 15:27
add comment

1 Answer

up vote 17 down vote accepted

The definition of \@gobble is equivalent to


so, when used, it will simply throw away its argument. When you say something like


you're telling TeX that \macro will throw away its argument. Instead


throws away {something} as soon as TeX finds it.

Let's see the code you're referring to:

  \expandafter\xdef\csname data-#1(\the\rowc,\the\colc)\endcsname
  {\zap@space## \@empty}\cr
  \@@input #1 

Its purpose is to load a file (the argument to \savedata) which contains what usually would go between \begin{tabular}{l...} and \end{tabular}, in order to gather data from it.

The table is typeset inside a box, which will not be used afterwards (\setbox0=\vbox\bgroup) and in this box, which forms a group, some macros are redefined: \let\\\cr and \let\midrule\@empty. The first is to make \\ into the simple table line terminator, the second is because \midrule is meaningless for the purpose. Also \multicolumn is redefined:


so that, when TeX will see \multicolumn{1}{c}{(1)} it will leave only {(1)} in the input stream, because \@gobbletwo looks for two arguments and doesn't do anything with them, so they simply disappear. Probably


would be theoretically better, but in the end the result is just the same. Can you see now why? Your input file will possibly contain \multicolumn, but in this context we are only interested in the third argument, because we are not really typesetting a table, but only storing its contents (cell by cell) in macros.

A technically important \everyeof{\noexpand} is issued (I won't discuss it) and then a \halign is opened.

The syntax for the primitive \halign is quite interesting; I'm not going into the details, but basically it is

  <table row>\cr
  <table row>\cr

where <template> is a collection of specifications for each table column in the form <before>#<after> and separated by &. The # represents the cell contents. A && sequence means that the following specifications are repeated as many times as the table needs.

In this case the template is

  \expandafter\xdef\csname data-#1(\the\rowc,\the\colc)\endcsname
  {\zap@space## \@empty}\cr

which specifies a first column where the counter representing the columns is set to 0 and the one representing rows is advanced by one. Then the cell contents is passed to \@gobble, so it will vanish, as we don't need it.

The rest of the table is a sequence of columns with the following specification: the column counter is stepped and macros of the form


(<argument> is the argument to \savedata, in parentheses are the row and column indices, as numbers; the macro name can't be written with ordinary means, but \csname...\endcsname allows for those strange characters in the name). The replacement text for this macro provides eventually the cell contents with leading and trailing spaces removed (\zap@space## \@empty). The \cr ends the template.

As Ahmed Musa remarks, the \zap@space macro should be used with care, because it zaps all spaces; in this case it's unimportant, because the significant entries don't contain spaces.

Finally the table contents is input so that the macros will be defined; \\ will be translated into the primitive \cr to provide line terminations (the more complex job that \\ does in LaTeX tabular environments is not needed here) and \multicol{1}{c}{(1)} will leave only {(1)}.

The table is terminated by \crcr which will not add a line if the code ends with \\. The first \egroup matches the \bgroup after \halign and the second one the \bgroup after \vbox.

Note that here the "cell contents placeholder", ordinarily #, has to be doubled because we are inside a definition.

share|improve this answer
"The replacement text for this macro is the cell contents with leading and trailing spaces removed." \zap@space is invasive. Try \edef\x{\zap@space a b c d \@empty}. And use \zap@space, not \zap@spaces. –  Ahmed Musa Dec 6 '12 at 20:40
@AhmedMusa I was commenting David's code; you find the link to the original answer. –  egreg Dec 6 '12 at 20:46
@AhmedMusa The code uses zap@space there is just a little typo in the answer above. –  Jörg Dec 7 '12 at 13:41
@egreg I wish I could upvote this answer several times. It's really helpful, thanks a lot! –  Jörg Dec 7 '12 at 13:41
I always wondered what that code was doing, good to see some documentation for it. –  David Carlisle Dec 20 '12 at 20:10
show 3 more comments

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.