[Tex/LaTex] Sub-/Superscripts in Headings/Normal Text

math-modesectioningsubscriptssuperscripts

Possible Duplicate:
How to typeset subscript in usual text mode?

I sometimes want to typeset something simple like $N_2$ or $3^2$ in a Heading, other times in a paragraph of normal text.
I want all of it to be typeset in the surrounding font.
In normal text this works quite good with $\textrm{N}^\textrm{2}$, even though it is too complicated.
For Headings I have to know how my headings are typeset (if they use sans, italic, bold, etc.)
And if I then use the appropriate command and later change my mind about heading formatting, I have to redo it.
Is there a command to somehow "step out" of math into whatever is the highermost level of current formatting?

So far I could only find answers like: use this package, or this command (that only solves a specialized case).
I am looking for a more general understanding of what's going on, does someone have a link at hand to a short summary to the fonts and their interaction in LaTeX?

Best Answer

Type your superscripts and subscripts using \textsuperscript and \textsubscript respectively. The former is defined in latex.ltx while the latter could be defined similarly:

enter image description here

\documentclass{article}
\makeatletter
% \textsubscript defined equivalent to \textsuperscript in latex.ltx
\DeclareRobustCommand*\textsubscript[1]{%
  \@textsubscript{\selectfont#1}}
\def\@textsubscript#1{%
  {\m@th\ensuremath{_{\mbox{\fontsize\sf@size\z@#1}}}}}
\makeatother
\begin{document}
\tableofcontents
\section{Section $N^2$ and $N_2$}
\section{Section N\textsuperscript{2} and N\textsubscript{2}}
\end{document}

fixltx2e also provides the above defintion by default. So, adding

\usepackage{fixltx2e}% http://ctan.org/pkg/fixltx2e

to your document preamble would allow you to use \textsubscript.

Related Question