# How do I typeset a chemical reaction equation? I want to have a long “=”

I am new to LaTeX. I searched ctan.org, but didn't find what I want. I want to typeset a chemical reaction equation. The = mark seems too short. I need a long one.

I tried to add an option 2cm to get a long = but failed.

Here is the raw code:

\documentclass{beamer}
\begin{document}
\begin{frame}
$H_{2}O =[2cm] H_{2}\uparrow+O_{2}\uparrow$
\end{frame}
\end{document}


The output screenshot is here:

In my opinion, the font doesn't look good. Would you give me some advice? For example, is there some font which would be appropriate for typesetting chemical reaction equations?

@Joseph already mentions the chemformula package which indeed has the net reaction “arrow” = for a stoichiometric equation:

\documentclass{article}
\usepackage{chemformula}
\begin{document}
\ch{H2O == H2 ^ + 1/2 O2 ^}
\end{document}


However, it is not scalable since it actually places a = in the centre of where an arrow would be.

\documentclass{article}
\usepackage{chemformula}
\begin{document}
\ch[arrow-min-length=2cm]{H2O == H2 ^ + 1/2 O2 ^}
\end{document}


But chemformula allows you to define your own arrow types or redefine the existing ones:

\documentclass{article}
\usepackage{chemformula}
\RenewChemArrow{==}
{
\draw ([yshift=.15ex]cf_arrow_start) -- ([yshift=.15ex]cf_arrow_end) ;
\draw ([yshift=-.15ex]cf_arrow_start) -- ([yshift=-.15ex]cf_arrow_end) ;
}

\begin{document}
\ch[arrow-min-length=2cm]{H2O == H2 ^ + 1/2 O2 ^}
\end{document}


For versions of chemformula < 3.6b you can add the arrow-min-length option as follows. However, an update is to be preferred.

\documentclass{article}
\usepackage{chemformula}

\ExplSyntaxOn
% ---------------------------------------------------------------------------
% define a key arrow-min-length' that sets a minimum length for chemformula's
% arrows. in the minimum length is less than two times the offset it is ignored.
% If an arrow must be longer because the label is longer the longer length is
% used.
%
% new dimension variable:
\dim_new:N \l__chemformula_arrow_minimum_length_dim

% redefine \__chemformula_determine_arrow_length:NN to obey the new minimum
% length:
\cs_set_protected:Npn \__chemformula_determine_arrow_length:NN #1#2
{
\box_set_eq:NN \l__chemformula_tmpa_box #1
\dim_set:Nn \l__chemformula_tmpa_dim { \box_wd:N \l__chemformula_tmpa_box }
\box_set_eq:NN \l__chemformula_tmpa_box #2
\dim_set:Nn \l__chemformula_tmpb_dim { \box_wd:N \l__chemformula_tmpa_box }
\box_clear:N \l__chemformula_tmpa_box
\dim_compare:nTF { \l__chemformula_tmpa_dim >= \l__chemformula_tmpb_dim }
{ \dim_set_eq:NN \l__chemformula_arrow_length_dim \l__chemformula_tmpa_dim }
{ \dim_set_eq:NN \l__chemformula_arrow_length_dim \l__chemformula_tmpb_dim }
{ 2\l__chemformula_arrow_offset_dim }
\dim_compare:nF
{ \l__chemformula_arrow_length_dim > \l__chemformula_arrow_minimum_length_dim }
{
\dim_set_eq:NN
\l__chemformula_arrow_length_dim
\l__chemformula_arrow_minimum_length_dim
}
\dim_set:Nn \l__chemformula_arrow_shortage_dim
{
(
\l__chemformula_arrow_length_dim
-
\l__chemformula_arrow_length_dim *
\dim_ratio:nn { \l__chemformula_arrow_ratio_tl pt } { 1pt }
) * 1/2
}
}

% define a key to set the minimum length:
\keys_define:nn { chemmacros / chemformula }
{ arrow-min-length .dim_set:N = \l__chemformula_arrow_minimum_length_dim }
\ExplSyntaxOff

\RenewChemArrow{==}
{
\draw ([yshift=.15ex]cf_arrow_start) -- ([yshift=.15ex]cf_arrow_end) ;
\draw ([yshift=-.15ex]cf_arrow_start) -- ([yshift=-.15ex]cf_arrow_end) ;
}

\begin{document}

\ch[arrow-min-length=2cm]{H2O ==[a][b] H2 ^ + 1/2 O2 ^}

\end{document}

• Thank you very much.The last formula is what I need.And If I want to add some special reaction condition,such as heat,electricity,how can I put the reaction condition on the top of the long"="? – nyRobot Aug 8 '13 at 8:52
• @nyRobot use the optional arguments that each arrow has: \ch{A ==[above][below] B} This is all described in the documentation – cgnieder Aug 8 '13 at 8:55
• I notice the redefine(customize) method is a pretty good idea. – nyRobot Aug 8 '13 at 8:56
• I can not compile successfully.Here I got "The key 'chemmacros/chemformula/arrow-min-length' is unknown and is being ignored.See the LaTeX3 documentation for further information".What should I do? – nyRobot Aug 8 '13 at 9:41
• @nyRobot You probably have an outdated version. arrow-min-length was introduced in version 3.6b (2013/04/19), the current version is 4.0 (2013/07/06). I suggest you update your TeX distribution. – cgnieder Aug 8 '13 at 9:52

I would use the mhchem package (as ChrisS suggested) for the formatting of chemical formulae:

\documentclass{beamer}

\usepackage{mhchem}

\begin{document}
\begin{frame}
\ce{H2O -> H2 ^ + 1/2 O2 ^}

min. 2 cm long arrow:

\ce{H2O ->[\hspace*{2cm}] H2 ^ + 1/2 O2 ^}
\end{frame}
\end{document}


Note, that chemical element are automatically typeset upright using this package. Furthermore, I use a reaction arrow to denote the chemical process instead of equality =. The equal sign is reserved for the indication of double bonds.

The lengths of the reaction arrow can be modified by inserting text or whitespace above or below the arrow, respectively.

• The equal sign is resverved?What should I do if I want to typeset an equal sign?Is there some method to customize a equal sign? – nyRobot Aug 8 '13 at 8:08
• In chemistry the equal sign can also be used in place of an arrow. This is called a stoichiometric equation or stoichiometric relation – cgnieder Aug 8 '13 at 9:22
• @hakaze ,I really want typeset out a long "=" equal sign.Because I now typeset using Tex Live 2012.I can not use cgnieder 's solution. Thank you in advance. I would like to update to Tex Live 2013 not now . – nyRobot Aug 8 '13 at 12:32
• @nyRobot yes you can, see my edited answer :) – cgnieder Aug 8 '13 at 13:26

As hakaze says, mhchem does this very nicely. There is also the chemformula package, which uses a very similar input syntax but which is part of a bigger bundle of chemistry support stuff with lots of features:

\documentclass{beamer}

\usepackage{chemmacros}

\begin{document}
\begin{frame}
\ch{H2O -> H2 ^ + 1/2 O2 ^}

min. 2 cm long arrow:

\ch{H2O ->[\hspace*{2cm}] H2 ^ + 1/2 O2 ^}
\end{frame}
\end{document}
`
• Thank you.I will read the package doc.By the way,what should I do if I insist on using a equal sign?Any advice? – nyRobot Aug 8 '13 at 8:21