How to typeset chemical formulas in roman?

The standard today is to use mhchem (or similar packages), less typing

\documentclass{article}
\usepackage[version=4]{mhchem}
\begin{document}

\ce{CO2}

\end{document}

The the mhchem documentation for details.


Another similar package is chemformula (as suggested by @Dailef) to type­set chem­i­cal for­mu­las and re­ac­tions. The link is taken from CTAN Comprehensive TEX Archive Network.

enter image description here

\documentclass{article}
\usepackage{chemformula}
\usepackage{lipsum}
\begin{document}
\ch{CO_2} \lipsum[1]
\ch{CO_2}
\end{document}

You should use $\mathrm{CO}_2$, which provides exactly what you're looking for.