views:

259

answers:

2

Minor point about LaTeX that bothers me. When one writes

a^b^c, a_b_c  

or

a'^b  

in math mode, LaTeX gives an error message complaining about multiple super/subscripts. This is particularly annoying after replacing a string containing a super/subscript or when using the apostrophe, '.

Is there a way to override the error and have LaTeX simply output

a^{bc} a_{bc} {a'}^b  

and so on?

+3  A: 

This is one of those cases where you really should be warned, and have to place the braces the way you want them - or write something without a double sub/superscript, if that's what you mean. Generally, when you're using superscript to indicate exponentiation, not indexing, a^b^c = a^{b^c}, so the output you describe is definitely incorrect in some cases. Sure, if they're superscript indices, you might mean a^{bc}, but how's LaTeX to know? And for subscripts, what if you really do mean a_{n_k}, not a_{nk}? (that is, double-indexing vs. a sequence of indices)

(And of course, if this crops up as part of a substitution, you can probably figure out a way to fix it as part of the substitution.)

Jefromi
Good point - it's true that in formulas exponentiation has funny rules in the order of operations. But in LaTeX, the convention is that only the first character after a ^ sign gets read as a superscript (unless there's a backslash or {},) so the logical way to interpret a^b^c would be to treat ^c independently from ^b as a first-order superscript. So while the warning behind the error message is understandable, is there a way to have LaTeX ignore these particular "errors" and interpret them in this way?
Dmitry Vaintrob
@Dmitry: No, I don't believe so. And your reasoning isn't really complete. It's more accurate to just use a single rule: only the first *group* after a `^` is placed in superscript. This means the real question is the associativity of the `^`; you could just as easily bind the `b^c` first. What I was trying to convey in my answer is that there's so much ambiguity that it'd be bad for the language to ever force it one way or another. And while suppressing warnings is one thing, this is an error message. LaTeX simply requires the syntax to be unambiguous, for better or worse.
Jefromi
@Jefromi, @Dmitry: I agree with Dmity's reasoning here. Latex doesn't have a concept of expression, instead it has it's eyes-mouth-stomach metaphor for handling input, and Dmitry's suggestion works fine with that.
Charles Stewart
@charles Stewart: I don't quite agree - it makes sense to be able to define your own notation which does this, and it possibly makes sense to even replace `^` and `_` with it as Alexey Malistov's answer suggests (though one has to consider whether this makes the source harder to read). It doesn't make sense to override the error, though.
Jefromi
+1  A: 

The following is what you wish

\catcode`\^ = 13 \def^#1{\sp{#1}{}}
\catcode`\_ = 13 \def_#1{\sb{#1}{}}
Alexey Malistov