Personal tools

You are here: Home / src / saveentry.txt

# saveentry.txt

This shows how to make a template where the entry is saved and procesed.
First, a self-explanatory definition:

\def\saveentry#1//{\def\entry{#1}}

Now, the problem is that we want #1 to be what the user (or ourselves) will write between the &'s,
i.e., the #-part. The template may be defined as

\saveentry#1//\dosomething{\entry},

where \dosomething is macro with one parameter that . . . does something!

\def\dosomething#1{${#1}^{#1-1}$}

Then, inside the table, we may write

A & .... \cr

or

A \cr

and we will get $A^{A-1}$.

The template definition works because, when TeX gets to the & or the \cr, it does not take it as part of the argument,
but as the ending of the #-part, and its reading mechanism goes to the v-part, where it founds the // that ends the argument.

\halign{\saveentry#//\dosomething& \saveentry#//\dosomething{\entry}\cr
A & e\cr
}

I owe the folloing remark to someone, I don't know who (I got a forwarded message via Barbara Beeton).

>
> You have to be careful with the use of & and \span and \cr, because these tokens
> are intercepted by TeX's scanner even when it is not expanding macros.
>
> but the final clause is confusing: what Don really means is "even when it
> is scanning tokens without processing them (perhaps skipping them)".
> What he is getting at is that an & will delimit the alignment entry
> even when "tokens are being absorbed at high speed", as when collecting
> a macro argument or skipping text until \else or \fi.

I have not noticed till now that, if we need the macro \dosomething for no more than the table's entries,
one may get along without \saveentry.

\def\processentry#1//{${#1}^{#1-1}$}

\halign{\processentry#//& \processentry#//\cr
A & e\cr
}

Document Actions