It seems that if I \let\amp&
, the alignment tab &
can be replaced by \amp
everywhere (e.g., in the preamble and in the body of an \halign
). It is also possible to make the character &
active, and give it the same meaning by \catcode`\&=13
\let&\amp
. It seems that that active &
which has been let to the alignment tab &
can be used wherever an alignment tab &
was used.
This idea is quite general: we can define macro which takes a character as its argument, lets its active version to itself (with its current catcode), and finally makes the character active. This uses an \lccode
trick, described by Phillipe Goutet.
\def\activate#1{\begingroup
\lccode`\~=`#1%
\lowercase{\endgroup \let~#1}%
\catcode`#1=13\relax}
Here is an example to show that this operation does not break most uses I can think of for $
, &
, etc. In particular, $$...$$
is still recognized, and macro parameters too.
\activate &
\halign{#&#\cr a&b\cr}
\activate $ \activate ^ \activate _
$$ x^2_2 + y^2_2 $$
\activate #
\def\myshow#1{\show#1}
\myshow #
\bye
So my question is: "what are the drawbacks of this approach?" It allows a fix for peeking ahead with \futurelet
in alignments.
\peek_ahead_...
in (nested?) alignments". Could you please point me to a description of that? It would make my c.t.t. post more complete.siunitx
source. Take a look at\siunitx_table_collect_get:
, and using\peek_catcode_ignore_spaces:NTF
(with appropriate values) in place of the 'by hand' version I have there at the moment. Result: lots of errors, and I think at some stage disaster (it's been a while since I tested this).\futurelet
from triggering the construction of a cell if it hits a&
or\cr
, we normally use:\safebegin\futurelet\@let@token\macro
, where\safebegin
is\iffalse{\fi\ifnum`}=0\fi
and\macro
starts with a\safeend
, defined as\ifnum`{=0}\fi
. But this breaks when put in an\halign
preamble (as insiunitx
).\def\safeboxalign{\safeend\vbox\bgroup\halign\bgroup##}
and use the\safebegin
and\safeend
above. Then\halign{#\cr \safebegin \futurelet \dummy \safeboxalign \cr ABC\cr \egroup \egroup \cr}
works. But now, move the\safebegin ... \safeboxalign
to the preamble of the main\halign
(before#
). The result,\halign{\safebegin \futurelet \dummy \safeboxalign #\cr \cr ABC\cr \egroup \egroup \cr}
, breaks horribly. --- OTOH, redefining\cr
and an active&
seems to work.