11

My query arises from my answer to Tab not as extra alignment tab and Andrey's rather nicer version. The question at hand involved making the TAB character usable for aligning tables. I assigned it to catcode 4, alignment, whereas Andrey used catcode 13, active characters, and then gdef'd it to &.

So my general question is: supposing we want to make a new character act like & or ^ or whatever, when is it best to reassign a character to a more specific catcode (like 1-4, 7, or 8), and when is it best to use the all-purpose catcode 13?

(In the related question Active characters let to a (non-active) character it was mentioned that it may not be a good idea to redefine existing characters in these categories to active versions of themselves, but I'm talking here about making new characters.)

1
  • 3
    I made the character active for the sole purpose of detecting multiple tabs. Otherwise, the specific catcode would seem better and more "correct". The general rule, IMO, is avoid active characters unless necessary. Oct 3, 2011 at 16:36

1 Answer 1

11

In Andrey's solution making ^^I active was necessary because he wanted to catch two consecutive tabs and reduce them to one:

\gdef^^I{\@ifnextchar^^I{}{&}}

Your (amended) definition

\newenvironment{tabbedtabular}[1]
  {\catcode`\^^I=4 \begin{tabular}{#1}}
  {\end{tabular}}

will do, but it won't catch consecutive tabs, interpreting each of them as if it were & (neither approach solves the original problem, in my opinion, but it's another matter).

A general rule could be: assign a particular category code when you need only that, use 13 when the character must do more than a simple character with a certain category code would.

I wouldn't forget category 9 (ignored). A category 9 character stops the scanning of a control sequence name, for instance. This approach is followed in LaTeX3: in .sty files the space is ignored, which is very handy for avoiding the "spurious space nightmare".

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .