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 Scheikunde →

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 poweredSchrijf LaTeX met AI

Beste AI LaTeX Editor, Overleaf Alternatief

Octree helpt onderzoekers van 15+ universiteiten sneller onderzoeksartikelen schrijven met AI

  • Genereer mooie TikZ-diagrammen met AI
  • Upload afbeelding en converteer naadloos naar LaTeX
  • Krijg directe hulp bij het schrijven en opmaken van onderzoeksartikelen