| 1 |
% arara: pdflatex |
| 2 |
% arara: biber |
| 3 |
% arara: pdflatex |
| 4 |
% arara: pdflatex |
| 5 |
% -------------------------------------------------------------------------- |
| 6 |
% the CHEMFORMULA package |
| 7 |
% |
| 8 |
% typeset chemical compounds and reactions |
| 9 |
% |
| 10 |
% -------------------------------------------------------------------------- |
| 11 |
% Clemens Niederberger |
| 12 |
% -------------------------------------------------------------------------- |
| 13 |
% https://github.com/cgnieder/chemformula/ |
| 14 |
% [email protected] |
| 15 |
% -------------------------------------------------------------------------- |
| 16 |
% If you have any ideas, questions, suggestions or bugs to report, please |
| 17 |
% feel free to contact me. |
| 18 |
% -------------------------------------------------------------------------- |
| 19 |
% Copyright 2011--2022 Clemens Niederberger |
| 20 |
% |
| 21 |
% This work may be distributed and/or modified under the |
| 22 |
% conditions of the LaTeX Project Public License, either version 1.3c |
| 23 |
% of this license or (at your option) any later version. |
| 24 |
% The latest version of this license is in |
| 25 |
% http://www.latex-project.org/lppl.txt |
| 26 |
% and version 1.3c or later is part of all distributions of LaTeX |
| 27 |
% version 2008/05/04 or later. |
| 28 |
% |
| 29 |
% This work has the LPPL maintenance status `maintained'. |
| 30 |
% |
| 31 |
% The Current Maintainer of this work is Clemens Niederberger. |
| 32 |
% -------------------------------------------------------------------------- |
| 33 |
\documentclass{chemformula-manual} |
| 34 |
|
| 35 |
\addbibresource{cnltx.bib} |
| 36 |
\addbibresource{\jobname.bib} |
| 37 |
\begin{filecontents*}{\jobname.bib} |
| 38 |
@book{iupac:greenbook, |
| 39 |
author = {E. Richard Cohan and Tomislav Cvita\v{s} and Jeremy G. Frey and |
| 40 |
Bertil Holmstr\"om and Kozo Kuchitsu and Roberto Marquardt and Ian Mills and |
| 41 |
Franco Pavese and Martin Quack and J\"urgen Stohner and Herbert L. Strauss and |
| 42 |
Michio Takami and Anders J Thor} , |
| 43 |
title = {``Quantities, Symbols and Units in Physical Chemistry'', \acs{iupac} |
| 44 |
Green Book} , |
| 45 |
sorttitle = {Quantities, Symbols and Units in Physical Chemistry} , |
| 46 |
indexsorttitle = {Quantities, Symbols and Units in Physical Chemistry} , |
| 47 |
edition = {3rd Edition. 2nd Printing} , |
| 48 |
year = {2008} , |
| 49 |
publisher = {\acs{iupac} \&\ RSC Publishing, Cambridge} |
| 50 |
} |
| 51 |
\end{filecontents*} |
| 52 |
|
| 53 |
\DeclareInstance{xfrac}{chemformula-text-frac}{text} |
| 54 |
{ |
| 55 |
scale-factor = 1 , |
| 56 |
denominator-bot-sep = -.2ex , |
| 57 |
denominator-format = \scriptsize #1 , |
| 58 |
numerator-top-sep = -.2ex , |
| 59 |
numerator-format = \scriptsize #1 , |
| 60 |
slash-right-kern = .05em , |
| 61 |
slash-left-kern = .05em |
| 62 |
} |
| 63 |
|
| 64 |
\begin{document} |
| 65 |
|
| 66 |
\section{Introduction} |
| 67 |
Probably every chemist using \LaTeXe\ is aware of the great \pkg{mhchem} |
| 68 |
package by \hensel. There have always been some difficulties intertwining it |
| 69 |
with the \chemmacros\ package, though. Also, some other minor points in |
| 70 |
\pkg{mhchem} always bothered me, but they hardly seemed enough for a new |
| 71 |
package. They weren't even enough for a feature request to the \pkg{mhchem} |
| 72 |
author. The challenge and the fun of creating a new package and the wish for |
| 73 |
a highly customizable alternative led to \chemformula\ after all. |
| 74 |
|
| 75 |
\chemformula\ works very similar to \pkg{mhchem} but is more strict as to how |
| 76 |
compounds, stoichiometric factors and arrows are input. In the same time |
| 77 |
\chemformula\ offers \emph{many} possibilities to customize the output. |
| 78 |
|
| 79 |
\section{Licence and Requirements} |
| 80 |
\license |
| 81 |
|
| 82 |
The \chemformula\ package needs and thus loads the packages |
| 83 |
\bnd{l3kernel}~\cite{bnd:l3kernel}, \pkg{xparse}, \pkg{l3keys2e} and |
| 84 |
\pkg{xfrac} (all three are part of the \bnd{l3packages} |
| 85 |
bundle~\cite{bnd:l3packages}), |
| 86 |
\pkg{tikz}\footnote{\CTANurl[graphics]{pgf}}~\cite{pkg:pgf}, |
| 87 |
\pkg{amstext}~\cite{pkg:amstext}, \pkg{nicefrac}~\cite{pkg:nicefrac} and |
| 88 |
\pkg{scrlfile} (from the \KOMAScript\footnote{\CTANurl{koma-script}} |
| 89 |
bundle~\cite{bnd:koma-script}). |
| 90 |
|
| 91 |
\section{Setup} |
| 92 |
|
| 93 |
If you're using \chemformula\ as a standalone package options are set up with |
| 94 |
the following command: |
| 95 |
\begin{commands} |
| 96 |
\command{setchemformula}[\marg{options}] |
| 97 |
Set up \chemformula. |
| 98 |
\end{commands} |
| 99 |
|
| 100 |
\chemformula\ is tightly intertwined with the \chemmacros\ package. If both |
| 101 |
packages are loaded together, \chemformula\ is integrated into the |
| 102 |
\chemmacros\ package. Then all of \chemformula's options belong to |
| 103 |
\chemmacros' module \module{chemformula}. This means if you load it via |
| 104 |
\chemmacros\ or in addition to \chemmacros\ they can be setup with |
| 105 |
\begin{commands} |
| 106 |
\command{chemsetup}[\Oarg{chemformula}\marg{options}] |
| 107 |
Set up options for \chemformula\ exclusively, or |
| 108 |
\command{chemsetup}[\Marg{chemformula/\meta{option1},chemformula/\meta{option2}}] |
| 109 |
Set up options for \chemformula\ together with others of \chemmacros' |
| 110 |
options. |
| 111 |
\end{commands} |
| 112 |
|
| 113 |
\section{The Basic Principle} |
| 114 |
\chemformula\ offers one main command. |
| 115 |
\begin{commands} |
| 116 |
\command{ch}[\oarg{options}\marg{input}] |
| 117 |
\chemformula's main command. |
| 118 |
\end{commands} |
| 119 |
The usage will seem very familiar to you if you're familiar with \pkg{mhchem}: |
| 120 |
\begin{example}[side-by-side] |
| 121 |
\ch{H2O} \par |
| 122 |
\ch{Sb2O3} \par |
| 123 |
\ch{H+} \par |
| 124 |
\ch{CrO4^2-} \par |
| 125 |
\ch{AgCl2-} \par |
| 126 |
\ch{[AgCl2]-} \par |
| 127 |
\ch{Y^{99}+} \par |
| 128 |
\ch{Y^{99+}} \par |
| 129 |
\ch{H2_{(aq)}} \par |
| 130 |
\ch{NO3-} \par |
| 131 |
\ch{(NH4)2S} \par |
| 132 |
\ch{^{227}_{90}Th+} \par |
| 133 |
$V_{\ch{H2O}}$ \par |
| 134 |
\ch{Ce^{IV}} \par |
| 135 |
\ch{KCr(SO4)2 * 12 H2O} |
| 136 |
\end{example} |
| 137 |
|
| 138 |
However, there are differences. The most notable one: \chemformula\ |
| 139 |
distinguishes between different types of input. These different parts |
| 140 |
\emph{have} to be separated with blanks: |
| 141 |
\begin{commands} |
| 142 |
\command{ch}[\Marg{part1 part2 part3 part4}] |
| 143 |
\end{commands} |
| 144 |
A blank in the input \emph{never} is a blank in the output. This role of the |
| 145 |
blank strictly holds and disregarding it can have unexpected results and even |
| 146 |
lead to errors. |
| 147 |
|
| 148 |
The most visible differences regard spacing and the shapes of the default |
| 149 |
arrows: |
| 150 |
\begin{example}[side-by-side] |
| 151 |
\ch{A + B ->[a] C} \par |
| 152 |
\ce{A + B ->[a] C} |
| 153 |
\end{example} |
| 154 |
|
| 155 |
This means that \cs{ch}\Marg{2H2O} is recognized as a \emph{single} part, |
| 156 |
which in this case is recognized as a compound. |
| 157 |
\begin{example}[side-by-side] |
| 158 |
\ch{2H2O} \par |
| 159 |
\ch{2 H2O} |
| 160 |
\end{example} |
| 161 |
This also means, that a part cannot contain a blank since this will |
| 162 |
automatically divide it into two parts. If you need an extra blank in the |
| 163 |
output you need to use \verbcode+~+ or \cs*{~}. However, since commands |
| 164 |
in most cases gobble a space after them a input like |
| 165 |
\cs{ch}\Marg{\cs*{command} ABC} will be treated as a single part. If you want |
| 166 |
or need to divide them you need to add an empty group: |
| 167 |
\cs{ch}\Marg{\cs*{command}\marg{} ABC}. The different input types are |
| 168 |
described in the following sections. |
| 169 |
|
| 170 |
\section{Stoichiometric Factors} |
| 171 |
A stoichiometric factor may only contain of numbers and the signs |
| 172 |
\verbcode+.,_/()+ |
| 173 |
\begin{example}[side-by-side] |
| 174 |
\ch{2} \par |
| 175 |
\ch{12} |
| 176 |
|
| 177 |
% decimals: |
| 178 |
\ch{.5} \par |
| 179 |
\ch{5,75} |
| 180 |
|
| 181 |
% fractions: |
| 182 |
\ch{3/2} \par |
| 183 |
\ch{1_1/2} |
| 184 |
|
| 185 |
% ``iupac'': |
| 186 |
\ch{(1/2)} |
| 187 |
\end{example} |
| 188 |
|
| 189 |
As you can see if you input decimal numbers a missing leading zero is added. |
| 190 |
|
| 191 |
You have to be a little bit careful with the right syntax but I believe it is |
| 192 |
rather intuitive. |
| 193 |
\begin{sourcecode} |
| 194 |
this won't work but will result in an error: \ch{1/1_1} |
| 195 |
\end{sourcecode} |
| 196 |
|
| 197 |
If stoichiometric factors are enclosed with parentheses the fractions are not |
| 198 |
recognized and missing leading zeros are not added. What's inside the |
| 199 |
parentheses is typeset as is. |
| 200 |
\begin{example} |
| 201 |
\ch{(1/2) H2O} \ch{1/2 H2O} \ch{0.5 H2O} |
| 202 |
\end{example} |
| 203 |
You can find many examples like the following for stoichiometric factors in |
| 204 |
parentheses in the \acs{iupac} Green Book~\cite{iupac:greenbook}: |
| 205 |
\begin{reaction*} |
| 206 |
(1/5) K "\ox{7,Mn}" O4 + (8/5) HCl == (1/5) "\ox{2,Mn}" Cl2 + (1/2) Cl2 + (1/5) KCl + (4/5) H2O |
| 207 |
\end{reaction*} |
| 208 |
|
| 209 |
There are a few possibilities to customize the output: |
| 210 |
\begin{options} |
| 211 |
\keyval{decimal-marker}{marker}\Default{.} |
| 212 |
The symbol to indicate the decimal. |
| 213 |
\keychoice{frac-style}{math,xfrac,nicefrac}\Default{math} |
| 214 |
Determines how fractions are displayed. |
| 215 |
\keyval{frac-math-cmd}{command sequence}\Default{\cs*{frac}\Marg{\#1}\Marg{\#2}} |
| 216 |
\changedversion{4.17}Allows you to choose which command is used with |
| 217 |
\keyis{frac-style}{math}. |
| 218 |
\keyval{stoich-space}{skip}\Default{.1667em plus .0333em minus .0117em} |
| 219 |
The space that is placed after the stoichiometric factor. A rubber |
| 220 |
length. |
| 221 |
\keybool{stoich-paren-parse}\Default{false} |
| 222 |
If set to true stoichiometric factors enclosed by parentheses also are |
| 223 |
parsed. |
| 224 |
\keyval{stoich-format}{code}\Default |
| 225 |
\sinceversion{4.17}Allows formatting of the stoichiometric factors. The |
| 226 |
last macro given may take an argument. |
| 227 |
\keyval{stoich-print}{code containing \#1}\Default{\#1} |
| 228 |
\changedversion{4.17}This option allows to use specify a macro for |
| 229 |
printing the stoichiometric factors where \code{\#1} represents the |
| 230 |
factor. \emph{This option is depecated and will be removed some time in |
| 231 |
the future. Use \option{stoich-format} instead.} |
| 232 |
\end{options} |
| 233 |
|
| 234 |
\begin{example} |
| 235 |
\ch[decimal-marker={,}]{3.5} \ch[decimal-marker={$\cdot$}]{3,5} |
| 236 |
\end{example} |
| 237 |
|
| 238 |
The option \keyis{frac-style}{xfrac} uses the \cs*{sfrac} command of the |
| 239 |
\pkg{xfrac} package. The output strongly depends on the font you use. |
| 240 |
\begin{example} |
| 241 |
\ch[frac-style=xfrac]{3/2} \ch[frac-style=xfrac]{1_1/2} |
| 242 |
\end{example} |
| 243 |
\chemformula\ defines the instance \code{chemformula-text-frac} which you can |
| 244 |
redefine to your needs. See the \pkg{xfrac} documentation for further |
| 245 |
information. The default definition is this: |
| 246 |
\begin{sourcecode} |
| 247 |
\DeclareInstance{xfrac}{chemformula-text-frac}{text} |
| 248 |
{ |
| 249 |
slash-left-kern = -.15em , |
| 250 |
slash-right-kern = -.15em |
| 251 |
} |
| 252 |
\end{sourcecode} |
| 253 |
This document uses the font Linux Libertine~O and the following definition: |
| 254 |
\begin{sourcecode} |
| 255 |
\DeclareInstance{xfrac}{chemformula-text-frac}{text} |
| 256 |
{ |
| 257 |
scale-factor = 1 , |
| 258 |
denominator-bot-sep = -.2ex , |
| 259 |
denominator-format = \scriptsize #1 , |
| 260 |
numerator-top-sep = -.2ex , |
| 261 |
numerator-format = \scriptsize #1 , |
| 262 |
slash-right-kern = .05em , |
| 263 |
slash-left-kern = .05em |
| 264 |
} |
| 265 |
\end{sourcecode} |
| 266 |
|
| 267 |
The option \keyis{frac-style}{nicefrac} uses the \cs*{nicefrac} command of the |
| 268 |
\pkg{nicefrac} package. |
| 269 |
\begin{example} |
| 270 |
\ch[frac-style=nicefrac]{3/2} \ch[frac-style=nicefrac]{1_1/2} |
| 271 |
\end{example} |
| 272 |
|
| 273 |
The option \option{stoich-space} allows you to customize the space between |
| 274 |
stoichiometric factor and the group following after it. |
| 275 |
\begin{example}[side-by-side] |
| 276 |
\ch{2 H2O} \par |
| 277 |
\ch[stoich-space=.3em]{2 H2O} |
| 278 |
\end{example} |
| 279 |
|
| 280 |
\section{Compounds}\label{ssec:compounds} |
| 281 |
\chemformula\ determines compounds as the type that ``doesn't fit in anywhere |
| 282 |
else.'' This point will become more clear when you know what the other types |
| 283 |
are. |
| 284 |
\begin{example}[side-by-side] |
| 285 |
\ch{H2SO4} \par |
| 286 |
\ch{[Cu(NH3)4]^2+} |
| 287 |
\end{example} |
| 288 |
|
| 289 |
\subsection{Adducts} |
| 290 |
\chemformula\ has two identifiers which will create adducts. |
| 291 |
\begin{commands} |
| 292 |
\command{ch}[\Marg{A.B}] \ch{A.B} |
| 293 |
\command{ch}[\Marg{A*B}] \ch{A*B} |
| 294 |
\end{commands} |
| 295 |
\begin{example}[side-by-side] |
| 296 |
\ch{CaSO4.H2O} \par |
| 297 |
\ch{CaSO4*H2O} |
| 298 |
\end{example} |
| 299 |
Since numbers in a compound always are treated as subscripts (see |
| 300 |
section~\ref{ssec:subscripts}) you sometimes need to introduce stoichiometric |
| 301 |
factors for the right output: |
| 302 |
\begin{example}[side-by-side] |
| 303 |
\ch{Na3PO4*12H2O} \par |
| 304 |
\ch{Na3PO4* 12 H2O} \par |
| 305 |
\ch{Na3PO4 * 12 H2O} |
| 306 |
\end{example} |
| 307 |
|
| 308 |
\subsection{Subscripts}\label{ssec:subscripts} |
| 309 |
\emph{All} numbers in a compound are treated as subscripts. |
| 310 |
\begin{example}[side-by-side] |
| 311 |
\ch{H2SO4} |
| 312 |
\end{example} |
| 313 |
If you want a letter to be a subscript you can use the math syntax: |
| 314 |
\begin{example}[side-by-side] |
| 315 |
\ch{A_nB_m} |
| 316 |
\end{example} |
| 317 |
The subscript recognizes groups. You can also use math inside it. |
| 318 |
\begin{example}[side-by-side] |
| 319 |
\ch{A_{$n$}B_{$m$}} \par |
| 320 |
\ch{NaCl_{(aq)}} |
| 321 |
\end{example} |
| 322 |
|
| 323 |
\subsection{Commands} |
| 324 |
Commands are allowed in a compound: |
| 325 |
\begin{example}[side-by-side] |
| 326 |
\ch{\textbf{A2}B3} \ch{A2\color{red}B3} |
| 327 |
\end{example} |
| 328 |
|
| 329 |
However, if the commands demand numbers as argument, \eg, space commands or |
| 330 |
\chemmacros' \verbcode+\ox+ command the direct use will fail. This is |
| 331 |
because the numbers are treated as subscripts \emph{before} the command |
| 332 |
expands. |
| 333 |
\begin{sourcecode} |
| 334 |
\ch{A\hspace{2mm}B} will raise an error because \hspace sees something like |
| 335 |
this: \hspace{$_2$mm}. Actually not at all like this but equally bad\ldots |
| 336 |
\end{sourcecode} |
| 337 |
See section~\ref{ssec:text} for a way around this. |
| 338 |
|
| 339 |
\subsection{Charges and Other Superscripts} |
| 340 |
\paragraph{Basics} |
| 341 |
If a compound \emph{ends} with a plus or minus sign it will be treated as |
| 342 |
charge sign and typeset as superscript. In other places a plus is treated as |
| 343 |
a triple bond and a dash will be used as a single bond, see |
| 344 |
section~\ref{ssec:bonds}. |
| 345 |
\begin{example}[side-by-side] |
| 346 |
\ch{A+B} \ch{AB+} \par |
| 347 |
\ch{A-B} \ch{AB-} |
| 348 |
\end{example} |
| 349 |
|
| 350 |
For longer charge groups or other superscripts you can use the math syntax. |
| 351 |
It recognizes groups and you can use math inside them. Inside these groups |
| 352 |
neither \code{+} nor \code{-} are treated as bonds. If a dot \code{.} is |
| 353 |
inside a superscript it is treated as indicator for a radical. A \code{*} |
| 354 |
gives the excited state. |
| 355 |
\begin{example}[side-by-side] |
| 356 |
\ch{A^{x-}} \par |
| 357 |
\ch{A^x-} \par |
| 358 |
\ch{A^{x}-} \par |
| 359 |
\ch{A^{$x-$}} \par |
| 360 |
\ch{RNO2^{-.}} \par |
| 361 |
\ch{^31H} \par |
| 362 |
\ch{^{14}6C} \par |
| 363 |
\ch{^{58}_{26}Fe} \par |
| 364 |
\ch{NO^*} |
| 365 |
\end{example} |
| 366 |
|
| 367 |
Actually\changedversion{4.5a} a dot \code{.} is not always treated as |
| 368 |
indicator for a radical: if the dot in the superscript is followed by a number |
| 369 |
it is interpreted as a decimal sign. It is typeset according to the option |
| 370 |
\option{decimal-marker}. This may be a good place to mention that a comma |
| 371 |
\code{,} in a superscript is also typeset according to |
| 372 |
\option{decimal-marker}. |
| 373 |
|
| 374 |
\begin{example}[side-by-side] |
| 375 |
\ch{^{22,98}_{11}Na} |
| 376 |
\ch{^{22.98}_{11}Na}\par |
| 377 |
\setchemformula{decimal-marker={,}} |
| 378 |
\ch{^{22,98}_{11}Na} |
| 379 |
\ch{^{22.98}_{11}Na} |
| 380 |
\end{example} |
| 381 |
|
| 382 |
Ions and ion composites with more than one charge can be typeset quite as |
| 383 |
easy: |
| 384 |
\begin{example}[side-by-side] |
| 385 |
\ch{SO4^2-} \ch{Ca^2+ SO4^2-} |
| 386 |
\end{example} |
| 387 |
|
| 388 |
\paragraph{Charge Commands} |
| 389 |
You don't need to use \cs{mch} and related commands inside \cs{ch}. Indeed, |
| 390 |
you \emph{shouldn't} use them as they might mess with the subscript and |
| 391 |
superscript alignment. The \chemmacros\ option \code{circled} is obeyed by |
| 392 |
\cs{ch}. |
| 393 |
\begin{example} |
| 394 |
\chemsetup[charges]{circled=all} |
| 395 |
\ch{H+ + OH- <=> H2O} |
| 396 |
\end{example} |
| 397 |
|
| 398 |
\chemformula\ knows the options \option{circled} and \option{circletype} also |
| 399 |
on its own. |
| 400 |
|
| 401 |
\begin{example} |
| 402 |
\setchemformula{circled=all} |
| 403 |
\ch{H+ + OH- <=> H2O} |
| 404 |
\end{example} |
| 405 |
|
| 406 |
These options are coupled with \chemmacros\ options, \ie, setting \chemmacros' |
| 407 |
options will also set \chemformula's equivalents. The other way around the |
| 408 |
options act independently: setting \chemformula's options will \emph{not} set |
| 409 |
\chemmacros' options. |
| 410 |
\begin{options} |
| 411 |
\keychoice{circled}{formal,\default{all},none}\Default{formal} |
| 412 |
\chemformula\ uses two different kinds of charges which indicate the usage |
| 413 |
of real ($+/-$) and formal (\fplus/\fminus) charges. The choice |
| 414 |
\code{formal} distinguishes between them, choice \code{none} displays them |
| 415 |
all without circle, choice \code{all} circles all. |
| 416 |
% circletype |
| 417 |
\keychoice{circletype}{\default{chem},math}\Default{chem} |
| 418 |
This option switches between two kinds of circled charge symbols: |
| 419 |
\cs{fplus} \fplus\ and \verbcode+$\oplus$+ $\oplus$. |
| 420 |
\end{options} |
| 421 |
|
| 422 |
\paragraph{Behaviour} |
| 423 |
The supercripts behave differently depending on their position in a compound, |
| 424 |
if there are super- and subscripts following each other directly. |
| 425 |
\begin{example} |
| 426 |
\ch{^33B} \ch{{}^33B} \ch{3^3B} \ch{B^3} \ch{B3^3} \par |
| 427 |
\ch{^{23}_{123}B} \ch{{}^{23}_{123}B} \ch{_{123}^{23}B} |
| 428 |
\ch{B^{23}} \ch{B_{123}^{23}} \par |
| 429 |
\ch{^{123}_{23}B} \ch{{}^{123}_{23}B} \ch{_{23}^{123}B} |
| 430 |
\ch{B^{123}} \ch{B23^{123}} |
| 431 |
\end{example} |
| 432 |
\begin{itemize} |
| 433 |
\item If a compound \emph{starts} with a sub- or superscript both sub- and |
| 434 |
superscript are aligned to the \emph{right} else to the \emph{left}. |
| 435 |
\item If a compound \emph{does not start} with a sub- or superscript and |
| 436 |
there is both a sub- and a superscript, the superscript is shifted |
| 437 |
additionally by a length determined from the option |
| 438 |
\key{charge-hshift}{dim}, also see page~\pageref{desc:charge-hshift}f. |
| 439 |
\end{itemize} |
| 440 |
The second point follows \ac{iupac}'s recommendations: |
| 441 |
\begin{cnltxquote}[{\acs{iupac} Green Book {\cite[][p.\,51]{iupac:greenbook}}}] |
| 442 |
In writing the formula for a complex ion, spacing for charge number can be |
| 443 |
added (staggered arrangement), as well as parentheses: |
| 444 |
\ch[charge-hshift=full]{SO4^2-}, \ch{(SO4)^2-}. The staggered arrangement |
| 445 |
is now recommended. |
| 446 |
\end{cnltxquote} |
| 447 |
|
| 448 |
\subsection{Bonds}\label{ssec:bonds} |
| 449 |
\subsubsection{Native Bonds} |
| 450 |
There are three kinds of what I will call ``native bonds'': |
| 451 |
\begin{example}[side-by-side] |
| 452 |
single: \ch{CH3-CH3} \par |
| 453 |
double: \ch{CH2=CH2} \par |
| 454 |
triple: \ch{CH+CH} |
| 455 |
\end{example} |
| 456 |
|
| 457 |
\subsubsection{Flexible Bonds} |
| 458 |
\paragraph{Predefined Bonds} |
| 459 |
In addition to the three native bonds there are a few more which can be called |
| 460 |
by |
| 461 |
\begin{commands} |
| 462 |
\command{bond}[\marg{bond name}] |
| 463 |
Prints the bond type specified by \meta{bond name}. |
| 464 |
\end{commands} |
| 465 |
The predefined bond types are shown in table~\vref{tab:bond_types}. |
| 466 |
|
| 467 |
\begin{table} |
| 468 |
\centering |
| 469 |
\caption{Bonds available with \cs*{bond}.} |
| 470 |
\label{tab:bond_types} |
| 471 |
\begin{tabular}{lcl} |
| 472 |
\toprule |
| 473 |
\bfseries name & \bfseries appearance & \bfseries aliases \\ |
| 474 |
\midrule |
| 475 |
\code{single} & \bond{single} & \code{normal}, \code{sb} \\ |
| 476 |
\code{double} & \bond{double} & \code{db} \\ |
| 477 |
\code{triple} & \bond{triple} & \code{tp} \\ |
| 478 |
\code{dotted} & \bond{dotted} & \code{semisingle} \\ |
| 479 |
\code{deloc} & \bond{deloc} & \code{semidouble} \\ |
| 480 |
\code{tdeloc} & \bond{tdeloc} & \code{semitriple} \\ |
| 481 |
\code{co>} & \bond{co>} & \code{coordright} \\ |
| 482 |
\code{<co} & \bond{<co} & \code{coordleft} \\ |
| 483 |
\bottomrule |
| 484 |
\end{tabular} |
| 485 |
\end{table} |
| 486 |
|
| 487 |
\begin{example} |
| 488 |
\ch{C\bond{sb}C\bond{db}C\bond{tp}C\bond{deloc}C\bond{tdeloc}C\bond{co>}C\bond{<co}C} |
| 489 |
\end{example} |
| 490 |
|
| 491 |
\paragraph{Own Bonds} |
| 492 |
\chemformula{} offers commands to define own bond types: |
| 493 |
\begin{commands} |
| 494 |
\command{NewChemBond}[\marg{name}\marg{code}] |
| 495 |
\sinceversion{4.3}Define the new bond type \meta{name}. Issue an error if |
| 496 |
a bond \meta{name} already exists. |
| 497 |
\command{DeclareChemBond}[\marg{name}\marg{code}] |
| 498 |
Define the new bond type \meta{name} or overwrite it if it already |
| 499 |
exists. |
| 500 |
\command{RenewChemBond}[\marg{name}\marg{code}] |
| 501 |
Redefine the existing bond type \meta{name}. Issue an error if a bond |
| 502 |
\meta{name} doesn't exist. |
| 503 |
\command{ProvideChemBond}[\marg{name}\marg{code}] |
| 504 |
\sinceversion{4.12a}Define the new bond type \meta{name} only if it |
| 505 |
doesn't exist yet. |
| 506 |
\command{NewChemBondAlias}[\marg{new name}\marg{old name}] |
| 507 |
\sinceversion{4.3}Declare the bond type \meta{new name} to be an alias of |
| 508 |
\meta{old name}. Issue an error if a bond \meta{new name} already |
| 509 |
exists. |
| 510 |
\command{DeclareChemBondAlias}[\marg{new name}\marg{old name}] |
| 511 |
Declare the bond type \meta{new name} to be an alias of \meta{old name}. |
| 512 |
\command{ShowChemBond}[\marg{name}] |
| 513 |
Print the definition of bond type \meta{name}. |
| 514 |
\end{commands} |
| 515 |
The usage is best described with an example. So let's see how the |
| 516 |
\code{single} bond and the \code{co>} bond are defined: |
| 517 |
\begin{sourcecode} |
| 518 |
\NewChemBond{single} |
| 519 |
{ \draw[chembond] (chemformula-bond-start) -- (chemformula-bond-end) ; } |
| 520 |
\NewChemBond{coordright} |
| 521 |
{ |
| 522 |
\draw[chembond,butt cap->] |
| 523 |
(chemformula-bond-start) -- (chemformula-bond-end) ; |
| 524 |
} |
| 525 |
\NewChemBondAlias{co>}{coordright} |
| 526 |
\end{sourcecode} |
| 527 |
|
| 528 |
Two points are important: |
| 529 |
\begin{itemize} |
| 530 |
\item the names of the starting and the ending coordinates, \\ |
| 531 |
\code{chemformula-bond-start} and \code{chemformula-bond-end}, |
| 532 |
\item and the \TikZ\ style of the bonds \code{chembond}. |
| 533 |
\end{itemize} |
| 534 |
|
| 535 |
So, let's say you want to define a special kind of dashed bond. You could do |
| 536 |
this: |
| 537 |
\begin{example} |
| 538 |
\usetikzlibrary{decorations.pathreplacing} |
| 539 |
\makeatletter |
| 540 |
\NewChemBond{dashed} |
| 541 |
{ |
| 542 |
\draw[ |
| 543 |
chembond, |
| 544 |
decorate, |
| 545 |
decoration={ |
| 546 |
ticks, |
| 547 |
segment length=\chemformula@bondlength/10,amplitude=1.5pt |
| 548 |
}] |
| 549 |
(chemformula-bond-start) -- (chemformula-bond-end) ; |
| 550 |
} |
| 551 |
\makeatother |
| 552 |
\setchemformula{bond-length=2ex} |
| 553 |
\ch{C\bond{dashed}C} |
| 554 |
\end{example} |
| 555 |
|
| 556 |
The last example showed you another macro: \verbcode+\chemformula@bondlength+. |
| 557 |
It only exists so you can use it to access the bond length as set with |
| 558 |
\option{bond-length} directly. |
| 559 |
|
| 560 |
\subsection{Customization}\label{ssec:compounds:customization} |
| 561 |
These options allow you to customize the ouptut of the compounds: |
| 562 |
\begin{options} |
| 563 |
\keyval{subscript-vshift}{dim}\Default{0pt} |
| 564 |
Extra vertical shift of the subscripts. This only works when |
| 565 |
\keyis{math-scripts}{false} is in effect. |
| 566 |
\keychoice{subscript-style}{text,math}\Default{text} |
| 567 |
Style that is used to typeset the subscripts. |
| 568 |
\keyval{charge-hshift}{dim}\Default{.25em} |
| 569 |
Shift of superscripts when following a subscript.\label{desc:charge-hshift} |
| 570 |
\keyval{charge-vshift}{dim}\Default{0pt} |
| 571 |
Extra vertical shift of the superscripts. This only works when |
| 572 |
\keyis{math-scripts}{false} is in effect. |
| 573 |
\keychoice{charge-style}{text,math}\Default{text} |
| 574 |
Style that is used to typeset the superscripts. |
| 575 |
\keybool{math-scripts}\Default{false} |
| 576 |
\sinceversion{4.16}Switches to \TeX's native subscript and superscript |
| 577 |
mechanism which might be your option of choice for the sake of |
| 578 |
typographical consistency. \emph{This option is experimental. Please |
| 579 |
report any problems you experience with this option to \chemformula's |
| 580 |
bug tracker.} |
| 581 |
\keychoice{circled}{formal,\default{all},none}\Default{formal} |
| 582 |
\sinceversion{4.6}Like \chemmacros' package option but local to |
| 583 |
\chemformula's \cs{ch}. That is: since \chemmacros' macros use |
| 584 |
\chemformula's mechanism this is effectively an alias. |
| 585 |
\keychoice{circletype}{\default{chem},math}\Default{chem} |
| 586 |
\sinceversion{4.6}Like \chemmacros' package option but local to |
| 587 |
\chemformula's \cs{ch}. That is: since \chemmacros' macros use |
| 588 |
\chemformula's mechanism this is effectively an alias. |
| 589 |
\keyval{adduct-space}{dim}\Default{.1333em} |
| 590 |
Space to the left and the right of the adduct point. |
| 591 |
\keyval{adduct-penalty}{num}\Default{300} |
| 592 |
The\sinceversion{4.14} penalty inserted after the adduct point for |
| 593 |
(dis-)allowing line breaks. |
| 594 |
\keyval{bond-length}{dim}\Default{.5833em} |
| 595 |
The length of the bonds. |
| 596 |
\keyval{bond-offset}{dim}\Default{.07em} |
| 597 |
Space between bond and atoms. |
| 598 |
\keyval{bond-style}{\TikZ}\Default |
| 599 |
\TikZ\ options for the bonds. |
| 600 |
\keyval{bond-penalty}{num}\Default{10000} |
| 601 |
\sinceversion{4.0a}The penalty that is inserted after a bond for |
| 602 |
(dis-)allowing line breaks. |
| 603 |
\keyval{radical-style}{\TikZ}\Default |
| 604 |
\TikZ\ options for the radical point. |
| 605 |
\keyval{radical-radius}{dim}\Default{.2ex} |
| 606 |
The radius of the radical point. |
| 607 |
\keyval{radical-hshift}{dim}\Default{.15em} |
| 608 |
Horizontal shift before the radical point is drawn. |
| 609 |
\keyval{radical-vshift}{dim}\Default{.5ex} |
| 610 |
Vertical shift relative to the current baseline. |
| 611 |
\keyval{radical-space}{dim}\Default{.15em} |
| 612 |
Horizontal shift after the radical point is drawn. |
| 613 |
\end{options} |
| 614 |
|
| 615 |
Maybe you have noticed that charges of certain ions are shifted to the |
| 616 |
right. |
| 617 |
\begin{example}[side-by-side] |
| 618 |
\ch{SO4^2-} \ch{NH4+} \ch{Na+} |
| 619 |
\end{example} |
| 620 |
They are shifted if they \emph{follow} a subscript which follows \ac{iupac} |
| 621 |
recommendations~\cite[][p.\,51]{iupac:greenbook}. The amount of the shift can |
| 622 |
be set with the option \option{charge-hshift}. |
| 623 |
\begin{example} |
| 624 |
\ch{SO4^2-} \ch{NH4+} \ch{Na+} \par |
| 625 |
\setchemformula{charge-hshift=.5ex} |
| 626 |
\ch{SO4^2-} \ch{NH4+} \ch{Na+} \par |
| 627 |
\setchemformula{charge-hshift=.5pt} |
| 628 |
\ch{SO4^2-} \ch{NH4+} \ch{Na+} |
| 629 |
\end{example} |
| 630 |
|
| 631 |
Despite \ac{iupac}'s recommendation \chemformula\ does not make fully staggered |
| 632 |
arrangements in the default setting as I find it hard to read in some cases |
| 633 |
and ugly in others. Since this is a subjective decision \chemformula\ not only |
| 634 |
let's you define the absolute amount of the shift but also provides a |
| 635 |
possibility for full staggered arrangements. For this you have to use |
| 636 |
\keyis{charge-hshift}{full}. |
| 637 |
\begin{example} |
| 638 |
\ch[charge-hshift=0pt]{C5H11+} \ch[charge-hshift=0pt]{SO4^2-} \par |
| 639 |
\ch{C5H11+} \ch{SO4^2-} \par |
| 640 |
\ch[charge-hshift=1ex]{C5H11+} \ch[charge-hshift=1ex]{SO4^2-} \par |
| 641 |
\ch[charge-hshift=full]{C5H11+} \ch[charge-hshift=full]{SO4^2-} |
| 642 |
\end{example} |
| 643 |
|
| 644 |
If you don't want the charges to be typeset in text mode you can switch to |
| 645 |
math mode: |
| 646 |
\begin{example} |
| 647 |
\ch{M^x+} \ch{SO4^2-} \par |
| 648 |
\setchemformula{charge-style = math} |
| 649 |
\ch{M^x+} \ch{SO4^2-} |
| 650 |
\end{example} |
| 651 |
|
| 652 |
The option \option{subscript-vshift} can be used to adjust the vertical shift |
| 653 |
of the subscripts: |
| 654 |
\begin{example} |
| 655 |
\ch{H2SO4} \ch{Na3PO4} \par |
| 656 |
\setchemformula{subscript-vshift=.5ex} |
| 657 |
\ch{H2SO4} \ch{Na3PO4} \par |
| 658 |
\setchemformula{subscript-vshift=-.2ex} |
| 659 |
\ch{H2SO4} \ch{Na3PO4} |
| 660 |
\end{example} |
| 661 |
|
| 662 |
You can choose the mode subscripts are typeset in the same way as it is |
| 663 |
possible for the charges: |
| 664 |
\begin{example} |
| 665 |
\ch{A_nB_m} \ch{H2SO4} \par |
| 666 |
\setchemformula{subscript-style = math} |
| 667 |
\ch{A_nB_m} \ch{H2SO4} |
| 668 |
\end{example} |
| 669 |
|
| 670 |
The option \option{adduct-space} sets the space left and right to the adduct |
| 671 |
symbol $\cdot$. |
| 672 |
\begin{example} |
| 673 |
\ch{Na3PO3*H2O} \par |
| 674 |
\setchemformula{adduct-space=.2em} |
| 675 |
\ch{Na3PO3*H2O} |
| 676 |
\end{example} |
| 677 |
|
| 678 |
Changing the length of the bonds: |
| 679 |
\begin{example} |
| 680 |
\setchemformula{bond-length=4mm}% |
| 681 |
single: \ch{CH3-CH3} \par |
| 682 |
double: \ch{CH2=CH2} \par |
| 683 |
triple: \ch{CH+CH} |
| 684 |
\end{example} |
| 685 |
|
| 686 |
You can change the distance between bond and atom, too: |
| 687 |
\begin{example} |
| 688 |
\ch{H-H + N+N + O=O} \par |
| 689 |
\ch[bond-offset=1pt]{H-H + N+N + O=O} |
| 690 |
\end{example} |
| 691 |
|
| 692 |
\subsection{Standalone Formulae} |
| 693 |
\chemformula\sinceversion{4.0} offers a command that \emph{only accepts} the |
| 694 |
\enquote{compound} input type: |
| 695 |
\begin{commands} |
| 696 |
\command{chcpd}[\oarg{options}\marg{compound}] |
| 697 |
Typeset single compounds. |
| 698 |
\end{commands} |
| 699 |
|
| 700 |
\subsection{Extend Compound Properties}\label{sec:extend-comp-prop} |
| 701 |
|
| 702 |
It\sinceversion{4.10} is possible to extend the range of special input symbols |
| 703 |
within compounds. In the default setting those are \verbcode|*.-=+'| and |
| 704 |
arabic numerals. Others can be added or the existing ones be changed with one |
| 705 |
of the following commmands: |
| 706 |
\begin{commands} |
| 707 |
\command{NewChemCompoundProperty}[\marg{token}\marg{replacement}] |
| 708 |
\meta{token} will be replaced by \meta{replacement} within compounds. The |
| 709 |
property is only added if \meta{token} is not yet part the compounds' |
| 710 |
property list. Otherwise an error is issued. |
| 711 |
\command{ProvideChemCompoundProperty}[\marg{token}\marg{replacement}] |
| 712 |
\meta{token}\sinceversion{4.12a} will be replaced by \meta{replacement} |
| 713 |
within compounds. The property is only added if \meta{token} is not yet |
| 714 |
part the compounds' property list. |
| 715 |
\command{RenewChemCompoundProperty}[\marg{token}\marg{replacement}] |
| 716 |
\meta{token} will be replaced by \meta{replacement} within compounds. The |
| 717 |
property is only added if \meta{token} is already part the compounds' |
| 718 |
property list. Otherwise an error is issued. |
| 719 |
\command{DeclareChemCompoundProperty}[\marg{token}\marg{replacement}] |
| 720 |
\meta{token} will be replaced by \meta{replacement} within compounds. The |
| 721 |
property silently overwrites any previously set \meta{replacement} for |
| 722 |
\meta{token} if \meta{token} is already part the compounds' property |
| 723 |
list. |
| 724 |
\command{RemoveChemCompoundProperty}[\marg{token}] |
| 725 |
Removes \meta{token} from the compounds' property list. |
| 726 |
\end{commands} |
| 727 |
|
| 728 |
For example you can use |
| 729 |
\begin{sourcecode} |
| 730 |
\NewChemCompoundProperty{\}{\slash} |
| 731 |
\end{sourcecode} |
| 732 |
to allow line breaks after slashes in compounds. |
| 733 |
|
| 734 |
\section{Special Input Types} |
| 735 |
There are some \enquote{special type} input groups. |
| 736 |
|
| 737 |
\subsection{Single Token Groups} |
| 738 |
The first kind are groups which consist of only one token. They are again |
| 739 |
divided into two groups, \enquote{addition symbols} and \enquote{symbols}. |
| 740 |
|
| 741 |
\subsubsection{Addition Symbols}\label{sec:addition-symbols} |
| 742 |
\begin{commands} |
| 743 |
\command{ch}[\Marg{ + } \ch{ + }] |
| 744 |
Creates the plus sign between compounds with space around it:\\ |
| 745 |
\cs{ch}\Marg{2 Na + Cl2} \ch{2 Na + Cl2} |
| 746 |
\command{ch}[\Marg{ - } \ch{ - }] |
| 747 |
\sinceversion{4.3a}Creates the minus sign between compounds with space |
| 748 |
around it:\\ |
| 749 |
\cs{ch}\Marg{M - H} \ch{M - H} |
| 750 |
\end{commands} |
| 751 |
Addition symbols are surrounded with space which can be customized according |
| 752 |
to options explained in a bit. There is also some penalty prohibiting a line |
| 753 |
break after them which also can be customized with an option. |
| 754 |
|
| 755 |
You can define/redefine your own addition symbols: |
| 756 |
\begin{commands} |
| 757 |
\command{NewChemAdditionSymbol}[\marg{name}\marg{input}\marg{output}] |
| 758 |
Defines\sinceversion{4.11} the addition symbol \meta{name} with input |
| 759 |
symbol \meta{input} and output \meta{output}. |
| 760 |
\command{ProvideChemAdditionSymbol}[\marg{name}\marg{input}\marg{output}] |
| 761 |
Defines\sinceversion{4.12a} the addition symbol \meta{name} with input |
| 762 |
symbol \meta{input} and output \meta{output} only no addition symbol with |
| 763 |
then name \meta{name} doesn't exist. |
| 764 |
\command{RenewChemAdditionSymbol}[\marg{name}\marg{input}\marg{output}] |
| 765 |
Redefines\sinceversion{4.11} the addition symbol \meta{name} with input |
| 766 |
symbol \meta{input} and output \meta{output}. |
| 767 |
\command{DeclareChemAdditionSymbol}[\marg{name}\marg{input}\marg{output}] |
| 768 |
(Re-)Defines\sinceversion{4.11} the addition symbol \meta{name} with input |
| 769 |
symbol \meta{input} and output \meta{output} without checking if the |
| 770 |
symbol exists or not. |
| 771 |
\end{commands} |
| 772 |
|
| 773 |
The space left and right of the plus and the minus sign and the signs |
| 774 |
themselves can be set with the following options: |
| 775 |
\begin{options} |
| 776 |
\keyval{plus-space}{skip}\Default{.3em plus .1em minus .1em} |
| 777 |
A rubber length. |
| 778 |
\keyval{plus-penalty}{num}\Default{700} |
| 779 |
\sinceversion{4.0a}The penalty that is inserted after the plus sign for |
| 780 |
(dis-)allowing line breaks. |
| 781 |
\keyval{plus-output-symbol}{code}\Default{+} |
| 782 |
\sinceversion{4.9}The \meta{code} that is used for the plus sign. |
| 783 |
\keyval{minus-space}{skip}\Default{.3em plus .1em minus .1em} |
| 784 |
\sinceversion{4.9}A rubber length. |
| 785 |
\keyval{minus-penalty}{num}\Default{700} |
| 786 |
\sinceversion{4.9}The penalty that is inserted after the minus sign for |
| 787 |
(dis-)allowing line breaks. |
| 788 |
\keyval{minus-output-symbol}{code}\Default{\$-\$} |
| 789 |
\sinceversion{4.9}The \meta{code} that is used for the minus sign. |
| 790 |
\end{options} |
| 791 |
The corresponding three options are defined when \cs{NewChemAdditionSymbol} |
| 792 |
or one of the variants is used, \code{\meta{name}-space} and |
| 793 |
\code{\meta{name}-penalty} both with the same defaults as above, and |
| 794 |
\code{\meta{name}-output-symbol}. |
| 795 |
|
| 796 |
\begin{example}[side-by-side] |
| 797 |
\ch{A + B}\par |
| 798 |
\ch[plus-space=4pt]{A + B} |
| 799 |
\end{example} |
| 800 |
|
| 801 |
\subsubsection{Symbols}\label{sec:symbols} |
| 802 |
\begin{commands} |
| 803 |
\command{ch}[\Marg{ v } \ch{ v }] |
| 804 |
Sign for precipitate: \cs{ch}\Marg{BaSO4 v} \ch{BaSO4 v} |
| 805 |
\command{ch}[\Marg{ \textasciicircum\ } \ch{ ^ }] |
| 806 |
Sign for escaping gas\footnotemark: \cs{ch}\Marg{H2 \textasciicircum} |
| 807 |
\ch{H2 ^} |
| 808 |
\end{commands} |
| 809 |
\footnotetext{Is this the correct English term? Please correct me if it isn't.} |
| 810 |
|
| 811 |
You can define/redefine your own symbols: |
| 812 |
\begin{commands} |
| 813 |
\command{NewChemSymbol}[\marg{input}\marg{output}] |
| 814 |
Defines\sinceversion{4.11} the addition symbol with input \meta{input} and |
| 815 |
output \meta{output}. |
| 816 |
\command{ProvideChemSymbol}[\marg{input}\marg{output}] |
| 817 |
Defines\sinceversion{4.12a} the addition symbol with input \meta{input} and |
| 818 |
output \meta{output} only if no symbol with input \meta{input} exists. |
| 819 |
\command{RenewChemSymbol}[\marg{input}\marg{output}] |
| 820 |
Redefines\sinceversion{4.11} the addition symbol with input \meta{input} |
| 821 |
and output \meta{output}. |
| 822 |
\command{DeclareChemSymbol}[\marg{input}\marg{output}] |
| 823 |
(Re-)Defines\sinceversion{4.11} the addition symbol with input |
| 824 |
\meta{input} and output \meta{output} without checking if the symbol |
| 825 |
exists or not. |
| 826 |
\end{commands} |
| 827 |
|
| 828 |
\subsection{Option Input} |
| 829 |
Sometimes you might want to apply an option only to a part of a, say, |
| 830 |
reaction. Of course you have the possibility to use \cs{ch} several times. |
| 831 |
\begin{example} |
| 832 |
\ch{H2O +}\textcolor{red}{\ch{H2SO4}}\ch{-> H3O+ + HSO4-} \par |
| 833 |
\ch{H2O +}\ch[subscript-vshift=2pt]{H2SO4}\ch{-> H3O+ + HSO4-} |
| 834 |
\end{example} |
| 835 |
This, however, interrupts the input in your source and \emph{may} mess with |
| 836 |
the spacing. That's why there is an alternative: |
| 837 |
\begin{commands} |
| 838 |
\command{ch}[\Marg{ @\marg{options} }] |
| 839 |
The options specified this way will be valid \emph{only} until the next |
| 840 |
compound is set. |
| 841 |
\end{commands} |
| 842 |
\begin{example} |
| 843 |
\ch{H2O +}\textcolor{red}{\ch{H2SO4}}\ch{-> H3O+ + HSO4-} \par |
| 844 |
\ch{H2O + @{atom-format=\color{red}} H2SO4 -> H3O+ + HSO4-} \par |
| 845 |
or of course:\par |
| 846 |
\ch{H2O + \textcolor{red}{H2SO4} -> H3O+ + HSO4-}\par\bigskip |
| 847 |
\ch{H2O +}\ch[subscript-vshift=2pt]{H2SO4}\ch{-> H3O+ + HSO4-} \par |
| 848 |
\ch{H2O + @{subscript-vshift=2pt} H2SO4 -> H3O+ + HSO4-} |
| 849 |
\end{example} |
| 850 |
|
| 851 |
\section{Escaped Input} |
| 852 |
In some cases it may be desirable to prevent \chemformula\ from parsing the |
| 853 |
input. This can be done in two ways. |
| 854 |
|
| 855 |
\subsection{Text}\label{ssec:text} |
| 856 |
If you put something between \verbcode+" "+ or \verbcode+' '+ then the input |
| 857 |
will be treated as normal text, except that spaces are not allowed and have to |
| 858 |
be input with \verbcode+~+. |
| 859 |
\begin{commands} |
| 860 |
\command{ch}[\Marg{ "\meta{escaped text}" }] |
| 861 |
One of two possibilities to \emph{escape} \chemformula's parsing. |
| 862 |
\command{ch}[\Marg{ \textquotesingle\meta{escaped text}\textquotesingle\ }] |
| 863 |
The second of two possibilities to \emph{escape} \chemformula's parsing. |
| 864 |
\end{commands} |
| 865 |
\begin{example}[add-sourcecode-options={literate=}] |
| 866 |
\ch{"\ox{2,Ca}" O} \par |
| 867 |
\ch{"\ldots\," Na + "\ldots\," Cl2 -> "\ldots\," NaCl} \par |
| 868 |
\ch{'A~->~B'} |
| 869 |
\end{example} |
| 870 |
In many cases you won't need to escape the input. But when you get into |
| 871 |
trouble when using a command inside \cs{ch} try hiding it. |
| 872 |
|
| 873 |
\subsection{Math} |
| 874 |
If you especially want to input math you just enclose it with \verbcode+$ $+. |
| 875 |
This output is different from the escaped text as it is followed by a space. |
| 876 |
The reasoning behind this is that I assume math will mostly be used to replace |
| 877 |
stoichiometric factors. |
| 878 |
\begin{commands} |
| 879 |
\command{ch}[\Marg{ \string$\meta{escaped math}\string$ }] |
| 880 |
One of two possibilities to \emph{escape} \chemformula's parsing into math |
| 881 |
mode. |
| 882 |
\command{ch}[\Marg{ \string\(\meta{escaped math}\string\) }] |
| 883 |
The second of two possibilities to \emph{escape} \chemformula's parsing |
| 884 |
into math mode. |
| 885 |
\end{commands} |
| 886 |
\begin{example}[side-by-side] |
| 887 |
escaped text: \ch{"$x$" H2O} \par |
| 888 |
escaped math: \ch{$x$ H2O} \par |
| 889 |
also escaped math: \ch{\(x\) H2O} \par |
| 890 |
\ch{$2n$ Na + $n$ Cl2 -> $2n$ NaCl} |
| 891 |
\end{example} |
| 892 |
|
| 893 |
The space that is inserted after a math group can be edited: |
| 894 |
\begin{options} |
| 895 |
\keyval{math-space}{skip}\Default{.1667em plus .0333em minus .0117em} |
| 896 |
A rubber length. |
| 897 |
\end{options} |
| 898 |
\begin{example} |
| 899 |
\ch{$2n$ Na + $n$ Cl2 -> $2n$ NaCl} \par |
| 900 |
\setchemformula{math-space=.25em} |
| 901 |
\ch{$2n$ Na + $n$ Cl2 -> $2n$ NaCl} \par |
| 902 |
\ch{$A->B$} |
| 903 |
\end{example} |
| 904 |
|
| 905 |
\section{Arrows}\label{sec:arrows} |
| 906 |
\subsection{Arrow types} |
| 907 |
Arrows are input in the same intuitive way they are with \pkg{mhchem}. |
| 908 |
There are various different types: |
| 909 |
\begin{arrows} |
| 910 |
\arrow{->}[ \charrow{->}] |
| 911 |
standard right arrow |
| 912 |
\arrow{<-}[ \charrow{<-}] |
| 913 |
standard left arrow |
| 914 |
\arrow{-/>}[ \charrow{-/>}] |
| 915 |
does not react (right) |
| 916 |
\arrow{</-}[ \charrow{</-}] |
| 917 |
does not react (left) |
| 918 |
\arrow{<->}[ \charrow{<->}] |
| 919 |
resonance arrow |
| 920 |
\arrow{<>}[ \charrow{<>}] |
| 921 |
reaction in both directions |
| 922 |
\arrow{==}[ \charrow{==}] |
| 923 |
stoichiometric equation |
| 924 |
\arrow{<=>}[ \charrow{<=>}] |
| 925 |
equilibrium arrow |
| 926 |
\arrow{>=<}[ \charrow{>=<}] |
| 927 |
\sinceversion{4.5}reversed equilibrium arrow |
| 928 |
\arrow{<=>{}>}[ \charrow{<=>>}] |
| 929 |
unbalanced equilibrium arrow to the right |
| 930 |
\arrow{>=<{}<}[ \charrow{>=<<}] |
| 931 |
\sinceversion{4.5}reversed unbalanced equilibrium arrow to the right |
| 932 |
\arrow{<{}<=>}[ \charrow{<<=>}] |
| 933 |
unbalanced equilibrium arrow to the left |
| 934 |
\arrow{>{}>=<}[ \charrow{>>=<}] |
| 935 |
\sinceversion{4.5}reversed unbalanced equilibrium arrow to the left |
| 936 |
\arrow{<=o>}[ \charrow{<=o>}] |
| 937 |
\sinceversion{4.15}quasi equilibrium arrow |
| 938 |
\arrow{<=o>{}>}[ \charrow{<=o>>}] |
| 939 |
\sinceversion{4.15}unbalanced quasi equilibrium arrow to the right |
| 940 |
\arrow{<{}<=o>}[ \charrow{<<=o>}] |
| 941 |
\sinceversion{4.15}unbalanced quasi equilibrium arrow to the left |
| 942 |
\arrow{<o>}[ \charrow{<o>}] |
| 943 |
isolobal arrow |
| 944 |
\arrow{<==>}[ \charrow{<==>}] |
| 945 |
\sinceversion{4.5}I've seen this one used. I'm not sure it actually has a |
| 946 |
meaning in chemical equations. If you have some official reference for |
| 947 |
this arrow type please feel free to contact me. |
| 948 |
\end{arrows} |
| 949 |
All these arrows are drawn with \TikZ. |
| 950 |
\begin{example} |
| 951 |
\ch{H2 + Cl2 -> 2 HCl} \par |
| 952 |
\ch{H2O + CO3^2- <=> OH- + HCO3-} \par |
| 953 |
\ch{A <- B} \par |
| 954 |
\ch{\{[CH2=CH-CH2]- <-> {}[CH2-CH=CH2]- \}} \par |
| 955 |
\ch{A <> B} \par |
| 956 |
\ch{H+ + OH- <=>> H2O} \par |
| 957 |
\ch{2 NO2 <<=> N2O4} |
| 958 |
\end{example} |
| 959 |
|
| 960 |
\subsection{Labels} |
| 961 |
The arrows take two optional arguments to label them. |
| 962 |
\begin{arrows} |
| 963 |
\arrow*{->\oarg{above}\oarg{below}} |
| 964 |
Add text above or under an arrow. |
| 965 |
\end{arrows} |
| 966 |
\begin{example}[side-by-side] |
| 967 |
\ch{A ->[a] B} \par |
| 968 |
\ch{A ->[a][b] B} \par |
| 969 |
\ch{A ->[\SI{100}{\celsius}] B} |
| 970 |
\end{example} |
| 971 |
The label text can be parsed seperately from the arrow. The recipe is easy: |
| 972 |
leave blanks. |
| 973 |
\begin{example}[side-by-side] |
| 974 |
\ch{A ->[H2O] B} \par |
| 975 |
\ch{A ->[ H2O ] B} \par |
| 976 |
\ch{A ->[ "\ox{2,Ca}" F2 ] B} \par |
| 977 |
\ch{A ->[ $\Delta$,~ [ H+ ]] B} |
| 978 |
\end{example} |
| 979 |
|
| 980 |
If you leave the blanks \chemformula\ treats the groups inside the square |
| 981 |
brackets as seperated input types. The arrow reads its arguments |
| 982 |
\emph{afterwards}. As you can see the arrows \enquote{grow} with the length |
| 983 |
of the labels. What stays constant is the part that protrudes the labels. |
| 984 |
\begin{example} |
| 985 |
\ch{A ->[a] B} \par |
| 986 |
\ch{A ->[ab] B} \par |
| 987 |
\ch{A ->[abc] B} \par |
| 988 |
\ch{A ->[abc~abc] B} \par |
| 989 |
% needs the `chemfig' package: |
| 990 |
\setchemfig{atom sep =15pt} |
| 991 |
\ch{A ->[ "\chemfig{-[:30]-[:-30]OH}" ] B} \par |
| 992 |
\end{example} |
| 993 |
|
| 994 |
The\sinceversion{4.17} labels are typeset inside of a \env*{tabular}\Marg{c} |
| 995 |
environment. This means you can get several lines: |
| 996 |
\begin{example}[side-by-side] |
| 997 |
\ch{A ->[{a\\b}] B} \par |
| 998 |
\ch{A ->[a \newline b] B} |
| 999 |
\end{example} |
| 1000 |
The command \cs*{\textbackslash} must be hidden in order to |
| 1001 |
work. \cs*{tabularnewline} does work, of course. For convenience \chemformula\ |
| 1002 |
also allows \cs*{newline} here. |
| 1003 |
|
| 1004 |
\subsection{Customization} |
| 1005 |
These are the options which enable you to customize the arrows: |
| 1006 |
\begin{options} |
| 1007 |
\keyval{arrow-offset}{dim}\Default{.75em} |
| 1008 |
This is the length that an arrow protrudes a label on both sides. This |
| 1009 |
means an empty arrow's length is two times \code{arrow-offset}. |
| 1010 |
\keyval{arrow-min-length}{dim}\Default{0pt} |
| 1011 |
\sinceversion{3.6b}The minimal length an error must have unless two times |
| 1012 |
\option{arrow-offset} plus the width of the label is larger. |
| 1013 |
\keyval{arrow-yshift}{dim}\Default{0pt} |
| 1014 |
Shifts an arrow up (positive value) or down (negative value). |
| 1015 |
\keyval{arrow-ratio}{<factor>}\Default{.6} |
| 1016 |
The ratio of the arrow lengths of the unbalanced equilibrium. \code{.4} |
| 1017 |
would mean that the length of the shorter arrow is $0.4\times$ the length |
| 1018 |
of the longer arrow. |
| 1019 |
\keyval{compound-sep}{dim}\Default{.5em} |
| 1020 |
The space between compounds and the arrows. |
| 1021 |
\keyval{label-offset}{dim}\Default{2pt} |
| 1022 |
The space between the labels and the arrows. |
| 1023 |
\keyval{label-style}{font command}\Default{\cs*{footnotesize}} |
| 1024 |
The relative font size of the labels. |
| 1025 |
\keyval{arrow-penalty}{num}\Default{0} |
| 1026 |
\sinceversion{4.0a}The penalty that is inserted after an arrow for |
| 1027 |
(dis-)allowing line breaks. |
| 1028 |
\keyval{arrow-style}{\TikZ}\Default |
| 1029 |
\sinceversion{4.1a}Additonal \TikZ\ keys for formatting the arrows. |
| 1030 |
\end{options} |
| 1031 |
|
| 1032 |
The following code shows the effect of the different options on the \verbcode+<=>>+ |
| 1033 |
arrow: |
| 1034 |
\begin{example} |
| 1035 |
standard: \ch{A <=>>[x][y] B} \par |
| 1036 |
longer: \ch[arrow-offset=12pt]{A <=>>[x][y] B} \par |
| 1037 |
higher: \ch[arrow-yshift=2pt]{A <=>>[x][y] B} \par |
| 1038 |
more balanced: \ch[arrow-ratio=.8]{A <=>>[x][y] B} \par |
| 1039 |
labels further away: \ch[label-offset=4pt]{A <=>>[x][y] B} \par |
| 1040 |
larger distance to compounds: \ch[compound-sep=2ex]{A <=>>[x][y] B} \par |
| 1041 |
smaller labels: \ch[label-style=\tiny]{A <=>[x][y] B} |
| 1042 |
\end{example} |
| 1043 |
|
| 1044 |
If you want to have different arrow tips\sinceversion{4.7} there is an easy |
| 1045 |
way to use existing arrow tips (as defined by \TikZ). \chemformula\ uses |
| 1046 |
three different arrow tips: \code{cf}, \code{left cf} and \code{right cf}. If |
| 1047 |
you want them to match those of \pkg{chemfig}~\cite{pkg:chemfig} for example |
| 1048 |
you could do: |
| 1049 |
\begin{sourcecode} |
| 1050 |
\pgfkeys{ |
| 1051 |
cf /.tip = {CF@full} , |
| 1052 |
left cf /.tip = {CF@half} |
| 1053 |
} |
| 1054 |
\end{sourcecode} |
| 1055 |
\pkg{chemfig} has no equivalent of \code{right cf}. This mechanism relies on |
| 1056 |
\TikZ\ version~3.0.0 and the new \code{arrows.meta} library. |
| 1057 |
|
| 1058 |
\subsection{Modify Arrow Types}\label{sec:arrows_modify} |
| 1059 |
The arrows are defined with the commands |
| 1060 |
\begin{commands} |
| 1061 |
\command{NewChemArrow}[\marg{type}\marg{\TikZ}] |
| 1062 |
Define the new arrow type \meta{type}. Issue an error if an arrow type |
| 1063 |
\meta{type} already exists. |
| 1064 |
\command{ProvideChemArrow}[\marg{type}\marg{\TikZ}] |
| 1065 |
Define\sinceversion{4.12a} the new arrow type \meta{type} only if it |
| 1066 |
doesn't exist, yet. |
| 1067 |
\command{DeclareChemArrow}[\marg{type}\marg{\TikZ}] |
| 1068 |
Define the new arrow type \meta{type} or overwrite it if it already |
| 1069 |
exists. |
| 1070 |
\command{RenewChemArrow}[\marg{type}\marg{\TikZ}] |
| 1071 |
Redefine the arrow type \meta{type}. Issue an error if an arrow type |
| 1072 |
\meta{type} doesn't exist. |
| 1073 |
\command{ShowChemArrow}[\marg{type}] |
| 1074 |
Print out the current definition of the arrow type \meta{type}. |
| 1075 |
\end{commands} |
| 1076 |
\meta{type} is the sequence of tokens that is replaced with the actual arrow |
| 1077 |
code. For example the basic arrow is defined via |
| 1078 |
\begin{sourcecode} |
| 1079 |
\NewChemArrow{->}{ |
| 1080 |
\draw[chemarrow,-cf] (cf_arrow_start) -- (cf_arrow_end) ; |
| 1081 |
} |
| 1082 |
\end{sourcecode} |
| 1083 |
In order to define arrows yourself you need to know the basics of |
| 1084 |
\TikZ\footnote{Please see the \manual{pgfmanual} for details.}. The |
| 1085 |
predefined arrows use the arrow tips \code{cf}, \code{left cf} and \code{right |
| 1086 |
cf}. They also all except the net reaction arrow \code{==} use the |
| 1087 |
\TikZ-style \code{chemarrow} that you should use, too, if you want the option |
| 1088 |
\option{arrow-style} to have an effect. |
| 1089 |
|
| 1090 |
There are some predefined coordinates you can and should use. For |
| 1091 |
completeness' sake the arrow tips and the \TikZ-style are also listed: |
| 1092 |
\begin{codedesc} |
| 1093 |
\Code{(cf\_arrow\_start)} |
| 1094 |
The beginning of the arrow. |
| 1095 |
\Code{(cf\_arrow\_end)} |
| 1096 |
The end of the arrow. |
| 1097 |
\Code{(cf\_arrow\_mid)} |
| 1098 |
The mid of the arrow. |
| 1099 |
\Code{(cf\_arrow\_mid\_start)} |
| 1100 |
The beginning of the shorter arrow in types like \verbcode+<=>>+. |
| 1101 |
\Code{(cf\_arrow\_mid\_end)} |
| 1102 |
The end of the shorter arrow in types like \verbcode+<=>>+. |
| 1103 |
\Code{cf} |
| 1104 |
A double-sided arrow tip. |
| 1105 |
\Code{left cf} |
| 1106 |
A left-sided arrow tip. |
| 1107 |
\Code{right cf} |
| 1108 |
A right-sided arrow tip. |
| 1109 |
\Code{chemarrow} |
| 1110 |
\chemformula's \TikZ-style that is applied to the arrows and set with |
| 1111 |
\option{arrow-style} |
| 1112 |
\end{codedesc} |
| 1113 |
\begin{example} |
| 1114 |
\NewChemArrow{.>}{ |
| 1115 |
\draw[chemarrow,-cf,dotted,red] (cf_arrow_start) -- (cf_arrow_end); |
| 1116 |
} |
| 1117 |
\NewChemArrow{n>}{ |
| 1118 |
\draw[chemarrow,-cf] |
| 1119 |
(cf_arrow_start) |
| 1120 |
.. controls ([yshift=3ex]cf_arrow_mid) .. |
| 1121 |
(cf_arrow_end); |
| 1122 |
} |
| 1123 |
\ch{A .> B} \ch{A .>[a][b] B} \ch{A n> B} |
| 1124 |
\end{example} |
| 1125 |
|
| 1126 |
\begin{example} |
| 1127 |
\texttt{\ShowChemArrow{->}} \par |
| 1128 |
\RenewChemArrow{->}{\draw[chemarrow,->,red] (cf_arrow_start) -- (cf_arrow_end) ;} |
| 1129 |
\texttt{\ShowChemArrow{->}} \par |
| 1130 |
\ch{A -> B} |
| 1131 |
\end{example} |
| 1132 |
|
| 1133 |
\subsection{Standalone Arrows} |
| 1134 |
\chemformula\ offers\sinceversion{4.0} a command that \emph{only accepts} the |
| 1135 |
\enquote{arrow} input type: |
| 1136 |
\begin{commands} |
| 1137 |
\command{charrow}[\marg{type}\oarg{above}\oarg{below}] |
| 1138 |
Print the arrow type \meta{type}. |
| 1139 |
\end{commands} |
| 1140 |
This command is internally used for the arrows, too, when \cs{ch} is parsed. |
| 1141 |
|
| 1142 |
\section{Names} |
| 1143 |
\subsection{Syntax} |
| 1144 |
\chemformula\ has a built-in syntax to write text under a compound. In a way |
| 1145 |
it works very similar to the arrows. |
| 1146 |
\begin{commands} |
| 1147 |
\command{ch}[\Marg{ !(\meta{text})( \meta{formula} ) }] |
| 1148 |
Writes \meta{text} below \meta{formula}. |
| 1149 |
\end{commands} |
| 1150 |
If an exclamation mark is followed by a pair of parentheses \chemformula\ will |
| 1151 |
parse it this way: |
| 1152 |
\begin{example} |
| 1153 |
\ch{!(ethanol)( CH3CH2OH )} |
| 1154 |
\end{example} |
| 1155 |
The same what's true for the arrows arguments holds for these arguments: if |
| 1156 |
you leave blanks the different parts will be treated according to their input |
| 1157 |
type before the text is set below the formula. |
| 1158 |
\begin{example} |
| 1159 |
\ch{!(water)(H2O)} \quad |
| 1160 |
\ch{!( "\textcolor{blue}{water}" )( H2O )} \quad |
| 1161 |
\ch{!( $2n-1$ )( H2O )} \quad |
| 1162 |
\ch{!( H2O )( H2O )} \quad |
| 1163 |
\ch{!(oxonium)( H3O+ )} |
| 1164 |
\end{example} |
| 1165 |
If for some reason you want to insert an exclamation mark \emph{without} it |
| 1166 |
creating a name you only have to make sure it isn't followed by parentheses. |
| 1167 |
\begin{example}[side-by-side] |
| 1168 |
\ch{H2O~(!)} \par |
| 1169 |
\ch{A!{}()} |
| 1170 |
\end{example} |
| 1171 |
|
| 1172 |
\subsection{Customization} |
| 1173 |
\chemformula\ provides two options to customize the output of the names: |
| 1174 |
\begin{options} |
| 1175 |
\keyval{name-format}{commands}\Default{\cs*{scriptsize}\cs*{centering}} |
| 1176 |
\changedversion{4.15d}The format of the name. This can be arbitrary input |
| 1177 |
and the last macro may receive the name as an argument. |
| 1178 |
\keychoice{name-width}{\meta{dim},auto}\Default{auto} |
| 1179 |
The width of the box where the label is put into. \code{auto} will detect |
| 1180 |
the width of the name and set the box to this width. |
| 1181 |
\end{options} |
| 1182 |
\begin{example} |
| 1183 |
\ch{!(acid)( H2SO4 ) -> B} \par |
| 1184 |
\ch[name-format=\sffamily\small]{!(acid)( H2SO4 ) -> B} \par |
| 1185 |
\ch[name-format=\scriptsize N:~]{!(acid)( H2SO4 ) -> B} \par |
| 1186 |
\ch[name-width=3em,name-format=\scriptsize\raggedright]{!(acid)( H2SO4 ) -> B} |
| 1187 |
\end{example} |
| 1188 |
|
| 1189 |
\subsection{Standalone Names} |
| 1190 |
\chemformula\ offers a command\sinceversion{4.0} that allows the usage of the |
| 1191 |
\enquote{name} syntax in normal text. This is the command that a bang is |
| 1192 |
replaced with in \chemformula's formulas, actually. Both arguments are |
| 1193 |
mandatory. |
| 1194 |
\begin{commands} |
| 1195 |
\command{chname}[\darg{text~1}\darg{text~2}] |
| 1196 |
The command that is useed internally for placing \meta{text~1} below of |
| 1197 |
\meta{text~2}. |
| 1198 |
\end{commands} |
| 1199 |
|
| 1200 |
\section{Format and Font}\label{sec:format} |
| 1201 |
In the standard setting \chemformula\ doesn't make any default changes to the |
| 1202 |
font of the formula output. Let's take a look at a nonsense input which shows |
| 1203 |
all features: |
| 1204 |
\begin{example}[pre-output={\biolinumLF\libertineLF\setchemformula{format=}}] |
| 1205 |
\newcommand*\sample{% |
| 1206 |
\ch{H2C-C+C-CH=CH+ + CrO4^2- |
| 1207 |
<=>[x][y] |
| 1208 |
2.5 Cl^{-.} + 3_1/2 Na*OH_{(aq)} + !(name)( A^n ) "\LaTeXe"} |
| 1209 |
} |
| 1210 |
\sample |
| 1211 |
\end{example} |
| 1212 |
\newcommand*\sample{% |
| 1213 |
\ch{H2C-C+C-CH=CH+ + CrO4^2- |
| 1214 |
<=>[x][y] |
| 1215 |
2.5 Cl^{-.} + 3_1/2 Na*OH_{(aq)} + !(name)( A^n ) "\LaTeXe"} |
| 1216 |
} |
| 1217 |
|
| 1218 |
Now we're going to change different aspects of the font a look what happens: |
| 1219 |
\begin{example}[pre-output={\biolinumLF\libertineLF\setchemformula{format=}}] |
| 1220 |
\sffamily Hallo \sample \\ |
| 1221 |
\ttfamily Hallo \sample \normalfont \\ |
| 1222 |
\bfseries Hallo \sample \normalfont \\ |
| 1223 |
\itshape Hallo \sample |
| 1224 |
\end{example} |
| 1225 |
As you can see most features adapt to the surrounding font. |
| 1226 |
|
| 1227 |
If you want to change the default format you need to use this option: |
| 1228 |
\begin{options} |
| 1229 |
\keyval{format}{code}\Default |
| 1230 |
Adds \meta{code} before the output of \cs{ch}. |
| 1231 |
\keyval{atom-format}{code}\Default |
| 1232 |
This\sinceversion{4.13} adds \meta{code} before each formula. This |
| 1233 |
allows to specify a format for the chemical formulas only and have a |
| 1234 |
different format for the rest of the chemical equation. |
| 1235 |
\end{options} |
| 1236 |
\begin{example}[pre-output={\biolinumLF\libertineLF\setchemformula{format=}}] |
| 1237 |
\definecolor{newblue}{rgb}{.1,.1,.5} |
| 1238 |
\setchemformula{format=\color{newblue}\sffamily} |
| 1239 |
\sffamily Hallo \sample \\ |
| 1240 |
\ttfamily Hallo \sample \normalfont \\ |
| 1241 |
\bfseries Hallo \sample \normalfont \\ |
| 1242 |
\itshape Hallo \sample |
| 1243 |
\end{example} |
| 1244 |
|
| 1245 |
You can also specifically change the fontfamily, fontseries and fontshape of |
| 1246 |
the output. |
| 1247 |
\begin{options} |
| 1248 |
\keyval{font-family}{family}\Default |
| 1249 |
Changes the fontfamily of the output with \cs*{fontfamily}\marg{family}. |
| 1250 |
\keyval{font-series}{series}\Default |
| 1251 |
Changes the fontseries of the output with \cs*{fontseries}\marg{series}. |
| 1252 |
\keyval{font-shape}{shape}\Default |
| 1253 |
Changes the fontshape of the output with \cs*{fontshape}\marg{shape}. |
| 1254 |
\end{options} |
| 1255 |
\begin{example}[pre-output={\biolinumLF\libertineLF\setchemformula{format=}}] |
| 1256 |
\setchemformula{font-series=bx} |
| 1257 |
Hallo \sample \par |
| 1258 |
\sffamily Hallo \sample \normalfont \par |
| 1259 |
\setchemformula{font-family=lmss,font-series=m} Hallo \sample |
| 1260 |
\normalfont \par |
| 1261 |
\itshape Hallo \sample |
| 1262 |
\end{example} |
| 1263 |
|
| 1264 |
If you're using \XeLaTeX\ or \LuaLaTeX\ and have loaded \pkg{fontspec} you |
| 1265 |
have the possibilty to set the font with it: |
| 1266 |
\begin{options} |
| 1267 |
\keyval{font-spec}{font}\Default |
| 1268 |
Use font \meta{font} for \chemformula's formulas. |
| 1269 |
\end{options} |
| 1270 |
or with options |
| 1271 |
\begin{options} |
| 1272 |
\keychoice{font-spec}{\Marg{[\meta{options}]\meta{font}}} |
| 1273 |
Use font \meta{font} with options \meta{options} for \chemformula's |
| 1274 |
formulas. |
| 1275 |
\end{options} |
| 1276 |
Since this document is typeset with \pdfLaTeX\ the option cannot be |
| 1277 |
demonstrated here. |
| 1278 |
|
| 1279 |
\section{Usage In Math Equations} |
| 1280 |
The \cs{ch} command can be used inside math equations. It recognizes |
| 1281 |
\verbcode+\\+ and \verbcode+&+ and passes them on. However, you can't use the |
| 1282 |
optional arguments of \verbcode+\\+ inside \cs{ch}. |
| 1283 |
\begin{example} |
| 1284 |
\begin{align} |
| 1285 |
\ch{ |
| 1286 |
H2O & ->[a] H2SO4 \\ |
| 1287 |
Cl2 & ->[x][y] CH4 |
| 1288 |
} |
| 1289 |
\end{align} |
| 1290 |
\begin{align*} |
| 1291 |
\ch{ |
| 1292 |
RNO2 &<=>[ + e- ] RNO2^{-.} \\ |
| 1293 |
RNO2^{-.} &<=>[ + e- ] RNO2^2- |
| 1294 |
} |
| 1295 |
\end{align*} |
| 1296 |
\end{example} |
| 1297 |
|
| 1298 |
\section{Usage with \TikZ\ or \pkg*{pgfplots} and externalization} |
| 1299 |
Since \chemformula\ uses\sinceversion{4.1} \TikZ\ to draw reaction arrows |
| 1300 |
and bonds they would be externalized, too, if you use that facility with |
| 1301 |
\TikZ\ or \needpackage{pgfplots}~\cite{pkg:pgfplots}. This may not be |
| 1302 |
desirable since they are very small pictures maybe containing of a single |
| 1303 |
line. This is why \chemformula's default behaviour is to disable |
| 1304 |
externalization for it's bonds and arrows. This can be turned on and off |
| 1305 |
through the following option: |
| 1306 |
\begin{options} |
| 1307 |
\keybool{tikz-external-disable}\Default{true} |
| 1308 |
dis- or enable \TikZ' externalization mechanism for \chemformula's arrows |
| 1309 |
and bonds. |
| 1310 |
\end{options} |
| 1311 |
|
| 1312 |
If you should be using a formula that contains bonds or arrows inside of a |
| 1313 |
\code{tikzpicture} that is externalized you should locally enable it for |
| 1314 |
\chemformula, too: |
| 1315 |
|
| 1316 |
\begin{sourcecode} |
| 1317 |
\begin{tikzpicture} |
| 1318 |
\setchemformula{tikz-external-disable=false} |
| 1319 |
\begin{axis}[xlabel={\ch{2 H+ + 2 e- -> H2}}] |
| 1320 |
\addplot ... ; |
| 1321 |
\end{axis} |
| 1322 |
\end{tikzpicture} |
| 1323 |
\end{sourcecode} |
| 1324 |
|
| 1325 |
\section{Lewis Formulae}\label{sec:lewis-formulae} |
| 1326 |
\chemformula\ offers\sinceversion{4.2} a command to typeset Lewis formulae. |
| 1327 |
This does not mean Lewis structures! Those can be achieved using the |
| 1328 |
\pkg{chemfig} package~\cite{pkg:chemfig}. \chemformula\ provides the |
| 1329 |
possibility to draw electrons as dots and pairs of dots or a line around an |
| 1330 |
atom. |
| 1331 |
|
| 1332 |
\begin{commands} |
| 1333 |
\command{chlewis}[\oarg{options}\marg{electron spec}\marg{atom}] |
| 1334 |
Draws electrons around the \meta{atom} according to \meta{electron spec}. |
| 1335 |
\end{commands} |
| 1336 |
|
| 1337 |
Electrons are specified by the angle to the horizontal in the couter-clockwise |
| 1338 |
direction. The default appearance is a pair of electrons drawn as a pair of |
| 1339 |
dots. Other specifications can be chosen. The specification follows the |
| 1340 |
pattern \meta{angle}\meta{separator}. \meta{angle} is a positiv or negativ |
| 1341 |
integer denoting the angle counter clockwise to the horizontal where the |
| 1342 |
electrons should be drawn. \meta{separator} is either a dot (\code{.}, single |
| 1343 |
electron), a colon (\code{:}, electron pair), a vertical line (\code{|}, |
| 1344 |
electron pair), an o (\code{o}, empty pair), or a comma (\code{,} default |
| 1345 |
spec). |
| 1346 |
|
| 1347 |
\begin{commands} |
| 1348 |
\command{chlewis}[\Marg{\meta{angle1}\meta{type1}\meta{angle2}\meta{type2}}% |
| 1349 |
\marg{atom}] |
| 1350 |
For example: \cs{chlewis}\Marg{0,180}\Marg{O} gives \chlewis{0,180}{O} and |
| 1351 |
\cs{chlewis}\Marg{0.90.180.270.}\Marg{C} gives |
| 1352 |
\chlewis{0.90.180.270.}{C}. |
| 1353 |
\end{commands} |
| 1354 |
|
| 1355 |
The appearance can be influenced by a number of options: |
| 1356 |
\begin{options} |
| 1357 |
\keychoice{lewis-default}{.,:,|,o,single,pair,pair (dotted),pair |
| 1358 |
(line),empty}\Default{pair} |
| 1359 |
Sets the default type that is used when no type is given in \meta{electron |
| 1360 |
spec}. |
| 1361 |
\keyval{lewis-distance}{dim}\Default{1ex} |
| 1362 |
The distance of two electrons in a pair. |
| 1363 |
\keyval{lewis-line-length}{dim}\Default{1.5ex} |
| 1364 |
The length of the line representing an electron pair. |
| 1365 |
\keyval{lewis-line-width}{dim}\Default{1pt} |
| 1366 |
The thickness of a line representing an electron pair. |
| 1367 |
\keyval{lewis-offset}{dim}\Default{.5ex} |
| 1368 |
The distance of the symbols from the atom. |
| 1369 |
\end{options} |
| 1370 |
The dots are drawn according to the \option{radical-radius} option mentioned |
| 1371 |
in section~\ref{ssec:compounds:customization}. |
| 1372 |
|
| 1373 |
The basic usage should be more or less self-explaining: |
| 1374 |
\begin{example}[side-by-side] |
| 1375 |
\chlewis{0:90|180.270}{O} |
| 1376 |
\quad |
| 1377 |
\chlewis{45,135}{O} |
| 1378 |
\quad |
| 1379 |
\chlewis{0o}{Na} |
| 1380 |
\end{example} |
| 1381 |
|
| 1382 |
The next example shows the effect of some of the options: |
| 1383 |
\begin{example} |
| 1384 |
\chlewis[lewis-default=.]{23,68,113,158,203,248,293,338}{X} |
| 1385 |
\quad |
| 1386 |
\chlewis{0,90,180,270}{X} |
| 1387 |
\quad |
| 1388 |
\chlewis[lewis-distance=1.25ex]{0,90,180,270}{X} |
| 1389 |
\quad |
| 1390 |
\chlewis[lewis-distance=.75ex,radical-radius=.5pt]{0,90,180,270}{X} |
| 1391 |
\quad |
| 1392 |
\chlewis[ |
| 1393 |
radical-radius=.5pt, |
| 1394 |
lewis-default=. |
| 1395 |
]{23,68,113,158,203,248,293,338}{X} |
| 1396 |
\end{example} |
| 1397 |
|
| 1398 |
\begin{example} |
| 1399 |
\ch{ |
| 1400 |
!($1s^22s^1$)( "\chlewis{180.}{Li}" ) + |
| 1401 |
!($1s^22s^22p^5$)( "\chlewis{0.90,180,270}{F}" ) |
| 1402 |
-> |
| 1403 |
!($1s^2$)( Li+ ) + !($1s^22s^22p^6$)( "\chlewis{0,90,180,270}{F}" {}- ) |
| 1404 |
} |
| 1405 |
\end{example} |
| 1406 |
|
| 1407 |
\section{Kröger-Vink Notation}\label{sec:kroger-vink-notation} |
| 1408 |
|
| 1409 |
\chemformula\ also supports the Kröger-Vink notation\sinceversion{4.5}. |
| 1410 |
\begin{options} |
| 1411 |
\keybool{kroeger-vink}\Default{false} |
| 1412 |
Enable the Kröger-Vink notation. As most options this can be enabled |
| 1413 |
globally via the setup command or locally as option to \cs{ch}. |
| 1414 |
\end{options} |
| 1415 |
|
| 1416 |
With this option enabled several changes come into effect: \verbcode|'| |
| 1417 |
produces a prime, a \code{x} in a superscript produces $\times$, and both a |
| 1418 |
\code{.} and a \code{*} produce a little filled circle. In the Kröger-Vink |
| 1419 |
notation a prime denotes a negative relative charge, the circle a positive |
| 1420 |
relative charge, and the cross denotes a neutral relative charge. |
| 1421 |
|
| 1422 |
\begin{example}[side-by-side,add-sourcecode-options={literate=}] |
| 1423 |
\setchemformula{kroeger-vink=true} |
| 1424 |
\ch{Al_{Al}^'} |
| 1425 |
\ch{Al_{Al}'}\par |
| 1426 |
\ch{Ni_{Cu}^{x}}\par |
| 1427 |
\ch{V_{Cl}^.} |
| 1428 |
\ch{V_{Cl}^*}\par |
| 1429 |
\ch{Ca_i^{..}}\par |
| 1430 |
\ch{e^'}\par |
| 1431 |
\ch{Cl_i^'} |
| 1432 |
\ch{Cl_i'}\par |
| 1433 |
\ch{O_i^{''}} |
| 1434 |
\ch{O_i''} |
| 1435 |
\end{example} |
| 1436 |
|
| 1437 |
There are a number of options for customizations: |
| 1438 |
\begin{options} |
| 1439 |
\keyval{kv-positive-style}{\TikZ}\Default |
| 1440 |
\TikZ\ code for positive charge dot. |
| 1441 |
\keyval{kv-positive-radius}{dim}\Default{.3ex} |
| 1442 |
Radius of positive charge dot |
| 1443 |
\keyval{kv-positive-hshift}{dim}\Default{.15em} |
| 1444 |
Horizontal shift of positive charge dot |
| 1445 |
\keyval{kv-positive-vshift}{dim}\Default{.5ex} |
| 1446 |
Vertical shift positive charge dot |
| 1447 |
\keyval{kv-positive-offset}{dim}\Default{.4em} |
| 1448 |
The offset of two consecutive positive charge dots |
| 1449 |
\keyval{kv-neutral-symbol}{\TeX\ code}\Default{\$\cs*{times}\$} |
| 1450 |
Symbol for neutral particles. |
| 1451 |
\end{options} |
| 1452 |
|
| 1453 |
\appendix |
| 1454 |
|
| 1455 |
\section{History Since Version~4.0} |
| 1456 |
|
| 1457 |
\begin{changes}{4.0} |
| 1458 |
\change Since version 4.0\sinceversion{4.0}, the \chemformula\ package is |
| 1459 |
distributed independently from \chemmacros. |
| 1460 |
\end{changes} |
| 1461 |
|
| 1462 |
\begin{changes}{4.1} |
| 1463 |
\change New option \option{tikz-external-disable}. |
| 1464 |
\change New option \option{frac-math-cmd}. |
| 1465 |
\end{changes} |
| 1466 |
|
| 1467 |
\begin{changes}{4.2} |
| 1468 |
\change New option \option{arrow-style}. |
| 1469 |
\change New command \cs{chlewis} that allows to add Lewis electrons to an |
| 1470 |
atom, see section~\ref{sec:lewis-formulae}. |
| 1471 |
\end{changes} |
| 1472 |
|
| 1473 |
\begin{changes}{4.3} |
| 1474 |
\change New option \option{stoich-print}. |
| 1475 |
\change New command \cs{chstoich}. |
| 1476 |
\change The commands \cs*{DeclareChem\meta{...}} now don't give an error any |
| 1477 |
more if the command already exists. This is more consistent with \LaTeX's |
| 1478 |
\cs*{DeclareRobustCommand}. For all those commands a version |
| 1479 |
\cs*{NewChem\meta{...}} is introduced that \emph{does} give an error if |
| 1480 |
the new command is already defined. |
| 1481 |
\end{changes} |
| 1482 |
|
| 1483 |
\begin{changes}{4.4} |
| 1484 |
\change A single dash \code{-} in \cs{ch} is now treated as a minus sign. |
| 1485 |
This is consistent with the behaviour of a \code{+}. |
| 1486 |
\end{changes} |
| 1487 |
|
| 1488 |
\begin{changes}{4.5} |
| 1489 |
\change New arrow types \arrowtype{>=<}, \arrowtype{>=<{}<}, \arrowtype{>{}>=<} |
| 1490 |
and \arrowtype{<==>}. |
| 1491 |
\change Internal changes to \cs{ch} allow usage of optional arguments of |
| 1492 |
\cs*{\textbackslash} and \cs*{label} in \chemmacros' \env*{reactions} |
| 1493 |
environment. |
| 1494 |
\end{changes} |
| 1495 |
|
| 1496 |
\begin{changes}{4.6} |
| 1497 |
\change New options \option{circled} and \option{circletype}. this allows to |
| 1498 |
set the behaviour as described on \chemmacros' manual for a specific usage |
| 1499 |
of \cs{ch}. |
| 1500 |
\end{changes} |
| 1501 |
|
| 1502 |
\begin{changes}{4.7} |
| 1503 |
\change Dependency change: \chemformula\ now requires the \TikZ\ library |
| 1504 |
\code{arrows.meta} instead of the library \code{arrows}. This requires |
| 1505 |
\TikZ\ version~3.0.0. |
| 1506 |
\end{changes} |
| 1507 |
|
| 1508 |
\begin{changes}{4.8} |
| 1509 |
\change The \chemformula\ package now is no longer part of the \chemmacros\ |
| 1510 |
bundle but is distributed as a package of it's own. |
| 1511 |
\end{changes} |
| 1512 |
|
| 1513 |
\begin{changes}{4.9} |
| 1514 |
\change New options \option{minus-space} and \option{minus-penalty} equivalent |
| 1515 |
to the existing \option{plus-space} and \option{plus-penalty} |
| 1516 |
\change New options \option{plus-output-symbol} and |
| 1517 |
\option{minus-output-symbol} for customizing the plus and minus signs in |
| 1518 |
the output. |
| 1519 |
\end{changes} |
| 1520 |
|
| 1521 |
\begin{changes}{4.10} |
| 1522 |
\change New macro set \cs{NewChemCompoundProperty}, see |
| 1523 |
section~\ref{sec:extend-comp-prop} for a description. |
| 1524 |
\end{changes} |
| 1525 |
|
| 1526 |
\begin{changes}{4.11} |
| 1527 |
\change New macro set \cs{NewChemAdditionSymbol}, see |
| 1528 |
section~\ref{sec:addition-symbols}. |
| 1529 |
\change New macro set \cs{NewChemSymbol}, see section~\ref{sec:symbols}. |
| 1530 |
\end{changes} |
| 1531 |
|
| 1532 |
\begin{changes}{4.12} |
| 1533 |
\change Change package requirement: \chemformula\ now not loads complete |
| 1534 |
\pkg{amsmath} but only \pkg{amstext}. |
| 1535 |
\end{changes} |
| 1536 |
|
| 1537 |
\begin{changes}{4.13} |
| 1538 |
\change Check for blank input parts and don't process them. |
| 1539 |
\change Drop support for \cs*{[} and \cs*{]} as replacement for \code{[} and |
| 1540 |
\code{]} inside arrow captions. |
| 1541 |
\change New option \option{atom-format}. |
| 1542 |
\end{changes} |
| 1543 |
|
| 1544 |
\begin{changes}{4.14} |
| 1545 |
\change New option \option{adduct-penalty}. |
| 1546 |
\end{changes} |
| 1547 |
|
| 1548 |
\begin{changes}{4.15} |
| 1549 |
\change The order of arrow definitions doesn't matter any more. |
| 1550 |
\change New quasi equilibria arrows. |
| 1551 |
\change Require \pkg{amsmath}. |
| 1552 |
\change Allow \option{name-format} to end with a macro that takes an |
| 1553 |
argument. |
| 1554 |
\change Various bug fixes. |
| 1555 |
\end{changes} |
| 1556 |
|
| 1557 |
\begin{changes}{4.16} |
| 1558 |
\change New option \option{math-scripts} |
| 1559 |
\change Use \LaTeX's new hooks and get rid of redundant package dependencies |
| 1560 |
and code. |
| 1561 |
\end{changes} |
| 1562 |
|
| 1563 |
\begin{changes}{4.17} |
| 1564 |
\change Various bug fixes. |
| 1565 |
\change Lazy boolean evaluation where possible. |
| 1566 |
\change Place arrow's arguments in a tabular. This allows for multiple |
| 1567 |
lines. |
| 1568 |
\end{changes} |
| 1569 |
|
| 1570 |
\printbibliography |
| 1571 |
|
| 1572 |
\end{document} |