Subscript Count in LaTeX (\text{H}_2\text{O})

H2O\text{H}_2\text{O}
LaTeX command
\text{H}_2\text{O}
Package
Add to your preamble:\usepackage{amsmath}
Mode
Math mode only

Where it is used

Molecular formula for water, with the subscript 2 counting hydrogen atoms in each molecule.

Element symbols must be upright, which is why each letter group is wrapped in \text; italic H_2O would look like variables. A shorter equivalent is \mathrm{H_2O}, which keeps everything upright including the subscript and is immune to surrounding italics. Subscripts count atoms only and should never be confused with superscript charges. Formulas with parentheses follow the same pattern, \mathrm{Ca(OH)_2}. For extensive chemistry, a dedicated chemistry package saves effort, but for a few formulas this manual approach is perfectly adequate.

Minimal compilable example

Paste this into an empty .tex file and compile it with pdfLaTeX, XeLaTeX or LuaLaTeX.

2H2+O2→2H2O2\text{H}_2 + \text{O}_2 \to 2\text{H}_2\text{O}
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Subscript Count: $\text{H}_2\text{O}$

\[ 2\text{H}_2 + \text{O}_2 \to 2\text{H}_2\text{O} \]
\end{document}

Related symbols

All Chemistry →

Frequently asked questions

How do I write Subscript Count in LaTeX?
Type \text{H}_2\text{O} in math mode, for example $2\text{H}_2 + \text{O}_2 \to 2\text{H}_2\text{O}$. Load amsmath first with \usepackage{amsmath}.
Which package do I need for \text{H}_2\text{O}?
\text{H}_2\text{O} needs amsmath: add \usepackage{amsmath} to your preamble before the document starts.
Can I use \text{H}_2\text{O} in text mode, or only in math mode?
Only in math mode. Outside $...$ LaTeX stops with "Missing $ inserted", so write $\text{H}_2\text{O}$ in running text.
Math poweredWrite LaTeX using AI

Best AI LaTeX Editor, Overleaf Alternative

Octree helps researchers from 15+ universities write research papers faster using AI

  • Generate beautiful TikZ diagrams using AI
  • Upload image and convert it to LaTeX seamlessly
  • Get instant assistance with writing and formatting research papers