[Tex/LaTex] How to typeset a chemical reaction equation? I want to have a long “=”

equationsrelation-symbols

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:

Screenshot

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?

Best Answer

@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}

enter image description here

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}

enter image description here

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}

enter image description here


Edit in response to comments

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 }
    \dim_add:Nn \l__chemformula_arrow_length_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}