3

I would like to include a picture of a reaction (png/pdf) inside chemmacros's reactions environment (also alongside with other reaction schemes) in order to keep up with the rest of reactions' numbers. Assume the raster/vector image is necessary and I cannot use chemfig of tikz for drawing that.

When I run the following MWE

\documentclass{article}

\usepackage{graphicx}
\graphicspath{ {graphics/} }

\usepackage{chemmacros}
\chemsetup{modules=all}

\begin{document}

\begin{reactions}
    2 H2O <=>[ $K_\mathrm{eq}$ ] H3O+ + OH-
    \includegraphics[width=0.8\linewidth]{Diels-Alder_rxn}
\end{reactions}

\end{document}

I receive tons of error messages:

line 14: Missing \endcsname inserted. \end
line 14: Missing number, treated as zero. \end
line 14: Illegal unit of measure (pt inserted). \end
line 14: Extra \endcsname. \end
line 14: Missing \endcsname inserted. \end
line 14: Missing number, treated as zero. \end
line 14: Illegal unit of measure (pt inserted). \end
line 14: Extra \endcsname. \end
line 14: File `Diels\chemformula_single_bond: Alder\chemformula_subscript:n rxn' not found. \end
line 14: Missing \endcsname inserted. \end
line 14: Missing number, treated as zero. \end
line 14: Illegal unit of measure (pt inserted). \end
line 14: Extra \endcsname. \end
line 14: Missing \endcsname inserted. \end
line 14: Missing number, treated as zero. \end
line 14: Illegal unit of measure (pt inserted). \end
line 14: Extra \endcsname. \end
line 14: Missing \endcsname inserted. \end
line 14: Missing number, treated as zero. \end
line 14: Illegal unit of measure (pt inserted). \end
line 14: Extra \endcsname. \end
line 14: Missing \endcsname inserted. \end
line 14: Missing number, treated as zero. \end
line 14: Illegal unit of measure (pt inserted). \end
line 14: Extra \endcsname. \end
line 14: Missing \endcsname inserted. \end
line 14: Missing number, treated as zero. \end
line 14: Illegal unit of measure (pt inserted). \end
line 14: Extra \endcsname. \end
line 14: Missing \endcsname inserted. \end
line 14: Missing number, treated as zero. \end
line 14: Illegal unit of measure (pt inserted). \end
line 14: Extra \endcsname. \end
line 14: Missing \endcsname inserted. \end
line 14: Missing number, treated as zero. \end
line 14: Illegal unit of measure (pt inserted). \end
line 14: Extra \endcsname. \end
line 14: Missing \endcsname inserted. \end
line 14: Missing number, treated as zero. \end
line 14: Illegal unit of measure (pt inserted). \end
line 14: Extra \endcsname. \end
line 14: File `Diels\chemformula_single_bond: Alder\chemformula_subscript:n rxn' not found. \end
line 14: Missing \endcsname inserted. \end
line 14: Missing number, treated as zero. \end
line 14: Illegal unit of measure (pt inserted). \end
line 14: Extra \endcsname. \end
line 14: Missing \endcsname inserted. \end
line 14: Missing number, treated as zero. \end
line 14: Illegal unit of measure (pt inserted). \end
line 14: Extra \endcsname. \end
line 14: Missing \endcsname inserted. \end
line 14: Missing number, treated as zero. \end
line 14: Illegal unit of measure (pt inserted). \end
line 14: Extra \endcsname. \end
line 14: Missing \endcsname inserted. \end
line 14: Missing number, treated as zero. \end
line 14: Illegal unit of measure (pt inserted). \end
line 14: Extra \endcsname. \end
line 14: Missing \endcsname inserted. \end
line 14: Missing number, treated as zero. \end
line 14: Illegal unit of measure (pt inserted). \end
line 14: Extra \endcsname. \end
line 14: Missing \endcsname inserted. \end
line 14: Missing number, treated as zero. \end
line 14: Illegal unit of measure (pt inserted). \end
line 14: Extra \endcsname. \end
line 14: Overfull \hbox (4692.08719pt too wide) in paragraph

So what is the proper way of including a graphical object into reaction/reactions environment, and number it accordingly?

Here is a little example of what I expect to see upon compilation: enter image description here

3

chemmacros per default uses chemformula for the reactions. chemformula treats numbers (here 0.8) as subscripts to compounds if they appear somewhere in between non-space tokens. But it provides users with an escape mechanism: "...". Also, you're missing a \\:

\documentclass{article}

\usepackage{graphicx}
\graphicspath{ {graphics/} }

\usepackage{chemmacros}
\chemsetup{modules=all}

\begin{document}

\begin{reactions}
    2 H2O <=>[ $K_\mathrm{eq}$ ] H3O+ + OH- \\
    "\includegraphics[width=0.8\linewidth]{Diels-Alder_rxn}"
\end{reactions}

\end{document}
12
  • For some reason I get a cluttered mix of both reactions with a single {1} number. Is it me being stupid or it's how chemformula supposed to work? – andselisk Sep 6 '17 at 8:09
  • Obviously the image is too big so it protrudes in the margin. The alignment is expected: the lower left corner of the image… IMHO what you want to achive is easier done with chemfig. – cgnieder Sep 6 '17 at 8:11
  • 1
    @andselisk you're missing a \\ – cgnieder Sep 6 '17 at 8:26
  • 1
    @andselisk you may try "\vcenter{\includegraphics[...]{...}}" – cgnieder Sep 6 '17 at 8:36
  • 1
    @andselisk that is because reactions behaves like amsmath's align. It's probably easier just using two reaction environments… – cgnieder Sep 6 '17 at 8:54

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.