5

I'm writing some software that interfaces with a LaTeX renderer.

I need to write chemical reactions and equilibria, but I don't have access to xrightleftharpoons, is there a way I can render the same thing inline without loading a package?

I do have access to some package stuff: amssymb, amsmath, bm, color, [latin1]inputenc, flexisym, breqn.

4

Here I have copied the macro definitions directly from the chemarr package, which defines the \xrightleftharpoons macro that you want. This way, you only have to load amsmath.

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newcommand*{\rightharpoonupfill@}{%
  \arrowfill@\relbar\relbar\rightharpoonup
}

\newcommand*{\leftharpoondownfill@}{%
  \arrowfill@\leftharpoondown\relbar\relbar
}

\newcommand{\xrightleftharpoons}[2][]{%
  \ensuremath{%
    \mathrel{%
      \settoheight{\dimen@}{\raise 2pt\hbox{$\rightharpoonup$}}%
      \setlength{\dimen@}{-\dimen@}%
      \edef\CA@temp{\the\dimen@}%
      \settoheight\dimen@{$\rightleftharpoons$}%
      \addtolength{\dimen@}{\CA@temp}%
      \raisebox{\dimen@}{%
        \rlap{%
          \raisebox{2pt}{%
            $%
            \ext@arrow 0359\rightharpoonupfill@{\hphantom{#1}}{#2}%
            $%
          }%
        }%
        \hbox{%
          $%
          \ext@arrow 3095\leftharpoondownfill@{#1}{\hphantom{#2}}%
          $%
        }%
      }%
    }%
  }%
}
\makeatother

\begin{document}
\[
A \xrightleftharpoons[\mathit{below}]{\mathit{above}} B
\]
\end{document}

enter image description here

  • I'm accepting this one on the very flimsy grounds of it being shorter and clearer than the other one. It was very close. – Lucas May 12 '14 at 1:28
4

The following example uses the implementation of \xrightleftharpoons from package mathtools. It uses macros from package amsmath. The example also provides the latter macros, thus that the loading of amsmath is not a requirement.

\documentclass{article}
%\usepackage{amsmath}% optional

% Implemenation for \xrightleftharpoons taken from package `mathtools'
\makeatletter
\newcommand*\xrightleftharpoons[2][]{%
  \mathrel{%
    \raise.22ex\hbox{%
      $\m@th\ext@arrow 0359\MT@rightharpoonup@fill{\phantom{#1}}{#2}$%
    }%
    \setbox0=\hbox{%
      $\m@th\ext@arrow 3095\MT@leftharpoondown@fill{#1}{\phantom{#2}}$%
    }%
    \kern-\wd0 \lower.22ex\box0 %
  }%
}
\def\MT@rightharpoonup@fill{%
  \arrowfill@\relbar\relbar\rightharpoonup
}
\def\MT@leftharpoondown@fill{%
  \arrowfill@\leftharpoondown\relbar\relbar
}

% The following definitions are taken from package `amsmath'.
\@ifpackageloaded{amsmath}{}{%
  \providecommand*{\arrowfill@}[4]{%
    $\m@th\thickmuskip0mu\medmuskip\thickmuskip\thinmuskip\thickmuskip
     \relax#4#1\mkern-7mu%
     \cleaders\hbox{$#4\mkern-2mu#2\mkern-2mu$}\hfill
     \mkern-7mu#3$%
  }
  \providecommand*{\ext@arrow}[7]{%
    \mathrel{\mathop{%
      \setbox\z@\hbox{#5\displaystyle}%
      \setbox\tw@\vbox{\m@th
        \hbox{$\scriptstyle\mkern#3mu{#6}\mkern#4mu$}%
        \hbox{$\scriptstyle\mkern#3mu{#7}\mkern#4mu$}%
        \copy\z@
      }%
      \hbox to\wd\tw@{\unhbox\z@}}%
    \limits
      \@ifnotempty{#7}{^{\if0#1\else\mkern#1mu\fi
                         #7\if0#2\else\mkern#2mu\fi}}%
      \@ifnotempty{#6}{_{\if0#1\else\mkern#1mu\fi
                         #6\if0#2\else\mkern#2mu\fi}}}%
  }
  \providecommand{\@ifnotempty}[1]{%
    \@ifempty{#1}{}%
  }
  \providecommand{\@ifempty}[1]{\@xifempty#1@@..\@nil}
  \@ifundefined{@xifempty}{%
    \long\def\@xifempty#1#2@#3#4#5\@nil{%
      \ifx#3#4\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
    }
  }{}
}
\makeatother

\begin{document}
  \[ a \xrightleftharpoons[below]{above} b \]
\end{document}

Result

  • I've accepted the other example, but it was close. See my comment on the other one. – Lucas May 12 '14 at 1:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.