Is there a way to override LaTeX's errors about double subscripts and superscripts?
-
05-10-2019 - |
Question
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?
Solution
The following is what you wish
\catcode`\^ = 13 \def^#1{\sp{#1}{}}
\catcode`\_ = 13 \def_#1{\sb{#1}{}}
OTHER TIPS
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.)
While Alexeys answer should be the acceppted one -- it does exactly what the author wants -- let me note there are also Latex packages available doing exactly this, most notably the Tensor package can do this:
You write \Gamma\indices{^\mu_{\nu\rho}}
for the first example. In contrast, with Alexeys answer you just can write \Gamma^\mu_{\nu\rho}
which is obviously shorter. However, the catcode redefinition of the ^
and _
characters will break any occurence of these characters in regular text which is annoying especially outside of math mode.