[texhax] tabbing in macros

Uwe Lück uwe.lueck at web.de
Thu Sep 7 00:46:19 CEST 2006


At 21:28 05.09.06, markrichard at cox.net wrote:
>I am trying to find a way to write tabbing commands (like \+ or
>\settabs) within a macro.  Can you help me with this or direct me to
>where this info can be located? I am using plain TeX.

At 19:13 06.09.06, Oleg Katsitadze wrote:
>\+ is defined as an outer macro, therefore it cannot be used
>inside another macro.  But \tabalign (which is what \+
>calls) can.  Unfortunately, \settabs will not work if you
>use \tabalign in the sample line:
>
>   \settabs\tabalign Text& More text&\cr % <- doesn't work
>
>because \settabs looks ahead for a \+ and doesn't find it.

Another point that I missed in my previous two postings!

>Probably the easiest way to deal with this is to redefine \+
>to be non-outer:
>
>   \def\+{\tabalign}

\let\+\tabalign works as well -- I tested it with Oleg's example below.

>   \def\table{%
>     \settabs\+ \quad& \quad&\cr
>     \+ 1& 2& 3\cr
>     \+  & 4& 5\cr
>     \+  &  & 6\cr
>   }
>
>   \table
>
>   \bye

To do penance additionally, I suggest another approach:
Define a variant \nosettabs of \settabs that deals with \tabalign
like \settabs deals with \+ (cf. \settabs etc. in
   http://www.dante.de/CTAN/macros/plain/base/plain.tex
[which is free!!?]):

   \catcode`\@=11

   \def\nosettabs{\setbox\tabs=\null \futurelet\next\n at sett@b}
   \def\n at sett@b{\ifx\next\tabalign
       \def\nxt{\afterassignment\n at s@tt at b\let\nxt}%
   %% <- You may replace the previous \n at s@tt at b with \s at tt@b
   %%    and drop the definition of \n at s@tt at b below if your
   %%    Plain Format is suffienctly recent ->
     \else\let\nxt\s at tcols\fi \let\next\relax \nxt}
   \def\n at s@tt at b{\let\nxt\relax \us at false\m at ketabbox} % local

   \catcode`\@=12

Test this with the following adaptation of Oleg's example
(\settabs replaced by \nosettabs, \+ by \tabalign):

   \def\table{%
     \nosettabs\tabalign \quad& \quad&\cr
     \tabalign 1& 2& 3\cr
     \tabalign  & 4& 5\cr
     \tabalign  &  & 6\cr
   }

   \table

   \bye

[OK -- better stop reading here if you are happy enough!]

A point in favour of this approach is that otherwise
your own tabbing macros should contain something like
\let\+\tabalign -- while \outer forbids such macros -- try

   \def\nonoutertabbing{\let\+\tabalign}

to experience how it fails (I tried some \begingroup \gdef
in vain as well).

A final suggestion of extreme crudeness:
Load

   \let\outer\relax [or \let\outer\empty!?]

before initex reads plain.tex ...
(not tested)

hope very much this helps
(please note that I have read considerable portions of the
TeXbook and have experimented a lot with this, while I'm
rather sure that there are Plain TeXperts knowing many
tricks I don't know)

-- Uwe. 



More information about the texhax mailing list