[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: More on subscripts and superscripts



> As far as I can see (grits teeth) there is *no* way to write a TeX macro
> \foo that is of type mathrel, and which will work when the user says
> $X_\foo$.

Very interesting! As far as I can see, you're right, and I never
noticed that before.

> One (rather drastic) way round this would be to say:
>
>    \def\superscript{^}  \def\subscript{_}
>    \catcode`\^=\active  \catcode`\_=\active
>    \edef^{\superscript} \edef_{\subscript}

Either I'm missing the point or this will not work. The net effect of
the \edef's in the last line is (still) that a ^7 or _8 token will be
sent to TeX's stomach, without any error-preventing effect on the
following contents of the subscript or superscript. Perhaps you meant
something like this?:

  \def\superscript#1{^{#1}}  \def\subscript#1{_{#1}}
  \catcode`\^=\active  \catcode`\_=\active
  \let^=\superscript \let _=\subscript

> Unfortunately, this means that any plain TeX documents that rely on the
> active _ being \_ will break.  So I don't think we can get away with this!

It should work, I think, to make the math mode versions local to math
mode via

  \everymath{\let _\subscript \let ^\superscript}
  \everydisplay=\everymath

Or conditional:

  \def _{\relax\ifmmode \expandafter\superscript \else\_\fi}

In a document with a high proportion of sub and superscripts, the
speed cost of making _ and ^ expandable macros instead of primitive
operations is rather dismaying; nevertheless, in some LaTeX3-related
experiments last year, Chris Rowley and I tried out the idea of making
sub and superscript active characters (although via mathcode "8000, if
I recall correctly) in order to be able to track current math style,
which then allows a simple ifcase implementation of \mathchoice that
not only eliminates the quadruple-typesetting overhead of the
primitive implementation (at the cost of macro-expansion overhead) but
also some of its other shortcomings (e.g., the usually inevitable
\hbox{$...$} inside each branch of the mathchoice, with the
concomitant need to worry about side effects from \everymath or
\mathsurround). I think something like this is necessary for serious
mathematical typesetting, despite the significant practical handicap
of TeX's current design. It would be infinitely preferable to change
TeX itself, than to try to redo mathchoice at the macro level, but the
ramifications are so extensive that I very much doubt Knuth would be
willing to make such a change, even if he found no technical reasons
that would make it a bad idea.

> Insert standard rant about the appalling TeX syntax for superscripts and
> subscripts here.

I'm curious---what syntax would you suggest instead? Do you just mean,
that TeX should require braces to be used always?

Michael Downes                              mjd@math.ams.org (Internet)