[Tex/LaTex] Using a ^ outside math mode

superscripts

I take it it is possible to redefine ^ (and _) to yield \textsuperscript
in text mode and work normally in math mode (is there a good reason why this is
not the default behaviour?), but I don't know how. This is what I tried:

\documentclass{article}

\begin{document}

\let\oldhat^
\def^{\ifmmode\expandafter\oldhat
  \else\expandafter\textsuperscript\fi}

$x^n$

% indulgence^2

indulgence\textsuperscript{2}

\end{document}

Best Answer

There are good reasons for not using ^ in text mode. However, if you want to live dangerously,

\documentclass{article}

\catcode`^=\active
\protected\def^{\ifmmode\expandafter\sp\else\expandafter\textsuperscript\fi}

\begin{document}

Indulgence^2

$x^2$

\end{document}

enter image description here