Short question:
Is there some font encoding or other trick that would allow the unicode character ²
(exponent 2) to be correctly interpreted by LaTeX, notably in math mode (i.e. translate it automatically into ^{2}
)?
(and likewise for ³, ⁴, …)
Detailed rationale:
Normally, to introduce an exponent in math mode one uses the ^ symbol, as in x^2
or e^{i\pi}
. I've been using LaTeX for decades and this feels very natural. However, with my current setup, when I type the characters x
^
2
on the keyboard, it results in the two unicode characters x²
.
I do have a \RequirePackage[utf8]{inputenc}
around the beginning of my personal style file, and Unicode characters in general are interpreted correctly (accented characters and such).
Usually I think about it and do type x
^
^
2
which results in x^2
, but often I'm typing fast and later have to go back to every line of code that produces a LaTeX Error: Command \texttwosuperior unavailable in en
error. This is annoying.
I could implement a workaround at the level of my editor (I use vim, so it would be simple to add a mapping to convert the ² into ^2), but I'm wondering if there's a better editor-independent way to handle this.
Best Answer
ConTeXt does it right.
The same can be achieved with LaTeX and
unicode-math
.In pdfLaTeX you have to use
newunicodechar
to redefine²
and³
to make them math-mode aware.