10

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?

Bernhard
  • 385
  • 1
  • 3
  • 16

2 Answers2

14

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.

Werner
  • 603,163
  • 4
    fixltx2e defines \textsubscript: I'd always load this package for the fix to \( ... \) anyway. – Joseph Wright Sep 12 '12 at 06:36
  • 1
    This answer, or at least the fixltx2e portion of it, is now depreciated. All fixes from the package were migrated into the latex kernel in 2015. – Taylor Raine Jun 12 '20 at 20:09
1

To avoid the complicated phrases, which I often encounter when I want multi-character subscripts, I would normally put macros like these at the start of the document.

%Macros    
% Italic text with italic exponent
\newcommand{\me}[2]{\ensuremath{\mathit{#1}^\mathit{#2}}}
% Normal text with normal exponent
\newcommand{\te}[2]{\ensuremath{\textrm{#1}^\textrm{#2}}} 
% Italic text with italic multi-character subscript index
\newcommand{\ms}[2]{\ensuremath{\mathit{#1}_\mathit{#2}}}
% Normal text with normal subscript index
\newcommand{\ts}[2]{\ensuremath{\textrm{#1}_\textrm{#2}}} 

They can be used inside or outside of the math environments.

HansK
  • 11
  • 1