Typing CO_2 easily

You want easy?

\documentclass{article}  
\usepackage{chemformula}
\begin{document}
\ch{CO2}
\end{document}

I would use the mhchem package. It makes a lot of chemistry things easier, including reactions as well as formulas.

Put the line

\usepackage{mhchem}

in the header section of your document, and then CO2 is just \ce{CO2}. You can use that in math mode or text mode, it works either way. Here are some examples of other formulae from the package documentation, to give an idea of what you can do. (Note from the very first example how easy it is to write a simple reaction.)

(Note also that, as mentioned in John Kormylo's answer, there is also a package chemformula. It seems to be very similar, and allows you to do the same things in very similar ways. It is a more recent package, but I have no experience with it.)

examples

more examples

more examples

more examples


I'm not sure if this is a question about how to use \co2 as a macro name or just a question about how to subscript in text mode. If you use \coo, the macro

\newcommand{\coo}{\ensuremath{\mathrm{CO_2}}}

works fine in both text and math mode. If you're only planning to use the macro in text mode, CO\textsubscript{2} works.

enter image description here

\documentclass{article}

\newcommand{\coo}{\ensuremath{\mathrm{CO_2}}}
\newcommand{\cooo}{CO\textsubscript{2}}

\begin{document}

With ensuremath: Text \coo\ and math $\coo$ both look fine.

With textsubscript: Text \cooo\ is fine, but math $\cooo$ isn't.

\end{document}

Don't forget the trainling \ and space after the call in text mode.

Tags:

Chemistry