TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
Cursive text after _

I need to have some subscripted and superscripted text in my thesis document. But when I try to do it the way as H_{2O} or S^{2}. I get an error at that point and if I compile it anyway I get text with so white spaces for the rest of the line. Like,


Do I need to use some package to have this functionality? I thought it was standard latex. Or may be it is due to conflict with some package. I'm using the university template so don't quite understand what the problem is. I have put the header section where the packages are called below. Please help.

share|improve this question

marked as duplicate by clemens, Werner, egreg, Kurt, lockstep Feb 1 '13 at 19:55

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

See also this question which is about the same thing. – Martin Scharrer Feb 18 '11 at 15:23

If you are typesetting chemical formula, look up the mhchem package. This allows you to typeset chemical formulae easily.

For example: \ce{CO2} has the "2" as a subscript. Neat.




share|improve this answer
+1 For chemical formula this is the way to go (Sorry Seamus, I'm already out of votes for today). My answer was more about the general case. – Martin Scharrer Feb 18 '11 at 15:28
One could also use the package chemmacros and its command \ch (not that there's anything wrong with mhchem :) ) – clemens Sep 30 '12 at 9:03
The chemmacros package looks a lot more powerful than mhchem, but for what was required for this question, I think mhchem is the simpler, smaller, cheaper option. – Seamus Oct 1 '12 at 10:40

The _ and ^ character only work in math-mode. For text you need to use \textsubscript (needs the fixltx2e package) and \textsuperscript instead.

The reason why all the whitespace after H_{2O} is missing is that TeX changing into math-mode at the _ and then all the letters afterwards are set as variables. Also I think you mean H_{2}O (BTW: the braces can be skipped when they include only one character).

share|improve this answer

No special package but you need to be in math-mode. Use $ $ or \ensuremath{}.

share|improve this answer
This is not a good solution. You shouldn't use mathmode for things that aren't maths. There is a textsubscript option mentioned in a different answer that is the Right Way to do this... – Seamus Feb 18 '11 at 15:18
@Seamus: is this the reason, why you never use footnotes ;-) – Herbert Feb 18 '11 at 16:12
@Herbert Is that how footnotes work? Huh. I am going to start boycotting footnotes now! But seriously, since footnotes are marked up "semantically" it's ok, even if they abuse mathmode internally... – Seamus Feb 21 '11 at 12:36

The easiest ways I have found to include super- and subscripts in text mode are shown below. The example is the chemical formula for silicon dioxide:

Method 1:

$\rm SiO_2$

Method 2:


I am using MikTeX 2.4 and dvips + ps2pdf, and my PDF output looks good: The letters are definitely in text mode, not math, and the results of the two methods look the same in PDF.

An addendum: If the super- or subscript is an expression, do the following:


which yields the chemical formula for polyethylene.

share|improve this answer
Regarding your use of \rm, please read: Does it matter if I use \textit or \it, \bfseries or \bf, etc. and Will two-letter font style commands (\bf, \it, …) ever be resurrected in LaTeX?. Also, MiKTeX 2.4 is heavily outdated. Consider an upgrade to the most current version (MiKTeX 2.9). – Werner Feb 1 '13 at 18:48
Thanks for the comment on using \rm, but I really don't need to be told that the latest version of MiKTeX is 2.9. I practice "minimal computing": Whatever gets the job done with the least amount of overhead. – Christoph Steinbruchel Feb 2 '13 at 22:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.