diff options
author | Karl Berry <karl@freefriends.org> | 2015-03-13 23:23:06 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2015-03-13 23:23:06 +0000 |
commit | 92c0eccd62a3eb57e56ee44400ebe63fec446bf6 (patch) | |
tree | 841103e4b6f8af074da637e3ac5ca53f2aac2759 /Master | |
parent | 40a46f311d540329fb7fb15ed97a491a710333d3 (diff) |
mhchem (13mar15)
git-svn-id: svn://tug.org/texlive/trunk@36504 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master')
-rw-r--r-- | Master/texmf-dist/doc/latex/mhchem/README | 4 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/mhchem/mhchem.pdf | bin | 202823 -> 206385 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/latex/mhchem/mhchem.tex | 317 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/mhchem/mhchem.sty | 1737 |
4 files changed, 1236 insertions, 822 deletions
diff --git a/Master/texmf-dist/doc/latex/mhchem/README b/Master/texmf-dist/doc/latex/mhchem/README index 797dd509ec4..0fc068570e5 100644 --- a/Master/texmf-dist/doc/latex/mhchem/README +++ b/Master/texmf-dist/doc/latex/mhchem/README @@ -1,7 +1,7 @@ -The mhchem Bundle 2015-02-09 +The mhchem Bundle 2015-03-13 containing -- mhchem v3.19 +- mhchem v3.21 - hpstatement v1.01 - rsphrase v3.11 diff --git a/Master/texmf-dist/doc/latex/mhchem/mhchem.pdf b/Master/texmf-dist/doc/latex/mhchem/mhchem.pdf Binary files differindex dae451d1870..261398f5f3a 100644 --- a/Master/texmf-dist/doc/latex/mhchem/mhchem.pdf +++ b/Master/texmf-dist/doc/latex/mhchem/mhchem.pdf diff --git a/Master/texmf-dist/doc/latex/mhchem/mhchem.tex b/Master/texmf-dist/doc/latex/mhchem/mhchem.tex index 418bf4f2fe0..e881716ec98 100644 --- a/Master/texmf-dist/doc/latex/mhchem/mhchem.tex +++ b/Master/texmf-dist/doc/latex/mhchem/mhchem.tex @@ -35,7 +35,7 @@ % http://www.ctan.org/tex-archive/fonts/tex-gyre/fonts \addtokomafont{disposition}{\rmfamily} \linespread{1.1} -\setmonofont[Mapping=tex-text]{Source Code Pro} +\setmonofont[Mapping=tex-text,Scale=MatchLowercase]{Source Code Pro} % http://sourceforge.net/projects/sourcecodepro.adobe/ \usepackage[bookmarks,bookmarksopen,pdfstartview=FitH]{hyperref} \usepackage[alwaysadjust]{paralist} @@ -62,7 +62,7 @@ The mhchem Bundle\\[0.3em] \Large\textmd{% Documentation for the Packages\\ - mhchem v3.19,\\% check + mhchem v3.21,\\% check hpstatement v1.01 and\\ rsphrase v3.11}% } @@ -71,7 +71,7 @@ mhchem\makebox[0pt][l]{\textcolor{white}{NOSPAM}}@MartinHensel\makebox[1pt][l]{\textcolor{white}{.}}.de% } \date{% - 2015-02-09% check + 2015-03-13% check } \maketitle @@ -81,7 +81,7 @@ \noindent The \textbf{mhchem} package provides commands for typesetting chemical molecular formulae and equations. \medskip - + \noindent The \textbf{hpstatement} package provides commands for the official hazard statements and precautionary statements (H and P statements) that are used to label chemicals. \medskip @@ -102,13 +102,11 @@ \section{Work in Progress} -\begin{annotation} The mhchem package is still work in progress. Admittedly, very slow progress with large breaks in between, but still progressing. Version 4 will be a major rewrite of the code with some new features and slight syntax changes (this will be the reason for the new number). While I try to support the old syntaxes via the \verb|version| option, please note that slight changes in spacing (and therefore changed line breaks and page breaks) can occur from release to release. -\end{annotation} -\section{Why that package?} +\section{Why this package?} \noindent For typesetting a single chemical formula from time to time, one can use \LaTeX's math mode, manually setting the letters in an upright font. @@ -149,19 +147,19 @@ mhchem is here to assist you. To mention a few of its features: \begin{compactitem} \item Adaptation to the surrounding environment\\ If used inside normal text or a section header, the formula is displayed using the current text font. If used inside a math environment, the current math font is used in the appropriate size. - + \item More natural input\\ I am convinced that (when expecting a chemical formula) it is easier to read and write \verb|H3PO4| than \verb|H_3PO_4|. The latter is grouped wrongly according to the Gestalt rules. Furthermore, you can copy formulas from text e-mails and even Word documents and save a lot of time as you do not have to insert underscores. (One could argue that this is inconsistend with math mode and could lead to confusions. I believe, however that \verb|O2| and \verb|x_2| are sufficiently distinct concepts.) - + \item Easy input of amount numbers\\ with automatic spacing; easy input of fractions - + \item Fine typographic corrections\\ - fine correction of the height of subscripts and superscripts; right-aligned left-side sub- and superscripts + fine correction of the height of subscripts and superscripts; right-aligned left-side subscripts and superscripts \end{compactitem} \noindent -\ldots{} and a lot more. But let us end the ad block here and see ourselves how easy it can be to typeset chemical formulae. +\ldots{} and a lot more. But let me end the ad block here and see for yourself how easy it can be to typeset chemical formulae. \section{Preamble} @@ -178,75 +176,71 @@ In order to use all of mhchem's features, request it in your document's preamble \begin{annotation} \noindent -What about the \verb|version=3|? During development, I became aware that additional functionality could not be added without changing the user-interface slightly. But what about backward compatibility? I could, of course, have freezed mhchem and published an mhchem2 package. However, I decided to use an option in order to switch to the new interface. One can use \verb|version=3| for the most-recent version of mhchem, but \verb|version=2| and \verb|version=1| (or no option at all, but this will yield a warning) are still there for existing documents that use an old user-interface of mhchem. Those old documents should still produce the same results. However, spacing might differ slightly. +What about the \verb|version=3|? During development, I became aware that additional functionality could not be added without changing the user-interface slightly. But what about backward compatibility? I could, of course freeze mhchem and publish an mhchem2 package. However, I decided to use a parameter in order to switch to the new interface. One can use \verb|version=3| for the most-recent version of mhchem, but \verb|version=2| and \verb|version=1| and \verb|0| are still there for existing documents that use an old user-interface of mhchem. Those old documents should still produce the same results. However, spacing might differ slightly. \end{annotation} \medskip \noindent -mhchem includes the following packages: amsmath, calc, graphics, ifthen, keyval, pdftexcmds, twoopt. +mhchem needs a couple of other packages. For instance, expl3, amsmath and calc. \section{Basics} \noindent -\begin{SideBySideExample}[xrightmargin=2cm] +\begin{SideBySideExample}[xrightmargin=2.5cm] \ce{H2O} \end{SideBySideExample} \medskip -\begin{SideBySideExample}[xrightmargin=2cm] +\begin{SideBySideExample}[xrightmargin=2.5cm] \ce{Sb2O3} \end{SideBySideExample} \medskip -\begin{SideBySideExample}[xrightmargin=2cm] +\begin{SideBySideExample}[xrightmargin=2.5cm] \ce{H+} \end{SideBySideExample} \medskip -\begin{SideBySideExample}[xrightmargin=2cm] +\begin{SideBySideExample}[xrightmargin=2.5cm] \ce{CrO4^2-} \end{SideBySideExample} \medskip -\begin{SideBySideExample}[xrightmargin=2cm] - \ce{AgCl2-} -\end{SideBySideExample} - -\medskip -\begin{SideBySideExample}[xrightmargin=2cm] +\begin{SideBySideExample}[xrightmargin=2.5cm] \ce{[AgCl2]-} \end{SideBySideExample} \medskip -\begin{SideBySideExample}[xrightmargin=2cm] - \ce{Y^{99}+} +\begin{SideBySideExample}[xrightmargin=2.5cm] + \ce{(NH4)2S} \end{SideBySideExample} \medskip -\begin{SideBySideExample}[xrightmargin=2cm] - \ce{Y^{99+}} +\begin{SideBySideExample}[xrightmargin=2.5cm] + \ce{Y^99+} \end{SideBySideExample} +\fromversion{3.21} \medskip -\begin{SideBySideExample}[xrightmargin=2cm] - \ce{H2_{(aq)}} +\begin{SideBySideExample}[xrightmargin=2.5cm] + \ce{Y^{99+}} \end{SideBySideExample} \medskip -\begin{SideBySideExample}[xrightmargin=2cm] - \ce{NO3-} +\begin{SideBySideExample}[xrightmargin=2.5cm] + \ce{H2(aq)} % IUPAC \end{SideBySideExample} \medskip -\begin{SideBySideExample}[xrightmargin=2cm] - \ce{(NH4)2S} +\begin{SideBySideExample}[xrightmargin=2.5cm] + \ce{CO3^2-{}_{(aq)}} % not according to IUPAC \end{SideBySideExample} -\subsection{Amounts} +\subsection{Amounts} Place amounts directly in front of a formula. A small space will be inserted automatically. @@ -275,52 +269,6 @@ automatically. \end{SideBySideExample} -\subsection{Fonts} - -A few words about fonts. LaTeX distinguishes between text fonts and math fonts. In general, the math fonts have much more glyphs: alphas, nabla operators and all that kind of suff. Ideally, the math font looks very similar to the text font and that is why many LaTeX users do not know about the two kinds of fonts. However, the distinction is important for the use of mhchem. - -\medskip - -\noindent -In the following examples, I will switch the text font to sans serif. This way, one can easily distinguish \textsf{text font (sans serif)} from $\mathrm{math\ font\ (with\ serifs)}$. - -\medskip - -\noindent -When you are in a math environment (e.g. opened and closed with a \$), you could simply use \macro{ce}. Its content will be set in an upright math font. (Remember: all variables---like $V$ for volume---are set using an italic font, physical units and chemical elements are set using an upright font.) - -\medskip - -\begin{SideBySideExample}[xrightmargin=5cm] - $V_{\ce{H2O}}$ -\end{SideBySideExample} - -\medskip - -\noindent -When used in text mode, \macro{ce} adapts to the current text font. You could simply write a formula in one of your section titles it would be set with the correct font, no matter where is appears (section title, header, table of contents, references, \dots). - -\medskip - -\begin{SideBySideExample}[xrightmargin=5cm] - £\sffamily - \ce{H2O}, $\ce{H2O}$ -\end{SideBySideExample} - -\medskip - -\begin{SideBySideExample}[xrightmargin=5cm] - £\sffamily - \ce{Ce^{IV}}, $\ce{Ce^{IV}}$ -\end{SideBySideExample} -\fromversion{2.04} - -\medskip - -\noindent -There are some special cases. A negative charge in text mode is replaced with a dash (--, normally input as \verb|--|), because a text minus sign is often too short (compare $\text{Cl}^{\text{-}}$ and \ce{Cl-}). All `operators' in equations, e.g. `+' and reaction arrows, are taken from the math font. - - \subsection{Special Symbols} \begin{SideBySideExample}[xrightmargin=5cm] @@ -342,12 +290,6 @@ There are some special cases. A negative charge in text mode is replaced with a \end{SideBySideExample} \fromversion{2} -\medskip -\begin{SideBySideExample}[xrightmargin=5cm] - \ce{$\mu\hyphen$Cl} -\end{SideBySideExample} -\fromversion{3.05} - \subsection{Bonds} @@ -363,8 +305,8 @@ Horizontal \fromversion{2} bonds can be set using the characters \verb|-|, \verb \medskip \begin{SideBySideExample}[xrightmargin=5cm] - \ce{X=Y#Z} -\end{SideBySideExample} + \ce{X=Y#Z} +\end{SideBySideExample} \medskip @@ -413,11 +355,58 @@ The \macro{bond} \fromversion{3} command allows you to typeset special bonds. Please be aware, that the dashed bonds use the \macro{scalebox} macro internally, which may not be visualised correctly by some DVI viewers. If you switch to another math font, the sidebearing of the minus sign may vary, which would cause the dashed bonds to align badly (in \verb|\bond{~--}|, for instance). In that case, you may want to adjust the layout by using the command \verb|\mhchemoptions{minus-sidebearing-left=0.06em,| \verb|minus-sidebearing-right=0.11em}| with the appropriate values. +\subsection{Fonts} + +A few words about fonts. LaTeX distinguishes between text fonts and math fonts. In general, the math fonts have much more glyphs: alphas, nabla operators and all that kind of suff. Ideally, the math font looks very similar to the text font and that is why many LaTeX users do not know about the two kinds of fonts. However, the distinction is important for the use of mhchem. + +\medskip + +\noindent +When you are in a math environment (e.g. opened and closed with a \$), \macro{ce}'s content will be set in an upright math font. (Remember: all variables---like $V$ for volume---are set using an italic font, physical units and chemical elements are set using an upright font.) + +\medskip + +\begin{SideBySideExample}[xrightmargin=5cm] + $V_{\ce{H2O}}$ +\end{SideBySideExample} + +\medskip + +\noindent +When used in text mode, \macro{ce} adapts to the current text font. You could simply write a formula in one of your section titles. It would be set with the correct font, no matter where is appears (section title, header, table of contents, references, \dots). + +\medskip + +\begin{SideBySideExample}[xrightmargin=5cm] + £\sffamily\textbf + This is text with \ce{H2O} and $\ce{H2O}$. +\end{SideBySideExample} + +\medskip + +\begin{SideBySideExample}[xrightmargin=5cm] + £\sffamily + \ce{Ce^{IV}}, $\ce{Ce^{IV}}$ +\end{SideBySideExample} +\fromversion{2.04} + +\medskip + +\noindent +There are some special cases. A negative charge in text mode is replaced with a dash (--, normally input as \verb|--|), because a text minus sign is often too short (compare $\text{Cl}^{\text{-}}$ and \ce{Cl-}). All `operators' in equations, e.g. `+' and reaction arrows, are taken from the math font. + + \subsection{Using Math} -To +To +\fromversion{3.05} +use math commands inside \macro{ce}, these commands can be enclosed by \verb|$|. Please be aware that a math font will be used for these parts, i.\,e., this might not look good in text that differs from math, like headlines. + +\medskip +\begin{SideBySideExample}[xrightmargin=5cm] + \ce{$\mu\hyphen$Cl} +\end{SideBySideExample} \fromversion{3.05} -use math commands inside \macro{ce}, these commands can be enclosed by \verb|$|. \medskip \begin{SideBySideExample}[xrightmargin=5cm] @@ -457,7 +446,6 @@ use math commands inside \macro{ce}, these commands can be enclosed by \verb|$|. \noindent \makebox[5cm][l]{\ce{H+ + OH- <=>> H2O}}\verb|\ce{H+ + OH- <=>> H2O}| - \medskip \begin{SideBySideExample}[xrightmargin=5cm] \ce{$A$ <-> $A'$} @@ -485,7 +473,7 @@ The content above and below reaction arrows is set in math font. When you want t \medskip \begin{SideBySideExample}[xrightmargin=5cm] - \ce{CO2 + C + \ce{CO2 + C ->[\text{above}][\text{below}] 2CO} \end{SideBySideExample} @@ -536,7 +524,7 @@ Both, \verb|\left| and \verb|\right| macros, need to be in the same math environ \ce{Zn^2+ <=>[\ce{+ 2OH-}][\ce{+ 2H+}] $\underset{\text{amphoteres Hydroxid}}{\ce{Zn(OH)2 v}}$ - <=>C[+2OH-][{+ 2H+}] + <=>C[+2OH-][{+ 2H+}] $\underset{\text{Hydroxozikat}}{\ce{[Zn(OH)4]^2-}}$ } \end{Example} @@ -550,7 +538,7 @@ Both, \verb|\left| and \verb|\right| macros, need to be in the same math environ \medskip \begin{Example}[xrightmargin=5cm] - \ce{Hg^2+ ->[\ce{I-}] + \ce{Hg^2+ ->[\ce{I-}] $\underset{\mathrm{red}}{\ce{HgI2}}$ ->C[I-] $\underset{\mathrm{red}}{\ce{[Hg^{II}I4]^2-}}$ @@ -559,9 +547,11 @@ Both, \verb|\left| and \verb|\right| macros, need to be in the same math environ \fromversion{3.05} -\subsection{Tips and Tricks} +\section[Equation Environments]{Equation Environments\fromversion{2}} + +\subsection{Own Equation Command} -When you use equation environments contining a \macro{ce} very often, you may want to create your own command. Then you could (in your preamble, preferably) define the following two commands +When you use equation environments containing a \macro{ce} very often, you might want to create your own command. You could---preferably in your preamble---define the following two commands \begin{Verbatim} \newcommand\reaction[1]{\begin{equation}\ce{#1}\end{equation}} @@ -578,7 +568,7 @@ and then use them as follows. £ {\begin{equation*}\ce{#1}\end{equation*}} \reaction{CO2 + C} \reactionnonumber{CO2 + C} -\end{SideBySideExample} +\end{SideBySideExample} \bigskip @@ -607,7 +597,7 @@ and then write \smallskip \noindent -for the same result. +for the same result. \minisec{} @@ -638,7 +628,7 @@ So far, so good. All reactions will be labelled exactly as all the equations. A \noindent With that, all reactions will be labelled independently of the equations. - + \begin{SideBySideExample}[xrightmargin=6.5cm] £\makeatletter £\newcounter{reaction} @@ -668,8 +658,7 @@ With that, all reactions will be labelled independently of the equations. \end{SideBySideExample} - -\section[Equation Environments]{Equation Environments\fromversion{2}} +\subsection{Aligning Equations} When using equation environments, you can use the \macro{cee} command. The advantage is, that \macro{cee} can take the \verb|&| and \verb|\\| macros as input and passes them on to the surrounding environment. @@ -682,9 +671,74 @@ When using equation environments, you can use the \macro{cee} command. The advan \end{SideBySideExample} + +\section[Splitting the \macro{ce} command]{Splitting the \macro{ce} command\fromversion{3.21}} + +\noindent +As mentioned before, you can use \verb|$| to switch to math mode inside \macro{ce}. But maybe, you want to `escape' to outside of \macro{ce}. + + +\subsection{Comma Example} + +\noindent +Assume, you are getting tired of typing + +\medskip +\begin{SideBySideExample}[xrightmargin=4cm] + \ce{N2}, \ce{O2}, \ce{CO2} +\end{SideBySideExample} + +\medskip + +\noindent +Then you could define your own command that splits at commas (plus space). + +\medskip +\begin{SideBySideExample}[xrightmargin=4cm] + \newcommand*\cec[1]{\cesplit{{\,\ }{\0}}{#1}} + \cec{N2, O2, CO2} +\end{SideBySideExample} + +\medskip + +\noindent +\macro{cesplit} takes two parameters. The first one is a list of search-and-replace pairs, the second parameter is the chemistry string as you would put into \macro{ce}. The search-and-replace list uses the syntax of \verb|l3regex|. As a rule of thumb, precede every non-letter with a backslash. You can replace it with some other text, or use \verb|\0| to retain the match. If you want to replace with a macro, write \verb|\c{macroname}|. For furhter details, refer to the \verb|l3regex| manual. + +\medskip + +\noindent +You could even re-define \macro{ce} with \verb|\newcommand*\ce{\cesplit{...}{#1}}|. + + +\subsection{Layer Stacks} + +\noindent +Another example shows how physicists can use mhchem to write layer stacks. + +\medskip +\begin{SideBySideExample}[xrightmargin=4cm] + \newcommand*\stackslash{\text{/}\allowbreak} + \newcommand*\stackdash{\text{-}\allowbreak} + \newcommand\stack[1]{% + \cesplit{% + {\/}{\c{stackslash}}% + {-}{\c{stackdash}}% + }{#1}% + } + \ldots\ structure of + \stack{Co-Fe-B/HfO2/Co-Fe-B} is resp\ldots +\end{SideBySideExample} + +\medskip + +\noindent +By the way, mhchem's \macro{cee} command is similarly defined. + + + \section{Fine Tuning} -In this section, several option switches will be explained. For instance, +In this section, several option switches will be explained. You can use them in the form \begin{Verbatim}[commandchars=+\[\]] \mhchemoptions{+textbf[option=abc]} @@ -721,7 +775,7 @@ in order to get sanf-serif fonts in both, text mode and math mode. There are two \end{Verbatim} \noindent -Only the latter options can be used with the \macro{usepackage} command when loading mhchem (as an optional argument in brackets), because the font commands are not properly defined in the preamble yet. +Only the latter options can be used with the \macro{usepackage} command, because the font commands are not properly defined in the preamble, yet. \medskip @@ -733,14 +787,14 @@ Furthermore, there are two shortcuts: \end{Verbatim} \noindent -sets the two fonts to sans-serif, as mentioned above, +sets the two fonts to sans-serif, as mentioned above, and \begin{Verbatim}[commandchars=+\[\]] \mhchemoptions{+textbf[font=]} \end{Verbatim} \noindent -switches back to the default, which is +switches back to the default, which is equivalent to \begin{Verbatim}[commandchars=+\[\]] \mhchemoptions{+textbf[textfontcommand=, mathfontcommand=\mathrm]} @@ -749,14 +803,14 @@ switches back to the default, which is \subsection{Arrows} -By default, mhchem uses arrows that are composed of different font characters (as does the \verb|amsmath| package. This may lead to undesirable effects when dislayed on a screen. Helmut Hänsel kindly provided a patch that used the pgf graphics package instead. pgf arrows are activated by +By default, mhchem uses arrows that are composed of different font characters, because it uses some features of the \verb|amsmath| package. This may lead to undesirable effects when dislayed on a screen. Helmut Hänsel kindly provided a patch that used the pgf graphics package instead. pgf arrows are activated by \begin{Verbatim}[commandchars=+\[\]] - \mhchemoptions{+textbf[arrows=pgf]} + \usepackage[version=3,+textbf(arrows=pgf)]{mhchem} \end{Verbatim} \noindent -As explained, you can set this option in the \macro{usepackage} as well. If you don't, please do not forget to load the \verb|tikz| package by hand. The \verb|tikz| package is a wrapper for (and included in) the pgf bundle. The default setting is +If you use this switch inside your document with \macro{mhchemoptions}, don't forget to load the \verb|tikz| package manually. (The \verb|tikz| package is a wrapper for---and included in---the pgf bundle. The default setting is \begin{Verbatim}[commandchars=+\[\]] \mhchemoptions{+textbf[arrows=font]} @@ -776,7 +830,7 @@ Here is how it looks: \mhchemoptions{arrows=pgf}% \ce{$A$ <->T[description] $A'$} \end{SideBySideExample} - + \subsubsection{Arrow Tips} @@ -796,6 +850,18 @@ The same considerations as for the \verb|pgf| option apply. \end{SideBySideExample} +\subsection{Stacked Superscripts} + +If you do not like the IUPAC recommendation, you could switch to stacked superscripts + +\medskip +\begin{SideBySideExample}[xrightmargin=5cm] + \ce{CrO4^2-}\\ + \mhchemoptions{superscripts=stacked} \ce{CrO4^2-} +\end{SideBySideExample} + + + \clearpage \section{Major Changes} \label{sec:WhatSNew} @@ -812,6 +878,15 @@ Meaning and usage of \macro{bond} changed. \section{Most Recent Changes}% check +\minisec{2015-03-13 mhchem v3.21} +\begin{compactitem} +\item rewrote further large parts using \LaTeX3 +\item introduced \macro{cesplit} +\item simplified creation two-digit superscripts and subscripts (less braces needed) +\end{compactitem} + +% 3.20 revoked + \minisec{2015-02-09 mhchem v3.19} \begin{compactitem} \item fixed an incompatibility when running without (implicit) pdftexcmds @@ -826,7 +901,7 @@ Meaning and usage of \macro{bond} changed. \minisec{2014-03-27 mhchem v3.17} \begin{compactitem} -\item fix of the 3.16 expansion fix -- sorry, my quality control failed +\item fix of the 3.16 expansion fix -- sorry, my quality control failed \end{compactitem} \minisec{2014-03-20 mhchem v3.16} @@ -837,7 +912,7 @@ Meaning and usage of \macro{bond} changed. \minisec{2014-02-01 mhchem v3.15} \begin{compactitem} -\item follow the IUPAC Red Book more closely (staggered superscripts, \ce{NO3-}) +\item follow the IUPAC Red Book more closely (staggered superscripts, \ce{NO3-}) \item rewrote large parts using \LaTeX3, needs package expl3 \item added: \verb|\bond{1}|, \verb|\bond{2}|, \verb|\bond{3}| (because \verb|#| cannot be used in all contexts) \end{compactitem} @@ -876,9 +951,9 @@ Meaning and usage of \macro{bond} changed. The \textbf{hpstatement} package contains all official hazard statements and precautionary statements (H and P) of the Globally Harmonized System of Classification and Labeling of Chemicals (GHS) -and of the CLP Regulation of the European Union. +and of the CLP Regulation of the European Union. -The statements are available in +The statements are available in English German. If you are a native speaker of either @@ -916,7 +991,7 @@ available in Danish, Englisch, French, German (current spelling), Spanish, and I \bigskip Please be advised that, as stated in the license, the authors provide no warranty of correctness. - + \section{Usage} @@ -1494,7 +1569,7 @@ turn were linked from \rs{R23/24} \rs{R23/25} \rs{R23/24/25} - \rs{R24/25} + \rs{R24/25} \rs{R26/27} \rs{R26/28} \rs{R26/27/28} @@ -1543,7 +1618,7 @@ turn were linked from \rs{R68/21/22} \rs{R68/20/21/22} \rsskip - \rs{S1} + \rs{S1} \rs{S2} \rs{S3} \rs{S4} @@ -1560,7 +1635,7 @@ turn were linked from \rs{S17} \rs{S18} \rs{S20} - \rs{S21} + \rs{S21} \rs{S22} \rs[\ldots]{S23} \rs{S23.0} @@ -1594,14 +1669,14 @@ turn were linked from \rs[\ldots]{S48} \rs{S49} \rs[\ldots]{S50} - \rs{S51} + \rs{S51} \rs{S52} \rs{S53} \rs{S56} \rs{S57} \rs{S59} \rs{S60} - \rs{S61} + \rs{S61} \rs[\ldots]{S62} \rs{S63} \rs{S64} @@ -1639,7 +1714,7 @@ Thanks to the extensive help of Rasmus Villemoes, the Danish phrases could be in \selectlanguage{UKenglish} \subsection{French} -Dominique Richard helped with the French phrases. Many thanks to him! +Dominique Richard helped with the French phrases. Many thanks to him! \selectlanguage{french} \allrsphrases \selectlanguage{UKenglish} diff --git a/Master/texmf-dist/tex/latex/mhchem/mhchem.sty b/Master/texmf-dist/tex/latex/mhchem/mhchem.sty index aba1aec977d..571c78dda85 100644 --- a/Master/texmf-dist/tex/latex/mhchem/mhchem.sty +++ b/Master/texmf-dist/tex/latex/mhchem/mhchem.sty @@ -27,13 +27,14 @@ % This work consists of all files listed in manifest.txt. % % -\ProvidesPackage{mhchem}[2015/02/09 v3.19 for typesetting chemical formulae] -\RequirePackage{ifthen} +\ProvidesPackage{mhchem}[2015/03/13 v3.21 for typesetting chemical formulae] +\RequirePackage{expl3} +\RequirePackage{l3keys2e} +\RequirePackage{l3regex} \RequirePackage{calc}[1998/07/07] \RequirePackage{amsmath} -\RequirePackage{keyval} \RequirePackage{graphics} -\RequirePackage{expl3} +\RequirePackage{ifthen} % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%% misc %%%%%%%%%% @@ -47,50 +48,62 @@ %%%%%%%%%% \cee %%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\newcommand*{\cee}[1]{% - \def\mhchem@ce@out{}% - {\mhchem@cee@i#1\\\mhchem@END\mhchem@ENDEND}% - \ensuremath{% - \mhchem@ce@out% - }% -}% +\ExplSyntaxOn -\def\mhchem@cee@i#1\\#2#3\mhchem@ENDEND{% - \ifx\mhchem@END#2% - \mhchem@cee@ii#1&\mhchem@END\mhchem@ENDEND% - \else% - \mhchem@cee@ii#1&\mhchem@END\mhchem@ENDEND% - \g@addto@macro\mhchem@ce@out{\\}% - \@ifnextchar[% - \mhchem@cee@optArg% - \mhchem@cee@i#2#3\mhchem@ENDEND% - \fi% -} -\def\mhchem@cee@optArg[#1]{% - \g@addto@macro\mhchem@ce@out{[#1]}\mhchem@cee@i% -} +\newcommand*{\cee}[1] + { + \cesplit + { + { \c{\\}(\[.*?\])? } { \0 } + { \& } { \0 } + } + {#1} + } -\long\def\mhchem@cee@ii#1#3\mhchem@ENDEND{% - \ifx\mhchem@END#2% - \g@addto@macro\mhchem@ce@out{\ce{#1}}% - \else% - \g@addto@macro\mhchem@ce@out{\ce{#1}}% - \g@addto@macro\mhchem@ce@out{&}% - \mhchem@cee@ii#2#3\mhchem@ENDEND% - \fi% -} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%% \cesplit %%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\cs_generate_variant:Nn \regex_replace_all:nnN { VnN } +\bool_new:N \__mhchem_cesplit_odd_bool + +\newcommand\cesplit[2] + { + \bool_set_true:N \__mhchem_cesplit_odd_bool + + \tl_set:Nn \l_tmpa_tl { \__mhchem_ce:n {#2} } + + \tl_map_inline:nn {#1} + { + \bool_if:NTF \__mhchem_cesplit_odd_bool + { + \tl_set:Nn \__mhchem_cesplit_key_tl {##1} + \bool_set_false:N \__mhchem_cesplit_odd_bool + } + % else + { + \regex_replace_all:VnN + \__mhchem_cesplit_key_tl + { \cE] ##1 \c{__mhchem_ce:n}\cB[ } + \l_tmpa_tl + \bool_set_true:N \__mhchem_cesplit_odd_bool + } + } + \tl_use:N \l_tmpa_tl + } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%% global helpers %%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\ExplSyntaxOff + \def\mhchem@appendToks#1#2{% #1=\expandafter{\the#1#2}% } \ExplSyntaxOn -\int_new:N \__mhchem_option_version_int \cs_generate_variant:Nn \str_if_eq:nnTF { Vn } \cs_generate_variant:Nn \peek_catcode_remove:NTF { oTF } \cs_generate_variant:Nn \peek_catcode:NTF { oTF } @@ -191,6 +204,8 @@ Assertion~failed:~Unexpected~internal~state~'#1' (ce).~You~found~a~bug.~ Please~contact~the~package~author. } +\bool_new:N \__mhchem_ce_ceActive_bool +\bool_set_false:N \__mhchem_ce_ceActive_bool \tl_new:N \__mhchem_ce_state_tl \tl_new:N \__mhchem_ce_arrowName_tl @@ -198,6 +213,8 @@ \tl_new:N \__mhchem_ce_arrowTextOne_tl \tl_new:N \__mhchem_ce_arrowTypeTwo_tl \tl_new:N \__mhchem_ce_arrowTextTwo_tl +\bool_new:N \__mhchem_ce_potentialSpacing_bool +\bool_new:N \__mhchem_ce_potentialSpacing_future_bool \newcommand*\mhchem@ce[1]{ \__mhchem_ce:n {#1} @@ -205,13 +222,18 @@ \cs_new_protected:Npn \__mhchem_ce:n #1 { \group_begin: + \bool_if:NF \__mhchem_cf_cfActive_bool + { + \bool_set_true:N \__mhchem_cf_cfActive_bool + \__mhchem_defMathOrText: + } \def\hyphen{\mhchem@hyphen}% \tl_clear_new:N \__mhchem_ce_result_tl \tl_clear_new:N \__mhchem_ce_part_tl + \bool_set_false:N \__mhchem_ce_potentialSpacing_bool \tl_set:Nn \__mhchem_ce_state_tl { c } \__mhchem_ce_loop: #1 \q_recursion_stop - \int_set:Nn \__mhchem_option_version_int { \mhchem@option@version } - \int_compare:nTF { 1 < \__mhchem_option_version_int } + \int_compare:nTF { \__mhchem_option_version_int > 1 } { \tl_use:N \__mhchem_ce_result_tl } { \ensuremath{\tl_use:N \__mhchem_ce_result_tl} } \group_end: @@ -228,6 +250,7 @@ { \tl_put_right:Nn \__mhchem_ce_result_tl { \ensuremath{{}+{}} } \tl_clear:N \__mhchem_ce_part_tl + \tl_set:Nn \__mhchem_ce_state_tl { a-end } } { -> } { @@ -280,6 +303,9 @@ \peek_charcode_remove:NTF \c_space_token { \__mhchem_ce_output: + \bool_if:NTF \__mhchem_ce_potentialSpacingAllowed_bool + { \bool_set_true:N \__mhchem_ce_potentialSpacing_bool } + { \bool_set_false:N \__mhchem_ce_potentialSpacing_bool } \__mhchem_ce_loop: }{ \peek_catcode_remove:NTF \c_math_toggle_token @@ -360,6 +386,7 @@ % else { \__mhchem_ce_output: + \tl_set:Nn \__mhchem_ce_state_tl { a-end } \__mhchem_ce_loop: } } @@ -377,6 +404,7 @@ % else { \__mhchem_ce_output: + \tl_set:Nn \__mhchem_ce_state_tl { a-end } \__mhchem_ce_loop: } } @@ -384,6 +412,7 @@ % else { \__mhchem_ce_output: + \tl_set:Nn \__mhchem_ce_state_tl { a-end } \__mhchem_ce_loop: } } @@ -399,6 +428,7 @@ % else { \__mhchem_ce_output: + \tl_set:Nn \__mhchem_ce_state_tl { a-end } \__mhchem_ce_loop: } } @@ -470,6 +500,7 @@ % else { \__mhchem_ce_output: + \tl_set:Nn \__mhchem_ce_state_tl { a-end } \__mhchem_ce_loop: } }}}} @@ -484,6 +515,7 @@ % else { \__mhchem_ce_output: + \tl_set:Nn \__mhchem_ce_state_tl { a-end } \__mhchem_ce_loop: } } @@ -497,6 +529,7 @@ \peek_charcode:NTF ] { \__mhchem_ce_output: + \tl_set:Nn \__mhchem_ce_state_tl { a-end } \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_ce_loop: }{ \peek_catcode:NTF \c_group_begin_token @@ -519,6 +552,19 @@ } }}} } + { a-end } + { + \bool_set_false:N \__mhchem_ce_potentialSpacing_bool + \tl_set:Nn \__mhchem_ce_state_tl { c } + \peek_charcode_remove:NTF \c_space_token + { + \__mhchem_ce_loop: + } + % else + { + \__mhchem_ce_loop: + } + } } { \msg_error:nnx { mhchem } { ce/unexpected-state } @@ -531,6 +577,7 @@ } \cs_new_protected:Npn \__mhchem_ce_output: { + \bool_set_true:N \__mhchem_ce_potentialSpacingAllowed_bool \str_case:Vnn \__mhchem_ce_state_tl { { c } @@ -538,32 +585,42 @@ \str_if_eq:VnTF \__mhchem_ce_part_tl { - } { \tl_put_right:Nn \__mhchem_ce_result_tl { \ensuremath{{}-{}} } + \bool_set_false:N \__mhchem_ce_potentialSpacingAllowed_bool }{ \str_if_eq:VnTF \__mhchem_ce_part_tl { (v) } { \tl_put_right:Nn \__mhchem_ce_result_tl { \ensuremath{{}\mathop{\downarrow}{}} } + \bool_set_false:N \__mhchem_ce_potentialSpacingAllowed_bool }{ \str_if_eq:VnTF \__mhchem_ce_part_tl { v } { \tl_put_right:Nn \__mhchem_ce_result_tl { \ensuremath{{}\mathop{\downarrow}{}} } + \bool_set_false:N \__mhchem_ce_potentialSpacingAllowed_bool }{ \str_if_eq:VnTF \__mhchem_ce_part_tl { (^) } { \tl_put_right:Nn \__mhchem_ce_result_tl { \ensuremath{{}\mathop{\uparrow}{}} } + \bool_set_false:N \__mhchem_ce_potentialSpacingAllowed_bool }{ \str_if_eq:VnTF \__mhchem_ce_part_tl { ^ } { \tl_put_right:Nn \__mhchem_ce_result_tl { \ensuremath{{}\mathop{\uparrow}{}} } + \bool_set_false:N \__mhchem_ce_potentialSpacingAllowed_bool } % else { \tl_if_empty:NTF \__mhchem_ce_part_tl {} { + \bool_if:NT \__mhchem_ce_potentialSpacing_bool + { + \int_compare:nT { \__mhchem_option_version_int > 3 } + { \tl_put_right:Nn \__mhchem_ce_result_tl { \mhchem@option@skipAfterAmount } } + } \tl_put_right:Nx \__mhchem_ce_result_tl { \exp_not:N \__mhchem_cf:nn @@ -593,6 +650,7 @@ {} \tl_set:NV \__mhchem_ce_part_tl \__mhchem_ce_arrowTypeOne_tl \tl_set:Nn \__mhchem_ce_state_tl { c } + \bool_set_false:N \__mhchem_ce_potentialSpacing_bool \__mhchem_ce_output: } { a-]1 } @@ -623,6 +681,7 @@ {} \tl_set:NV \__mhchem_ce_part_tl \__mhchem_ce_arrowTypeTwo_tl \tl_set:Nn \__mhchem_ce_state_tl { c } + \bool_set_false:N \__mhchem_ce_potentialSpacing_bool \__mhchem_ce_output: } { a-]2 } @@ -638,6 +697,7 @@ {} \tl_clear:N \__mhchem_ce_part_tl \tl_set:Nn \__mhchem_ce_state_tl { c } + \bool_set_false:N \__mhchem_ce_potentialSpacing_bool } \cs_new_protected:Npn \__mhchem_ce_outputArrow:nnnnn #1#2#3#4#5 { @@ -691,7 +751,7 @@ { { } { - \int_compare:nTF { 3 < \__mhchem_option_version_int } + \int_compare:nTF { \__mhchem_option_version_int > 3 } { \cs:w mhchem@arrow@#1T \cs_end: {#3}{#5} } { \cs:w mhchem@arrow@#1M \cs_end: {#3}{#5} } } @@ -910,7 +970,10 @@ \mathop{\makebox[#7]{#8\displaystyle}}% \limits% \@ifnotempty{#3}{^{\mkern#1mu#3\mkern#2mu}}% - \@ifnotempty{#6}{_{\mkern#4mu#6\mkern#5mu}}% + \@ifnotempty{#6}{_{% + \makebox{\raisebox{1.25ex-\heightof{$\scriptstyle\mkern#4mu#6\mkern#5mu$}}[0pt]% + {$\scriptstyle\mkern#4mu#6\mkern#5mu$}} + }}% }% } \def\mhchem@rightharpoonupfill@{\arrowfill@\relbar\relbar\rightharpoonup} @@ -1126,17 +1189,17 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \ExplSyntaxOn -\msg_new:nnn { mhchem } { cf/unexpected-input } +\msg_new:nnn { mhchem } { cf / unexpected-input } { Assertion~failed:~Unexpected~input~character.~You~found~a~bug.~ Please~contact~the~package~author. } -\msg_new:nnn { mhchem } { cf/unexpected-state } +\msg_new:nnn { mhchem } { cf / unexpected-state } { Assertion~failed:~Unexpected~internal~state~'#1' (cf).~You~found~a~bug.~ Please~contact~the~package~author. } -\msg_new:nnn { mhchem } { cf/unexpected-two-superscripts } +\msg_new:nnn { mhchem } { cf / unexpected-two-superscripts } { Assertion~failed:~Two~superscripts.~You~entered~an~invalid~formula.~ Or~you~found~a~bug,~in~which~case~you~should~contact~the~package~author. @@ -1166,64 +1229,61 @@ \newcommand*\mhchem@cf[2][]{ \__mhchem_cf:nn {#1} {#2} } -\tl_new:N \__mhchem_cf_state_tl + \bool_new:N \__mhchem_cf_startedWithBond_bool + +\tl_new:N \__mhchem_cf_state_tl +\tl_new:N \__mhchem_cf_presup_tl +\tl_new:N \__mhchem_cf_presub_tl +\tl_new:N \__mhchem_cf_presupState_tl +\tl_new:N \__mhchem_cf_presubState_tl +\tl_new:N \__mhchem_cf_element_tl +\tl_new:N \__mhchem_cf_supA_tl +\tl_new:N \__mhchem_cf_sub_tl +\tl_new:N \__mhchem_cf_sup_tl +\tl_new:N \__mhchem_cf_supState_tl +\tl_new:N \__mhchem_cf_subState_tl +\cs_new_protected:Npn \__mhchem_cf_resetOutput: + { + \tl_clear:N \__mhchem_cf_presup_tl + \tl_clear:N \__mhchem_cf_presub_tl + \tl_set:Nn \__mhchem_cf_presupState_tl { - } + \tl_set:Nn \__mhchem_cf_presubState_tl { - } + \tl_clear:N \__mhchem_cf_element_tl + \tl_clear:N \__mhchem_cf_supA_tl + \tl_clear:N \__mhchem_cf_sub_tl + \tl_clear:N \__mhchem_cf_sup_tl + \tl_set:Nn \__mhchem_cf_supState_tl { - } + \tl_set:Nn \__mhchem_cf_subState_tl { - } + } + \bool_new:N \__mhchem_cf_cfActive_bool \bool_set_false:N \__mhchem_cf_cfActive_bool \cs_new_protected:Npn \__mhchem_cf:nn #1#2 { \group_begin: - \int_set:Nn \__mhchem_option_version_int { \mhchem@option@version } \def\sbond{{\ensuremath{-}}} - \ifnum 2=\mhchem@option@version - \let\bond\sbond - \else\ifnum 2<\mhchem@option@version - \def\bond{\mhchem@bond} - \fi\fi + \int_compare:nTF { 2 = \__mhchem_option_version_int } + { + \let\bond\sbond + } + % else + { + \int_compare:nT { \__mhchem_option_version_int > 2 } + { + \def\bond{\mhchem@bond} + } + } \def\dbond{\rlap{\protect\raisebox{.2ex}{\sbond}}\protect\raisebox{-.2ex}{\sbond}} \def\tbond{\rlap{\protect\raisebox{.4ex}{\sbond}} \rlap{\sbond}\protect\raisebox{-.4ex}{\sbond}} \def\hyphen{\mhchem@hyphen} - \bool_if:NF \__mhchem_cf_cfActive_bool - { - \bool_set_true:N \__mhchem_cf_cfActive_bool - \mode_if_math:F - { - \def\mhchem@option@alwaystextmode{1} - \mhchem@option@textFont - } - \str_if_eq:nnTF { 1 } { \mhchem@option@alwaystextmode } - { - \cs_set:Npx \mhchem@mathOrText ##1 { \exp_not:N \text{##1} } - \cs_set:Npx \mhchem@mathOrText@ii ##1##2 { ##2 } - } - { - \int_compare:nTF { 1 < \__mhchem_option_version_int } - { - \cs_set:Npx \mhchem@mathOrText ##1 - { - \mode_if_math:TF - { \exp_not:N \mhchem@option@mathFont{##1} } - { \exp_not:N \text{##1} } - } - \cs_set:Npx \mhchem@mathOrText@ii ##1##2 - { - \mode_if_math:TF - { \exp_not:N \mhchem@option@mathFont{##1} } - { ##2 } - } - } - { - \cs_set:Npx \mhchem@mathOrText ##1 - { - \mode_if_math:TF { ##1 } { \exp_not:N \text{##1} } - } - \cs_set:Npx \mhchem@mathOrText@ii ##1##2 - { - \mode_if_math:TF { ##1 } { ##2 } - } - } - } + \bool_if:NF \__mhchem_ce_ceActive_bool { + \bool_if:NF \__mhchem_cf_cfActive_bool + { + \bool_set_true:N \__mhchem_cf_cfActive_bool + \__mhchem_defMathOrText: + } } \tl_set:Nn \__mhchem_cf_state_tl { s } \bool_set_false:N \__mhchem_cf_startedWithBond_bool @@ -1233,7 +1293,6 @@ \str_if_eq:nnTF {#1} {} { \ensuremath{\tl_use:N \__mhchem_cf_result_tl} } { \ensuremath{\overset{#1}{\tl_use:N \__mhchem_cf_result_tl}} } - \bool_set_false:N \__mhchem_cf_cfActive_bool \group_end: } \cs_new_protected:Npn \__mhchem_cf_loop: @@ -1247,9 +1306,9 @@ \bool_if:NTF \__mhchem_cf_startedWithBond_bool { \__mhchem_cf_outputAndReset: - \tl_put_right:Nn \__mhchem_cf_result_tl {\sbond} + \tl_put_right:Nn \__mhchem_cf_result_tl { \sbond } } - { \tl_put_right:Nn \__mhchem_cf_sup_tl {-} } + { \tl_put_right:Nn \__mhchem_cf_sup_tl { - } } } { 1 } { \tl_set:Nn \__mhchem_cf_state_tl {9} } @@ -1267,27 +1326,30 @@ { \__mhchem_cf_outputAndReset: \tl_put_right:Nn \__mhchem_cf_result_tl {\sbond} - \tl_set:Nn \__mhchem_cf_state_tl { + } + \tl_set:Nn \__mhchem_cf_state_tl { a } \__mhchem_cf_loop: } { s } { \peek_charcode:NTF - { - \int_compare:nTF { 1 < \__mhchem_option_version_int } + \__mhchem_cf_outputAndReset: + \int_compare:nTF { \__mhchem_option_version_int > 1 } { \tl_set:Nn \__mhchem_cf_state_tl { - } \bool_set_true:N \__mhchem_cf_startedWithBond_bool \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: } + % else { - \tl_set:Nn \__mhchem_cf_state_tl { + } - \tl_put_right:Nn \__mhchem_cf_sup_tl { - } + \tl_set:Nn \__mhchem_cf_state_tl { a } + \tl_put_right:Nn \__mhchem_cf_sup_tl { - } % z. B. \cmath{mu}-Cl \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: } }{ \peek_charcode:NTF = { + \__mhchem_cf_outputAndReset: \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn { \dbond } { s } @@ -1295,6 +1357,7 @@ }{ \peek_charcode:NTF ## { + \__mhchem_cf_outputAndReset: \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn { \tbond } { s } @@ -1302,21 +1365,31 @@ }{ \peek_charcode:NTF ^ { + \str_if_eq:VnF \__mhchem_cf_presupState_tl { - } + { \__mhchem_cf_outputAndReset: } + \tl_set:Nn \__mhchem_cf_presupState_tl { d } \tl_set:Nn \__mhchem_cf_state_tl { p } \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: }{ \peek_charcode:NTF _ { + \str_if_eq:VnF \__mhchem_cf_presubState_tl { - } + { \__mhchem_cf_outputAndReset: } + \tl_set:Nn \__mhchem_cf_presubState_tl { d } \tl_set:Nn \__mhchem_cf_state_tl { q } \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: }{ \peek_charcode:NTF ` { - \int_compare:nTF { 4 > \__mhchem_option_version_int } + \int_compare:nTF { \__mhchem_option_version_int < 4 } { - \tl_set:Nn \__mhchem_cf_state_tl { P } + \str_if_eq:VnF \__mhchem_cf_presupState_tl { - } + { \__mhchem_cf_outputAndReset: } + \tl_set:Nn \__mhchem_cf_presupState_tl { rm } + \tl_set:Nn \__mhchem_cf_state_tl { p } \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: } + % else { \tl_set:Nn \__mhchem_cf_state_tl { a } \__mhchem_loopHelper_appendNextToken:NNn @@ -1326,23 +1399,27 @@ }{ \peek_charcode:NTF , { - \int_compare:nTF { 4 > \__mhchem_option_version_int } + \int_compare:nTF { \__mhchem_option_version_int < 4 } { - \tl_set:Nn \__mhchem_cf_state_tl { Q } + \str_if_eq:VnF \__mhchem_cf_presubState_tl { - } + { \__mhchem_cf_outputAndReset: } + \tl_set:Nn \__mhchem_cf_presubState_tl { rm } + \tl_set:Nn \__mhchem_cf_state_tl { q } \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: } + % else { + \__mhchem_cf_outputAndReset: \tl_set:Nn \__mhchem_cf_state_tl { 1 } - \tl_put_right:Nn \__mhchem_cf_sub_tl { {,} } - \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: + \__mhchem_cf_loop: } }{ \peek_charcode:NTF . { - \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn - { \mhchem@mathOrText@ii{{}\cdot{}}{\mhchem@option@textcdot} } - { s } - \__mhchem_cf_loop: + + \__mhchem_cf_outputAndReset: + \tl_set:Nn \__mhchem_cf_state_tl { 1 } + \__mhchem_cf_loop: }{ \peek_charcode:NTF * { @@ -1353,10 +1430,11 @@ }{ \peek_charcode:NTF + { - \tl_set:Nn \__mhchem_cf_state_tl { + } - \__mhchem_loopHelper_appendNextToken:NNn - \__mhchem_cf_sup_tl - \__mhchem_cf_loop: + \str_if_eq:VnF \__mhchem_cf_presupState_tl { - } + { \__mhchem_cf_outputAndReset: } + \tl_set:Nn \__mhchem_cf_presupState_tl { d } + \tl_set:Nn \__mhchem_cf_state_tl { p } + \__mhchem_cf_loop: }{ \peek_charcode:NTF | { @@ -1388,6 +1466,7 @@ }{ \peek_catcode:NTF \mhchem@macro { + \__mhchem_cf_outputAndReset: \tl_set:Nn \__mhchem_cf_state_tl { c } \__mhchem_loopHelper_appendNextToken:NNn \__mhchem_cf_result_tl @@ -1402,6 +1481,7 @@ }{ \peek_catcode:NTF 1 { + \__mhchem_cf_outputAndReset: \tl_set:Nn \__mhchem_cf_state_tl { 1 } \__mhchem_loopHelper_appendNextToken:NNn \__mhchem_cf_element_tl @@ -1409,37 +1489,20 @@ }{ \peek_catcode:NTF \c_group_begin_token { - \int_compare:nTF { 4 > \__mhchem_option_version_int } - { - \__mhchem_loopHelper_appendNextGroup:NNn - \__mhchem_cf_result_tl - \__mhchem_cf_loop: - } - { - \tl_set:Nn \__mhchem_cf_state_tl { 1 } - \__mhchem_loopHelper_appendNextGroup:NNn - \__mhchem_cf_sub_tl - \__mhchem_cf_loop: - } + \__mhchem_cf_outputAndReset: + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_result_tl + \__mhchem_cf_loop: }{ \peek_catcode_remove:NTF \c_math_toggle_token { - \int_compare:nTF { 4 > \__mhchem_option_version_int } - { - \tl_set:Nn \__mhchem_cf_state_tl { a } - \__mhchem_loopHelper_appendMathB:NNw - \__mhchem_cf_element_tl - \__mhchem_cf_loop: - } - { - \tl_set:Nn \__mhchem_cf_state_tl { 1 } - \__mhchem_loopHelper_appendMathB:NNw - \__mhchem_cf_element_tl - \__mhchem_cf_loop: - } + \tl_set:Nn \__mhchem_cf_state_tl { a } + \__mhchem_loopHelper_appendMathB:NNw + \__mhchem_cf_element_tl + \__mhchem_cf_loop: } % else - { \msg_error:nnn { mhchem } { cf/unexpected-input } } + { \msg_error:nnn { mhchem } { cf / unexpected-input } } }}}}}}}}}}}}}}}}}}} } { c } @@ -1450,6 +1513,7 @@ \__mhchem_cf_result_tl \__mhchem_cf_loop: } + % else { \tl_set:Nn \__mhchem_cf_state_tl { a } \__mhchem_cf_loop: @@ -1577,22 +1641,38 @@ }{ \peek_charcode:NTF ^ { - \tl_set:Nn \__mhchem_cf_state_tl { k } + \str_if_eq:VnF \__mhchem_cf_supState_tl { - } + { \__mhchem_cf_outputAndReset: } + \str_if_eq:VnTF \__mhchem_cf_subState_tl { - } + { \tl_set:Nn \__mhchem_cf_supState_tl { kv } } + { \tl_set:Nn \__mhchem_cf_supState_tl { d } } + \tl_set:Nn \__mhchem_cf_state_tl { e } \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: }{ \peek_charcode:NTF _ { + \str_if_eq:VnF \__mhchem_cf_subState_tl { - } + { \__mhchem_cf_outputAndReset: } + \tl_set:Nn \__mhchem_cf_subState_tl { d } \tl_set:Nn \__mhchem_cf_state_tl { f } \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: }{ \peek_charcode:NTF ` { - \int_compare:nTF { 4 > \__mhchem_option_version_int } + \int_compare:nTF { \__mhchem_option_version_int < 4 } { - \tl_set:Nn \__mhchem_cf_state_tl { E } + \str_if_eq:VnF \__mhchem_cf_supState_tl { - } + { \__mhchem_cf_outputAndReset: } + \tl_set:Nn \__mhchem_cf_supState_tl { rm } + \tl_set:Nn \__mhchem_cf_state_tl { e } \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: } + % else { + \str_if_eq:VnF \__mhchem_cf_supState_tl { - } + { \__mhchem_cf_outputAndReset: } + \str_if_eq:VnF \__mhchem_cf_subState_tl { - } + { \__mhchem_cf_outputAndReset: } \__mhchem_loopHelper_appendNextToken:NNn \__mhchem_cf_element_tl \__mhchem_cf_loop: @@ -1600,15 +1680,20 @@ }{ \peek_charcode:NTF , { - \int_compare:nTF { 4 > \__mhchem_option_version_int } + \int_compare:nTF { \__mhchem_option_version_int < 4 } { - \tl_set:Nn \__mhchem_cf_state_tl { F } + \str_if_eq:VnF \__mhchem_cf_subState_tl { - } + { \__mhchem_cf_outputAndReset: } + \tl_set:Nn \__mhchem_cf_subState_tl { rm } + \tl_set:Nn \__mhchem_cf_state_tl { f } \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: } + % else { - \tl_set:Nn \__mhchem_cf_state_tl { 1 } - \tl_put_right:Nn \__mhchem_cf_sub_tl { , } - \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: + \__mhchem_cf_outputAndReset: + \tl_put_right:Nn \__mhchem_cf_result_tl { {,} } + \__mhchem_loopHelper_ignoreNextToken:Nn + \__mhchem_cf_loop: } }{ \peek_charcode:NTF . @@ -1627,10 +1712,11 @@ }{ \peek_charcode:NTF + { - \tl_set:Nn \__mhchem_cf_state_tl { + } - \__mhchem_loopHelper_appendNextToken:NNn - \__mhchem_cf_sup_tl - \__mhchem_cf_loop: + \str_if_eq:VnF \__mhchem_cf_supState_tl { - } + { \__mhchem_cf_outputAndReset: } + \tl_set:Nn \__mhchem_cf_supState_tl { d } + \tl_set:Nn \__mhchem_cf_state_tl { e } + \__mhchem_cf_loop: }{ \peek_charcode:NTF | { @@ -1669,18 +1755,23 @@ \__mhchem_cf_result_tl \__mhchem_cf_loop: }{ - \peek_catcode:NTF a + \peek_catcode:NTF a % letter { + \str_if_eq:VnF \__mhchem_cf_supState_tl { - } + { \__mhchem_cf_outputAndReset: } + \str_if_eq:VnF \__mhchem_cf_subState_tl { - } + { \__mhchem_cf_outputAndReset: } \__mhchem_loopHelper_appendNextToken:NNn \__mhchem_cf_element_tl \__mhchem_cf_loop: }{ - \peek_catcode:NTF 1 + \peek_catcode:NTF 1 % number { - \tl_set:Nn \__mhchem_cf_state_tl { 2 } - \__mhchem_loopHelper_appendNextToken:NNn - \__mhchem_cf_sub_tl - \__mhchem_cf_loop: + \str_if_eq:VnF \__mhchem_cf_subState_tl { - } + { \__mhchem_cf_outputAndReset: } + \tl_set:Nn \__mhchem_cf_subState_tl { d } + \tl_set:Nn \__mhchem_cf_state_tl { f } + \__mhchem_cf_loop: }{ \peek_catcode:NTF \c_group_begin_token { @@ -1691,519 +1782,663 @@ }{ \peek_catcode_remove:NTF \c_math_toggle_token { + \str_if_eq:VnF \__mhchem_cf_supState_tl { - } + { \__mhchem_cf_outputAndReset: } + \str_if_eq:VnF \__mhchem_cf_subState_tl { - } + { \__mhchem_cf_outputAndReset: } \__mhchem_loopHelper_appendMathB:NNw \__mhchem_cf_element_tl \__mhchem_cf_loop: } % else - { \msg_error:nnn { mhchem } { cf/unexpected-input } } + { + \__mhchem_cf_outputAndReset: + \tl_set:Nn \__mhchem_cf_state_tl { s } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_result_tl + \__mhchem_cf_loop: + } }}}}}}}}}}}}}}}}}}} } - { 2 } + { e } { - \peek_charcode:NTF - + \peek_charcode:NTF 1 { - \tl_set:Nn \__mhchem_cf_state_tl { - } - \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: + \tl_set:Nn \__mhchem_cf_state_tl { e+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sup_tl + \__mhchem_cf_loop: }{ - \peek_charcode:NTF = + \peek_charcode:NTF 2 { - \__mhchem_cf_outputAndReset: - \tl_put_right:Nn \__mhchem_cf_result_tl {\dbond} - \tl_set:Nn \__mhchem_cf_state_tl { s } - \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: + \tl_set:Nn \__mhchem_cf_state_tl { e+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sup_tl + \__mhchem_cf_loop: }{ - \peek_charcode:NTF ## + \peek_charcode:NTF 3 { - \__mhchem_cf_outputAndReset: - \tl_put_right:Nn \__mhchem_cf_result_tl {\tbond} - \tl_set:Nn \__mhchem_cf_state_tl { s } - \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: + \tl_set:Nn \__mhchem_cf_state_tl { e+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sup_tl + \__mhchem_cf_loop: }{ - \peek_charcode:NTF ^ + \peek_charcode:NTF 4 { - \tl_set:Nn \__mhchem_cf_state_tl { e } - \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: + \tl_set:Nn \__mhchem_cf_state_tl { e+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sup_tl + \__mhchem_cf_loop: }{ - \peek_charcode:NTF _ + \peek_charcode:NTF 5 { - \tl_set:Nn \__mhchem_cf_state_tl { f } - \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: + \tl_set:Nn \__mhchem_cf_state_tl { e+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sup_tl + \__mhchem_cf_loop: }{ - \peek_charcode:NTF ` + \peek_charcode:NTF 6 { - \int_compare:nTF { 4 > \__mhchem_option_version_int } - { - \tl_set:Nn \__mhchem_cf_state_tl { E } - \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: - } - { - \__mhchem_loopHelper_appendNextToken:NNn - \__mhchem_cf_sub_tl - \__mhchem_cf_loop: - } + \tl_set:Nn \__mhchem_cf_state_tl { e+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sup_tl + \__mhchem_cf_loop: }{ - \peek_charcode:NTF , + \peek_charcode:NTF 7 { - \int_compare:nTF { 4 > \__mhchem_option_version_int } - { - \tl_set:Nn \__mhchem_cf_state_tl { F } - \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: - } - { - \tl_put_right:Nn \__mhchem_cf_sub_tl { , } - \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: - } + \tl_set:Nn \__mhchem_cf_state_tl { e+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sup_tl + \__mhchem_cf_loop: }{ - \peek_charcode:NTF . + \peek_charcode:NTF 8 { - \int_compare:nTF { 4 > \__mhchem_option_version_int } - { - \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn - { \mhchem@mathOrText@ii{{}\cdot{}}{\mhchem@option@textcdot} } - { s } - \__mhchem_cf_loop: - } - { - \__mhchem_loopHelper_appendNextToken:NNn - \__mhchem_cf_sub_tl - \__mhchem_cf_loop: - } + \tl_set:Nn \__mhchem_cf_state_tl { e+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sup_tl + \__mhchem_cf_loop: }{ - \peek_charcode:NTF * + \peek_charcode:NTF 9 { - \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn - { \mhchem@mathOrText@ii{{}\cdot{}}{\mhchem@option@textcdot} } - { s } + \tl_set:Nn \__mhchem_cf_state_tl { e+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sup_tl \__mhchem_cf_loop: }{ - \peek_charcode:NTF + + \peek_charcode:NTF 0 { - \tl_set:Nn \__mhchem_cf_state_tl { + } + \tl_set:Nn \__mhchem_cf_state_tl { e+ } \__mhchem_loopHelper_appendNextToken:NNn \__mhchem_cf_sup_tl \__mhchem_cf_loop: }{ - \peek_charcode:NTF | + \peek_catcode_remove:NTF \c_math_toggle_token { - \PackageWarning{mhchem}{The symbol | is not allowed here} - \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: - }{ - \peek_charcode:NTF ( + \tl_set:Nn \__mhchem_cf_state_tl { a } + \__mhchem_loopHelper_appendMathAsGroup:NNw + \__mhchem_cf_sup_tl + \__mhchem_cf_loop: + } + % else { - \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn - { s } + \tl_set:Nn \__mhchem_cf_state_tl { a } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sup_tl + \__mhchem_cf_loop: + } + }}}}}}}}}} + } + { e+ } + { + \peek_charcode:NTF 1 + { + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sup_tl \__mhchem_cf_loop: }{ - \peek_charcode:NTF ) + \peek_charcode:NTF 2 { - \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn - { a } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sup_tl \__mhchem_cf_loop: }{ - \peek_charcode:NTF [ + \peek_charcode:NTF 3 { - \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn - { s } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sup_tl \__mhchem_cf_loop: }{ - \peek_charcode:NTF ] + \peek_charcode:NTF 4 { - \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn - { a } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sup_tl \__mhchem_cf_loop: }{ - \peek_catcode:NTF \mhchem@macro + \peek_charcode:NTF 5 { - \__mhchem_cf_outputAndReset: - \tl_set:Nn \__mhchem_cf_state_tl { c } \__mhchem_loopHelper_appendNextToken:NNn - \__mhchem_cf_result_tl + \__mhchem_cf_sup_tl \__mhchem_cf_loop: }{ - \peek_catcode:NTF a + \peek_charcode:NTF 6 { - \__mhchem_cf_outputAndReset: - \tl_set:Nn \__mhchem_cf_state_tl { a } \__mhchem_loopHelper_appendNextToken:NNn - \__mhchem_cf_element_tl + \__mhchem_cf_sup_tl \__mhchem_cf_loop: }{ - \peek_catcode:NTF 1 + \peek_charcode:NTF 7 { \__mhchem_loopHelper_appendNextToken:NNn - \__mhchem_cf_sub_tl + \__mhchem_cf_sup_tl \__mhchem_cf_loop: }{ - \peek_catcode:NTF \c_group_begin_token + \peek_charcode:NTF 8 { - \int_compare:nTF { 4 > \__mhchem_option_version_int } - { - \__mhchem_cf_outputAndReset: - \tl_set:Nn \__mhchem_cf_state_tl { s } - \__mhchem_loopHelper_appendNextGroup:NNn - \__mhchem_cf_result_tl - \__mhchem_cf_loop: - } - { - \__mhchem_cf_outputAndReset: - \tl_set:Nn \__mhchem_cf_state_tl { a } - \__mhchem_loopHelper_appendNextGroup:NNn - \__mhchem_cf_element_tl - \__mhchem_cf_loop: - } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sup_tl + \__mhchem_cf_loop: }{ - \peek_catcode_remove:NTF \c_math_toggle_token + \peek_charcode:NTF 9 { - \__mhchem_cf_outputAndReset: - \tl_set:Nn \__mhchem_cf_state_tl { a } - \__mhchem_loopHelper_appendMathB:NNw - \__mhchem_cf_element_tl + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sup_tl \__mhchem_cf_loop: - } - % else + }{ + \peek_charcode:NTF 0 { - \__mhchem_cf_outputAndReset: - \tl_set:Nn \__mhchem_cf_state_tl { s } \__mhchem_loopHelper_appendNextToken:NNn - \__mhchem_cf_result_tl + \__mhchem_cf_sup_tl \__mhchem_cf_loop: - } - }}}}}}}}}}}}}}}}}}} - } - { e } - { - \tl_set:Nn \__mhchem_cf_state_tl { + } - \peek_catcode_remove:NTF \c_math_toggle_token + }{ + \peek_charcode:NTF + { - \__mhchem_loopHelper_appendMathAsGroup:NNw + \__mhchem_loopHelper_appendNextToken:NNn \__mhchem_cf_sup_tl \__mhchem_cf_loop: - } + }{ + \peek_charcode:NTF - { \__mhchem_loopHelper_appendNextToken:NNn \__mhchem_cf_sup_tl \__mhchem_cf_loop: } + % else + { + \tl_set:Nn \__mhchem_cf_state_tl { a } + \__mhchem_cf_loop: + } + }}}}}}}}}}} } - { k } + { f } { - \tl_set:Nn \__mhchem_cf_state_tl { + } + \peek_charcode:NTF 1 + { + \tl_set:Nn \__mhchem_cf_state_tl { f+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sub_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 2 + { + \tl_set:Nn \__mhchem_cf_state_tl { f+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sub_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 3 + { + \tl_set:Nn \__mhchem_cf_state_tl { f+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sub_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 4 + { + \tl_set:Nn \__mhchem_cf_state_tl { f+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sub_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 5 + { + \tl_set:Nn \__mhchem_cf_state_tl { f+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sub_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 6 + { + \tl_set:Nn \__mhchem_cf_state_tl { f+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sub_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 7 + { + \tl_set:Nn \__mhchem_cf_state_tl { f+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sub_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 8 + { + \tl_set:Nn \__mhchem_cf_state_tl { f+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sub_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 9 + { + \tl_set:Nn \__mhchem_cf_state_tl { f+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sub_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 0 + { + \tl_set:Nn \__mhchem_cf_state_tl { f+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sub_tl + \__mhchem_cf_loop: + }{ \peek_catcode_remove:NTF \c_math_toggle_token { + \tl_set:Nn \__mhchem_cf_state_tl { a } \__mhchem_loopHelper_appendMathAsGroup:NNw - \__mhchem_cf_supA_tl + \__mhchem_cf_sub_tl \__mhchem_cf_loop: } + % else { + \tl_set:Nn \__mhchem_cf_state_tl { a } \__mhchem_loopHelper_appendNextToken:NNn - \__mhchem_cf_supA_tl + \__mhchem_cf_sub_tl \__mhchem_cf_loop: } + }}}}}}}}}} } - { f } + { f+ } { - \tl_set:Nn \__mhchem_cf_state_tl { + } - \peek_catcode_remove:NTF \c_math_toggle_token + \peek_charcode:NTF 1 { - \__mhchem_loopHelper_appendMathAsGroup:NNw + \__mhchem_loopHelper_appendNextToken:NNn \__mhchem_cf_sub_tl \__mhchem_cf_loop: - } + }{ + \peek_charcode:NTF 2 + { + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sub_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 3 + { + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sub_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 4 + { + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sub_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 5 + { + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sub_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 6 + { + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sub_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 7 + { + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sub_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 8 + { + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sub_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 9 + { + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_sub_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 0 { \__mhchem_loopHelper_appendNextToken:NNn \__mhchem_cf_sub_tl \__mhchem_cf_loop: } + % else + { + \tl_set:Nn \__mhchem_cf_state_tl { a } + \__mhchem_cf_loop: + } + }}}}}}}}} } { p } { - \tl_set:Nn \__mhchem_cf_state_tl { * } - \peek_catcode_remove:NTF \c_math_toggle_token + \peek_charcode:NTF 1 { - \__mhchem_loopHelper_appendMathAsGroup:NNw + \tl_set:Nn \__mhchem_cf_state_tl { p+ } + \__mhchem_loopHelper_appendNextToken:NNn \__mhchem_cf_presup_tl \__mhchem_cf_loop: - } + }{ + \peek_charcode:NTF 2 { + \tl_set:Nn \__mhchem_cf_state_tl { p+ } \__mhchem_loopHelper_appendNextToken:NNn \__mhchem_cf_presup_tl \__mhchem_cf_loop: - } - } - { q } - { - \tl_set:Nn \__mhchem_cf_state_tl { * } + }{ + \peek_charcode:NTF 3 + { + \tl_set:Nn \__mhchem_cf_state_tl { p+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presup_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 4 + { + \tl_set:Nn \__mhchem_cf_state_tl { p+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presup_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 5 + { + \tl_set:Nn \__mhchem_cf_state_tl { p+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presup_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 6 + { + \tl_set:Nn \__mhchem_cf_state_tl { p+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presup_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 7 + { + \tl_set:Nn \__mhchem_cf_state_tl { p+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presup_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 8 + { + \tl_set:Nn \__mhchem_cf_state_tl { p+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presup_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 9 + { + \tl_set:Nn \__mhchem_cf_state_tl { p+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presup_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 0 + { + \tl_set:Nn \__mhchem_cf_state_tl { p+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presup_tl + \__mhchem_cf_loop: + }{ \peek_catcode_remove:NTF \c_math_toggle_token { + \tl_set:Nn \__mhchem_cf_state_tl { s } \__mhchem_loopHelper_appendMathAsGroup:NNw - \__mhchem_cf_presub_tl + \__mhchem_cf_presup_tl \__mhchem_cf_loop: } + % else { + \tl_set:Nn \__mhchem_cf_state_tl { s } \__mhchem_loopHelper_appendNextToken:NNn - \__mhchem_cf_presub_tl + \__mhchem_cf_presup_tl \__mhchem_cf_loop: - } - } - { E } - { - \tl_set:Nn \__mhchem_cf_state_tl { + } - \__mhchem_loopHelper_appendNextTokenAsMathrm:NNn - \__mhchem_cf_sup_tl - \__mhchem_cf_loop: - } - { F } - { - \tl_set:Nn \__mhchem_cf_state_tl { + } - \__mhchem_loopHelper_appendNextTokenAsMathrm:NNn - \__mhchem_cf_sub_tl - \__mhchem_cf_loop: + }}}}}}}}}}} } - { P } + { p+ } { - \tl_set:Nn \__mhchem_cf_state_tl { * } - \__mhchem_loopHelper_appendNextTokenAsMathrm:NNn - \__mhchem_cf_presup_tl - \__mhchem_cf_loop: - } - { Q } - { - \tl_set:Nn \__mhchem_cf_state_tl { * } - \__mhchem_loopHelper_appendNextTokenAsMathrm:NNn - \__mhchem_cf_presub_tl - \__mhchem_cf_loop: - } - { + } - { - \peek_charcode:NTF - + \peek_charcode:NTF 1 { - \tl_set:Nn \__mhchem_cf_state_tl { - } - \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presup_tl + \__mhchem_cf_loop: }{ - \peek_charcode:NTF = + \peek_charcode:NTF 2 { - \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn - { \dbond } - { s } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presup_tl \__mhchem_cf_loop: }{ - \peek_charcode:NTF ## + \peek_charcode:NTF 3 { - \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn - { \tbond } - { s } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presup_tl \__mhchem_cf_loop: }{ - \peek_charcode:NTF ^ + \peek_charcode:NTF 4 { - \tl_set:Nn \__mhchem_cf_state_tl { e } - \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presup_tl + \__mhchem_cf_loop: }{ - \peek_charcode:NTF _ + \peek_charcode:NTF 5 { - \tl_set:Nn \__mhchem_cf_state_tl { f } - \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presup_tl + \__mhchem_cf_loop: }{ - \peek_charcode:NTF ` + \peek_charcode:NTF 6 { - \int_compare:nTF { 4 > \__mhchem_option_version_int } - { - \tl_set:Nn \__mhchem_cf_state_tl { E } - \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: - } - { - \__mhchem_cf_outputAndReset: - \tl_set:Nn \__mhchem_cf_state_tl { a } - \__mhchem_loopHelper_appendNextToken:NNn - \__mhchem_cf_element_tl - \__mhchem_cf_loop: - } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presup_tl + \__mhchem_cf_loop: }{ - \peek_charcode:NTF , + \peek_charcode:NTF 7 { - \int_compare:nTF { 4 > \__mhchem_option_version_int } - { - \tl_set:Nn \__mhchem_cf_state_tl { F } - \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: - } - { - \__mhchem_cf_outputAndReset: - \tl_set:Nn \__mhchem_cf_state_tl { a } - \tl_put_right:Nn \__mhchem_cf_element_tl { , } - \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: - } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presup_tl + \__mhchem_cf_loop: }{ - \peek_charcode:NTF . + \peek_charcode:NTF 8 { - \int_compare:nTF { 4 > \__mhchem_option_version_int } - { - \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn - { \mhchem@mathOrText@ii{{}\cdot{}}{\mhchem@option@textcdot} } - { s } - \__mhchem_cf_loop: - } - { - \__mhchem_cf_outputAndReset: - \tl_set:Nn \__mhchem_cf_state_tl { a } - \__mhchem_loopHelper_appendNextToken:NNn - \__mhchem_cf_element_tl - \__mhchem_cf_loop: - } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presup_tl + \__mhchem_cf_loop: }{ - \peek_charcode:NTF * + \peek_charcode:NTF 9 { - \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn - { \mhchem@mathOrText@ii{{}\cdot{}}{\mhchem@option@textcdot} } - { s } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presup_tl \__mhchem_cf_loop: }{ - \peek_charcode:NTF + + \peek_charcode:NTF 0 { - \tl_set:Nn \__mhchem_cf_state_tl { + } \__mhchem_loopHelper_appendNextToken:NNn - \__mhchem_cf_sup_tl + \__mhchem_cf_presup_tl + \__mhchem_cf_loop: + } + % else + { + \tl_set:Nn \__mhchem_cf_state_tl { s } + \__mhchem_cf_loop: + }}}}}}}}}} + } + { q } + { + \peek_charcode:NTF 1 + { + \tl_set:Nn \__mhchem_cf_state_tl { q+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presub_tl \__mhchem_cf_loop: }{ - \peek_charcode:NTF | + \peek_charcode:NTF 2 { - \PackageWarning{mhchem}{The symbol | is not allowed here} - \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: + \tl_set:Nn \__mhchem_cf_state_tl { q+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presub_tl + \__mhchem_cf_loop: }{ - \peek_charcode:NTF ( + \peek_charcode:NTF 3 { - \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn - { s } + \tl_set:Nn \__mhchem_cf_state_tl { q+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presub_tl \__mhchem_cf_loop: }{ - \peek_charcode:NTF ) + \peek_charcode:NTF 4 { - \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn - { a } + \tl_set:Nn \__mhchem_cf_state_tl { q+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presub_tl \__mhchem_cf_loop: }{ - \peek_charcode:NTF [ + \peek_charcode:NTF 5 { - \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn - { s } + \tl_set:Nn \__mhchem_cf_state_tl { q+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presub_tl \__mhchem_cf_loop: }{ - \peek_charcode:NTF ] + \peek_charcode:NTF 6 { - \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn - { a } + \tl_set:Nn \__mhchem_cf_state_tl { q+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presub_tl \__mhchem_cf_loop: }{ - \peek_catcode:NTF \mhchem@macro + \peek_charcode:NTF 7 { - \__mhchem_cf_outputAndReset: - \tl_set:Nn \__mhchem_cf_state_tl { c } + \tl_set:Nn \__mhchem_cf_state_tl { q+ } \__mhchem_loopHelper_appendNextToken:NNn - \__mhchem_cf_result_tl + \__mhchem_cf_presub_tl \__mhchem_cf_loop: }{ - \peek_catcode:NTF a + \peek_charcode:NTF 8 { - \__mhchem_cf_outputAndReset: - \tl_set:Nn \__mhchem_cf_state_tl { a } + \tl_set:Nn \__mhchem_cf_state_tl { q+ } \__mhchem_loopHelper_appendNextToken:NNn - \__mhchem_cf_element_tl + \__mhchem_cf_presub_tl \__mhchem_cf_loop: }{ - \peek_catcode:NTF 1 + \peek_charcode:NTF 9 { - \__mhchem_cf_outputAndReset: - \tl_set:Nn \__mhchem_cf_state_tl { a } + \tl_set:Nn \__mhchem_cf_state_tl { q+ } \__mhchem_loopHelper_appendNextToken:NNn - \__mhchem_cf_element_tl + \__mhchem_cf_presub_tl \__mhchem_cf_loop: }{ - \peek_catcode:NTF \c_group_begin_token + \peek_charcode:NTF 0 { - \int_compare:nTF { 4 > \__mhchem_option_version_int } - { - \__mhchem_cf_outputAndReset: - \tl_set:Nn \__mhchem_cf_state_tl { s } - \__mhchem_loopHelper_appendNextGroup:NNn - \__mhchem_cf_result_tl - \__mhchem_cf_loop: - } - { - \__mhchem_cf_outputAndReset: - \tl_set:Nn \__mhchem_cf_state_tl { a } - \__mhchem_loopHelper_appendNextGroup:NNn - \__mhchem_cf_element_tl - \__mhchem_cf_loop: - } + \tl_set:Nn \__mhchem_cf_state_tl { q+ } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presub_tl + \__mhchem_cf_loop: }{ \peek_catcode_remove:NTF \c_math_toggle_token { - \__mhchem_cf_outputAndReset: - \tl_set:Nn \__mhchem_cf_state_tl { a } - \__mhchem_loopHelper_appendMathB:NNw - \__mhchem_cf_element_tl + \tl_set:Nn \__mhchem_cf_state_tl { s } + \__mhchem_loopHelper_appendMathAsGroup:NNw + \__mhchem_cf_presub_tl \__mhchem_cf_loop: } % else { - \__mhchem_cf_outputAndReset: \tl_set:Nn \__mhchem_cf_state_tl { s } \__mhchem_loopHelper_appendNextToken:NNn - \__mhchem_cf_result_tl + \__mhchem_cf_presub_tl \__mhchem_cf_loop: - } - }}}}}}}}}}}}}}}}}}} + }}}}}}}}}}} } - { * } + { q+ } { - \peek_charcode:NTF ^ + \peek_charcode:NTF 1 { - \tl_set:Nn \__mhchem_cf_state_tl { p } - \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presub_tl + \__mhchem_cf_loop: }{ - \peek_charcode:NTF _ + \peek_charcode:NTF 2 { - \tl_set:Nn \__mhchem_cf_state_tl { q } - \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presub_tl + \__mhchem_cf_loop: }{ - \peek_charcode:NTF ` + \peek_charcode:NTF 3 { - \int_compare:nTF { 4 > \__mhchem_option_version_int } - { - \tl_set:Nn \__mhchem_cf_state_tl { P } - \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: - } - { - \tl_set:Nn \__mhchem_cf_state_tl { a } - \__mhchem_loopHelper_appendNextToken:NNn - \__mhchem_cf_element_tl - \__mhchem_cf_loop: - } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presub_tl + \__mhchem_cf_loop: }{ - \peek_charcode:NTF , + \peek_charcode:NTF 4 { - \int_compare:nTF { 4 > \__mhchem_option_version_int } - { - \tl_set:Nn \__mhchem_cf_state_tl { Q } - \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: - } - { - \tl_set:Nn \__mhchem_cf_state_tl { a } - \tl_put_right:Nn \__mhchem_cf_element_tl { , } - \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: - } + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presub_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 5 + { + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presub_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 6 + { + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presub_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 7 + { + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presub_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 8 + { + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presub_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 9 + { + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presub_tl + \__mhchem_cf_loop: + }{ + \peek_charcode:NTF 0 + { + \__mhchem_loopHelper_appendNextToken:NNn + \__mhchem_cf_presub_tl + \__mhchem_cf_loop: } % else { - \__mhchem_cf_outputAndReset: \tl_set:Nn \__mhchem_cf_state_tl { s } \__mhchem_cf_loop: - } - }}} + }}}}}}}}}} } } { - \msg_error:nnx { mhchem } { cf/unexpected-state } + \msg_error:nnx { mhchem } { cf / unexpected-state } { \__mhchem_cf_state_tl } \__mhchem_loopHelper_appendNextToken:NNn \__mhchem_cf_result_tl @@ -2220,92 +2455,119 @@ \mhchem@cf@continue% }% -\tl_new:N \__mhchem_cf_presup_tl -\tl_new:N \__mhchem_cf_presub_tl -\tl_new:N \__mhchem_cf_element_tl -\tl_new:N \__mhchem_cf_supA_tl -\tl_new:N \__mhchem_cf_sub_tl -\tl_new:N \__mhchem_cf_sup_tl \cs_new_protected:Npn \__mhchem_cf_output: { - \str_case:Vnn \__mhchem_cf_state_tl + \str_if_eq:nnTF { - { s } { } - { 1 } + \__mhchem_cf_presup_tl + \__mhchem_cf_presub_tl + \__mhchem_cf_element_tl + \__mhchem_cf_supA_tl%todo remove + \__mhchem_cf_sub_tl + \__mhchem_cf_sup_tl + } + {} % is empty? + { + } + { + \str_case:Vnn \__mhchem_cf_state_tl { - \tl_put_right:Nx \__mhchem_cf_result_tl + { 1 } { - \exp_not:N \mhchem@mathOrText { - \exp_not:N \mhchem@cf@frac - \exp_not:V \__mhchem_cf_element_tl / \exp_not:N \mhchem@END - { \mhchem@option@skipAfterFracAmount } } + \tl_put_right:Nx \__mhchem_cf_result_tl + { + \exp_not:N \mhchem@mathOrText { + \exp_not:N \mhchem@cf@frac + \exp_not:V \__mhchem_cf_element_tl / \exp_not:N \mhchem@END + { \exp_not:N \mhchem@option@skipAfterAmount } } + } } - } - { 9 } - { - \tl_put_right:Nx \__mhchem_cf_result_tl + { 9 } { - \exp_not:N \mhchem@mathOrText { - \exp_not:N \mhchem@cf@frac - \exp_not:V \__mhchem_cf_element_tl / - \exp_not:N \mhchem@END - {} } + \tl_put_right:Nx \__mhchem_cf_result_tl + { + \exp_not:N \mhchem@mathOrText { + \exp_not:N \mhchem@cf@frac + \exp_not:V \__mhchem_cf_element_tl / + \exp_not:N \mhchem@END + {} } + } } } - } - { - \tl_if_empty:NTF \__mhchem_cf_sub_tl - { - \tl_put_right:NV \__mhchem_cf_supA_tl \__mhchem_cf_sup_tl - \tl_clear:N \__mhchem_cf_sup_tl - } { - \tl_if_empty:NTF \__mhchem_cf_sup_tl - { } + \str_if_eq:VnTF \__mhchem_cf_supState_tl { rm } { - \tl_if_empty:NTF \__mhchem_cf_supA_tl - { } - { - \msg_error:nnn { mhchem } { cf/unexpected-two-superscripts } - } + \tl_set:Nx \__mhchem_cf_sup_tl { \exp_not:N \ensuremath { \exp_not:N \mathrm { \exp_not:V \__mhchem_cf_sup_tl } } } } - } - \tl_put_right:Nx \__mhchem_cf_result_tl - { - \exp_not:N \__mhchem_chemfive:nnnnnn + {} + \str_if_eq:VnT \__mhchem_cf_subState_tl { rm } { - \exp_not:N \__mhchem_cf_replaceMath:n - { \exp_not:V \__mhchem_cf_presup_tl } + \tl_set:Nx \__mhchem_cf_sub_tl { \exp_not:N \ensuremath { \exp_not:N \mathrm { \exp_not:V \__mhchem_cf_sub_tl } } } } + \str_if_eq:VnTF \__mhchem_cf_presupState_tl { rm } { - \exp_not:N \__mhchem_cf_replaceMath:n - { \exp_not:V \__mhchem_cf_presub_tl } + \tl_set:Nx \__mhchem_cf_presup_tl { \exp_not:N \ensuremath { \exp_not:N \mathrm { \exp_not:V \__mhchem_cf_presup_tl } } } } - { \exp_not:V \__mhchem_cf_element_tl } + {} + \str_if_eq:VnT \__mhchem_cf_presubState_tl { rm } { - \exp_not:N \__mhchem_cf_replaceMathMinusDot:n - { \exp_not:V \__mhchem_cf_supA_tl } + \tl_set:Nx \__mhchem_cf_presub_tl { \exp_not:N \ensuremath { \exp_not:N \mathrm { \exp_not:V \__mhchem_cf_presub_tl } } } } + \str_case:Vnn \__mhchem_cf_supState_tl { - \exp_not:N \__mhchem_cf_replaceMath:n - { \exp_not:V \__mhchem_cf_sub_tl } + { kv } + { + \tl_put_right:Nx \__mhchem_cf_result_tl + { + \exp_not:N \__mhchem_chemfive:nnnnnn + { + \exp_not:N \__mhchem_cf_replaceMath:n + { \exp_not:V \__mhchem_cf_presup_tl } + } + { + \exp_not:N \__mhchem_cf_replaceMath:n + { \exp_not:V \__mhchem_cf_presub_tl } + } + { \exp_not:V \__mhchem_cf_element_tl } + { + \exp_not:N \__mhchem_cf_replaceMathMinusDot:n + { \exp_not:V \__mhchem_cf_sup_tl } + } + { + \exp_not:N \__mhchem_cf_replaceMath:n + { \exp_not:V \__mhchem_cf_sub_tl } + } + {} + } + } } { - \exp_not:N \__mhchem_cf_replaceMathMinusDot:n - { \exp_not:V \__mhchem_cf_sup_tl } + \tl_put_right:Nx \__mhchem_cf_result_tl + { + \exp_not:N \__mhchem_chemfive:nnnnnn + { + \exp_not:N \__mhchem_cf_replaceMath:n + { \exp_not:V \__mhchem_cf_presup_tl } + } + { + \exp_not:N \__mhchem_cf_replaceMath:n + { \exp_not:V \__mhchem_cf_presub_tl } + } + { \exp_not:V \__mhchem_cf_element_tl } + {} + { + \exp_not:N \__mhchem_cf_replaceMath:n + { \exp_not:V \__mhchem_cf_sub_tl } + } + { + \exp_not:N \__mhchem_cf_replaceMathMinusDot:n + { \exp_not:V \__mhchem_cf_sup_tl } + } + } } - } + } } } -\cs_new_protected:Npn \__mhchem_cf_resetOutput: - { - \tl_clear:N \__mhchem_cf_presup_tl - \tl_clear:N \__mhchem_cf_presub_tl - \tl_clear:N \__mhchem_cf_element_tl - \tl_clear:N \__mhchem_cf_supA_tl - \tl_clear:N \__mhchem_cf_sub_tl - \tl_clear:N \__mhchem_cf_sup_tl - } \cs_new_protected:Npn \__mhchem_cf_outputAndReset: { \__mhchem_cf_output: @@ -2410,16 +2672,56 @@ }}}} } +\cs_new_protected:Npn \__mhchem_defMathOrText: + { + \mode_if_math:TF + { + \int_compare:nTF { \__mhchem_option_version_int > 1 } + { + \cs_set:Npx \mhchem@mathOrText ##1 + { + \mode_if_math:TF + { \exp_not:N \mhchem@option@mathFont{##1} } + { \exp_not:N \text{##1} } + } + \cs_set:Npx \mhchem@mathOrText@ii ##1##2 + { + \mode_if_math:TF + { \exp_not:N \mhchem@option@mathFont{##1} } + { ##2 } + } + } + % else + { + \cs_set:Npx \mhchem@mathOrText ##1 + { + \mode_if_math:TF { ##1 } { \exp_not:N \text{##1} } + } + \cs_set:Npx \mhchem@mathOrText@ii ##1##2 + { + \mode_if_math:TF { ##1 } { ##2 } + } + } + } + % else + { + + \mhchem@option@textFont + \cs_set:Npx \mhchem@mathOrText ##1 { \exp_not:N \text{##1} } + \cs_set:Npx \mhchem@mathOrText@ii ##1##2 { ##2 } + } + } %%%%%%%%%%%%%%%%%%%%% %%% @chemfive %%% %%%%%%%%%%%%%%%%%%%%% \cs_new_protected:Npn \__mhchem_chemfive:nnnnnn #1#2#3#4#5#6 { - \str_if_eq:VnTF \mhchem@option@superscriptstacked { true } + \bool_if:NTF \__mhchem_option_superscriptsStacked_bool { - \mhchem@prepostscript% - {\mhchem@mathOrText{\smash[t]{2+}}}% - {\mhchem@mathOrText{\smash[t]{2}}}% + \__mhchem_prepostscript:nnnnnnnnn% + {\mhchem@mathOrText{2+}}% + {\mhchem@mathOrText{2}}% + {\mhchem@mathOrText{X}}% {\mhchem@mathOrText{#1}}% {\mhchem@mathOrText{#2}}% {\mhchem@mathOrText@ii{\mhchem@option@mathFont{#3}}{\text{#3}}}% @@ -2428,9 +2730,10 @@ {}% } { - \mhchem@prepostscript% - {\mhchem@mathOrText{\smash[t]{2+}}}% - {\mhchem@mathOrText{\smash[t]{2}}}% + \__mhchem_prepostscript:nnnnnnnnn% + {\mhchem@mathOrText{2+}}% + {\mhchem@mathOrText{2}}% + {\mhchem@mathOrText{X}}% {\mhchem@mathOrText{#1}}% {\mhchem@mathOrText{#2}}% {\mhchem@mathOrText@ii{\mhchem@option@mathFont{#3}}{\text{#3}}}% @@ -2439,68 +2742,72 @@ {\mhchem@mathOrText{#6}}% } } -\ExplSyntaxOff %%% @prepostscript -\newlength\mhchem@prepostscript@tmp@i% -\newlength\mhchem@prepostscript@tmp@ii% -\newcommand*\mhchem@prepostscript[8]{% - \m@th% - \ensuremath{% - \setlength{\mhchem@prepostscript@tmp@i}{\widthof{$#3#4$}}% - \ifdim\mhchem@prepostscript@tmp@i>0pt% - \setlength{\mhchem@prepostscript@tmp@i}{\widthof{${}^{#3}$}}% - \setlength{\mhchem@prepostscript@tmp@ii}{\widthof{${}_{#4}$}}% - \ifdim\mhchem@prepostscript@tmp@i<\mhchem@prepostscript@tmp@ii% - \setlength{\mhchem@prepostscript@tmp@i}{\mhchem@prepostscript@tmp@ii}\fi% - \vphantom{#5}% - {}% - ^{% - \mhchem@mathboxright{\mhchem@prepostscript@tmp@i}{% - \vphantom{#6#8}% - \vphantom{#1}% - #3% - }% - }% - _{% - \mhchem@mathboxright{\mhchem@prepostscript@tmp@i}{% - \vphantom{#7}% - \vphantom{#2}% - #4% - }% - }% - \mhchem@minispace% - \fi% - #5% - \setlength{\mhchem@prepostscript@tmp@i}{\widthof{$#7#6$}}% - \ifdim\mhchem@prepostscript@tmp@i>0pt% - _{% - \vphantom{#4}% - \vphantom{#2}% - #7% - }% - ^{% - \vphantom{#3#8}% - \vphantom{#1}% - #6% - }% - \fi% - \setlength{\mhchem@prepostscript@tmp@i}{\widthof{$#8$}}% - \ifdim\mhchem@prepostscript@tmp@i>0pt% - \mhchem@minispace% - {}% - _{% - \vphantom{#4#7}% - \vphantom{#2}% - }% - ^{% - \vphantom{#3#6}% - \vphantom{#1}% - #8% - }% - \fi% - }% -} +\newlength\__mhchem_prepostscript_leftwidth% +\newlength\__mhchem_prepostscript_leftwidth_ii% +\cs_new_protected:Npn \__mhchem_prepostscript:nnnnnnnnn #1#2#3#4#5#6#7#8#9 + { + \m@th + \ensuremath + { + \hbox_set:Nn \l_tmpa_box { $#4#5$ } + \dim_compare:nNnT { \box_wd:N \l_tmpa_box } > { 0pt } + { + \hphantom { {}^{#4}\c_math_subscript_token{#5} } + { \vphantom {#3#6} } + ^ { + \mhchem@mathboxrightt + { + \vphantom {#1} + #4 + } + } + \c_math_subscript_token { + \mhchem@mathboxrightt + { + \vphantom {#2} + #5 + } + } + \mhchem@minispace % + } + #6 + \hbox_set:Nn \l_tmpa_box { $#7#8#9$ } + \dim_compare:nNnT { \box_wd:N \l_tmpa_box } > { 0pt } + { + \hbox_set:Nn \l_tmpa_box { $#6$ } + \dim_compare:nNnTF { \box_wd:N \l_tmpa_box } > { 0pt } + { { \vphantom {#3#6} } } + { \mhchem@minibackspace { \vphantom {#3} } } + \hbox_set:Nn \l_tmpa_box { $#8$ } + \dim_compare:nNnT { \box_wd:N \l_tmpa_box } > { 0pt } + { + \c_math_subscript_token { + \vphantom { \smash[b]{#2} } + #8 + } + } + \hbox_set:Nn \l_tmpa_box { $#9$ } + \dim_compare:nNnTF { \box_wd:N \l_tmpa_box } = { 0pt } + { + ^ { + \vphantom { \smash[t]{#1} } + #7 + } + } + { + ^ { + \vphantom { \smash[t]{#1} } + \hphantom {#8} + #9 + } + } + } + } + } + +\ExplSyntaxOff %%% @mathbox \newcommand*\mhchem@mathbox[2][]{% @@ -2531,6 +2838,11 @@ {\makebox[#1][r]{\ensuremath{\textstyle#2}}}% {\makebox[#1][r]{\ensuremath{\scriptstyle#2}}}% {\makebox[#1][r]{\ensuremath{\scriptscriptstyle#2}}}} +\newcommand*\mhchem@mathboxrightt[1]{\mathchoice% + {\ensuremath{\displaystyle\llap{\ensuremath{\displaystyle#1}}}}% + {\ensuremath{\textstyle\llap{\ensuremath{\textstyle#1}}}}% + {\ensuremath{\scriptstyle\llap{\ensuremath{\scriptstyle#1}}}}% + {\ensuremath{\scriptscriptstyle\llap{\ensuremath{\scriptscriptstyle#1}}}}}% %%% @minispace \newlength\mhchem@minispace@tmp @@ -2539,113 +2851,140 @@ \widthof{$\text{C}^8_8$}-\widthof{$\text{C}^{}_{}$}}% \kern\mhchem@minispace@tmp% } +%%% @minibackspace +\newlength\mhchem@minibackspace@tmp +\newcommand*\mhchem@minibackspace{% + \setlength{\mhchem@minibackspace@tmp}{0pt-\widthof{${}_{2}{}_{2}$}+\widthof{${}_{22}$}}% + \kern\mhchem@minibackspace@tmp% +} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%% Package Options %%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\def\mhchem@option@version{0} -\define@key{mhchem}{version}{\def\mhchem@option@version{#1}} +\ExplSyntaxOn + +\msg_new:nnn { mhchem } { options / no-version } + { + You~did~not~specify~a~'version'~option~for~the~mhchem~package.~ + Please~write~ + \string\usepackage[version=3]{mhchem}~in~your~preamble~ + (or~any~lower~number~for~compatibility~mode). + } +\msg_new:nnn { mhchem } { options / version-too-high } + { + You~are~using~version~3.xx~of~mhchem, + but~you~entered~a~higher~version~number.~ + This~means,~you~are~using~some~beta~features~of~mhchem~ + that~are~subject~to~change~without~notice. + } \def\mhchem@option@mathFont{\mathrm} \def\mhchem@option@textFont{} -\define@key{mhchem}{textfontcommand}{\def\mhchem@option@textFont{#1}} -\define@key{mhchem}{textfontname}{\def\mhchem@option@textFont{\csname#1\endcsname}} -\define@key{mhchem}{mathfontcommand}{\def\mhchem@option@mathFont{#1}} -\define@key{mhchem}{mathfontname}{\def\mhchem@option@mathFont{\csname#1\endcsname}} -\define@key{mhchem}{font}{% - \ifthenelse{\equal{sf}{#1}}{% - \def\mhchem@option@textFont{\sffamily}% - \def\mhchem@option@mathFont{\mathsf}% - }{\ifthenelse{\equal{}{#1}}{% - \def\mhchem@option@textFont{}% - \def\mhchem@option@mathFont{\mathrm}% - }{\PackageError{mhchem}{Font option `#1' unknown}}}% -} +\bool_new:N \__mhchem_option_superscriptsStacked_bool -\def\mhchem@option@alwaystextmode{0}% - -\newlength\mhchem@option@minussidebearingleft -\newlength\mhchem@option@minussidebearingright -\setlength\mhchem@option@minussidebearingleft{0.06em} -\setlength\mhchem@option@minussidebearingright{0.11em} -\define@key{mhchem}{minus-sidebearing-left}{\setlength\mhchem@option@minussidebearingleft{#1}} -\define@key{mhchem}{minus-sidebearing-right}{\setlength\mhchem@option@minussidebearingright{#1}} - -\mhchem@definearrows{font} -\define@key{mhchem}{arrows}{% - \ifthenelse{\equal{pgf}{#1} \or \equal{pgf-filled}{#1}}{% - \RequirePackage{pgf}% for finding the tikz package more easily - \RequirePackage{tikz}% - }{}% - \mhchem@definearrows{#1}% -} +\keys_define:nn {mhchem} + { + version .int_set:N = \__mhchem_option_version_int, + version .value_required:, + version .initial:n = { -1 }, + version .default:n = { -1 }, -\def\mhchem@option@skipAfterAmount{\,} -\define@key{mhchem}{skip-after-amount}{\def\mhchem@option@skipAfterAmount{#1}\def\mhchem@option@skipAfterFracAmount{#1}} -\def\mhchem@option@skipAfterFracAmount{\,} -\define@key{mhchem}{skip-after-frac-amount}{\def\mhchem@option@skipAfterFracAmount{#1}} - -\def\mhchem@option@textminus{--} -\define@key{mhchem}{textminus}{\def\mhchem@option@textminus{#1}} - -\def\mhchem@option@textcdot{\cdot} -\define@key{mhchem}{textcdot}{\def\mhchem@option@textcdot{#1}} - -\def\mhchem@option@superscriptstacked{0} -\define@key{mhchem}{superscriptstacked}[true]{\def\mhchem@option@superscriptstacked{#1}}% - -%%% begin: standard keyval handling as in many other packages -\def\ProcessOptionsWithKV#1{% - \let\@tempc\relax% - \let\mhchem@tempa\@empty% - \@for\CurrentOption:=\@classoptionslist\do{% - \@ifundefined{KV@#1@\CurrentOption}% - {}% - {% - \edef\mhchem@tempa{\mhchem@tempa,\CurrentOption,}% - \@expandtwoargs\@removeelement\CurrentOption% - \@unusedoptionlist\@unusedoptionlist% - }% - }% - \edef\mhchem@tempa{% - \noexpand\setkeys{#1}{% - \mhchem@tempa\@ptionlist{\@currname.\@currext}% - }% - }% - \mhchem@tempa% - \let\CurrentOption\@empty% - \AtEndOfPackage{\let\@unprocessedoptions\relax}% -} -\ProcessOptionsWithKV{mhchem}\relax -%%% end: - -\define@key{mhchem}{arrows}{\mhchem@definearrows{#1}}% - -\newcommand*\mhchemoptions[1]{\setkeys{mhchem}{#1}} - -\ifnum 0=\mhchem@option@version% - \PackageWarningNoLine{mhchem}{% - You did not specify a 'version' option for the mhchem\MessageBreak - package. If you are about to create a new document,\MessageBreak - please write \string\usepackage[version=3]{mhchem} in your\MessageBreak - preamble in order to use the most recent version of\MessageBreak - mhchem}% - \def\mhchem@option@version{3}% -\else\ifnum 4=\mhchem@option@version% - \PackageWarningNoLine{mhchem}{% - You are using version 3.xx of mhchem. You entered\MessageBreak - the parameter version=4. This means, you are using\MessageBreak - some beta features of mhchem that are subject\MessageBreak - to change without notice}% -\fi\fi% + textfontcommand .code:n = { \def\mhchem@option@textFont{#1} }, + textfontname .code:n = { \def\mhchem@option@textFont{\csname#1\endcsname} }, + mathfontcommand .code:n = { \def\mhchem@option@mathFont{#1} }, + mathfontname .code:n = { \def\mhchem@option@mathFont{\csname#1\endcsname} }, + font .choice:, + font / sf .code:n = + { + \def\mhchem@option@textFont{\sffamily}% + \def\mhchem@option@mathFont{\mathsf}% + }, + font / .code:n = + { + \def\mhchem@option@textFont{}% + \def\mhchem@option@mathFont{\mathrm}% + }, + + minus-sidebearing-left .dim_set:N = \mhchem@option@minussidebearingleft, + minus-sidebearing-left .initial:n = { 0.06em }, + minus-sidebearing-right .dim_set:N = \mhchem@option@minussidebearingright, + minus-sidebearing-right .initial:n = { 0.11em }, + + arrows .choice:, + arrows / font .code:n = { \mhchem@definearrows{#1} }, + arrows / pgf .code:n = + { + \bool_if:NT { \__mhchem_option_inPreamble_bool } + { + \RequirePackage{pgf} + \RequirePackage{tikz} + } + \mhchem@definearrows{#1} + }, + arrows / pgf-filled .code:n = + { + \bool_if:NT { \__mhchem_option_inPreamble_bool } + { + \RequirePackage{pgf} + \RequirePackage{tikz} + } + \mhchem@definearrows{#1} + }, + arrows .initial:n = { font }, + + skip-after-amount .code:n = + { + \def\mhchem@option@skipAfterAmount{#1} + }, + skip-after-amount .initial:n = { \, }, + + textminus .code:n = { \def\mhchem@option@textminus{#1} }, + textminus .initial:n = { -- }, + + textcdot .code:n = { \def\mhchem@option@textcdot{#1} }, + textcdot .initial:n = { \cdot }, + + superscripts .choice:, + superscripts / stacked .code:n = + { \bool_set_true:N \__mhchem_option_superscriptsStacked_bool }, + superscripts / shifted .code:n = + { \bool_set_true:N \__mhchem_option_superscriptsStacked_bool }, + superscripts / .code:n = + { \bool_set_true:N \__mhchem_option_superscriptsStacked_bool }, + superscripts .initial:n .code:n = + { \bool_set_true:N \__mhchem_option_superscriptsStacked_bool }, + } + +\newcommand*\mhchemoptions[1] + { \keys_set:nn { mhchem } {#1} } + +\bool_new:N \__mhchem_option_inPreamble_bool +\bool_set_true:N \__mhchem_option_inPreamble_bool +\ProcessKeysPackageOptions{mhchem} +\bool_set_false:N \__mhchem_option_inPreamble_bool + +\int_compare:nT { -1 = \__mhchem_option_version_int } + { + \msg_error:nn { mhchem } { options / no-version } + \int_set:Nn \__mhchem_option_version_int { 3 } + } +% else + { + \int_compare:nT { \__mhchem_option_version_int > 3} + { + \msg_warning:nn { mhchem } { options / version-too-high } + } + } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%% legacy %%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\ifnum 4>\mhchem@option@version - \newcommand*\mhchem@cmath[1]{\ensuremath{\text{\ensuremath{#1}}}}% - \newcommand*\cmath[1]{\mhchem@cmath{#1}} - \DeclareRobustCommand\cf[2][]{\mhchem@cf[#1]{#2}} -\fi +\int_compare:nT { \__mhchem_option_version_int < 4 } + { + \newcommand*\mhchem@cmath[1]{\ensuremath{\text{\ensuremath{#1}}}}% + \newcommand*\cmath[1]{\mhchem@cmath{#1}} + \DeclareRobustCommand\cf[2][]{\mhchem@cf[#1]{#2}} + } + |