From 8d754cbf10de076da7e9ed829767c29420978cf2 Mon Sep 17 00:00:00 2001 From: Kenneth Odle Date: Wed, 5 Jun 2024 15:19:28 -0400 Subject: [PATCH] =?UTF-8?q?Updated=20=C2=ABmhchem=C2=BB=20section?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 004/codex-004.tex | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/004/codex-004.tex b/004/codex-004.tex index e106407..78cab2a 100644 --- a/004/codex-004.tex +++ b/004/codex-004.tex @@ -506,13 +506,50 @@ As it turns out, people have written a number of different packages over the yea \section{Package \texttt{mhchem}} -For typesetting chemical equations: +This package is useful for typesetting chemical equations and reactions and has a fairly intuitive interface. For example, to typeset this equation: +\vspace{\baselineskip} +\noindent{}\ce{CO2 + C -> 2 CO} +\vspace{\baselineskip} + +we would simply use this markup: + +\begin{Verbatim}[] \ce{CO2 + C -> 2 CO} +\end{Verbatim} +As you can see, numbers placed after a letter are automatically formatted as a subscript. To format them as a superscript, we just use a caret (\texttt{\^}) before the number. For example, \verb|\ce{CrO4^2-}| produces \ce{CrO4^2-}. Pretty nifty, huh? + +Note that the superscripts and subscripts are not stacked; this is the preferred method according to the IUPAC\footnote{International Union of Pure and Applied Chemistry} Green Book. But if you want them to be stacked, \texttt{mhchem} has this option: + +\begin{Verbatim}[] +\mhchemoptions{layout=stacked} +\end{Verbatim} + +\mhchemoptions{layout=stacked} + +which will give us stacked superscripts: + +\vspace{\baselineskip} +\noindent{}\ce{CrO4^2-} +\vspace{\baselineskip} + +\mhchemoptions{layout=staggered-flat} + +It also does a pretty nice job of rendering fractions. \verb|\ce{1/2H2O}| gives us \ce{1/2H2O}. That's not the preferred way according to IUPAC, however. To accomplish that, you should use \verb|\ce{(1/2)H2O}| which gives us \ce{(1/2)H2O}. + +You can also do some fancier things. Here's another example from the manual: + +\begin{Verbatim}[] \ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-} +\end{Verbatim} + +which will give us: + +\vspace{\baselineskip} +\noindent{}\ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-} +\vspace{\baselineskip} -\ce{1/2H2O} \section{Package \texttt{chemformula}}