summaryrefslogtreecommitdiff
path: root/Master
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2015-04-07 21:16:59 +0000
committerKarl Berry <karl@freefriends.org>2015-04-07 21:16:59 +0000
commitd78455f684469ab6c480b05e84332d30c32f5b52 (patch)
treeef36b468e7d927b6daa4731ae4a4aadd47078425 /Master
parent48a19dc74b35f6b94debd3e82fd1ccbed71d6f76 (diff)
mhchem (7apr15)
git-svn-id: svn://tug.org/texlive/trunk@36738 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master')
-rw-r--r--Master/texmf-dist/doc/latex/mhchem/README4
-rw-r--r--Master/texmf-dist/doc/latex/mhchem/mhchem.pdfbin206385 -> 329396 bytes
-rw-r--r--Master/texmf-dist/doc/latex/mhchem/mhchem.tex805
-rw-r--r--Master/texmf-dist/tex/latex/mhchem/mhchem.sty3074
4 files changed, 1965 insertions, 1918 deletions
diff --git a/Master/texmf-dist/doc/latex/mhchem/README b/Master/texmf-dist/doc/latex/mhchem/README
index 0fc068570e5..d68a8b1ffd4 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-03-13
+The mhchem Bundle 2015-04-07
containing
-- mhchem v3.21
+- mhchem v4.00
- 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
index 261398f5f3a..a9ef2485772 100644
--- a/Master/texmf-dist/doc/latex/mhchem/mhchem.pdf
+++ b/Master/texmf-dist/doc/latex/mhchem/mhchem.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/mhchem/mhchem.tex b/Master/texmf-dist/doc/latex/mhchem/mhchem.tex
index e881716ec98..660487a951f 100644
--- a/Master/texmf-dist/doc/latex/mhchem/mhchem.tex
+++ b/Master/texmf-dist/doc/latex/mhchem/mhchem.tex
@@ -27,23 +27,24 @@
% This work consists of all files listed in manifest.txt.
%
%
-\documentclass[a4paper,notitlepage]{scrreprt}
-\usepackage{fontspec}
-\usepackage[danish,french,ngerman,italian,spanish,UKenglish]{babel}
-\usepackage{mathpazo}% math font
-\setmainfont[Mapping=tex-text]{TeX Gyre Pagella}% URWPalladioL
- % http://www.ctan.org/tex-archive/fonts/tex-gyre/fonts
+\documentclass[a4paper,notitlepage,parskip=half]{scrreprt}
+\usepackage[T1]{fontenc}
+\usepackage[utf8]{inputenc}
+\usepackage[danish,french,ngerman,spanish,italian,UKenglish]{babel}
+\usepackage{tgpagella}% URW Palladio
\addtokomafont{disposition}{\rmfamily}
\linespread{1.1}
-\setmonofont[Mapping=tex-text,Scale=MatchLowercase]{Source Code Pro}
- % http://sourceforge.net/projects/sourcecodepro.adobe/
+\usepackage{mathpazo}% math font
+\usepackage[scale=0.9]{sourcecodepro}
+\usepackage{AlegreyaSans}
\usepackage[bookmarks,bookmarksopen,pdfstartview=FitH]{hyperref}
\usepackage[alwaysadjust]{paralist}
\usepackage{ragged2e}
\usepackage{fvrb-ex}% example environments
-\usepackage{color}
+\usepackage{xcolor}
+\usepackage{nameref}
-\usepackage[version=3]{mhchem}
+\usepackage[version=4]{mhchem}
\usepackage{hpstatement}
\usepackage{rsphrase}
\usepackage{tikz}
@@ -54,7 +55,10 @@
\newcommand\fromversion[1]{\marginpar{{\scriptsize version$\geq$#1}}}
\newenvironment{annotation}{\bgroup\footnotesize}{\par\egroup}
-
+\definecolor{mhchem}{HTML}{A33E00}
+\makeatletter
+\def\mhchem@hook@beforeCe{\color{mhchem}}
+\makeatother
\begin{document}
@@ -62,7 +66,7 @@
The mhchem Bundle\\[0.3em]
\Large\textmd{%
Documentation for the Packages\\
- mhchem v3.21,\\% check
+ mhchem v4.00,\\% check
hpstatement v1.01 and\\
rsphrase v3.11}%
}
@@ -71,7 +75,7 @@
mhchem\makebox[0pt][l]{\textcolor{white}{NOSPAM}}@MartinHensel\makebox[1pt][l]{\textcolor{white}{.}}.de%
}
\date{%
- 2015-03-13% check
+ 2015-04-07% check
}
\maketitle
@@ -80,11 +84,11 @@
\begin{abstract}
\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
+ \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
\noindent
The \textbf{rsphrase} package provides commands for the official Risk and Safety (R and S) Phrases that are used to label chemicals.
\end{abstract}
@@ -97,457 +101,408 @@
\clearpage
-
\chapter{The mhchem Package}
+
\section{Work in Progress}
-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.
+Even after years, the mhchem package is still work in progress. I try to never invalidate valid, old syntaxes (via the \verb|version| option). However, slight changes in spacing (and therefore changed line breaks and page breaks) can occur from release to release.
+\textbf{The version 4 syntax is subject to change if I find a serious flaw, for a couple of months after first release.} After that, it will be stable and syntax incompatible changes would only occur in a future version 5.
+\section{Preamble}
-\section{Why this package?}
+In order to use all of mhchem's features, request it in your document's preamble with the command
-\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.
+{\color{mhchem}\Large\verb|\usepackage|{\ttfamily\bfseries [version=4]}\verb|{mhchem}|}
+\marginpar{\Large !}
-\begin{addmargin}[4em]{0em}
-\begin{SideBySideExample}[xrightmargin=3cm]
- $\frac{1}{2}\,\mathrm{H}_2\mathrm{O}$
-\end{SideBySideExample}
-\end{addmargin}
+\begin{annotation}
+What about the \verb|version=4|? 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=4| for the most-recent version of mhchem, but \verb|version=2| to \verb|version=1| 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}
-\noindent
-In addition, one has to care about the height of subscripts, as the following example shows. The 2 and the 7 are not aligned properly.
+mhchem needs a couple of other packages. For instance, expl3, amsmath and calc.
-\begin{addmargin}[4em]{0em}
-\begin{SideBySideExample}[xrightmargin=3cm]
- $3\,\mathrm{Cr}_2\mathrm{O}_7^{2-}$
-\end{SideBySideExample}
-\end{addmargin}
-\noindent
-So one would have to write
+\section{Chemical Equations}
-\begin{addmargin}[4em]{0em}
-\begin{SideBySideExample}[xrightmargin=3cm]
- $3\,\mathrm{Cr}_2^{\strut}\mathrm{O}_7^{2-}$
+\begin{SideBySideExample}[xrightmargin=6cm]
+ \ce{CO2 + C -> 2 CO}
\end{SideBySideExample}
-\end{addmargin}
-\noindent
-But this in turn changes the line height. That has to be compensated. And so on and so forth. At the end, you have to write long commands and may be lost eventually, when a formula should appear inside a section header with a different font.
+\begin{SideBySideExample}[xrightmargin=6cm]
+ \ce{Hg^2+ ->[I-] HgI2
+ ->[I-] [Hg^{II}I4]^2-}
+\end{SideBySideExample}
-\bigskip
-\noindent
-mhchem is here to assist you. To mention a few of its features:
-\smallskip
-\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.
+\section{Chemical Formulae}
- \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.)
+\begin{SideBySideExample}[xrightmargin=2.5cm]
+ \ce{H2O}
+\end{SideBySideExample}
- \item Easy input of amount numbers\\
- with automatic spacing; easy input of fractions
+\begin{SideBySideExample}[xrightmargin=2.5cm]
+ \ce{Sb2O3}
+\end{SideBySideExample}
- \item Fine typographic corrections\\
- 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 me end the ad block here and see for yourself how easy it can be to typeset chemical formulae.
+This works in text mode (even in headings) and in math mode. (For PDF bookmarks you might have to specify a text-only version.)
+{
+\let\sffamilyorig\sffamily
+\def\sffamily{\color{mhchem}\sffamilyorig}
+\begin{SideBySideExample}[xrightmargin=5cm]
+ \sffamily\itshape
+ This is text with \ce{H2O} and $\ce{H2O}$.
+\end{SideBySideExample}
+}
-\section{Preamble}
+For how to fine-tune the font usage, see \nameref{sec:FineTuning}.
-\noindent
-In order to use all of mhchem's features, request it in your document's preamble with the command
-\smallskip
+\section{Charges}
-{\Large\verb|\usepackage|{\ttfamily\bfseries [version=3]}\verb|{mhchem}|}
-\marginpar{\Large !}
+\begin{SideBySideExample}[xrightmargin=2.5cm]
+ \ce{H+}
+\end{SideBySideExample}
-\medskip
+\begin{SideBySideExample}[xrightmargin=2.5cm]
+ \ce{CrO4^2-}
+\end{SideBySideExample}
-\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 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}
+\begin{SideBySideExample}[xrightmargin=2.5cm]
+ \ce{[AgCl2]-}
+\end{SideBySideExample}
-\medskip
+\begin{SideBySideExample}[xrightmargin=2.5cm]
+ \ce{Y^99+}
+\end{SideBySideExample}
-\noindent
-mhchem needs a couple of other packages. For instance, expl3, amsmath and calc.
+\begin{SideBySideExample}[xrightmargin=2.5cm]
+ \ce{Y^{99+}}
+\end{SideBySideExample}
+This will work in text mode and math mode. For text, the en-dash will be used as a minus sign.
-\section{Basics}
+\section{Stoichiometric Numbers}
-\noindent
\begin{SideBySideExample}[xrightmargin=2.5cm]
- \ce{H2O}
+ \ce{2H2O}
\end{SideBySideExample}
-\medskip
\begin{SideBySideExample}[xrightmargin=2.5cm]
- \ce{Sb2O3}
+ \ce{2 H2O}
\end{SideBySideExample}
-\medskip
\begin{SideBySideExample}[xrightmargin=2.5cm]
- \ce{H+}
+ \ce{0.5H2O}
\end{SideBySideExample}
-\medskip
\begin{SideBySideExample}[xrightmargin=2.5cm]
- \ce{CrO4^2-}
+ \ce{1/2H2O}
\end{SideBySideExample}
-\medskip
\begin{SideBySideExample}[xrightmargin=2.5cm]
- \ce{[AgCl2]-}
+ \ce{(1/2)H2O} % IUPAC Green Book
\end{SideBySideExample}
-\medskip
+This works in text mode and math mode. (The fraction line always comes from math mode and might appear too small when using bold text fonts.)
+
+
+\section{Isotopes}
+
\begin{SideBySideExample}[xrightmargin=2.5cm]
- \ce{(NH4)2S}
+ \ce{^{227}_{90}Th+}
\end{SideBySideExample}
-\medskip
\begin{SideBySideExample}[xrightmargin=2.5cm]
- \ce{Y^99+}
+ \ce{^227_90Th+}
\end{SideBySideExample}
-\fromversion{3.21}
-\medskip
\begin{SideBySideExample}[xrightmargin=2.5cm]
- \ce{Y^{99+}}
+ \ce{H{}^3HO}
\end{SideBySideExample}
-\medskip
-\begin{SideBySideExample}[xrightmargin=2.5cm]
- \ce{H2(aq)} % IUPAC
+Of course, this works in text mode and math mode.
+
+
+\section{Greek Letters}
+
+Just write \macro{alpha} etc.
+
+\begin{SideBySideExample}[xrightmargin=4cm]
+ \ce{\mu-Cl}
\end{SideBySideExample}
-\medskip
-\begin{SideBySideExample}[xrightmargin=2.5cm]
- \ce{CO3^2-{}_{(aq)}} % not according to IUPAC
+\begin{SideBySideExample}[xrightmargin=4cm]
+ \ce{[Pt(\eta^2-C2H4)Cl3]-}
\end{SideBySideExample}
+This works in text mode and math mode. For the time being, the math font will be used. But for the next release, an improvement is currently in the making.
-\subsection{Amounts}
-Place amounts directly in front of a formula. A small space will be inserted
-automatically.
+\section{Parenthesis, Brackets, Braces}
-\medskip
-\begin{SideBySideExample}[xrightmargin=2cm]
- \ce{2H2O}
-\end{SideBySideExample}
+Use parenthesis \verb|( )| and brackets \verb|[ ]| normally. Write braces as \verb|\{ \}|.
-\medskip
-\begin{SideBySideExample}[xrightmargin=2cm]
- \ce{0.5H2O}
+\begin{SideBySideExample}[xrightmargin=4cm]
+ \ce{(NH4)2S}
\end{SideBySideExample}
-\fromversion{3.13}
-\medskip
-\begin{SideBySideExample}[xrightmargin=2cm]
- \ce{1/2H2O}
+\begin{SideBySideExample}[xrightmargin=4cm]
+ \ce{[\{(X2)3\}2]^3+}
\end{SideBySideExample}
+Small parenthesis etc. work in both, text mode and math mode. Large parenthesis etc. are a math-mode only feature.
-\subsection{Isotopes}
+Both, \macro{left} and \macro{right} macros, need to be in the same math environment, so you might have to put \macro{ce} into \verb|$| into \macro{ce}, but that's fine.
-\begin{SideBySideExample}[xrightmargin=2cm]
- \ce{^{227}_{90}Th+}
+$\displaystyle\ce{CH4 + 2 $\left( \ce{O2 + 79/21 N2} \right)$}$\par
+{\raggedleft\verb|\[\ce{CH4 + 2 $\left( \ce{O2 + 79/21 N2} \right)$}\]|\par}
+
+
+\section{States of Aggregation}
+
+\begin{SideBySideExample}[xrightmargin=4cm]
+ \ce{H2(aq)} % IUPAC recommendation
\end{SideBySideExample}
+\begin{SideBySideExample}[xrightmargin=4cm]
+ \ce{CO3^2-{}_{(aq)}} % not according to IUPAC
+\end{SideBySideExample}
+
+\begin{SideBySideExample}[xrightmargin=4cm]
+ \ce{NaOH(aq,$\infty$)}
+\end{SideBySideExample}
+
+This works in text mode and math mode.
-\subsection{Special Symbols}
+
+\section{Addition Compounds}
\begin{SideBySideExample}[xrightmargin=5cm]
\ce{KCr(SO4)2*12H2O}
\end{SideBySideExample}
-\medskip
\begin{SideBySideExample}[xrightmargin=5cm]
\ce{KCr(SO4)2.12H2O}
\end{SideBySideExample}
-\medskip
-\noindent\ce{[Cd\{SC(NH2)2\}2].[Cr(SCN)4(NH3)2]2}\par
-\noindent\hspace{5cm}\verb|\ce{[Cd\{SC(NH2)2\}2].[Cr(SCN)4(NH3)2]2}|
-
-\medskip
\begin{SideBySideExample}[xrightmargin=5cm]
- $\ce{RNO2^{-.}}$, \ce{RNO2^{-.}}
+ \ce{KCr(SO4)2 * 12 H2O}
\end{SideBySideExample}
-\fromversion{2}
+The centered dot is taken from math font.
-\subsection{Bonds}
-\noindent
-Horizontal \fromversion{2} bonds can be set using the characters \verb|-|, \verb|=| and \verb|#| (single, double, triple bond) inside a formula (a \verb|-| at the end of a formula yields a negative charge).
+\section{Unpaired Electrons, Radical Dots}
-\medskip
+\begin{SideBySideExample}[xrightmargin=3cm]
+ \ce{OCO^{.-}}
+\end{SideBySideExample}
-\begin{SideBySideExample}[xrightmargin=5cm]
- \ce{C6H5-CHO}
+\begin{SideBySideExample}[xrightmargin=3cm]
+ \ce{NO^{(2.)-}}
\end{SideBySideExample}
-\medskip
+This superscript-only feature works in text mode and math mode. A math bullet is used.
-\begin{SideBySideExample}[xrightmargin=5cm]
- \ce{X=Y#Z}
+
+\section{Bonds}
+
+\begin{SideBySideExample}[xrightmargin=3cm]
+ \ce{C6H5-CHO}
\end{SideBySideExample}
-\medskip
+\begin{SideBySideExample}[xrightmargin=3cm]
+ \ce{A-B=C#D}
+\end{SideBySideExample}
-\noindent
-Different books visualise bonds in extremely different ways. Here, the minus sign from the math font is used to display the bonds (even in text mode). The bonds are vertically aligned on the math axis. For most math fonts, this is slightly lower than half the height of a capital letter.
+\begin{SideBySideExample}[xrightmargin=3cm]
+ \sffamily\bfseries
+ \ce{A-B=C#D}
+\end{SideBySideExample}
-\medskip
+mhchem tries to differentiate if \verb|\ce{-}| should be a bond, a charge or even a hyphen.
-\noindent
-The \macro{bond} \fromversion{3} command allows you to typeset special bonds.
+The \verb|#| bond might not work if you pass it through other commands. In this case, use \verb|\bond{3}| instead.
-\medskip
-\begin{SideBySideExample}[xrightmargin=5cm]
+\begin{SideBySideExample}[xrightmargin=3cm]
\ce{A\bond{-}B\bond{=}C\bond{#}D}
\end{SideBySideExample}
-\medskip
-\begin{SideBySideExample}[xrightmargin=5cm]
+\begin{SideBySideExample}[xrightmargin=3cm]
\ce{A\bond{1}B\bond{2}C\bond{3}D}
\end{SideBySideExample}
-\fromversion{3.15}
-\medskip
-\begin{SideBySideExample}[xrightmargin=5cm]
+\mhchemoptions{minus-text-sidebearing-left=0.1em,minus-text-sidebearing-right=0.18em}
+\begin{SideBySideExample}[xrightmargin=3cm]
\ce{A\bond{~}B\bond{~-}C}
\end{SideBySideExample}
-\medskip
-\begin{SideBySideExample}[xrightmargin=5cm]
+\begin{SideBySideExample}[xrightmargin=3cm]
\ce{A\bond{~--}B\bond{~=}C\bond{-~-}D}
\end{SideBySideExample}
-\medskip
-\begin{SideBySideExample}[xrightmargin=5cm]
+\begin{SideBySideExample}[xrightmargin=3cm]
\ce{A\bond{...}B\bond{....}C}
\end{SideBySideExample}
-\medskip
-\begin{SideBySideExample}[xrightmargin=5cm]
+\begin{SideBySideExample}[xrightmargin=3cm]
\ce{A\bond{->}B\bond{<-}C}
\end{SideBySideExample}
-\medskip
-
-\noindent
-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.
-
+Text mode: Line-based bonds are based on the text-font's en-dash. For all the others, math glyphs are used.
-\subsection{Fonts}
+Math mode: Bonds are based on the math-font minus sign. All bonds are vertically aligned on the math axis. For most math fonts, this is slightly lower than half the height of a capital letter.
-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.
+If you switch to another font, the sidebearing of the minus sign may vary, which would cause the dashed bonds to align badly. In that case, adjust the alignment by using the following command with slightly changed values. Use \verb|\mhchemoptions{minus-text-sidebearing-left=0.10em,| \verb|minus-text-sidebearing-right=0.16em}| for text font adjustment and \verb|\mhchemoptions{minus-math-sidebearing-left=0.06em,| \verb|minus-math-sidebearing-right=0.11em}| for math font.
-\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.)
+\section{Using Math, Variables}
-\medskip
+You can `half-escape' to math by using \verb|$...$|. Remember, that the math font might not always match with the text font (e.\,g. in headings).
-\begin{SideBySideExample}[xrightmargin=5cm]
- $V_{\ce{H2O}}$
+\begin{SideBySideExample}[xrightmargin=4cm]
+ $\ce{NaOH(aq,$\infty$)}$\\
+ \sffamily\bfseries
+ \ce{NaOH(aq,$\infty$)}
\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}$.
+\begin{SideBySideExample}[xrightmargin=4cm]
+ $\ce{Fe(CN)_{$\frac{6}{2}$}}$\\
+ \sffamily\bfseries
+ \ce{Fe(CN)_{$\frac{6}{2}$}}
\end{SideBySideExample}
-\medskip
+When `half-escaped', mhchem tries to recognize common patterns and still use the correct font.
-\begin{SideBySideExample}[xrightmargin=5cm]
- £\sffamily
- \ce{Ce^{IV}}, $\ce{Ce^{IV}}$
+\begin{SideBySideExample}[xrightmargin=4cm]
+ $\ce{Fe^$n$+}$ \sffamily\bfseries \ce{Fe^$n$+}
\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.
+You can prevent this recognition by `fully escaping' to math with \verb|${...}$|.
-\subsection{Using Math}
+\begin{SideBySideExample}[xrightmargin=4cm]
+ $\ce{Fe^${n}$+}$ \sffamily\bfseries \ce{Fe^${n}$+}
+\end{SideBySideExample}
-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.
+The same common patterns are also recognized at many places when used without \verb|$...$|.
-\medskip
-\begin{SideBySideExample}[xrightmargin=5cm]
- \ce{$\mu\hyphen$Cl}
+\begin{SideBySideExample}[xrightmargin=4cm]
+ $\ce{Fe^n+}$ \sffamily\bfseries \ce{Fe^$n$+}
\end{SideBySideExample}
-\fromversion{3.05}
-\medskip
-\begin{SideBySideExample}[xrightmargin=5cm]
- \ce{Fe(CN)_{$\frac{6}{2}$}}
+\begin{SideBySideExample}[xrightmargin=4cm]
+ $\ce{NO_$x$}$ \sffamily\bfseries \ce{NO_$x$}
\end{SideBySideExample}
-\medskip
-\noindent\ce{$x\,$ Na(NH4)HPO4 ->[\Delta] (NaPO3)_{$x$} + $x\,$ NH3 ^ + $x\,$ H2O}\par
-\noindent\hspace{5cm}\verb|\ce{$x\,$ Na(NH4)HPO4 ->[\Delta]|\par
-\noindent\hspace{5cm}\verb| (NaPO3)_{$x$} +|\par
-\noindent\hspace{5cm}\verb| $x\,$ NH3 ^ + $x\,$ H2O}|
-
+$\ce{x Na(NH4)HPO4 ->[\Delta] (NaPO3)_x + x NH3 ^ + x H2O}$\par
+{\raggedleft\verb|$\ce{x Na(NH4)HPO4 ->[\Delta] (NaPO3)_x + x NH3 ^ + x H2O}$|\par}
-\section{Formulae}
+\section{Italic Text}
-\subsection{Reaction Arrows}
+With the same mechanism, you can switch to italic font.
-\begin{SideBySideExample}[xrightmargin=5cm]
- \ce{CO2 + C -> 2CO}
+\begin{SideBySideExample}[xrightmargin=4cm]
+ $\ce{$cis${-}[PtCl2(NH3)2]}$\\
+ \sffamily\bfseries
+ \ce{$cis${-}[PtCl2(NH3)2]}
\end{SideBySideExample}
-\medskip
-\begin{SideBySideExample}[xrightmargin=5cm]
- \ce{CO2 + C <- 2CO}
-\end{SideBySideExample}
+Spaces will be ignored. Use a \verb|~| when you need to typeset a space.
-\medskip
-\begin{SideBySideExample}[xrightmargin=5cm]
- \ce{CO2 + C <=> 2CO}
-\end{SideBySideExample}
+This works for the text mode as long as you use latin characters. It also works for math font. Remember, however, that italic math is normally reserved for variables and $cis$ mostly means `product of $c$, $i$, and $s$'.
-\medskip
-%\begin{SideBySideExample}[xrightmargin=5cm]
-% \ce{H+ + OH- <=>> H2O}
-%\end{SideBySideExample}
-\noindent
-\makebox[5cm][l]{\ce{H+ + OH- <=>> H2O}}\verb|\ce{H+ + OH- <=>> H2O}|
-\medskip
-\begin{SideBySideExample}[xrightmargin=5cm]
- \ce{$A$ <-> $A'$}
-\end{SideBySideExample}
+\section{Escape Parsing, Upright Text}
-\medskip
-\begin{SideBySideExample}[xrightmargin=5cm]
- \ce{CO2 + C ->[\alpha] 2CO}
-\end{SideBySideExample}
+If you want to escape parsing, for instance for a simple hyphen, use \verb|{...}|.
-\medskip
-\begin{SideBySideExample}[xrightmargin=5cm]
- \ce{CO2 + C ->[\alpha][\beta] 2CO}
+\begin{SideBySideExample}[xrightmargin=4cm]
+ \ce{{(+)}_589{-}[Co(en)3]Cl3}
\end{SideBySideExample}
-\medskip
-\noindent
-The content above and below reaction arrows is set in math font. When you want to put descriptive text there, use the \macro{text} command. Or, as a shortcut, you could type a `T' between reaction arrow and opening bracket.
+\section{Reaction Arrows}
-\medskip
-\begin{SideBySideExample}[xrightmargin=5cm]
- \ce{CO2 + C ->[\text{above}] 2CO}
-\end{SideBySideExample}
+\makebox[3cm][l]{\ce{A -> B}}\verb|\ce{A -> B}|\\
+\makebox[3cm][l]{\ce{A <- B}}\verb|\ce{A <- B}|\\
+\makebox[3cm][l]{\ce{A <-> B}}\verb|\ce{A <-> B}|\\
+\makebox[3cm][l]{\ce{A <--> B}}\verb|\ce{A <--> B}|\\
+\makebox[3cm][l]{\ce{A <=>> B}}\verb|\ce{A <=>> B}|\\
+\makebox[3cm][l]{\ce{A <<=> B}}\verb|\ce{A <<=> B}|
-\medskip
-\begin{SideBySideExample}[xrightmargin=5cm]
- \ce{CO2 + C
- ->[\text{above}][\text{below}] 2CO}
-\end{SideBySideExample}
+The arrow arguments use the same syntax as the \macro{ce} command.
-\medskip
-\begin{SideBySideExample}[xrightmargin=5cm]
- \ce{CO2 + C ->T[above][below] 2CO}
+\begin{SideBySideExample}[xrightmargin=3cm]
+ \ce{A ->[H2O] B}
\end{SideBySideExample}
-\medskip
-
-\noindent
-Similarly, there is a shortcut for using \macro{ce} with reaction arrows:
-
-\medskip
-\begin{SideBySideExample}[xrightmargin=5cm]
- \ce{$A$ ->[\ce{+H2O}] $B$}
+\begin{SideBySideExample}[xrightmargin=3cm]
+ \ce{A ->[{text above}][{text below}] B}
\end{SideBySideExample}
-\medskip
-\begin{SideBySideExample}[xrightmargin=5cm]
- \ce{$A$ ->C[+H2O] $B$}
+\begin{SideBySideExample}[xrightmargin=3cm]
+ \ce{A ->[$x_i$] B}
\end{SideBySideExample}
+For how to can change the layout of the arrows, see \nameref{sec:FineTuning}.
-\subsection{Precipitate and Gas}
-\noindent Use \verb|v| or \verb|(v)| for precipitate (arrow down) and \verb|^| or \verb|(^)| for gas (arrow up), all of them separated by spaces.
+\section{Precipitate and Gas}
-\medskip
-\begin{SideBySideExample}[xrightmargin=7cm]
+\begin{SideBySideExample}[xrightmargin=6cm]
\ce{SO4^2- + Ba^2+ -> BaSO4 v}
\end{SideBySideExample}
-
-\subsection{Large Parenthesis}
-
-Both, \verb|\left| and \verb|\right| macros, need to be in the same math environment, so you might have to put \verb|$| into \verb|\ce| into \verb|$| into \verb|\ce|, but that's fine.
-
-\begin{Example}[xrightmargin=15cm]
- \[\ce{CH4 + 2 $\left( \ce{O2 + $\frac{79}{21}\,$ N2} \right)$}\]
-\end{Example}
-\fromversion{3.18}
+\begin{SideBySideExample}[xrightmargin=6cm]
+ \ce{A v B (v) -> B ^ B (^)}
+\end{SideBySideExample}
-\subsection{Further Examples}
+\section{Further Examples}
\begin{Example}[xrightmargin=15cm]
\ce{Zn^2+
- <=>[\ce{+ 2OH-}][\ce{+ 2H+}]
+ <=>[+ 2OH-][+ 2H+]
$\underset{\text{amphoteres Hydroxid}}{\ce{Zn(OH)2 v}}$
- <=>C[+2OH-][{+ 2H+}]
+ <=>[+ 2OH-][+ 2H+]
$\underset{\text{Hydroxozikat}}{\ce{[Zn(OH)4]^2-}}$
}
\end{Example}
-\fromversion{3.05}
-
-\bigskip
\begin{Example}[xrightmargin=5cm]
$K = \frac{[\ce{Hg^2+}][\ce{Hg}]}{[\ce{Hg2^2+}]}$
\end{Example}
-\medskip
\begin{Example}[xrightmargin=5cm]
- \ce{Hg^2+ ->[\ce{I-}]
+ \ce{Hg^2+ ->[I-]
$\underset{\mathrm{red}}{\ce{HgI2}}$
- ->C[I-]
+ ->[I-]
$\underset{\mathrm{red}}{\ce{[Hg^{II}I4]^2-}}$
}
\end{Example}
-\fromversion{3.05}
-\section[Equation Environments]{Equation Environments\fromversion{2}}
+
+\section{Equation Environments}
+
+\subsection{Aligning Equations}
+
+You can use \verb|&| and \verb|\\| inside \macro{ce} to align equations.
+
+\begin{SideBySideExample}[xrightmargin=5cm]
+ \begin{align*}
+ \ce{RNO2 &<=>[+e] RNO2^{-.} \\
+ RNO2^{-.} &<=>[+e] RNO2^2-}
+ \end{align*}
+\end{SideBySideExample}
+
\subsection{Own Equation Command}
@@ -559,21 +514,17 @@ When you use equation environments containing a \macro{ce} very often, you might
{\begin{equation*}\ce{#1}\end{equation*}}
\end{Verbatim}
-\noindent
and then use them as follows.
+\newcommand\reaction[1]{\begin{equation}\ce{#1}\end{equation}}
+\newcommand\reactionnonumber[1]%
+ {\begin{equation*}\ce{#1}\end{equation*}}
\begin{SideBySideExample}[xrightmargin=5cm]
- £\newcommand\reaction[1]{\begin{equation}\ce{#1}\end{equation}}
- £\newcommand\reactionnonumber[1]%
- £ {\begin{equation*}\ce{#1}\end{equation*}}
\reaction{CO2 + C}
\reactionnonumber{CO2 + C}
\end{SideBySideExample}
-\bigskip
-
-\noindent
-The advanced \LaTeX\ user could replace the two definitions by
+The advanced \LaTeX\ user could replace the two definitions by one
\begin{Verbatim}
\makeatletter
\newcommand\reaction@[1]{\begin{equation}\ce{#1}\end{equation}}
@@ -582,26 +533,25 @@ The advanced \LaTeX\ user could replace the two definitions by
\newcommand\reaction{\@ifstar{\reaction@nonumber}{\reaction@}}
\makeatother
\end{Verbatim}
+
and then write
+
+\makeatletter
+ \newcommand\reaction@[1]{\begin{equation}\ce{#1}\end{equation}}
+ \newcommand\reaction@nonumber[1]%
+ {\begin{equation*}\ce{#1}\end{equation*}}
+ \renewcommand\reaction{\@ifstar{\reaction@nonumber}{\reaction@}}
+\makeatother
\begin{SideBySideExample}[xrightmargin=5cm]
- £\makeatletter
- £ \newcommand\reaction@[1]{\begin{equation}\ce{#1}\end{equation}}
- £ \newcommand\reaction@nonumber[1]%
- £ {\begin{equation*}\ce{#1}\end{equation*}}
- £ \newcommand\reaction{\@ifstar{\reaction@nonumber}{\reaction@}}
- £\makeatother
\reaction{CO2 + C}
\reaction*{CO2 + C}
\end{SideBySideExample}
-\smallskip
-
-\noindent
for the same result.
\minisec{}
-So far, so good. All reactions will be labelled exactly as all the equations. A few people asked for a diffent set of numbers for equations and reactions. One could use this code:
+So far, so good. All reactions will be labelled exactly as all the equations. A few people asked for a \emph{different} set of numbers for equations and reactions. One could use this code:
\begin{Verbatim}
\makeatletter
@@ -626,30 +576,29 @@ So far, so good. All reactions will be labelled exactly as all the equations. A
\makeatother
\end{Verbatim}
-\noindent
With that, all reactions will be labelled independently of the equations.
+\makeatletter
+\newcounter{reaction}
+%%% >> for article <<
+%\renewcommand\thereaction{C\,\arabic{reaction}}
+%%% << for article <<
+%%% >> for report and book >>
+\renewcommand\thereaction{C\,\thechapter.\arabic{reaction}}
+\@addtoreset{reaction}{chapter}
+%%% << for report and book <<
+\newcommand\reactiontag%
+ {\refstepcounter{reaction}\tag{\thereaction}}
+\renewcommand\reaction@[2][]%
+ {\begin{equation}\ce{#2}%
+ \ifx\@empty#1\@empty\else\label{#1}\fi%
+ \reactiontag\end{equation}}
+\renewcommand\reaction@nonumber[1]%
+ {\begin{equation*}\ce{#1}\end{equation*}}
+\renewcommand\reaction%
+ {\@ifstar{\reaction@nonumber}{\reaction@}}
+\makeatother
\begin{SideBySideExample}[xrightmargin=6.5cm]
- £\makeatletter
- £\newcounter{reaction}
- £%%% >> for article <<
- £%\renewcommand\thereaction{C\,\arabic{reaction}}
- £%%% << for article <<
- £%%% >> for report and book >>
- £\renewcommand\thereaction{C\,\thechapter.\arabic{reaction}}
- £\@addtoreset{reaction}{chapter}
- £%%% << for report and book <<
- £\newcommand\reactiontag%
- £ {\refstepcounter{reaction}\tag{\thereaction}}
- £\newcommand\reaction@[2][]%
- £ {\begin{equation}\ce{#2}%
- £ \ifx\@empty#1\@empty\else\label{#1}\fi%
- £ \reactiontag\end{equation}}
- £\newcommand\reaction@nonumber[1]%
- £ {\begin{equation*}\ce{#1}\end{equation*}}
- £\newcommand\reaction%
- £ {\@ifstar{\reaction@nonumber}{\reaction@}}
- £\makeatother
\begin{equation}a+b\end{equation}
\reaction{CO2 + C}
\reaction*{CO2 + C}
@@ -658,107 +607,89 @@ With that, all reactions will be labelled independently of the equations.
\end{SideBySideExample}
-\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.
-
-\medskip
-\begin{SideBySideExample}[xrightmargin=5cm]
- \begin{align*}
- \cee{RNO2 &<=>C[+e] RNO2^{-.} \\
- RNO2^{-.} &<=>C[+e] RNO2^2-}
- \end{align*}
-\end{SideBySideExample}
-
-
-\section[Splitting the \macro{ce} command]{Splitting the \macro{ce} command\fromversion{3.21}}
+\section{Splitting the \macro{ce} command}
-\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}}|.
+You could re-define \macro{ce} with \verb|\newcommand*\ce{\cesplit{...}{#1}}|, if you do not like to create a new name.
\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*\stackhyphen{\text{-}\allowbreak}
\newcommand\stack[1]{%
\cesplit{%
{\/}{\c{stackslash}}%
- {-}{\c{stackdash}}%
+ {-}{\c{stackhyphen}}%
}{#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.
+\subsection{The Details}
+
+\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 further details, refer to the \verb|l3regex| manual.
+
+Do not nest \macro{cesplit} commands.
+The result of \macro{cesplit} does \emph{not} have the feature to use \verb|&| and \verb|\\| as you might to want to deal with them differently. \macro{ce} is itself defined by \macro{cesplit} (which, technically speaking, does not split \macro{ce}, but an internal command). As \macro{ce} is defined by
+\begin{Verbatim}
+ \cesplit % spaced added for readability
+ {
+ { \c{\\}(\[.*?\])? } { \0 }
+ { \& } { \0 }
+ }
+ {#1}
+\end{Verbatim}
-\section{Fine Tuning}
+you could add these rules to you own \macro{cesplit} definition.
-In this section, several option switches will be explained. You can use them in the form
-\begin{Verbatim}[commandchars=+\[\]]
- \mhchemoptions{+textbf[option=abc]}
+
+\section{Fine Tuning}\label{sec:FineTuning}
+
+All options explained here, can either be set using the \macro{mhchemoptions} command
+
+\begin{Verbatim}
+ \mhchemoptions{arrows=pgf}
\end{Verbatim}
-\noindent
-All options can also be used in the \macro{usepackage} command in your preamble, like
+or as options to the package
\begin{Verbatim}[commandchars=+()]
- \usepackage[version=3,+textbf(option=abc)]{mhchem}
+ \usepackage[version=4,arrows=pgf]{mhchem}
\end{Verbatim}
\subsection{Fonts} \label{sec:Fonts}
-As mentioned previously, mhchem uses the current text font (if you use \macro{ce} in text mode) or the current math font (if you use \macro{ce} in math mode). If you want, however, you can set a font that will be used for all your formulae and equations.
+mhchem uses the current text font (if you use \macro{ce} in text mode) or the current math font (if you use \macro{ce} in math mode). If you want, however, you can set a font that will be used for all your formulae and equations.
-\medskip
-
-\noindent
Inside your document, you can use
\begin{Verbatim}[commandchars=+\[\]]
@@ -766,8 +697,11 @@ Inside your document, you can use
\mhchemoptions{+textbf[mathfontcommand=\mathsf]}
\end{Verbatim}
-\noindent
-in order to get sanf-serif fonts in both, text mode and math mode. There are two further options, that basically do the same, but only take the name of a single font command without the initial backslash.
+in order to get sanf-serif fonts in both, text mode and math mode.
+
+You can use any font command there, not only the mentioned ones. Please be aware that the text-font command is a font switching command (taking no arguments) while the math-font command takes one argument and typesets it.
+
+You can specify the commands by name only, i.\,e. without the \verb|\|.
\begin{Verbatim}[commandchars=+\[\]]
\mhchemoptions{+textbf[textfontname=sffamily]}
@@ -775,25 +709,18 @@ 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, because the font commands are not properly defined in the preamble, yet.
-
-\medskip
-
-\noindent
-Furthermore, there are two shortcuts:
+Only the latter options can be used with the \macro{usepackage} command, because the font commands are not properly defined in the preamble, yet. The shortcut
\begin{Verbatim}[commandchars=+\[\]]
\mhchemoptions{+textbf[font=sf]}
\end{Verbatim}
-\noindent
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 equivalent to
\begin{Verbatim}[commandchars=+\[\]]
@@ -803,61 +730,48 @@ switches back to the default, which is equivalent to
\subsection{Arrows}
-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
+By default, mhchem uses arrows that are composed of different math-font characters, because it uses some features of the amsmath package. This may lead to undesirable effects when displayed 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=+\[\]]
+\begin{Verbatim}[commandchars=+()]
\usepackage[version=3,+textbf(arrows=pgf)]{mhchem}
\end{Verbatim}
-\noindent
-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]}
-\end{Verbatim}
-
-\noindent
-Here is how it looks:
+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.)
\medskip
-\begin{SideBySideExample}[xrightmargin=5cm]
- \mhchemoptions{arrows=font}%
- \ce{$A$ <->T[description] $A'$}
+\begin{SideBySideExample}[xrightmargin=3cm]
+ \mhchemoptions{arrows=font}% default
+ \ce{A <-> B}
\end{SideBySideExample}
\medskip
-\begin{SideBySideExample}[xrightmargin=5cm]
- \mhchemoptions{arrows=pgf}%
- \ce{$A$ <->T[description] $A'$}
+\begin{SideBySideExample}[xrightmargin=3cm]
+ \mhchemoptions{arrows=pgf}
+ \ce{A <-> B}
\end{SideBySideExample}
-\subsubsection{Arrow Tips}
-
-If you do not like the standard LaTeX arrows (or the ones of your current math font, respectively), here is the option for you:
-
-\begin{Verbatim}[commandchars=+\[\]]
- \mhchemoptions{+textbf[arrows=pgf-filled]}
-\end{Verbatim}
-
-\noindent
-The same considerations as for the \verb|pgf| option apply.
-
-\medskip
-\begin{SideBySideExample}[xrightmargin=5cm]
+\begin{SideBySideExample}[xrightmargin=3cm]
\mhchemoptions{arrows=pgf-filled}
- \ce{$A$ <->T[description] $A'$}
+ \ce{A <-> B}
\end{SideBySideExample}
-\subsection{Stacked Superscripts}
+\subsection{Stacked Superscripts and Subscripts}
+
+\begin{SideBySideExample}[xrightmargin=3cm]
+ \mhchemoptions{layout=staggered-flat}% default
+ \ce{CrO4^2-}
+\end{SideBySideExample}
-If you do not like the IUPAC recommendation, you could switch to stacked superscripts
+\begin{SideBySideExample}[xrightmargin=3cm]
+ \mhchemoptions{layout=staggered-deep}
+ \ce{CrO4^2-}
+\end{SideBySideExample}
-\medskip
-\begin{SideBySideExample}[xrightmargin=5cm]
- \ce{CrO4^2-}\\
- \mhchemoptions{superscripts=stacked} \ce{CrO4^2-}
+\begin{SideBySideExample}[xrightmargin=3cm]
+ \mhchemoptions{layout=stacked}
+ \ce{CrO4^2-}% not according to IUPAC
\end{SideBySideExample}
@@ -866,18 +780,30 @@ If you do not like the IUPAC recommendation, you could switch to stacked supersc
\section{Major Changes}
\label{sec:WhatSNew}
-\subsection{Migration from version 1}
+\subsection{Migrating from version 1}
-Inner \verb|-| characters are considered to be bonds.\\
-Use \verb|$| for math mode inside \macro{ce} (no braces any more).
+Inner \verb|-| characters are considered to be bonds. Use \verb|$...$| for math mode inside \macro{ce} (no braces any more).
\subsection{Migrating from version 2}
Meaning and usage of \macro{bond} changed.
+\subsection{Migrating from version 3}
+
+\verb|{...}| does escape to text now, not math. \verb|$...$| does only `half-escape' to math---check the results. Additional spaces will be inserted: A \verb|$x\,$H2O| should be changed to \verb|$x$ H2O|. Appearance of bonds, radical dot, $x$, single-letter variables, \verb|-| in subscripts etc. slightly changed---check if this fits with your font, in particular your text font. Check all complex subscripts and superscripts (more than just number or a charge). The arrow arguments are set with the same syntax as the \macro{ce} command---use \verb|$...$| or \verb|${...}$| for math. Deprecated commands like \macro{cf}, \verb|,| and \verb|`| and \macro{hyphen} and \macro{cmath} were removed completely. \macro{cee} was removed---just use \macro{ce}.
+
\section{Most Recent Changes}% check
+\minisec{2015-04-07 mhchem v4.00}
+\begin{compactitem}
+\item many syntax improvements
+\item many layout improvements
+\item stricter distinction between text font and math font, many math features are translated into their text equivalent, e.g. italic variables
+\item new options
+\item some removed commands
+\end{compactitem}
+
\minisec{2015-03-13 mhchem v3.21}
\begin{compactitem}
\item rewrote further large parts using \LaTeX3
@@ -899,58 +825,13 @@ Meaning and usage of \macro{bond} changed.
\item several fixes for text above and below arrows
\end{compactitem}
-\minisec{2014-03-27 mhchem v3.17}
-\begin{compactitem}
-\item fix of the 3.16 expansion fix -- sorry, my quality control failed
-\end{compactitem}
-
-\minisec{2014-03-20 mhchem v3.16}
-\begin{compactitem}
-\item fix: \verb|\bond| not expanded too early -- thanks to Heiko Oberdiek
-\item fix: \verb|\cee| understands \verb|\\[10pt]| -- thanks to David Carlisle
-\end{compactitem}
-
-\minisec{2014-02-01 mhchem v3.15}
-\begin{compactitem}
-\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}
-
-\minisec{2013-06-23 mhchem v3.13}
-\begin{compactitem}
-\item compatibility with many more babel languages
-\item fraction possible in amounts (\verb|\ce{0.5H2O}|)
-\end{compactitem}
-
-\minisec{2013-06-17 mhchem v3.12}
-\begin{compactitem}
-\item fixed: incompatibility with babel Czech
-\item major internal refactorings
-\end{compactitem}
-
-\minisec{2011-06-03 mhchem v3.11}
-\begin{compactitem}
-\item fixed: incompatibility with mathdesign and other font-related packages
-\end{compactitem}
-
-\minisec{2011-04-29 mhchem v3.10}
-\begin{compactitem}
-\item fixed: incompatibility with biblatex
-\end{compactitem}
-
-\minisec{2011-03-18 mhchem v3.09}
-\begin{compactitem}
- \item fixed: \verb|_{$x$}| now works properly
-\end{compactitem}
-
\chapter{The hpstatement Package and the rsphrase Package}\label{sec:rsphrase}
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)
+Globally Harmonized System of Classification and Labelling of Chemicals (GHS)
and of the CLP Regulation of the European Union.
The statements are available in
@@ -972,13 +853,13 @@ Latvian,
Lithuanian,
Maltese,
Polish,
-Portugese,
+Portuguese,
Romanian,
Slovak,
Slovenian,
Spanish or
Swedish,
-and would like to help offering the statments in those languages, please contact me.
+and would like to help offering the statements in those languages, please contact me.
\bigskip
@@ -996,7 +877,7 @@ Please be advised that, as stated in the license, the authors provide no warrant
\section{Usage}
The \textbf{hpstatement} package provides two commands: \verb|\hpstatement| and
-\verb|\hpnumber|. \verb|\hpstatement| insterts the statement's text,
+\verb|\hpnumber|. \verb|\hpstatement| inserts the statement's text,
\verb|\hpnumber| it's formatted number.\bigskip
\begin{addmargin}[1em]{0em}
diff --git a/Master/texmf-dist/tex/latex/mhchem/mhchem.sty b/Master/texmf-dist/tex/latex/mhchem/mhchem.sty
index 571c78dda85..f2940915438 100644
--- a/Master/texmf-dist/tex/latex/mhchem/mhchem.sty
+++ b/Master/texmf-dist/tex/latex/mhchem/mhchem.sty
@@ -27,77 +27,26 @@
% This work consists of all files listed in manifest.txt.
%
%
-\ProvidesPackage{mhchem}[2015/03/13 v3.21 for typesetting chemical formulae]
+\ProvidesPackage{mhchem}[2015/04/07 v4.00 for typesetting chemical formulae]
\RequirePackage{expl3}
\RequirePackage{l3keys2e}
\RequirePackage{l3regex}
\RequirePackage{calc}[1998/07/07]
\RequirePackage{amsmath}
\RequirePackage{graphics}
-\RequirePackage{ifthen} %
+\RequirePackage{ifthen}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%% misc %%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\DeclareMathSymbol{\mhchem@hyphen}{0}{operators}{45}
-\def\mhchem@END{\mhchem@END}
\def\mhchem@macro{}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%% \cee %%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-\ExplSyntaxOn
-
-\newcommand*{\cee}[1]
- {
- \cesplit
- {
- { \c{\\}(\[.*?\])? } { \0 }
- { \& } { \0 }
- }
- {#1}
- }
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%% \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}%
}
@@ -105,9 +54,19 @@
\ExplSyntaxOn
\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 }
\cs_generate_variant:Nn \str_case:nnn { Vnn }
+\cs_generate_variant:Nn \regex_match:nnTF { nV }
+\cs_generate_variant:Nn \regex_match:nnTF { no }
+\cs_new_protected:Npn \__mhchem_regex_peek:nTF #1 #2 #3
+ {
+ \peek_catcode:NTF ##
+ {#3}
+ {
+ \regex_match:noTF
+ { \A the\ (character|letter)\ (#1) \Z }
+ { \token_to_meaning:N \l_peek_token } {#2} {#3}
+ }
+ }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%% loop helpers %%%%%%%%%%
@@ -123,26 +82,49 @@
\tl_put_right:Nn #1 { { #3 } }
#2
}
+\cs_new_protected:Npn \__mhchem_loopHelper_appendNextGroup_prefix_ifEmpty:NnnNn #1#2#3#4#5
+ {
+ \str_if_eq:nnTF {#5} {}
+ { #3 }
+ { \tl_put_right:Nn #1 { #2 { #5 } } }
+ #4
+ }
\cs_new_protected:Npn \__mhchem_loopHelper_appendMathA:NNw #1#2#3$
{
\tl_put_right:Nn #1 { $ #3 $ }
#2
}
-\cs_new_protected:Npn \__mhchem_loopHelper_appendMathB:NNw #1#2#3$
+\cs_new_protected:Npn \__mhchem_loopHelper_appendMathAAsGroup:NNw #1#2#3$
{
- \tl_put_right:Nn #1 { \text { \ensuremath { #3 } } }
+ \tl_put_right:Nn #1 { $ { #3 } $ }
#2
}
-\cs_new_protected:Npn \__mhchem_loopHelper_appendMathAsGroup:NNw #1#2#3$
+\cs_new_protected:Npn \__mhchem_loopHelper_appendMathB:nn #1#2
+ {
+ \peek_catcode:NTF \c_group_begin_token
+ {
+ \__mhchem_loopHelper_appendMathB_aux_group:ccw
+ {#1}
+ {#2}
+ }
+ {
+ \__mhchem_loopHelper_appendMathB_aux:ccw
+ {#1}
+ {#2}
+ }
+ }
+\cs_new_protected:Npn \__mhchem_loopHelper_appendMathB_aux:NNw #1#2#3$
{
- \tl_put_right:Nn #1 { \text { \ensuremath { #3 } } }
+ \tl_put_right:Nn #1 { \__mhchem_cg_withinMathTokens:n { #3 } }
#2
}
-\cs_new_protected:Npn \__mhchem_loopHelper_appendNextTokenAsMathrm:NNn #1#2#3
+\cs_generate_variant:Nn \__mhchem_loopHelper_appendMathB_aux:NNw {ccw}
+\cs_new_protected:Npn \__mhchem_loopHelper_appendMathB_aux_group:NNw #1#2#3$
{
- \tl_put_right:Nn #1 { \ensuremath { \mathrm { #3 } } }
+ \tl_put_right:Nn #1 { \__mhchem_cg_withinMathTokens:n { { #3 } } }
#2
}
+\cs_generate_variant:Nn \__mhchem_loopHelper_appendMathB_aux_group:NNw {ccw}
\cs_new_protected:Npn \__mhchem_loopHelper_ignoreNextToken:Nn #1#2
{
#1
@@ -173,7 +155,7 @@
\fi
}
\expandafter\newcommand\csname ce \endcsname[1]{%
- \mhchem@ce{#1}%
+ \mhchem@cee{#1}%
}
% unexpanded protect
\def\protect@unexpand@cmd@arg#1\else#2\fi\fi\fi#3{%
@@ -198,93 +180,248 @@
%%%%%%%%%%
%%% /\ %%%
+%%%%%%%%%%%%%%%%%%%%%%%%%5%%%%%%%%
+%%%%%%%%%% \cesplit %%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%5%%%%%%%
\ExplSyntaxOn
-\msg_new:nnn { mhchem } { ce/unexpected-state }
+
+\cs_generate_variant:Nn \regex_replace_all:nnN { VnN }
+\bool_new:N \l__mhchem_cesplit_odd_bool
+
+\newcommand\cesplit[2]
{
- Assertion~failed:~Unexpected~internal~state~'#1' (ce).~You~found~a~bug.~
- Please~contact~the~package~author.
+ \bool_set_true:N \l__mhchem_cesplit_odd_bool
+ \tl_set:Nn \l_tmpa_tl { \__mhchem_ce:n {#2} }
+
+ \tl_map_inline:nn {#1}
+ {
+ \bool_if:NTF \l__mhchem_cesplit_odd_bool
+ {
+ \tl_set:Nn \__mhchem_cesplit_key_tl {##1}
+ \bool_set_false:N \l__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 \l__mhchem_cesplit_odd_bool
+ }
+ }
+ \tl_use:N \l_tmpa_tl
}
-\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
-\tl_new:N \__mhchem_ce_arrowTypeOne_tl
-\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
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%% \cee %%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\newcommand*\mhchem@ce[1]{
- \__mhchem_ce:n {#1}
+\newcommand*\mhchem@cee[1]{
+ \__mhchem_cee:n {#1}
}
+
+\ExplSyntaxOn
+\cs_new_protected:Npn \__mhchem_cee:n #1
+ {
+ \cesplit
+ {
+ { \c{\\}(\[.*?\])? } { \0 }
+ { \& } { \0 }
+ }
+ {#1}
+ }
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%% \__mhchem_ce:n %%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\msg_new:nnn { mhchem } { ce / unexpected-state }
+ {
+ Assertion~failed:~Unexpected~internal~state~'#1' (ce).~You~found~a~bug.~
+ Please~contact~the~package~author.
+ }
+\bool_new:N \l__mhchem_ce_ceActive_bool
+\bool_set_false:N \l__mhchem_ce_ceActive_bool
+\tl_new:N \l__mhchem_ce_state_tl
+
+\int_new:N \l__mhchem_ce_distanceFromLastComma_int
+\tl_new:N \l__mhchem_ce_result_tl
+\tl_new:N \l__mhchem_ce_part_tl
+\tl_new:N \l__mhchem_ce_arrowName_tl
+\tl_new:N \l__mhchem_ce_arrowTypeOne_tl
+\tl_new:N \l__mhchem_ce_arrowTextOne_tl
+\tl_new:N \l__mhchem_ce_arrowTypeTwo_tl
+\tl_new:N \l__mhchem_ce_arrowTextTwo_tl
+\bool_new:N \l__mhchem_ce_potentialSpacing_bool
+\bool_new:N \l__mhchem_ce_potentialSpacing_future_bool
+
\cs_new_protected:Npn \__mhchem_ce:n #1
{
\group_begin:
- \bool_if:NF \__mhchem_cf_cfActive_bool
+ \mhchem@hook@beforeCe
+ \bool_if:NF \l__mhchem_ce_ceActive_bool
{
- \bool_set_true:N \__mhchem_cf_cfActive_bool
- \__mhchem_defMathOrText:
+ \bool_set_true:N \l__mhchem_ce_ceActive_bool
+ \__mhchem_output_defMathOrText:
+ \def\hyphen{\mhchem@hyphen}%
+ \let\mhchem@orig@alpha\alpha
+ \let\mhchem@orig@beta\beta
+ \let\mhchem@orig@gamma\gamma
+ \let\mhchem@orig@delta\delta
+ \let\mhchem@orig@epsilon\epsilon
+ \let\mhchem@orig@zeta\zeta
+ \let\mhchem@orig@eta\eta
+ \let\mhchem@orig@theta\theta
+ \let\mhchem@orig@iota\iota
+ \let\mhchem@orig@kappa\kappa
+ \let\mhchem@orig@lambda\lambda
+ \let\mhchem@orig@mu\mu
+ \let\mhchem@orig@nu\nu
+ \let\mhchem@orig@xi\xi
+ \let\mhchem@orig@omicron\omicron
+ \let\mhchem@orig@pi\pi
+ \let\mhchem@orig@rho\rho
+ \let\mhchem@orig@sigma\sigma
+ \let\mhchem@orig@tau\tau
+ \let\mhchem@orig@upsilon\upsilon
+ \let\mhchem@orig@phi\phi
+ \let\mhchem@orig@chi\chi
+ \let\mhchem@orig@psi\psi
+ \let\mhchem@orig@omega\omega
+ \let\mhchem@orig@Alpha\Alpha
+ \let\mhchem@orig@Beta\Beta
+ \let\mhchem@orig@Gamma\Gamma
+ \let\mhchem@orig@Delta\Delta
+ \let\mhchem@orig@Epsilon\Epsilon
+ \let\mhchem@orig@Zeta\Zeta
+ \let\mhchem@orig@Eta\Eta
+ \let\mhchem@orig@Theta\Theta
+ \let\mhchem@orig@Iota\Iota
+ \let\mhchem@orig@Kappa\Kappa
+ \let\mhchem@orig@Lambda\Lambda
+ \let\mhchem@orig@Mu\Mu
+ \let\mhchem@orig@Nu\Nu
+ \let\mhchem@orig@Xi\Xi
+ \let\mhchem@orig@Omicron\Omicron
+ \let\mhchem@orig@Pi\Pi
+ \let\mhchem@orig@Rho\Rho
+ \let\mhchem@orig@Sigma\Sigma
+ \let\mhchem@orig@Tau\Tau
+ \let\mhchem@orig@Upsilon\Upsilon
+ \let\mhchem@orig@Phi\Phi
+ \let\mhchem@orig@Chi\Chi
+ \let\mhchem@orig@Psi\Psi
+ \let\mhchem@orig@Omega\Omega
+ \def\alpha{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@alpha}}
+ \def\beta{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@beta}}
+ \def\gamma{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@gamma}}
+ \def\delta{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@delta}}
+ \def\epsilon{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@epsilon}}
+ \def\zeta{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@zeta}}
+ \def\eta{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@eta}}
+ \def\theta{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@theta}}
+ \def\iota{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@iota}}
+ \def\kappa{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@kappa}}
+ \def\lambda{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@lambda}}
+ \def\mu{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@mu}}
+ \def\nu{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@nu}}
+ \def\xi{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@xi}}
+ \def\omicron{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@omicron}}
+ \def\pi{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@pi}}
+ \def\rho{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@rho}}
+ \def\sigma{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@sigma}}
+ \def\tau{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@tau}}
+ \def\upsilon{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@upsilon}}
+ \def\phi{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@phi}}
+ \def\chi{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@chi}}
+ \def\psi{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@psi}}
+ \def\omega{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@omega}}
+ \def\Alpha{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@Alpha}}
+ \def\Beta{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@Beta}}
+ \def\Gamma{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@Gamma}}
+ \def\Delta{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@Delta}}
+ \def\Epsilon{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@Epsilon}}
+ \def\Zeta{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@Zeta}}
+ \def\Eta{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@Eta}}
+ \def\Theta{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@Theta}}
+ \def\Iota{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@Iota}}
+ \def\Kappa{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@Kappa}}
+ \def\Lambda{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@Lambda}}
+ \def\Mu{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@Mu}}
+ \def\Nu{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@Nu}}
+ \def\Xi{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@Xi}}
+ \def\Omicron{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@Omicron}}
+ \def\Pi{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@Pi}}
+ \def\Rho{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@Rho}}
+ \def\Sigma{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@Sigma}}
+ \def\Tau{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@Tau}}
+ \def\Upsilon{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@Upsilon}}
+ \def\Phi{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@Phi}}
+ \def\Chi{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@Chi}}
+ \def\Psi{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@Psi}}
+ \def\Omega{\__mhchem_output_escapeToItalicMath:n{\mhchem@orig@Omega}}
}
- \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 }
+ \tl_clear:N \l__mhchem_ce_result_tl
+ \tl_clear:N \l__mhchem_ce_part_tl
+ \tl_set:Nn \l__mhchem_ce_state_tl { c }
+ \bool_set_false:N \l__mhchem_ce_potentialSpacing_bool
+ \int_set:Nn \l__mhchem_ce_distanceFromLastComma_int { 9 }
+ \tl_clear:N \l__mhchem_cf_lastElement_tl
\__mhchem_ce_loop: #1 \q_recursion_stop
- \int_compare:nTF { \__mhchem_option_version_int > 1 }
- { \tl_use:N \__mhchem_ce_result_tl }
- { \ensuremath{\tl_use:N \__mhchem_ce_result_tl} }
+ \int_compare:nTF { \l__mhchem_option_version_int > 1 }
+ { \tl_use:N \l__mhchem_ce_result_tl }
+ { \ensuremath{\tl_use:N \l__mhchem_ce_result_tl} }
+ \mhchem@hook@afterCe
\group_end:
}
\cs_new_protected:Npn \__mhchem_ce_loop:
{
- \str_case:Vnn \__mhchem_ce_state_tl
+ \int_incr:N \l__mhchem_ce_distanceFromLastComma_int
+ \str_case:Vnn \l__mhchem_ce_state_tl
{
{ c }
{
- \str_case:Vnn \__mhchem_ce_part_tl
+ \str_case:Vnn \l__mhchem_ce_part_tl
{
{ + }
{
- \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 }
+ \tl_put_right:Nn \l__mhchem_ce_result_tl { \__mhchem_output_operatorPlus: }
+ \tl_clear:N \l__mhchem_ce_part_tl
+ \tl_set:Nn \l__mhchem_ce_state_tl { a-end }
}
{ -> }
{
- \tl_set:Nn \__mhchem_ce_arrowName_tl { yields }
+ \tl_set:Nn \l__mhchem_ce_arrowName_tl { yields }
\__mhchem_ce_loop_startArrow:
}
{ <- }
{
- \tl_set:Nn \__mhchem_ce_arrowName_tl { yieldsLeft }
+ \tl_set:Nn \l__mhchem_ce_arrowName_tl { yieldsLeft }
\__mhchem_ce_loop_startArrow:
}
{ <--> }
{
- \tl_set:Nn \__mhchem_ce_arrowName_tl { yieldsLeftRight }
+ \tl_set:Nn \l__mhchem_ce_arrowName_tl { yieldsLeftRight }
\__mhchem_ce_loop_startArrow:
}
{ <-> }
{
- \tl_set:Nn \__mhchem_ce_arrowName_tl { mesomerism }
+ \tl_set:Nn \l__mhchem_ce_arrowName_tl { mesomerism }
\__mhchem_ce_loop_startArrow:
}
{ <=> }
{
- \tl_set:Nn \__mhchem_ce_arrowName_tl { equilibrium }
+ \tl_set:Nn \l__mhchem_ce_arrowName_tl { equilibrium }
\__mhchem_ce_loop_startArrow:
}
{ <<=> }
{
- \tl_set:Nn \__mhchem_ce_arrowName_tl { equilibriumLeft }
+ \tl_set:Nn \l__mhchem_ce_arrowName_tl { equilibriumLeft }
\__mhchem_ce_loop_startArrow:
}
{ <=>> }
{
- \tl_set:Nn \__mhchem_ce_arrowName_tl { equilibriumRight }
+ \tl_set:Nn \l__mhchem_ce_arrowName_tl { equilibriumRight }
\__mhchem_ce_loop_startArrow:
}
}
@@ -296,37 +433,59 @@
{
\__mhchem_ce_output:
}{
- \str_case:Vnn \__mhchem_ce_state_tl
+ \str_case:Vnn \l__mhchem_ce_state_tl
{
{ c }
{
\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 }
+ \int_compare:nTF { \l__mhchem_ce_distanceFromLastComma_int = 1 }
+ {
+ \__mhchem_ce_output:
+ \bool_set_false:N \l__mhchem_ce_potentialSpacing_bool
+ }
+ {
+ \__mhchem_ce_output:
+ \bool_if:NTF \__mhchem_ce_potentialSpacingAllowed_bool
+ { \bool_set_true:N \l__mhchem_ce_potentialSpacing_bool }
+ { \bool_set_false:N \l__mhchem_ce_potentialSpacing_bool }
+ }
\__mhchem_ce_loop:
}{
- \peek_catcode_remove:NTF \c_math_toggle_token
+ \peek_charcode:NTF ,
{
- \__mhchem_loopHelper_appendMathA:NNw
- \__mhchem_ce_part_tl
+ \int_set:Nn \l__mhchem_ce_distanceFromLastComma_int { 0 }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \l__mhchem_ce_part_tl
\__mhchem_ce_loop:
}{
+ \peek_catcode_remove:NTF \c_math_toggle_token
+ {
+ \peek_catcode:NTF \c_group_begin_token
+ {
+ \__mhchem_loopHelper_appendMathAAsGroup:NNw
+ \l__mhchem_ce_part_tl
+ \__mhchem_ce_loop:
+ }
+ {
+ \__mhchem_loopHelper_appendMathA:NNw
+ \l__mhchem_ce_part_tl
+ \__mhchem_ce_loop:
+ }
+ }{
\peek_catcode:NTF \c_group_begin_token
{
\__mhchem_loopHelper_appendNextGroup:NNn
- \__mhchem_ce_part_tl
+ \l__mhchem_ce_part_tl
\__mhchem_ce_loop:
}
% else
{
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_ce_part_tl
+ \l__mhchem_ce_part_tl
\__mhchem_ce_loop:
}
- }}
+ }}}
}
{ a-t1 }
{
@@ -337,56 +496,56 @@
}{
\peek_charcode:NTF T
{
- \tl_set:Nn \__mhchem_ce_state_tl { a-[1 }
+ \tl_set:Nn \l__mhchem_ce_state_tl { a-[1 }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_ce_arrowTypeOne_tl
+ \l__mhchem_ce_arrowTypeOne_tl
\__mhchem_ce_loop:
}{
\peek_charcode:NTF M
{
- \tl_set:Nn \__mhchem_ce_state_tl { a-[1 }
+ \tl_set:Nn \l__mhchem_ce_state_tl { a-[1 }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_ce_arrowTypeOne_tl
+ \l__mhchem_ce_arrowTypeOne_tl
\__mhchem_ce_loop:
}{
\peek_charcode:NTF C
{
- \tl_set:Nn \__mhchem_ce_state_tl { a-[1 }
+ \tl_set:Nn \l__mhchem_ce_state_tl { a-[1 }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_ce_arrowTypeOne_tl
+ \l__mhchem_ce_arrowTypeOne_tl
\__mhchem_ce_loop:
}{
\peek_charcode:NTF [
{
- \tl_set:Nn \__mhchem_ce_state_tl { a-]1 }
+ \tl_set:Nn \l__mhchem_ce_state_tl { a-]1 }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_ce_loop:
}
% else
{
- \str_case:Vnn \__mhchem_ce_arrowName_tl
+ \str_case:Vnn \l__mhchem_ce_arrowName_tl
{
{ yieldsLeft }
{
\peek_charcode:NTF -
{
- \tl_set:Nn \__mhchem_ce_state_tl { c }
- \tl_set:Nn \__mhchem_ce_part_tl { <- }
+ \tl_set:Nn \l__mhchem_ce_state_tl { c }
+ \tl_set:Nn \l__mhchem_ce_part_tl { <- }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_ce_part_tl
+ \l__mhchem_ce_part_tl
\__mhchem_ce_loop:
}{
\peek_charcode:NTF >
{
- \tl_set:Nn \__mhchem_ce_state_tl { c }
- \tl_set:Nn \__mhchem_ce_part_tl { <- }
+ \tl_set:Nn \l__mhchem_ce_state_tl { c }
+ \tl_set:Nn \l__mhchem_ce_part_tl { <- }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_ce_part_tl
+ \l__mhchem_ce_part_tl
\__mhchem_ce_loop:
}
% else
{
\__mhchem_ce_output:
- \tl_set:Nn \__mhchem_ce_state_tl { a-end }
+ \tl_set:Nn \l__mhchem_ce_state_tl { a-end }
\__mhchem_ce_loop:
}
}
@@ -395,16 +554,16 @@
{
\peek_charcode:NTF >
{
- \tl_set:Nn \__mhchem_ce_state_tl { c }
- \tl_set:Nn \__mhchem_ce_part_tl { <=> }
+ \tl_set:Nn \l__mhchem_ce_state_tl { c }
+ \tl_set:Nn \l__mhchem_ce_part_tl { <=> }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_ce_part_tl
+ \l__mhchem_ce_part_tl
\__mhchem_ce_loop:
}
% else
{
\__mhchem_ce_output:
- \tl_set:Nn \__mhchem_ce_state_tl { a-end }
+ \tl_set:Nn \l__mhchem_ce_state_tl { a-end }
\__mhchem_ce_loop:
}
}
@@ -412,7 +571,7 @@
% else
{
\__mhchem_ce_output:
- \tl_set:Nn \__mhchem_ce_state_tl { a-end }
+ \tl_set:Nn \l__mhchem_ce_state_tl { a-end }
\__mhchem_ce_loop:
}
}
@@ -422,13 +581,13 @@
{
\peek_charcode:NTF [
{
- \tl_set:Nn \__mhchem_ce_state_tl { a-]1 }
+ \tl_set:Nn \l__mhchem_ce_state_tl { a-]1 }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_ce_loop:
}
% else
{
\__mhchem_ce_output:
- \tl_set:Nn \__mhchem_ce_state_tl { a-end }
+ \tl_set:Nn \l__mhchem_ce_state_tl { a-end }
\__mhchem_ce_loop:
}
}
@@ -436,30 +595,30 @@
{
\peek_charcode_remove:NTF \c_space_token
{
- \tl_put_right:Nn \__mhchem_ce_arrowTextOne_tl { ~ }
+ \tl_put_right:Nn \l__mhchem_ce_arrowTextOne_tl { ~ }
\__mhchem_ce_loop:
}{
\peek_charcode:NTF ]
{
- \tl_set:Nn \__mhchem_ce_state_tl { a-t2 }
+ \tl_set:Nn \l__mhchem_ce_state_tl { a-t2 }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_ce_loop:
}{
\peek_catcode:NTF \c_group_begin_token
{
\__mhchem_loopHelper_appendNextGroup:NNn
- \__mhchem_ce_arrowTextOne_tl
+ \l__mhchem_ce_arrowTextOne_tl
\__mhchem_ce_loop:
}{
\peek_catcode_remove:NTF \c_math_toggle_token
{
- \__mhchem_loopHelper_appendMathB:NNw
- \__mhchem_ce_arrowTextOne_tl
- \__mhchem_ce_loop:
+ \__mhchem_loopHelper_appendMathB:nn
+ { l__mhchem_ce_arrowTextOne_tl }
+ { __mhchem_ce_loop: }
}
% else
{
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_ce_arrowTextOne_tl
+ \l__mhchem_ce_arrowTextOne_tl
\__mhchem_ce_loop:
}
}}}
@@ -473,34 +632,34 @@
}{
\peek_charcode:NTF T
{
- \tl_set:Nn \__mhchem_ce_state_tl { a-[2 }
+ \tl_set:Nn \l__mhchem_ce_state_tl { a-[2 }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_ce_arrowTypeTwo_tl
+ \l__mhchem_ce_arrowTypeTwo_tl
\__mhchem_ce_loop:
}{
\peek_charcode:NTF M
{
- \tl_set:Nn \__mhchem_ce_state_tl { a-[2 }
+ \tl_set:Nn \l__mhchem_ce_state_tl { a-[2 }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_ce_arrowTypeTwo_tl
+ \l__mhchem_ce_arrowTypeTwo_tl
\__mhchem_ce_loop:
}{
\peek_charcode:NTF C
{
- \tl_set:Nn \__mhchem_ce_state_tl { a-[2 }
+ \tl_set:Nn \l__mhchem_ce_state_tl { a-[2 }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_ce_arrowTypeTwo_tl
+ \l__mhchem_ce_arrowTypeTwo_tl
\__mhchem_ce_loop:
}{
\peek_charcode:NTF [
{
- \tl_set:Nn \__mhchem_ce_state_tl { a-]2 }
+ \tl_set:Nn \l__mhchem_ce_state_tl { a-]2 }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_ce_loop:
}
% else
{
\__mhchem_ce_output:
- \tl_set:Nn \__mhchem_ce_state_tl { a-end }
+ \tl_set:Nn \l__mhchem_ce_state_tl { a-end }
\__mhchem_ce_loop:
}
}}}}
@@ -509,13 +668,13 @@
{
\peek_charcode:NTF [
{
- \tl_set:Nn \__mhchem_ce_state_tl { a-]2 }
+ \tl_set:Nn \l__mhchem_ce_state_tl { a-]2 }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_ce_loop:
}
% else
{
\__mhchem_ce_output:
- \tl_set:Nn \__mhchem_ce_state_tl { a-end }
+ \tl_set:Nn \l__mhchem_ce_state_tl { a-end }
\__mhchem_ce_loop:
}
}
@@ -523,39 +682,39 @@
{
\peek_charcode_remove:NTF \c_space_token
{
- \tl_put_right:Nn \__mhchem_ce_arrowTextTwo_tl { ~ }
+ \tl_put_right:Nn \l__mhchem_ce_arrowTextTwo_tl { ~ }
\__mhchem_ce_loop:
}{
\peek_charcode:NTF ]
{
\__mhchem_ce_output:
- \tl_set:Nn \__mhchem_ce_state_tl { a-end }
+ \tl_set:Nn \l__mhchem_ce_state_tl { a-end }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_ce_loop:
}{
\peek_catcode:NTF \c_group_begin_token
{
\__mhchem_loopHelper_appendNextGroup:NNn
- \__mhchem_ce_arrowTextTwo_tl
+ \l__mhchem_ce_arrowTextTwo_tl
\__mhchem_ce_loop:
}{
\peek_catcode_remove:NTF \c_math_toggle_token
{
- \__mhchem_loopHelper_appendMathB:NNw
- \__mhchem_ce_arrowTextTwo_tl
- \__mhchem_ce_loop:
+ \__mhchem_loopHelper_appendMathB:nn
+ { l__mhchem_ce_arrowTextTwo_tl }
+ { __mhchem_ce_loop: }
}
% else
{
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_ce_arrowTextTwo_tl
+ \l__mhchem_ce_arrowTextTwo_tl
\__mhchem_ce_loop:
}
}}}
}
{ a-end }
{
- \bool_set_false:N \__mhchem_ce_potentialSpacing_bool
- \tl_set:Nn \__mhchem_ce_state_tl { c }
+ \bool_set_false:N \l__mhchem_ce_potentialSpacing_bool
+ \tl_set:Nn \l__mhchem_ce_state_tl { c }
\peek_charcode_remove:NTF \c_space_token
{
\__mhchem_ce_loop:
@@ -567,10 +726,10 @@
}
}
{
- \msg_error:nnx { mhchem } { ce/unexpected-state }
- { \__mhchem_ce_state_tl }
+ \msg_error:nnx { mhchem } { ce / unexpected-state }
+ { \l__mhchem_ce_state_tl }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_ce_result_tl
+ \l__mhchem_ce_result_tl
\__mhchem_ce_loop:
}
}
@@ -578,63 +737,82 @@
\cs_new_protected:Npn \__mhchem_ce_output:
{
\bool_set_true:N \__mhchem_ce_potentialSpacingAllowed_bool
- \str_case:Vnn \__mhchem_ce_state_tl
+ \str_case:Vnn \l__mhchem_ce_state_tl
{
{ c }
{
- \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) }
+ \str_case:Vnn \l__mhchem_ce_part_tl
{
- \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
+ { - }
+ {
+ \tl_put_right:Nn \l__mhchem_ce_result_tl { \ensuremath{{}-{}} }
+ \bool_set_false:N \__mhchem_ce_potentialSpacingAllowed_bool
+ }
+ { (v) }
+ {
+ \tl_put_right:Nn \l__mhchem_ce_result_tl
+ { \ensuremath{{}\mathop{\downarrow}{}} }
+ \bool_set_false:N \__mhchem_ce_potentialSpacingAllowed_bool
+ }
+ { v }
+ {
+ \tl_put_right:Nn \l__mhchem_ce_result_tl
+ { \ensuremath{{}\mathop{\downarrow}{}} }
+ \bool_set_false:N \__mhchem_ce_potentialSpacingAllowed_bool
+ }
+ { (^) }
+ {
+ \tl_put_right:Nn \l__mhchem_ce_result_tl
+ { \ensuremath{{}\mathop{\uparrow}{}} }
+ \bool_set_false:N \__mhchem_ce_potentialSpacingAllowed_bool
+ }
+ { ^ }
+ {
+ \tl_put_right:Nn \l__mhchem_ce_result_tl
+ { \ensuremath{{}\mathop{\uparrow}{}} }
+ \bool_set_false:N \__mhchem_ce_potentialSpacingAllowed_bool
+ }
+ { = }
+ {
+ \tl_put_right:Nn \l__mhchem_ce_result_tl
+ { \__mhchem_output_operatorEquals: }
+ \bool_set_false:N \__mhchem_ce_potentialSpacingAllowed_bool
+ }
+ { . }
+ {
+ \tl_put_right:Nn \l__mhchem_ce_result_tl
+ { \__mhchem_output_additionCompound: }
+ \bool_set_false:N \__mhchem_ce_potentialSpacingAllowed_bool
+ }
+ { * }
+ {
+ \tl_put_right:Nn \l__mhchem_ce_result_tl
+ { \__mhchem_output_additionCompound: }
+ \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
- {}
- { \exp_not:V \__mhchem_ce_part_tl }
- }
- }
+ \bool_if:NT \l__mhchem_ce_potentialSpacing_bool
+ {
+ \int_compare:nT { \l__mhchem_option_version_int > 3 }
+ { \tl_put_right:Nn \l__mhchem_ce_result_tl { \mhchem@option@skipAfterAmount } }
+ }
+ \tl_put_right:Nx \l__mhchem_ce_result_tl
+ {
+ \exp_not:N \__mhchem_cf:nn
+ {}
+ { \exp_not:V \l__mhchem_ce_part_tl }
+ }
}
- }}}}
}
{ a-t1 }
{
\__mhchem_ce_outputArrow:ooooo
- { \__mhchem_ce_arrowName_tl }
+ { \l__mhchem_ce_arrowName_tl }
{}
{}
{}
@@ -643,92 +821,92 @@
{ a-[1 }
{
\__mhchem_ce_outputArrow:ooooo
- { \__mhchem_ce_arrowName_tl }
+ { \l__mhchem_ce_arrowName_tl }
{}
{}
{}
{}
- \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
+ \tl_set:NV \l__mhchem_ce_part_tl \l__mhchem_ce_arrowTypeOne_tl
+ \tl_set:Nn \l__mhchem_ce_state_tl { c }
+ \bool_set_false:N \l__mhchem_ce_potentialSpacing_bool
\__mhchem_ce_output:
}
{ a-]1 }
{
\__mhchem_ce_outputArrow:ooooo
- { \__mhchem_ce_arrowName_tl }
- { \__mhchem_ce_arrowTypeOne_tl }
- { \__mhchem_ce_arrowTextOne_tl }
+ { \l__mhchem_ce_arrowName_tl }
+ { \l__mhchem_ce_arrowTypeOne_tl }
+ { \l__mhchem_ce_arrowTextOne_tl }
{}
{}
}
{ a-t2 }
{
\__mhchem_ce_outputArrow:ooooo
- { \__mhchem_ce_arrowName_tl }
- { \__mhchem_ce_arrowTypeOne_tl }
- { \__mhchem_ce_arrowTextOne_tl }
+ { \l__mhchem_ce_arrowName_tl }
+ { \l__mhchem_ce_arrowTypeOne_tl }
+ { \l__mhchem_ce_arrowTextOne_tl }
{}
{}
}
{ a-[2 }
{
\__mhchem_ce_outputArrow:ooooo
- { \__mhchem_ce_arrowName_tl }
- { \__mhchem_ce_arrowTypeOne_tl }
- { \__mhchem_ce_arrowTextOne_tl }
+ { \l__mhchem_ce_arrowName_tl }
+ { \l__mhchem_ce_arrowTypeOne_tl }
+ { \l__mhchem_ce_arrowTextOne_tl }
{}
{}
- \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
+ \tl_set:NV \l__mhchem_ce_part_tl \l__mhchem_ce_arrowTypeTwo_tl
+ \tl_set:Nn \l__mhchem_ce_state_tl { c }
+ \bool_set_false:N \l__mhchem_ce_potentialSpacing_bool
\__mhchem_ce_output:
}
{ a-]2 }
{
\__mhchem_ce_outputArrow:ooooo
- { \__mhchem_ce_arrowName_tl }
- { \__mhchem_ce_arrowTypeOne_tl }
- { \__mhchem_ce_arrowTextOne_tl }
- { \__mhchem_ce_arrowTypeTwo_tl }
- { \__mhchem_ce_arrowTextTwo_tl }
+ { \l__mhchem_ce_arrowName_tl }
+ { \l__mhchem_ce_arrowTypeOne_tl }
+ { \l__mhchem_ce_arrowTextOne_tl }
+ { \l__mhchem_ce_arrowTypeTwo_tl }
+ { \l__mhchem_ce_arrowTextTwo_tl }
}
}
{}
- \tl_clear:N \__mhchem_ce_part_tl
- \tl_set:Nn \__mhchem_ce_state_tl { c }
- \bool_set_false:N \__mhchem_ce_potentialSpacing_bool
+ \tl_clear:N \l__mhchem_ce_part_tl
+ \tl_set:Nn \l__mhchem_ce_state_tl { c }
+ \bool_set_false:N \l__mhchem_ce_potentialSpacing_bool
}
\cs_new_protected:Npn \__mhchem_ce_outputArrow:nnnnn #1#2#3#4#5
{
- \tl_put_right:Nn \__mhchem_ce_result_tl
+ \tl_put_right:Nn \l__mhchem_ce_result_tl
{
\__mhchem_arrow_deploy:nnnnn {#1} {#2} {#3} {#4} {#5}
}
- \tl_clear:N \__mhchem_ce_part_tl
- \tl_set:Nn \__mhchem_ce_state_tl { c }
+ \tl_clear:N \l__mhchem_ce_part_tl
+ \tl_set:Nn \l__mhchem_ce_state_tl { c }
}
\cs_generate_variant:Nn \__mhchem_ce_outputArrow:nnnnn {ooooo}
\cs_new_protected:Npn \__mhchem_ce_loop_startArrow:
{
- \tl_set:Nn \__mhchem_ce_state_tl { a-t1 }
- \tl_clear:N \__mhchem_ce_arrowTypeOne_tl
- \tl_clear:N \__mhchem_ce_arrowTextOne_tl
- \tl_clear:N \__mhchem_ce_arrowTypeTwo_tl
- \tl_clear:N \__mhchem_ce_arrowTextTwo_tl
- \tl_clear:N \__mhchem_ce_part_tl
+ \tl_set:Nn \l__mhchem_ce_state_tl { a-t1 }
+ \tl_clear:N \l__mhchem_ce_arrowTypeOne_tl
+ \tl_clear:N \l__mhchem_ce_arrowTextOne_tl
+ \tl_clear:N \l__mhchem_ce_arrowTypeTwo_tl
+ \tl_clear:N \l__mhchem_ce_arrowTextTwo_tl
+ \tl_clear:N \l__mhchem_ce_part_tl
}
\cs_new_protected:Npn \__mhchem_ce_loop_abortArrow:
{
- \tl_put_right:Nx \__mhchem_ce_part_tl
+ \tl_put_right:Nx \l__mhchem_ce_part_tl
{
- \tl_set:Nn \__mhchem_ce_state_tl { a-t1 }
- \exp_not:V \__mhchem_ce_arrowTypeOne_tl
- \exp_not:V \__mhchem_ce_arrowTextOne_tl
- \exp_not:V \__mhchem_ce_arrowTypeTwo_tl
- \exp_not:V \__mhchem_ce_arrowTextTwo_tl
+ \tl_set:Nn \l__mhchem_ce_state_tl { a-t1 }
+ \exp_not:V \l__mhchem_ce_arrowTypeOne_tl
+ \exp_not:V \l__mhchem_ce_arrowTextOne_tl
+ \exp_not:V \l__mhchem_ce_arrowTypeTwo_tl
+ \exp_not:V \l__mhchem_ce_arrowTextTwo_tl
}
- \tl_set:Nn \__mhchem_ce_state_tl { c }
+ \tl_set:Nn \l__mhchem_ce_state_tl { c }
}
\ExplSyntaxOff
@@ -751,8 +929,8 @@
{
{ }
{
- \int_compare:nTF { \__mhchem_option_version_int > 3 }
- { \cs:w mhchem@arrow@#1T \cs_end: {#3}{#5} }
+ \int_compare:nTF { \l__mhchem_option_version_int > 3 }
+ { \cs:w mhchem@arrow@#1C \cs_end: {#3}{#5} }
{ \cs:w mhchem@arrow@#1M \cs_end: {#3}{#5} }
}
{ M }
@@ -903,15 +1081,26 @@
%%% Arrow compositions with text or chemistry
\newtoks\mhchem@arrow@params%
+\ExplSyntaxOn
\def\mhchem@arrow@setParamsT#1#2{%
\mhchem@arrow@params={}%
\@ifempty{#1}%
{\mhchem@appendToks{\mhchem@arrow@params}{{}}}%
- {\mhchem@appendToks{\mhchem@arrow@params}{{\text{#1}}}}%
+ {\mhchem@appendToks{\mhchem@arrow@params}{{\__mhchem_output_escapeFromMathToText:n{#1}}}}%
+ \@ifempty{#2}%
+ {\mhchem@appendToks{\mhchem@arrow@params}{{}}}%
+ {\mhchem@appendToks{\mhchem@arrow@params}{{\__mhchem_output_escapeFromMathToText:n{#2}}}}%
+}%
+\def\mhchem@arrow@setParamst#1#2{%
+ \mhchem@arrow@params={}%
+ \@ifempty{#1}%
+ {\mhchem@appendToks{\mhchem@arrow@params}{{}}}%
+ {\mhchem@appendToks{\mhchem@arrow@params}{{\__mhchem_cg_escapeFromMathToTextOrFaketext:n{#1}}}}%
\@ifempty{#2}%
{\mhchem@appendToks{\mhchem@arrow@params}{{}}}%
- {\mhchem@appendToks{\mhchem@arrow@params}{{\text{#2}}}}%
+ {\mhchem@appendToks{\mhchem@arrow@params}{{\__mhchem_cg_escapeFromMathToTextOrFaketext:n{#2}}}}%
}%
+\ExplSyntaxOff
\def\mhchem@arrow@setParamsC#1#2{%
\mhchem@arrow@params={}%
\@ifempty{#1}%
@@ -924,43 +1113,64 @@
\newcommand*\mhchem@arrow@yieldsT[2]{%
\mhchem@arrow@setParamsT{#1}{#2}%
\expandafter\mhchem@arrow@yieldsM\the\mhchem@arrow@params}%
+\newcommand*\mhchem@arrow@yieldst[2]{%
+ \mhchem@arrow@setParamst{#1}{#2}%
+ \expandafter\mhchem@arrow@yieldsM\the\mhchem@arrow@params}%
\newcommand*\mhchem@arrow@yieldsC[2]{%
\mhchem@arrow@setParamsC{#1}{#2}%
\expandafter\mhchem@arrow@yieldsM\the\mhchem@arrow@params}%
\newcommand*\mhchem@arrow@yieldsLeftT[2]{%
\mhchem@arrow@setParamsT{#1}{#2}%
\expandafter\mhchem@arrow@yieldsLeftM\the\mhchem@arrow@params}%
+\newcommand*\mhchem@arrow@yieldsLeftt[2]{%
+ \mhchem@arrow@setParamst{#1}{#2}%
+ \expandafter\mhchem@arrow@yieldsLeftM\the\mhchem@arrow@params}%
\newcommand*\mhchem@arrow@yieldsLeftC[2]{%
\mhchem@arrow@setParamsC{#1}{#2}%
\expandafter\mhchem@arrow@yieldsLeftM\the\mhchem@arrow@params}%
\newcommand*\mhchem@arrow@yieldsLeftRightT[2]{%
\mhchem@arrow@setParamsT{#1}{#2}%
\expandafter\mhchem@arrow@yieldsLeftRightM\the\mhchem@arrow@params}%
+\newcommand*\mhchem@arrow@yieldsLeftRightt[2]{%
+ \mhchem@arrow@setParamst{#1}{#2}%
+ \expandafter\mhchem@arrow@yieldsLeftRightM\the\mhchem@arrow@params}%
\newcommand*\mhchem@arrow@yieldsLeftRightC[2]{%
\mhchem@arrow@setParamsC{#1}{#2}%
\expandafter\mhchem@arrow@yieldsLeftRightM\the\mhchem@arrow@params}%
\newcommand*\mhchem@arrow@mesomerismT[2]{%
\mhchem@arrow@setParamsT{#1}{#2}%
\expandafter\mhchem@arrow@mesomerismM\the\mhchem@arrow@params}%
+\newcommand*\mhchem@arrow@mesomerismt[2]{%
+ \mhchem@arrow@setParamst{#1}{#2}%
+ \expandafter\mhchem@arrow@mesomerismM\the\mhchem@arrow@params}%
\newcommand*\mhchem@arrow@mesomerismC[2]{%
\mhchem@arrow@setParamsC{#1}{#2}%
\expandafter\mhchem@arrow@mesomerismM\the\mhchem@arrow@params}%
-\newcommand*{\mhchem@arrow@equilibriumT}[2]{%
+\newcommand*\mhchem@arrow@equilibriumT[2]{%
\mhchem@arrow@setParamsT{#1}{#2}%
\expandafter\mhchem@arrow@equilibriumM\the\mhchem@arrow@params}%
-\newcommand*{\mhchem@arrow@equilibriumC}[2]{%
+\newcommand*\mhchem@arrow@equilibriumt[2]{%
+ \mhchem@arrow@setParamst{#1}{#2}%
+ \expandafter\mhchem@arrow@equilibriumM\the\mhchem@arrow@params}%
+\newcommand*\mhchem@arrow@equilibriumC[2]{%
\mhchem@arrow@setParamsC{#1}{#2}%
\expandafter\mhchem@arrow@equilibriumM\the\mhchem@arrow@params}%
-\newcommand*{\mhchem@arrow@equilibriumRightT}[2]{%
+\newcommand*\mhchem@arrow@equilibriumRightT[2]{%
\mhchem@arrow@setParamsT{#1}{#2}%
\expandafter\mhchem@arrow@equilibriumRightM\the\mhchem@arrow@params}%
-\newcommand*{\mhchem@arrow@equilibriumRightC}[2]{%
+\newcommand*\mhchem@arrow@equilibriumRightt[2]{%
+ \mhchem@arrow@setParamst{#1}{#2}%
+ \expandafter\mhchem@arrow@equilibriumRightM\the\mhchem@arrow@params}%
+\newcommand*\mhchem@arrow@equilibriumRightC[2]{%
\mhchem@arrow@setParamsC{#1}{#2}%
\expandafter\mhchem@arrow@equilibriumRightM\the\mhchem@arrow@params}%
-\newcommand*{\mhchem@arrow@equilibriumLeftT}[2]{%
+\newcommand*\mhchem@arrow@equilibriumLeftT[2]{%
\mhchem@arrow@setParamsT{#1}{#2}%
\expandafter\mhchem@arrow@equilibriumLeftM\the\mhchem@arrow@params}%
-\newcommand*{\mhchem@arrow@equilibriumLeftC}[2]{%
+\newcommand*\mhchem@arrow@equilibriumLeftt[2]{%
+ \mhchem@arrow@setParamst{#1}{#2}%
+ \expandafter\mhchem@arrow@equilibriumLeftM\the\mhchem@arrow@params}%
+\newcommand*\mhchem@arrow@equilibriumLeftC[2]{%
\mhchem@arrow@setParamsC{#1}{#2}%
\expandafter\mhchem@arrow@equilibriumLeftM\the\mhchem@arrow@params}%
@@ -1102,88 +1312,6 @@
\end{tikzpicture}%
}%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%% bonds %%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-\newlength\mhchem@bondwidth%
-\newlength\mhchem@bondheight%
-\newlength\mhchem@smallbondwidth@tmpA%
-\newlength\mhchem@smallbondwidth@tmpB%
-\newlength\mhchem@smallbondwidth%
-
-\def\mhchem@setbondwidth{%
- \setlength\mhchem@bondwidth{\widthof{\sbond}}%
- \setlength\mhchem@bondheight{\heightof{\sbond}}%
- \setlength\mhchem@smallbondwidth@tmpA{%
- \mhchem@bondwidth-\mhchem@option@minussidebearingleft-\mhchem@option@minussidebearingright}%
- \setlength\mhchem@smallbondwidth@tmpB{%
- \widthof{\sbond\sbond\sbond}-\mhchem@option@minussidebearingleft-%
- \mhchem@option@minussidebearingright}%
- \setlength\mhchem@smallbondwidth{\mhchem@bondwidth*%
- \ratio{\mhchem@smallbondwidth@tmpA}{\mhchem@smallbondwidth@tmpB}}%
-}
-\def\mhchem@halfbond{\rlap{\hspace{\mhchem@option@minussidebearingleft}%
- \resizebox{\mhchem@smallbondwidth}{\mhchem@bondheight}{\sbond}\unskip%
- \resizebox{\mhchem@smallbondwidth}{\mhchem@bondheight}{\sbond}%
- \resizebox{\mhchem@smallbondwidth}{\mhchem@bondheight}{\sbond}}%
- \phantom{\sbond}}%
-\ExplSyntaxOn
-\char_set_catcode_letter:n { 126 } % tilde
-\cs_new_protected:Npn \mhchem@bond #1
- {
- \str_case:nnn {#1}
- {
- { - } { \sbond }
- { 1 } { \sbond }
- { = } { \dbond }
- { 2 } { \dbond }
- { ## } { \tbond }
- { 3 } { \tbond }
- { ~ }
- {
- \mhchem@setbondwidth
- \mhchem@halfbond
- }
- { ~- }
- {
- \mhchem@setbondwidth
- \rlap{\protect\raisebox{.2ex}{\mhchem@halfbond}}
- \protect\raisebox{-.2ex}{\sbond}
- }
- { ~-- }
- {
- \mhchem@setbondwidth
- \rlap{\protect\raisebox{.4ex}{\mhchem@halfbond}}
- \rlap{\sbond}
- \protect\raisebox{-.4ex}{\sbond}
- }
- { ~= }
- {
- \mhchem@setbondwidth
- \rlap{\protect\raisebox{.4ex}{\mhchem@halfbond}}
- \rlap{\sbond}
- \protect\raisebox{-.4ex}{\sbond}
- }
- { -~- }
- {
- \mhchem@setbondwidth
- \rlap{\protect\raisebox{.4ex}{\sbond}}
- \rlap{\mhchem@halfbond}
- \protect\raisebox{-.4ex}{\sbond}
- }
- { ... } { {\cdot}{\cdot}{\cdot} }
- { .... } { {\cdot}{\cdot}{\cdot}{\cdot} }
- { -> } { {\rightarrow} }
- { <- } { {\leftarrow} }
- }
- {
- %todo Tilde is not a space anymore, here
- \PackageError{mhchem}{Unknown~bond~type~in~\string\bond~(#1)}%
- }
- }
-\ExplSyntaxOff % end of Expl with tilde
-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%% loop helpers %%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -1206,21 +1334,32 @@
}
\cs_new_protected:Npn
- \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn #1#2#3
+ \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:nNn #1#2#3
{
\__mhchem_cf_outputAndReset:
- \tl_put_right:Nn \__mhchem_cf_result_tl { \mhchem@mathOrText{#3} }
- \tl_set:Nn \__mhchem_cf_state_tl {#1}
+ \tl_put_right:Nn \l__mhchem_cf_element_tl { \__mhchem_output_withFont:n {#3} }
+ \__mhchem_cf_outputRawElementAndReset:
+ \tl_set:Nn \l__mhchem_cf_state_tl {#1}
#2
}
\cs_new_protected:Npn
- \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn #1#2#3#4
+ \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:nnNn #1#2#3#4
{
\__mhchem_cf_outputAndReset:
- \tl_put_right:Nn \__mhchem_cf_result_tl {#1}
- \tl_set:Nn \__mhchem_cf_state_tl {#2}
+ \tl_put_right:Nn \l__mhchem_cf_element_tl {#1}
+ \__mhchem_cf_outputRawElementAndReset:
+ \tl_set:Nn \l__mhchem_cf_state_tl {#2}
#3
}
+\cs_new_protected:Npn
+ \__mhchem_loopHelper_outputAndReset_append_appendNextGroupToResult:nNnn #1#2#3
+ {
+ \__mhchem_cf_outputAndReset:
+ \tl_put_right:Nn \l__mhchem_cf_element_tl {#1}
+ \tl_put_right:Nn \l__mhchem_cf_element_tl {{#3}}
+ \__mhchem_cf_outputRawElementAndReset:
+ #2
+ }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%% \cf %%%%%%%%%%
@@ -1230,46 +1369,46 @@
\__mhchem_cf:nn {#1} {#2}
}
-\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
+\bool_new:N \l__mhchem_cf_startedWithBond_bool
+
+\tl_new:N \l__mhchem_cf_state_tl
+\tl_new:N \l__mhchem_cf_presup_tl
+\tl_new:N \l__mhchem_cf_presub_tl
+\tl_new:N \l__mhchem_cf_presupState_tl
+\tl_new:N \l__mhchem_cf_presubState_tl
+\tl_new:N \l__mhchem_cf_element_tl
+\tl_new:N \l__mhchem_cf_sub_tl
+\tl_new:N \l__mhchem_cf_sup_tl
+\tl_new:N \l__mhchem_cf_supState_tl
+\tl_new:N \l__mhchem_cf_subState_tl
+\tl_new:N \l__mhchem_cf_lastElement_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 { - }
+ \tl_clear:N \l__mhchem_cf_presup_tl
+ \tl_clear:N \l__mhchem_cf_presub_tl
+ \tl_set:Nn \l__mhchem_cf_presupState_tl { - }
+ \tl_set:Nn \l__mhchem_cf_presubState_tl { - }
+ \tl_clear:N \l__mhchem_cf_element_tl
+ \tl_clear:N \l__mhchem_cf_sub_tl
+ \tl_clear:N \l__mhchem_cf_sup_tl
+ \tl_set:Nn \l__mhchem_cf_supState_tl { - }
+ \tl_set:Nn \l__mhchem_cf_subState_tl { - }
}
-\bool_new:N \__mhchem_cf_cfActive_bool
-\bool_set_false:N \__mhchem_cf_cfActive_bool
+\bool_new:N \l__mhchem_cf_cfActive_bool
+\bool_set_false:N \l__mhchem_cf_cfActive_bool
+\tl_new:N \l__mhchem_cf_result_tl
\cs_new_protected:Npn \__mhchem_cf:nn #1#2
{
\group_begin:
- \def\sbond{{\ensuremath{-}}}
- \int_compare:nTF { 2 = \__mhchem_option_version_int }
+ \let\sbond\__mhchem_output_sbond:
+ \int_compare:nTF { 2 = \l__mhchem_option_version_int }
{
\let\bond\sbond
}
% else
{
- \int_compare:nT { \__mhchem_option_version_int > 2 }
+ \int_compare:nT { \l__mhchem_option_version_int > 2 }
{
\def\bond{\mhchem@bond}
}
@@ -1278,40 +1417,50 @@
\def\tbond{\rlap{\protect\raisebox{.4ex}{\sbond}}
\rlap{\sbond}\protect\raisebox{-.4ex}{\sbond}}
\def\hyphen{\mhchem@hyphen}
- \bool_if:NF \__mhchem_ce_ceActive_bool {
- \bool_if:NF \__mhchem_cf_cfActive_bool
+ \bool_if:NF \l__mhchem_ce_ceActive_bool {
+ \bool_if:NF \l__mhchem_cf_cfActive_bool
{
- \bool_set_true:N \__mhchem_cf_cfActive_bool
- \__mhchem_defMathOrText:
+ \bool_set_true:N \l__mhchem_cf_cfActive_bool
+ \__mhchem_output_defMathOrText:
}
}
- \tl_set:Nn \__mhchem_cf_state_tl { s }
- \bool_set_false:N \__mhchem_cf_startedWithBond_bool
+ \tl_set:Nn \l__mhchem_cf_state_tl { s }
+ \bool_set_false:N \l__mhchem_cf_startedWithBond_bool
\__mhchem_cf_resetOutput:
- \tl_clear_new:N \__mhchem_cf_result_tl
- \__mhchem_cf_loop: #2 \q_recursion_stop
- \str_if_eq:nnTF {#1} {}
- { \ensuremath{\tl_use:N \__mhchem_cf_result_tl} }
- { \ensuremath{\overset{#1}{\tl_use:N \__mhchem_cf_result_tl}} }
+ \tl_set:Nn \l__mhchem_cf_result_tl {#2}
+ \regex_replace_once:nnNTF
+ { \A [nmpx] \Z } { \c{__mhchem_output_withFont:n}\cB[ \c{__mhchem_cg_itshape:n}\cB[ \0 \cE]\cE] } \l__mhchem_cf_result_tl
+ {}
+ {
+ \tl_clear:N \l__mhchem_cf_result_tl
+ \__mhchem_cf_loop: #2 \q_recursion_stop
+ }
+ \str_if_eq:nnTF {#1} {}
+ { \ensuremath{\tl_use:N \l__mhchem_cf_result_tl} }
+ { \ensuremath{\overset{#1}{\tl_use:N \l__mhchem_cf_result_tl}} }
\group_end:
}
+\tl_new:N \l__mhchem_cf_loop_tmpa_l
+\tl_new:N \l__mhchem_cf_loop_tmpb_l
+\tl_new:N \l__mhchem_cf_loop_tmpc_l
+\tl_new:N \l__mhchem_cf_loop_tmpd_l
\cs_new_protected:Npn \__mhchem_cf_loop:
{
\peek_meaning_remove:NTF \q_recursion_stop
{
- \str_case:Vnn \__mhchem_cf_state_tl
+ \str_case:Vnn \l__mhchem_cf_state_tl
{
{ - }
{
- \bool_if:NTF \__mhchem_cf_startedWithBond_bool
+ \bool_if:NTF \l__mhchem_cf_startedWithBond_bool
{
\__mhchem_cf_outputAndReset:
- \tl_put_right:Nn \__mhchem_cf_result_tl { \sbond }
+ \__mhchem_cf_outputRawElementAndReset:n { \sbond }
}
- { \tl_put_right:Nn \__mhchem_cf_sup_tl { - } }
+ { \tl_put_right:Nn \l__mhchem_cf_sup_tl { - } }
}
{ 1 }
- { \tl_set:Nn \__mhchem_cf_state_tl {9} }
+ { \tl_set:Nn \l__mhchem_cf_state_tl {9} }
}
{}
\__mhchem_cf_outputAndReset:
@@ -1320,37 +1469,62 @@
{ \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: }{
\peek_meaning:NTF \protect
{ \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: }{
- \str_case:Vnn \__mhchem_cf_state_tl
+ \str_case:Vnn \l__mhchem_cf_state_tl
{
{ - }
{
\__mhchem_cf_outputAndReset:
- \tl_put_right:Nn \__mhchem_cf_result_tl {\sbond}
- \tl_set:Nn \__mhchem_cf_state_tl { a }
+ \regex_match:nVTF
+ { \A (n|\c{eta}|\c{mu}|\c{kappa}|\c{__mhchem_cg_withinMathTokens:n}\cB.n\cE.|\d+|\(\+\)) \Z }
+ \l__mhchem_cf_lastElement_tl
+ {
+ \__mhchem_cf_outputRawElementAndReset:n
+ { \__mhchem_cg_escapeFromMathToTextOrFaketext:n { - } }
+ }
+ {
+ \__mhchem_cf_outputRawElementAndReset:n { \sbond }
+ }
+ \tl_set:Nn \l__mhchem_cf_state_tl { a }
\__mhchem_cf_loop:
}
+ { ( }
+ {
+ \__mhchem_regex_peek:nTF { [0-9] }
+ {
+ \tl_set:Nn \l__mhchem_cf_state_tl { 1 }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \l__mhchem_cf_element_tl
+ \__mhchem_cf_loop:
+ }
+ % else
+ {
+ \__mhchem_cf_outputAndReset:
+ \tl_set:Nn \l__mhchem_cf_state_tl { s }
+ \__mhchem_cf_loop:
+ }
+ }
{ s }
{
\peek_charcode:NTF -
{
\__mhchem_cf_outputAndReset:
- \int_compare:nTF { \__mhchem_option_version_int > 1 }
+ \int_compare:nTF { \l__mhchem_option_version_int > 1 }
{
- \tl_set:Nn \__mhchem_cf_state_tl { - }
- \bool_set_true:N \__mhchem_cf_startedWithBond_bool
+ \tl_set:Nn \l__mhchem_cf_state_tl { - }
+ \bool_set_true:N \l__mhchem_cf_startedWithBond_bool
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
}
% else
{
- \tl_set:Nn \__mhchem_cf_state_tl { a }
- \tl_put_right:Nn \__mhchem_cf_sup_tl { - } % z. B. \cmath{mu}-Cl
+ \tl_set:Nn \l__mhchem_cf_state_tl { a }
+ \tl_put_right:Nn \l__mhchem_cf_sup_tl { - }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
}
}{
\peek_charcode:NTF =
{
\__mhchem_cf_outputAndReset:
- \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn
+ \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:nnNn
{ \dbond }
{ s }
\__mhchem_cf_loop:
@@ -1358,1479 +1532,1428 @@
\peek_charcode:NTF ##
{
\__mhchem_cf_outputAndReset:
- \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn
+ \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:nnNn
{ \tbond }
{ s }
\__mhchem_cf_loop:
}{
\peek_charcode:NTF ^
{
- \str_if_eq:VnF \__mhchem_cf_presupState_tl { - }
+ \str_if_eq:VnF \l__mhchem_cf_presupState_tl { - }
{ \__mhchem_cf_outputAndReset: }
- \tl_set:Nn \__mhchem_cf_presupState_tl { d }
- \tl_set:Nn \__mhchem_cf_state_tl { p }
+ \tl_set:Nn \l__mhchem_cf_presupState_tl { d }
+ \tl_set:Nn \l__mhchem_cf_state_tl { p }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
}{
\peek_charcode:NTF _
{
- \str_if_eq:VnF \__mhchem_cf_presubState_tl { - }
+ \str_if_eq:VnF \l__mhchem_cf_presubState_tl { - }
{ \__mhchem_cf_outputAndReset: }
- \tl_set:Nn \__mhchem_cf_presubState_tl { d }
- \tl_set:Nn \__mhchem_cf_state_tl { q }
+ \tl_set:Nn \l__mhchem_cf_presubState_tl { d }
+ \tl_set:Nn \l__mhchem_cf_state_tl { q }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
}{
\peek_charcode:NTF `
{
- \int_compare:nTF { \__mhchem_option_version_int < 4 }
+ \int_compare:nTF { \l__mhchem_option_version_int < 4 }
{
- \str_if_eq:VnF \__mhchem_cf_presupState_tl { - }
+ \str_if_eq:VnF \l__mhchem_cf_presupState_tl { - }
{ \__mhchem_cf_outputAndReset: }
- \tl_set:Nn \__mhchem_cf_presupState_tl { rm }
- \tl_set:Nn \__mhchem_cf_state_tl { p }
+ \tl_set:Nn \l__mhchem_cf_presupState_tl { rm }
+ \tl_set:Nn \l__mhchem_cf_state_tl { p }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
}
% else
{
- \tl_set:Nn \__mhchem_cf_state_tl { a }
+ \tl_set:Nn \l__mhchem_cf_state_tl { a }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_element_tl
+ \l__mhchem_cf_element_tl
\__mhchem_cf_loop:
}
}{
\peek_charcode:NTF ,
{
- \int_compare:nTF { \__mhchem_option_version_int < 4 }
+ \int_compare:nTF { \l__mhchem_option_version_int < 4 }
{
- \str_if_eq:VnF \__mhchem_cf_presubState_tl { - }
+ \str_if_eq:VnF \l__mhchem_cf_presubState_tl { - }
{ \__mhchem_cf_outputAndReset: }
- \tl_set:Nn \__mhchem_cf_presubState_tl { rm }
- \tl_set:Nn \__mhchem_cf_state_tl { q }
+ \tl_set:Nn \l__mhchem_cf_presubState_tl { rm }
+ \tl_set:Nn \l__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_set:Nn \l__mhchem_cf_state_tl { 1 }
\__mhchem_cf_loop:
}
}{
- \peek_charcode:NTF .
- {
-
- \__mhchem_cf_outputAndReset:
- \tl_set:Nn \__mhchem_cf_state_tl { 1 }
- \__mhchem_cf_loop:
- }{
\peek_charcode:NTF *
{
- \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn
- { \mhchem@mathOrText@ii{{}\cdot{}}{\mhchem@option@textcdot} }
+ \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:nnNn
+ { \__mhchem_output_additionCompound: }
{ s }
\__mhchem_cf_loop:
}{
\peek_charcode:NTF +
{
- \str_if_eq:VnF \__mhchem_cf_presupState_tl { - }
+ \str_if_eq:VnF \l__mhchem_cf_presupState_tl { - }
{ \__mhchem_cf_outputAndReset: }
- \tl_set:Nn \__mhchem_cf_presupState_tl { d }
- \tl_set:Nn \__mhchem_cf_state_tl { p }
+ \tl_set:Nn \l__mhchem_cf_presupState_tl { d }
+ \tl_set:Nn \l__mhchem_cf_state_tl { p }
\__mhchem_cf_loop:
}{
- \peek_charcode:NTF |
- {
- \let\mhchem@cf@action\mhchem@cf@switchState
- }{
\peek_charcode:NTF (
{
- \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn
- { s }
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF )
- {
- \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn
- { a }
+ \__mhchem_cf_outputAndReset:
+ \tl_set:Nn \l__mhchem_cf_state_tl { ( }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \l__mhchem_cf_element_tl
\__mhchem_cf_loop:
}{
\peek_charcode:NTF [
{
- \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn
+ \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:nNn
{ s }
\__mhchem_cf_loop:
}{
- \peek_charcode:NTF ]
+ \__mhchem_regex_peek:nTF { [ \) \] \/ ] }
{
- \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn
+ \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:nNn
{ a }
\__mhchem_cf_loop:
}{
\peek_catcode:NTF \mhchem@macro
{
\__mhchem_cf_outputAndReset:
- \tl_set:Nn \__mhchem_cf_state_tl { c }
+ \tl_set:Nn \l__mhchem_cf_state_tl { c }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_result_tl
+ \l__mhchem_cf_element_tl
\__mhchem_cf_loop:
}{
\peek_catcode:NTF a
{
- \tl_set:Nn \__mhchem_cf_state_tl { a }
+ \tl_set:Nn \l__mhchem_cf_state_tl { a }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_element_tl
+ \l__mhchem_cf_element_tl
\__mhchem_cf_loop:
}{
- \peek_catcode:NTF 1
+ \__mhchem_regex_peek:nTF { [ 0-9 . ] }
{
\__mhchem_cf_outputAndReset:
- \tl_set:Nn \__mhchem_cf_state_tl { 1 }
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_element_tl
- \__mhchem_cf_loop:
+ \tl_set:Nn \l__mhchem_cf_state_tl { 1 }
+ \__mhchem_cf_loop:
}{
\peek_catcode:NTF \c_group_begin_token
{
- \__mhchem_cf_outputAndReset:
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_result_tl
- \__mhchem_cf_loop:
+ \__mhchem_cf_outputAndReset:
+ \int_compare:nTF { \l__mhchem_option_version_int < 4 }
+ {
+ \__mhchem_loopHelper_outputAndReset_append_appendNextGroupToResult:nNnn
+ {}
+ \__mhchem_cf_loop:
+ }
+ % else
+ {
+ \tl_set:Nn \l__mhchem_cf_state_tl { a }
+ \__mhchem_loopHelper_appendNextGroup_prefix_ifEmpty:NnnNn
+ \l__mhchem_cf_element_tl
+ { \__mhchem_cg_escapeFromMathToTextOrFaketext:n }
+ { \tl_set:Nn \l__mhchem_cf_state_tl { s } }
+ \__mhchem_cf_loop:
+ }
}{
\peek_catcode_remove:NTF \c_math_toggle_token
{
- \tl_set:Nn \__mhchem_cf_state_tl { a }
- \__mhchem_loopHelper_appendMathB:NNw
- \__mhchem_cf_element_tl
- \__mhchem_cf_loop:
+ \tl_set:Nn \l__mhchem_cf_state_tl { a }
+ \__mhchem_loopHelper_appendMathB:nn
+ { l__mhchem_cf_element_tl }
+ { __mhchem_cf_loop: }
}
% else
{ \msg_error:nnn { mhchem } { cf / unexpected-input } }
- }}}}}}}}}}}}}}}}}}}
+ }}}}}}}}}}}}}}}}
}
{ c }
{
- \peek_catcode:NTF \c_group_begin_token
+ \regex_match:nVTF
+ { \A [\c{alpha}\c{beta}\c{gamma}\c{delta}\c{epsilon}\c{zeta}\c{eta}\c{theta}\c{iota}\c{kappa}\c{lambda}\c{mu}\c{nu}\c{xi}\c{omicron}\c{pi}\c{rho}\c{sigma}\c{tau}\c{upsilon}\c{phi}\c{chi}\c{psi}\c{omega}\c{Alpha}\c{Beta}\c{Gamma}\c{Delta}\c{Epsilon}\c{Zeta}\c{Eta}\c{Theta}\c{Iota}\c{Kappa}\c{Lambda}\c{Mu}\c{Nu}\c{Xi}\c{Omicron}\c{Pi}\c{Rho}\c{Sigma}\c{Tau}\c{Upsilon}\c{Phi}\c{Chi}\c{Psi}\c{Omega}] \Z }
+ \l__mhchem_cf_element_tl
{
- \__mhchem_loopHelper_appendNextGroup:NNn
- \__mhchem_cf_result_tl
- \__mhchem_cf_loop:
+ \tl_set:Nn \l__mhchem_cf_state_tl { a }
+ \__mhchem_cf_loop:
}
- % else
{
- \tl_set:Nn \__mhchem_cf_state_tl { a }
- \__mhchem_cf_loop:
+ \peek_catcode:NTF \c_group_begin_token
+ {
+ \__mhchem_loopHelper_appendNextGroup:NNn
+ \l__mhchem_cf_element_tl
+ \__mhchem_cf_loop:
+ }
+ % else
+ {
+ \__mhchem_cf_outputAndReset:
+ \tl_set:Nn \l__mhchem_cf_state_tl { a }
+ \__mhchem_cf_loop:
+ }
}
}
{ 1 }
{
- \peek_charcode:NTF 1
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_element_tl
- \__mhchem_cf_loop:
- }
- {
- \peek_charcode:NTF 2
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_element_tl
- \__mhchem_cf_loop:
- }
- {
- \peek_charcode:NTF 3
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_element_tl
- \__mhchem_cf_loop:
- }
- {
- \peek_charcode:NTF 4
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_element_tl
- \__mhchem_cf_loop:
- }
- {
- \peek_charcode:NTF 5
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_element_tl
- \__mhchem_cf_loop:
- }
- {
- \peek_charcode:NTF 6
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_element_tl
- \__mhchem_cf_loop:
- }
- {
- \peek_charcode:NTF 7
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_element_tl
- \__mhchem_cf_loop:
- }
- {
- \peek_charcode:NTF 8
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_element_tl
- \__mhchem_cf_loop:
- }
- {
- \peek_charcode:NTF 9
+ \__mhchem_regex_peek:nTF { [ 0-9 \) \. \/ ] }
{
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_element_tl
+ \l__mhchem_cf_element_tl
\__mhchem_cf_loop:
- }
- {
- \peek_charcode:NTF 0
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_element_tl
- \__mhchem_cf_loop:
- }
- {
- \peek_charcode:NTF .
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_element_tl
- \__mhchem_cf_loop:
- }
- {
+ }{
\peek_charcode:NTF ,
{
- \tl_put_right:Nn \__mhchem_cf_element_tl { {,} }
+ \tl_put_right:Nn \l__mhchem_cf_element_tl { \__mhchem_output_commaDecimal: }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
- }
- {
- \peek_charcode:NTF /
+ }{
+ \peek_charcode:NTF -
{
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_element_tl
- \__mhchem_cf_loop:
+ \tl_set:Nn \l__mhchem_cf_state_tl { - }
+ \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
}
% else
{
\__mhchem_cf_outputAndReset:
- \tl_set:Nn \__mhchem_cf_state_tl { s }
+ \tl_set:Nn \l__mhchem_cf_state_tl { s }
\__mhchem_cf_loop:
}
- }}}}}}}}}}}}
+ }}
}
{ a }
{
\peek_charcode:NTF -
{
- \tl_set:Nn \__mhchem_cf_state_tl { - }
+ \tl_set:Nn \l__mhchem_cf_state_tl { - }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
}{
\peek_charcode:NTF =
{
- \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn
+ \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:nnNn
{ \dbond }
{ s }
\__mhchem_cf_loop:
}{
\peek_charcode:NTF ##
{
- \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn
+ \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:nnNn
{ \tbond }
{ s }
\__mhchem_cf_loop:
}{
\peek_charcode:NTF ^
{
- \str_if_eq:VnF \__mhchem_cf_supState_tl { - }
+ \str_if_eq:VnF \l__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 }
+ \str_if_eq:VnTF \l__mhchem_cf_subState_tl { - }
+ { \tl_set:Nn \l__mhchem_cf_supState_tl { kv } }
+ { \tl_set:Nn \l__mhchem_cf_supState_tl { d } }
+ \tl_set:Nn \l__mhchem_cf_state_tl { e }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
}{
\peek_charcode:NTF _
{
- \str_if_eq:VnF \__mhchem_cf_subState_tl { - }
+ \str_if_eq:VnF \l__mhchem_cf_subState_tl { - }
{ \__mhchem_cf_outputAndReset: }
- \tl_set:Nn \__mhchem_cf_subState_tl { d }
- \tl_set:Nn \__mhchem_cf_state_tl { f }
+ \tl_set:Nn \l__mhchem_cf_subState_tl { d }
+ \tl_set:Nn \l__mhchem_cf_state_tl { f }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
}{
\peek_charcode:NTF `
{
- \int_compare:nTF { \__mhchem_option_version_int < 4 }
+ \int_compare:nTF { \l__mhchem_option_version_int < 4 }
{
- \str_if_eq:VnF \__mhchem_cf_supState_tl { - }
+ \str_if_eq:VnF \l__mhchem_cf_supState_tl { - }
{ \__mhchem_cf_outputAndReset: }
- \tl_set:Nn \__mhchem_cf_supState_tl { rm }
- \tl_set:Nn \__mhchem_cf_state_tl { e }
+ \tl_set:Nn \l__mhchem_cf_supState_tl { rm }
+ \tl_set:Nn \l__mhchem_cf_state_tl { e }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
}
% else
{
- \str_if_eq:VnF \__mhchem_cf_supState_tl { - }
+ \str_if_eq:VnF \l__mhchem_cf_supState_tl { - }
{ \__mhchem_cf_outputAndReset: }
- \str_if_eq:VnF \__mhchem_cf_subState_tl { - }
+ \str_if_eq:VnF \l__mhchem_cf_subState_tl { - }
{ \__mhchem_cf_outputAndReset: }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_element_tl
+ \l__mhchem_cf_element_tl
\__mhchem_cf_loop:
}
}{
\peek_charcode:NTF ,
{
- \int_compare:nTF { \__mhchem_option_version_int < 4 }
+ \int_compare:nTF { \l__mhchem_option_version_int < 4 }
{
- \str_if_eq:VnF \__mhchem_cf_subState_tl { - }
+ \str_if_eq:VnF \l__mhchem_cf_subState_tl { - }
{ \__mhchem_cf_outputAndReset: }
- \tl_set:Nn \__mhchem_cf_subState_tl { rm }
- \tl_set:Nn \__mhchem_cf_state_tl { f }
+ \tl_set:Nn \l__mhchem_cf_subState_tl { rm }
+ \tl_set:Nn \l__mhchem_cf_state_tl { f }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
}
% else
{
\__mhchem_cf_outputAndReset:
- \tl_put_right:Nn \__mhchem_cf_result_tl { {,} }
- \__mhchem_loopHelper_ignoreNextToken:Nn
- \__mhchem_cf_loop:
+ \__mhchem_cf_outputRawElementAndReset:n
+ { \__mhchem_output_commaEnumeration: }
+ \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
}
}{
- \peek_charcode:NTF .
+ \__mhchem_regex_peek:nTF { [ \. \* ] }
{
- \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn
- { \mhchem@mathOrText@ii{{}\cdot{}}{\mhchem@option@textcdot} }
- { s }
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF *
- {
- \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn
- { \mhchem@mathOrText@ii{{}\cdot{}}{\mhchem@option@textcdot} }
+ \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:nnNn
+ { \__mhchem_output_additionCompound: }
{ s }
\__mhchem_cf_loop:
}{
\peek_charcode:NTF +
{
- \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 }
+ \tl_set:Nn \l__mhchem_cf_supState_tl { d }
+ \tl_set:Nn \l__mhchem_cf_state_tl { e }
\__mhchem_cf_loop:
}{
- \peek_charcode:NTF |
+ \__mhchem_regex_peek:nTF { [ \( \[ ] }
{
- \PackageWarning{mhchem}{The symbol | is not allowed here}
- \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF (
- {
- \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn
- { s }
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF )
- {
- \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn
- { a }
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF [
- {
- \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn
+ \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:nNn
{ s }
\__mhchem_cf_loop:
}{
- \peek_charcode:NTF ]
+ \__mhchem_regex_peek:nTF { [ \) \] \/ ] }
{
- \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn
+ \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:nNn
{ a }
\__mhchem_cf_loop:
}{
\peek_catcode:NTF \mhchem@macro
{
\__mhchem_cf_outputAndReset:
- \tl_set:Nn \__mhchem_cf_state_tl { c }
+ \tl_set:Nn \l__mhchem_cf_state_tl { c }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_result_tl
+ \l__mhchem_cf_element_tl
\__mhchem_cf_loop:
}{
\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: }
+ \str_if_eq:VnTF \l__mhchem_cf_supState_tl { - }
+ {
+ \str_if_eq:VnF \l__mhchem_cf_subState_tl { - }
+ { \__mhchem_cf_outputAndReset: }
+ }
+ {
+ \regex_match:nVTF
+ { \A [0-9]+ \Z}
+ \l__mhchem_cf_sup_tl
+ {
+ \tl_set:NV \l__mhchem_cf_loop_tmpa_l \l__mhchem_cf_sup_tl
+ \tl_set:NV \l__mhchem_cf_loop_tmpb_l \l__mhchem_cf_supState_tl
+ \tl_set:NV \l__mhchem_cf_loop_tmpc_l \l__mhchem_cf_sub_tl
+ \tl_set:NV \l__mhchem_cf_loop_tmpd_l \l__mhchem_cf_subState_tl
+ \tl_clear:N \l__mhchem_cf_sup_tl
+ \tl_set:Nn \l__mhchem_cf_supState_tl { - }
+ \tl_clear:N \l__mhchem_cf_sub_tl
+ \tl_set:Nn \l__mhchem_cf_subState_tl { - }
+ \__mhchem_cf_outputAndReset:
+ \tl_set:NV \l__mhchem_cf_presup_tl \l__mhchem_cf_loop_tmpa_l
+ \tl_set:NV \l__mhchem_cf_presupState_tl \l__mhchem_cf_loop_tmpb_l
+ \tl_set:NV \l__mhchem_cf_presub_tl \l__mhchem_cf_loop_tmpc_l
+ \tl_set:NV \l__mhchem_cf_presubState_tl \l__mhchem_cf_loop_tmpd_l
+ }
+ { \__mhchem_cf_outputAndReset: }
+ }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_element_tl
+ \l__mhchem_cf_element_tl
\__mhchem_cf_loop:
}{
- \peek_catcode:NTF 1 % number
+ \__mhchem_regex_peek:nTF { [ 0-9 ] }
{
- \str_if_eq:VnF \__mhchem_cf_subState_tl { - }
+ \str_if_eq:VnF \l__mhchem_cf_subState_tl { - }
{ \__mhchem_cf_outputAndReset: }
- \tl_set:Nn \__mhchem_cf_subState_tl { d }
- \tl_set:Nn \__mhchem_cf_state_tl { f }
+ \tl_set:Nn \l__mhchem_cf_subState_tl { d }
+ \tl_set:Nn \l__mhchem_cf_state_tl { f }
\__mhchem_cf_loop:
}{
\peek_catcode:NTF \c_group_begin_token
{
\__mhchem_cf_outputAndReset:
- \__mhchem_loopHelper_appendNextGroup:NNn
- \__mhchem_cf_result_tl
- \__mhchem_cf_loop:
+ \int_compare:nTF { \l__mhchem_option_version_int < 4 }
+ {
+ \__mhchem_loopHelper_appendNextGroup:NNn
+ \l__mhchem_cf_result_tl
+ \__mhchem_cf_loop:
+ }
+ % else
+ {
+ \__mhchem_loopHelper_appendNextGroup_prefix_ifEmpty:NnnNn
+ \l__mhchem_cf_element_tl
+ { \__mhchem_cg_escapeFromMathToTextOrFaketext:n }
+ {}
+ \__mhchem_cf_loop:
+ }
}{
\peek_catcode_remove:NTF \c_math_toggle_token
{
- \str_if_eq:VnF \__mhchem_cf_supState_tl { - }
+ \str_if_eq:VnF \l__mhchem_cf_supState_tl { - }
{ \__mhchem_cf_outputAndReset: }
- \str_if_eq:VnF \__mhchem_cf_subState_tl { - }
+ \str_if_eq:VnF \l__mhchem_cf_subState_tl { - }
{ \__mhchem_cf_outputAndReset: }
- \__mhchem_loopHelper_appendMathB:NNw
- \__mhchem_cf_element_tl
- \__mhchem_cf_loop:
+ \__mhchem_loopHelper_appendMathB:nn
+ { l__mhchem_cf_element_tl }
+ { __mhchem_cf_loop: }
}
% else
{
\__mhchem_cf_outputAndReset:
- \tl_set:Nn \__mhchem_cf_state_tl { s }
+ \tl_set:Nn \l__mhchem_cf_state_tl { s }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_result_tl
+ \l__mhchem_cf_result_tl
\__mhchem_cf_loop:
}
- }}}}}}}}}}}}}}}}}}}
+ }}}}}}}}}}}}}}}
}
{ e }
{
- \peek_charcode:NTF 1
- {
- \tl_set:Nn \__mhchem_cf_state_tl { e+ }
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 2
- {
- \tl_set:Nn \__mhchem_cf_state_tl { e+ }
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 3
- {
- \tl_set:Nn \__mhchem_cf_state_tl { e+ }
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 4
- {
- \tl_set:Nn \__mhchem_cf_state_tl { e+ }
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 5
- {
- \tl_set:Nn \__mhchem_cf_state_tl { e+ }
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 6
- {
- \tl_set:Nn \__mhchem_cf_state_tl { e+ }
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 7
- {
- \tl_set:Nn \__mhchem_cf_state_tl { e+ }
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 8
- {
- \tl_set:Nn \__mhchem_cf_state_tl { e+ }
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 9
- {
- \tl_set:Nn \__mhchem_cf_state_tl { e+ }
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 0
+ \__mhchem_regex_peek:nTF { [0-9] }
{
- \tl_set:Nn \__mhchem_cf_state_tl { e+ }
+ \tl_set:Nn \l__mhchem_cf_state_tl { e+ }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
+ \l__mhchem_cf_sup_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_sup_tl
- \__mhchem_cf_loop:
+ \tl_set:Nn \l__mhchem_cf_state_tl { a }
+ \__mhchem_loopHelper_appendMathB:nn
+ { l__mhchem_cf_sup_tl }
+ { __mhchem_cf_loop: }
}
% else
{
- \tl_set:Nn \__mhchem_cf_state_tl { a }
+ \tl_set:Nn \l__mhchem_cf_state_tl { a }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
+ \l__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 2
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 3
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 4
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 5
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 6
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 7
+ \__mhchem_regex_peek:nTF { [ 0-9 \+ ] }
{
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 8
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 9
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 0
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF +
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
+ \l__mhchem_cf_sup_tl
\__mhchem_cf_loop:
}{
\peek_charcode:NTF -
{
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
- \__mhchem_cf_loop:
+ \regex_match:nVTF
+ { \A (\c{eta}|\c{mu}|\c{kappa}) \Z }
+ \l__mhchem_cf_element_tl
+ {
+ \tl_set:Nn \l__mhchem_cf_state_tl { - }
+ \__mhchem_loopHelper_ignoreNextToken:Nn
+ \__mhchem_cf_loop:
+ }
+ {
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \l__mhchem_cf_sup_tl
+ \__mhchem_cf_loop:
+ }
}
% else
{
- \tl_set:Nn \__mhchem_cf_state_tl { a }
+ \tl_set:Nn \l__mhchem_cf_state_tl { a }
\__mhchem_cf_loop:
}
- }}}}}}}}}}}
+ }
}
{ f }
{
- \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
+ \__mhchem_regex_peek:nTF { [0-9] }
{
- \tl_set:Nn \__mhchem_cf_state_tl { f+ }
+ \tl_set:Nn \l__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
+ \l__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_sub_tl
- \__mhchem_cf_loop:
+ \tl_set:Nn \l__mhchem_cf_state_tl { a }
+ \__mhchem_loopHelper_appendMathB:nn
+ { l__mhchem_cf_sub_tl }
+ { __mhchem_cf_loop: }
}
% else
{
- \tl_set:Nn \__mhchem_cf_state_tl { a }
+ \tl_set:Nn \l__mhchem_cf_state_tl { a }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sub_tl
+ \l__mhchem_cf_sub_tl
\__mhchem_cf_loop:
}
- }}}}}}}}}}
+ }
}
{ f+ }
{
- \peek_charcode:NTF 1
+ \__mhchem_regex_peek:nTF { [0-9] }
{
\__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
+ \l__mhchem_cf_sub_tl
\__mhchem_cf_loop:
}
% else
{
- \tl_set:Nn \__mhchem_cf_state_tl { a }
+ \tl_set:Nn \l__mhchem_cf_state_tl { a }
\__mhchem_cf_loop:
}
- }}}}}}}}}
}
{ p }
{
- \peek_charcode:NTF 1
- {
- \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:
- }{
- \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
+ \__mhchem_regex_peek:nTF { [0-9] }
{
- \tl_set:Nn \__mhchem_cf_state_tl { p+ }
+ \tl_set:Nn \l__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
+ \l__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_presup_tl
- \__mhchem_cf_loop:
+ \tl_set:Nn \l__mhchem_cf_state_tl { s }
+ \__mhchem_loopHelper_appendMathB:nn
+ { l__mhchem_cf_presup_tl }
+ { __mhchem_cf_loop: }
}
% else
{
- \tl_set:Nn \__mhchem_cf_state_tl { s }
+ \tl_set:Nn \l__mhchem_cf_state_tl { s }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presup_tl
+ \l__mhchem_cf_presup_tl
\__mhchem_cf_loop:
- }}}}}}}}}}}
+ }
+ }
}
{ p+ }
{
- \peek_charcode:NTF 1
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 2
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 3
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 4
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 5
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 6
+ \__mhchem_regex_peek:nTF { [0-9] }
{
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 7
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 8
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 9
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presup_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 0
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presup_tl
+ \l__mhchem_cf_presup_tl
\__mhchem_cf_loop:
}
% else
{
- \tl_set:Nn \__mhchem_cf_state_tl { s }
+ \tl_set:Nn \l__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 2
- {
- \tl_set:Nn \__mhchem_cf_state_tl { q+ }
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presub_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 3
- {
- \tl_set:Nn \__mhchem_cf_state_tl { q+ }
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presub_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 4
- {
- \tl_set:Nn \__mhchem_cf_state_tl { q+ }
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presub_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 5
+ \__mhchem_regex_peek:nTF { [0-9] }
{
- \tl_set:Nn \__mhchem_cf_state_tl { q+ }
+ \tl_set:Nn \l__mhchem_cf_state_tl { q+ }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presub_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 6
- {
- \tl_set:Nn \__mhchem_cf_state_tl { q+ }
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presub_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 7
- {
- \tl_set:Nn \__mhchem_cf_state_tl { q+ }
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presub_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 8
- {
- \tl_set:Nn \__mhchem_cf_state_tl { q+ }
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presub_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 9
- {
- \tl_set:Nn \__mhchem_cf_state_tl { q+ }
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presub_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 0
- {
- \tl_set:Nn \__mhchem_cf_state_tl { q+ }
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presub_tl
+ \l__mhchem_cf_presub_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_loop:
+ \tl_set:Nn \l__mhchem_cf_state_tl { s }
+ \__mhchem_loopHelper_appendMathB:nn
+ { l__mhchem_cf_presub_tl }
+ { __mhchem_cf_loop: }
}
% else
{
- \tl_set:Nn \__mhchem_cf_state_tl { s }
+ \tl_set:Nn \l__mhchem_cf_state_tl { s }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presub_tl
+ \l__mhchem_cf_presub_tl
\__mhchem_cf_loop:
- }}}}}}}}}}}
+ }
+ }
}
{ q+ }
{
- \peek_charcode:NTF 1
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presub_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 2
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presub_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 3
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presub_tl
- \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF 4
- {
- \__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_regex_peek:nTF { [0-9] }
{
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presub_tl
+ \l__mhchem_cf_presub_tl
\__mhchem_cf_loop:
}
% else
{
- \tl_set:Nn \__mhchem_cf_state_tl { s }
+ \tl_set:Nn \l__mhchem_cf_state_tl { s }
\__mhchem_cf_loop:
- }}}}}}}}}}
+ }
}
}
{
\msg_error:nnx { mhchem } { cf / unexpected-state }
- { \__mhchem_cf_state_tl }
+ { \l__mhchem_cf_state_tl }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_result_tl
+ \l__mhchem_cf_result_tl
\__mhchem_cf_loop:
}
}}}
}
-\def\mhchem@cf@switchState#1#2|{%
- \ifthenelse{\equal{1}{#2}}{%
- \tl_set:Nn \__mhchem_cf_state_tl { a }%
- }{%
- \PackageWarning{mhchem}{Command |#2| unknown}%
- }%
- \mhchem@cf@continue%
-}%
\cs_new_protected:Npn \__mhchem_cf_output:
{
- \str_if_eq:nnTF
+ \bool_if:nTF
{
- \__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
+ \tl_if_empty_p:N \l__mhchem_cf_presup_tl &&
+ \tl_if_empty_p:N \l__mhchem_cf_presub_tl &&
+ \tl_if_empty_p:N \l__mhchem_cf_element_tl &&
+ \tl_if_empty_p:N \l__mhchem_cf_sub_tl &&
+ \tl_if_empty_p:N \l__mhchem_cf_sup_tl
}
- {} % is empty?
{
}
{
- \str_case:Vnn \__mhchem_cf_state_tl
+ \tl_set:NV \l__mhchem_cf_lastElement_tl \l__mhchem_cf_element_tl
+ \str_case:Vnn \l__mhchem_cf_state_tl
{
{ 1 }
{
- \tl_put_right:Nx \__mhchem_cf_result_tl
+ \__mhchem_cg_replaceForAmount:N \l__mhchem_cf_element_tl
+ \tl_put_right:Nx \l__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 } }
+ \exp_not:N \__mhchem_output_withFont:n {
+ \exp_not:V \l__mhchem_cf_element_tl
+ }
+ \exp_not:N \mhchem@option@skipAfterAmount
}
}
{ 9 }
{
- \tl_put_right:Nx \__mhchem_cf_result_tl
+ \__mhchem_cg_replaceForAmount:N \l__mhchem_cf_element_tl
+ \tl_put_right:Nx \l__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_output_withFont:n {
+ \exp_not:V \l__mhchem_cf_element_tl
+ }
}
}
}
{
- \str_if_eq:VnTF \__mhchem_cf_supState_tl { rm }
- {
- \tl_set:Nx \__mhchem_cf_sup_tl { \exp_not:N \ensuremath { \exp_not:N \mathrm { \exp_not:V \__mhchem_cf_sup_tl } } }
- }
- {}
- \str_if_eq:VnT \__mhchem_cf_subState_tl { rm }
- {
- \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 }
- {
- \tl_set:Nx \__mhchem_cf_presup_tl { \exp_not:N \ensuremath { \exp_not:N \mathrm { \exp_not:V \__mhchem_cf_presup_tl } } }
- }
- {}
- \str_if_eq:VnT \__mhchem_cf_presubState_tl { rm }
- {
- \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
+ \str_if_eq:VnTF \l__mhchem_cf_presupState_tl { rm }
+ { \tl_set:Nx \l__mhchem_cf_presup_tl { \exp_not:N \__mhchem_output_escapeToRomanMath:n { \exp_not:V \l__mhchem_cf_presup_tl } } }
+ { \__mhchem_cg_replaceForSuperscript:N \l__mhchem_cf_presup_tl }
+ \str_if_eq:VnTF \l__mhchem_cf_presubState_tl { rm }
+ { \tl_set:Nx \l__mhchem_cf_presub_tl { \exp_not:N \__mhchem_output_escapeToRomanMath:n { \exp_not:V \l__mhchem_cf_presub_tl } } }
+ { \__mhchem_cg_replaceForSubscript:N \l__mhchem_cf_presub_tl }
+ \__mhchem_cg_replaceForElement:N \l__mhchem_cf_element_tl
+ \str_if_eq:VnTF \l__mhchem_cf_subState_tl { rm }
+ { \tl_set:Nx \l__mhchem_cf_sub_tl { \exp_not:N \__mhchem_output_escapeToRomanMath:n { \exp_not:V \l__mhchem_cf_sub_tl } } }
+ { \__mhchem_cg_replaceForSubscript:N \l__mhchem_cf_sub_tl }
+ \str_if_eq:VnTF \l__mhchem_cf_supState_tl { rm }
+ { \tl_set:Nx \l__mhchem_cf_sup_tl { \exp_not:N \__mhchem_output_escapeToRomanMath:n { \exp_not:V \l__mhchem_cf_sup_tl } } }
+ { \__mhchem_cg_replaceForSuperscript:N \l__mhchem_cf_sup_tl }
+ \bool_if:nT
+ {
+ \str_if_eq_p:Vn \l__mhchem_cf_supState_tl { kv } &&
+ \str_if_eq_p:Vn \l__mhchem_cf_sub_tl {}
+ }
+ { \tl_set:Nn \l__mhchem_cf_supState_tl { d } }
+ \str_case:Vnn \l__mhchem_cf_supState_tl
{
{ kv }
{
- \tl_put_right:Nx \__mhchem_cf_result_tl
+ \tl_put_right:Nx \l__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_output_coreFive:nnnnnn
+ { \exp_not:V \l__mhchem_cf_presup_tl }
+ { \exp_not:V \l__mhchem_cf_presub_tl }
+ { \exp_not:V \l__mhchem_cf_element_tl }
+ { \exp_not:V \l__mhchem_cf_sup_tl }
+ { \exp_not:V \l__mhchem_cf_sub_tl }
{}
}
}
}
{
- \tl_put_right:Nx \__mhchem_cf_result_tl
+ \tl_put_right:Nx \l__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_output_coreFive:nnnnnn
+ { \exp_not:V \l__mhchem_cf_presup_tl }
+ { \exp_not:V \l__mhchem_cf_presub_tl }
+ { \exp_not:V \l__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 }
- }
- }
+ { \exp_not:V \l__mhchem_cf_sub_tl }
+ { \exp_not:V \l__mhchem_cf_sup_tl }
+ }
}
}
}
}
+\cs_new_protected:Npn \__mhchem_cf_outputRawElement:
+ {
+ \tl_set:NV \l__mhchem_cf_lastElement_tl \l__mhchem_cf_element_tl
+ \tl_put_right:Nx \l__mhchem_cf_result_tl { \exp_not:V \l__mhchem_cf_element_tl }
+ }
\cs_new_protected:Npn \__mhchem_cf_outputAndReset:
{
\__mhchem_cf_output:
\__mhchem_cf_resetOutput:
}
+\cs_new_protected:Npn \__mhchem_cf_outputRawElementAndReset:
+ {
+ \__mhchem_cf_outputRawElement:
+ \__mhchem_cf_resetOutput:
+ }
+\cs_new_protected:Npn \__mhchem_cf_outputRawElementAndReset:n #1
+ {
+ \tl_put_right:Nn \l__mhchem_cf_element_tl {#1}
+ \__mhchem_cf_outputRawElementAndReset:
+ }
-%%% frac
-\def\mhchem@cf@frac#1/#2\mhchem@END#3{%
- \ifthenelse{\equal{#2}{}}{%
- #1#3%
- }{%
- \ensuremath{\mathchoice%
- {\textstyle%
- \frac{\mhchem@mathOrText{#1}}{\mhchem@mathOrText{\mhchem@getfirstchar#2\mhchem@ENDgetfirstchar}}#3}%
- {\frac{\mhchem@mathOrText{#1}}{\mhchem@mathOrText{\mhchem@getfirstchar#2\mhchem@ENDgetfirstchar}}#3}%
- {\frac{\mhchem@mathOrText{#1}}{\mhchem@mathOrText{\mhchem@getfirstchar#2\mhchem@ENDgetfirstchar}}#3}%
- {\frac{\mhchem@mathOrText{#1}}{\mhchem@mathOrText{\mhchem@getfirstchar#2\mhchem@ENDgetfirstchar}}#3}%
- }%
- }%
-}%
-\def\mhchem@getfirstchar#1#2\mhchem@ENDgetfirstchar{#1}
-\def\mhchem@getlastchars#1#2\mhchem@ENDgetlastchars{#2}
-
-%%% replaceMath
-\tl_new:N \__mhchem_cf_replaceMath_result_tl
-\cs_new_protected:Npn \__mhchem_cf_replaceMath:n #1
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%% cg %%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\cs_new_protected:Npn \__mhchem_cg_withinMathTokens:n #1
{
- \tl_clear:N \__mhchem_cf_replaceMath_result_tl
- \__mhchem_cf_replaceMath_loop: #1 \q_recursion_stop
- \__mhchem_cf_replaceMath_result_tl
+ \int_compare:nTF { \l__mhchem_option_version_int > 3 }
+ {
+ \regex_match:nnTF
+ { \A \cB. [^\cE.]* \cE. \Z } {#1}
+ {
+ \__mhchem_output_escapeFromMathToItalicMath:n { #1 }
+ }
+ % else
+ {
+ \regex_match:nnTF
+ { \A [1-9a-zA-Z\ \~\+\-\,\.\(\)\c{alpha}\c{beta}\c{gamma}\c{delta}\c{epsilon}\c{zeta}\c{eta}\c{theta}\c{iota}\c{kappa}\c{lambda}\c{mu}\c{nu}\c{xi}\c{omicron}\c{pi}\c{rho}\c{sigma}\c{tau}\c{upsilon}\c{phi}\c{chi}\c{psi}\c{omega}\c{Alpha}\c{Beta}\c{Gamma}\c{Delta}\c{Epsilon}\c{Zeta}\c{Eta}\c{Theta}\c{Iota}\c{Kappa}\c{Lambda}\c{Mu}\c{Nu}\c{Xi}\c{Omicron}\c{Pi}\c{Rho}\c{Sigma}\c{Tau}\c{Upsilon}\c{Phi}\c{Chi}\c{Psi}\c{Omega}]+ \Z }
+ {#1}
+ {
+ {
+ \bool_if:NTF \l__mhchem_output_isMathMode_bool
+ {
+ \int_compare:nT
+ { \l__mhchem_option_version_int > 3 }
+ {
+ \thinmuskip=0mu
+ \medmuskip=0mu
+ \thickmuskip=0mu
+ }
+ \__mhchem_output_escapeFromMathToItalicMath:n {#1}
+ }
+ {
+ \tl_set:Nn \l_tmpa_tl { #1 }
+ \regex_replace_all:nnN
+ { [a-zA-Z]+ }
+ { \c{__mhchem_output_escapeFromTextToItalicText:n} \cB[ \0 \cE] }
+ \l_tmpa_tl
+ \regex_replace_all:nnN
+ { [\ ]+ }
+ {}
+ \l_tmpa_tl
+ \regex_replace_all:nnN
+ { - }
+ { \c{mhchem@option@textminus} }
+ \l_tmpa_tl
+ \tl_use:N \l_tmpa_tl
+ }
+ }
+ }
+ {
+ \bool_if:NTF \l__mhchem_output_isMathMode_bool
+ { \__mhchem_output_escapeFromMathToItalicMath:n {#1} }
+ { \__mhchem_output_escapeFromTextToItalicMath:n {#1} }
+ }
+ }
+ }
+ % else
+ {
+ \__mhchem_output_escapeFromMathToItalicMath:n {#1}
+ }
}
-\cs_new_protected:Npn \__mhchem_cf_replaceMath_loop:
+\cs_new_protected:Npn \__mhchem_cg_itshape:n #1
+ {
+ \int_compare:nTF { \l__mhchem_option_version_int > 3 }
+ {
+ \bool_if:NTF \l__mhchem_output_isMathMode_bool
+ { \__mhchem_output_escapeFromMathToItalicMath:n {#1} }
+ { \__mhchem_output_escapeFromTextToItalicText:n {#1} }
+ }
+ { #1 }
+ }
+\cs_new_protected:Npn \__mhchem_cg_escapeFromMathToTextOrFaketext:n #1
+ {
+ \bool_if:NTF \l__mhchem_output_isMathMode_bool
+ { \__mhchem_cg_escapeFromMathToFakeText:n {#1} }
+ { \__mhchem_output_escapeFromMathToText:n { #1 } }
+ }
+\tl_new:N \l__mhchem_cg_escapeFromMathToFakeText_result_tl
+\cs_new_protected:Npn \__mhchem_cg_escapeFromMathToFakeText:n #1
+ {
+ \tl_clear:N \l__mhchem_cg_escapeFromMathToFakeText_result_tl
+ \__mhchem_cg_escapeFromMathToFakeText_loop: #1 \q_recursion_stop
+ \__mhchem_output_escapeFromMathToRomanMath:n { \tl_use:N \l__mhchem_cg_escapeFromMathToFakeText_result_tl }
+ }
+\cs_new_protected:Npn \__mhchem_cg_escapeFromMathToFakeText_loop:
{
\peek_meaning:NTF \q_recursion_stop
{ \use_none:n }
{
- \peek_catcode_remove:NTF \c_math_toggle_token % math $
+ \peek_charcode_remove:NTF \c_space_token
+ {
+ \tl_put_right:Nn
+ \l__mhchem_cg_escapeFromMathToFakeText_result_tl
+ { \mkern6mu }
+ \__mhchem_cg_escapeFromMathToFakeText_loop:
+ }{
+ \peek_charcode_remove:NTF -
+ {
+ \tl_put_right:Nn
+ \l__mhchem_cg_escapeFromMathToFakeText_result_tl
+ { \mhchem@hyphen }
+ \__mhchem_cg_escapeFromMathToFakeText_loop:
+ }{
+ \peek_catcode_remove:NTF \c_math_toggle_token
{
- \__mhchem_loopHelper_appendMathB:NNw
- \__mhchem_cf_replaceMath_result_tl
- \__mhchem_cf_replaceMath_loop:
+ \__mhchem_loopHelper_appendMathB:nn
+ { l__mhchem_cg_escapeFromMathToFakeText_result_tl }
+ { __mhchem_cg_escapeFromMathToFakeText_loop: }
}
{
\peek_catcode:NTF \c_group_begin_token
{
\__mhchem_loopHelper_appendNextGroup:NNn
- \__mhchem_cf_replaceMath_result_tl
- \__mhchem_cf_replaceMath_loop:
+ \l__mhchem_cg_escapeFromMathToFakeText_result_tl
+ \__mhchem_cg_escapeFromMathToFakeText_loop:
}
% else
{
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_replaceMath_result_tl
- \__mhchem_cf_replaceMath_loop:
+ \l__mhchem_cg_escapeFromMathToFakeText_result_tl
+ \__mhchem_cg_escapeFromMathToFakeText_loop:
}
- }}
+ }}}}
+ }
+
+\cs_new_protected:Npn \__mhchem_cg_replaceForAmount:N #1
+ {
+ \regex_replace_once:nnN
+ { \A ([0-9]+)\/([0-9]+) \Z } { \c{__mhchem_cg_frac:nn} \cB[\1\cE] \cB[\2\cE] } #1
}
-%%% replaceMathMinusDot
-\tl_new:N \__mhchem_cf_replaceMathMinusDot_result_tl
-\cs_new_protected:Npn \__mhchem_cf_replaceMathMinusDot:n #1
+\cs_new_protected:Npn \__mhchem_cg_frac:nn #1#2
{
- \tl_clear:N \__mhchem_cf_replaceMathMinusDot_result_tl
- \__mhchem_cf_replaceMathMinusDot_loop: #1 \q_recursion_stop
- \__mhchem_cf_replaceMathMinusDot_result_tl
+ \ensuremath{\frac
+ { \__mhchem_output_withFont:n {#1} }
+ { \__mhchem_output_withFont:n {#2} }
+ }
+ }
+
+\cs_new_protected:Npn \__mhchem_cg_replaceForElement:N #1
+ {}
+
+\tl_new:N \l__mhchem_cg_replaceForSubscript_result_tl
+\tl_new:N \l__mhchem_cg_replaceForSubscript_state_tl
+\cs_new_protected:Npn \__mhchem_cg_replaceForSubscript:N #1
+ {
+ \int_compare:nTF { \l__mhchem_option_version_int > 3}
+ {
+ \regex_match:nVTF
+ { \A( [nmpx] | ([0-9\ \+\-\,\.\(\)]+ [nmpx] [0-9\ \+\-\,\.\(\)]*)+ | ([0-9\ \+\-\,\.\(\)]* [nmpx] [0-9\ \+\-\,\.\(\)]+)+ )\Z }
+ #1
+ {
+ \regex_replace_all:nnN
+ { [nmpx] }
+ { \c{__mhchem_output_withFont:n}\cB[ \c{__mhchem_cg_itshape:n}\cB[ \0 \cE]\cE] }
+ #1
+ \regex_replace_all:nnN
+ { - }
+ { \c{__mhchem_output_minus:} }
+ #1
+ \regex_replace_all:nnN
+ { \d\,\d }
+ { \c{__mhchem_output_commaDecimal:} }
+ #1
+ }
+ {
+ \tl_clear:N \l__mhchem_cg_replaceForSubscript_result_tl
+ \tl_set:Nn \l__mhchem_cg_replaceForSubscript_state_tl { s }
+ \exp_after:wN \__mhchem_cg_replaceForSubscript_loop: #1 \q_recursion_stop
+ \tl_set:NV #1 \l__mhchem_cg_replaceForSubscript_result_tl
+ }
+ }
+ % else
+ {
+ \tl_clear:N \l__mhchem_cg_replaceForSubscript_result_tl
+ \tl_set:Nn \l__mhchem_cg_replaceForSubscript_state_tl { s }
+ \exp_after:wN \__mhchem_cg_replaceForSubscript_loop: #1 \q_recursion_stop
+ \tl_set:NV #1 \l__mhchem_cg_replaceForSubscript_result_tl
+ }
}
-\cs_new_protected:Npn \__mhchem_cf_replaceMathMinusDot_loop:
+\cs_new_protected:Npn \__mhchem_cg_replaceForSubscript_loop:
{
\peek_meaning:NTF \q_recursion_stop
{ \use_none:n }
{
+ \__mhchem_regex_peek:nTF { [0-9] }
+ {
+ \tl_set:Nn \l__mhchem_cg_replaceForSubscript_state_tl { 9 }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \l__mhchem_cg_replaceForSubscript_result_tl
+ \__mhchem_cg_replaceForSubscript_loop:
+ }{
\peek_charcode_remove:NTF -
{
- \tl_put_right:Nn \__mhchem_cf_replaceMathMinusDot_result_tl
- { \mhchem@mathOrText@ii{-}{\mhchem@option@textminus} }
- \__mhchem_cf_replaceMathMinusDot_loop:
+ \int_compare:nTF { \l__mhchem_option_version_int > 3 }
+ {
+ \tl_put_right:Nn \l__mhchem_cg_replaceForSubscript_result_tl
+ { \__mhchem_output_minus: }
+ }
+ {
+ \tl_put_right:Nn \l__mhchem_cg_replaceForSubscript_result_tl { - }
+ }
+ \tl_set:Nn \l__mhchem_cg_replaceForSubscript_state_tl { s }
+ \__mhchem_cg_replaceForSubscript_loop:
}{
- \peek_charcode_remove:NTF .
+ \peek_charcode_remove:NTF ,
{
- \tl_put_right:Nn \__mhchem_cf_replaceMathMinusDot_result_tl
- { \ensuremath{\textbf{\fontfamily{cmr}\selectfont\textperiodcentered}} }
- \__mhchem_cf_replaceMathMinusDot_loop:
+ \str_if_eq:VnTF \l__mhchem_cg_replaceForSubscript_state_tl { 9 }
+ {
+ \tl_put_right:Nn \l__mhchem_cg_replaceForSubscript_result_tl
+ { \__mhchem_output_commaAutoSmall: }
+ }
+ {
+ \tl_put_right:Nn \l__mhchem_cg_replaceForSubscript_result_tl
+ { \__mhchem_output_commaEnumerationSmall: }
+ }
+ \tl_set:Nn \l__mhchem_cg_replaceForSubscript_state_tl { s }
+ \__mhchem_cg_replaceForSubscript_loop:
}{
- \peek_catcode_remove:NTF \c_math_toggle_token % math $
+ \peek_catcode_remove:NTF \c_math_toggle_token
{
- \__mhchem_loopHelper_appendMathB:NNw
- \__mhchem_cf_replaceMathMinusDot_result_tl
- \__mhchem_cf_replaceMathMinusDot_loop:
+ \tl_set:Nn \l__mhchem_cg_replaceForSubscript_state_tl { s }
+ \__mhchem_loopHelper_appendMathB:nn
+ { l__mhchem_cg_replaceForSubscript_result_tl }
+ { __mhchem_cg_replaceForSubscript_loop: }
}
{
\peek_catcode:NTF \c_group_begin_token
{
+ \tl_set:Nn \l__mhchem_cg_replaceForSubscript_state_tl { s }
\__mhchem_loopHelper_appendNextGroup:NNn
- \__mhchem_cf_replaceMathMinusDot_result_tl
- \__mhchem_cf_replaceMathMinusDot_loop:
+ \l__mhchem_cg_replaceForSubscript_result_tl
+ \__mhchem_cg_replaceForSubscript_loop:
}
% else
{
+ \tl_set:Nn \l__mhchem_cg_replaceForSubscript_state_tl { s }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_replaceMathMinusDot_result_tl
- \__mhchem_cf_replaceMathMinusDot_loop:
+ \l__mhchem_cg_replaceForSubscript_result_tl
+ \__mhchem_cg_replaceForSubscript_loop:
}
- }}}}
+ }}}}}
}
-\cs_new_protected:Npn \__mhchem_defMathOrText:
+\tl_new:N \l__mhchem_cg_replaceForSuperscript_result_tl
+\tl_new:N \l__mhchem_cg_replaceForSuperscript_state_tl
+\cs_new_protected:Npn \__mhchem_cg_replaceForSuperscript:N #1
{
- \mode_if_math:TF
+ \tl_clear:N \l__mhchem_cg_replaceForSuperscript_result_tl
+ \tl_set:Nn \l__mhchem_cg_replaceForSuperscript_state_tl { s }
+ \exp_after:wN \__mhchem_cg_replaceForSuperscript_loop: #1 \q_recursion_stop
+ \tl_set:NV #1 \l__mhchem_cg_replaceForSuperscript_result_tl
+ }
+\cs_new_protected:Npn \__mhchem_cg_replaceForSuperscript_loop:
+ {
+ \peek_meaning:NTF \q_recursion_stop
{
- \int_compare:nTF { \__mhchem_option_version_int > 1 }
+ \str_if_eq:VnT \l__mhchem_cg_replaceForSuperscript_state_tl { 9. }
{
- \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
+ \tl_put_right:Nn \l__mhchem_cg_replaceForSuperscript_result_tl
+ { \__mhchem_output_electronDot: }
+ }
+ \use_none:n
+ }{
+ \peek_charcode_remove:NTF -
+ {
+ \str_if_eq:VnT \l__mhchem_cg_replaceForSuperscript_state_tl { 9. }
+ {
+ \tl_put_right:Nn \l__mhchem_cg_replaceForSuperscript_result_tl
+ { \__mhchem_output_electronDot: }
+ }
+ \tl_set:Nn \l__mhchem_cg_replaceForSuperscript_state_tl { s }
+ \tl_put_right:Nn \l__mhchem_cg_replaceForSuperscript_result_tl
+ { \__mhchem_output_minus: }
+ \__mhchem_cg_replaceForSuperscript_loop:
+ }{
+ \peek_charcode_remove:NTF .
+ {
+ \str_case:Vnn \l__mhchem_cg_replaceForSuperscript_state_tl
+ {
+ { 9. }
{
- \mode_if_math:TF
- { \exp_not:N \mhchem@option@mathFont{##1} }
- { ##2 }
+ \tl_put_right:Nn \l__mhchem_cg_replaceForSuperscript_result_tl
+ { \__mhchem_output_electronDot: \__mhchem_output_electronDot: }
+ \tl_set:Nn \l__mhchem_cg_replaceForSuperscript_state_tl { s }
}
+ { 9 }
+ { \tl_set:Nn \l__mhchem_cg_replaceForSuperscript_state_tl { 9. } }
}
- % else
{
- \cs_set:Npx \mhchem@mathOrText ##1
+ \tl_put_right:Nn \l__mhchem_cg_replaceForSuperscript_result_tl
+ { \__mhchem_output_electronDot: }
+ }
+ \__mhchem_cg_replaceForSuperscript_loop:
+ }{
+ \__mhchem_regex_peek:nTF { [ nmpx ] }
+ {
+ \str_if_eq:VnT \l__mhchem_cg_replaceForSuperscript_state_tl { 9. }
+ {
+ \tl_put_right:Nn \l__mhchem_cg_replaceForSuperscript_result_tl
+ { \__mhchem_output_electronDot: }
+ }
+ \tl_set:Nn \l__mhchem_cg_replaceForSuperscript_state_tl { s }
+ \tl_put_right:Nn \l__mhchem_cg_replaceForSuperscript_result_tl
+ { \__mhchem_cg_itshape:n }
+ \__mhchem_loopHelper_appendNextGroup:NNn
+ \l__mhchem_cg_replaceForSuperscript_result_tl
+ \__mhchem_cg_replaceForSuperscript_loop:
+ }{
+ \__mhchem_regex_peek:nTF { [0-9] }
+ {
+ \str_if_eq:VnT \l__mhchem_cg_replaceForSuperscript_state_tl { 9. }
+ { \tl_put_right:Nn \l__mhchem_cg_replaceForSuperscript_result_tl { . } }
+ \tl_set:Nn \l__mhchem_cg_replaceForSuperscript_state_tl { 9 }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \l__mhchem_cg_replaceForSuperscript_result_tl
+ \__mhchem_cg_replaceForSuperscript_loop:
+ }{
+ \peek_charcode_remove:NTF *
+ {
+ \str_if_eq:VnT \l__mhchem_cg_replaceForSuperscript_state_tl { 9. }
+ {
+ \tl_put_right:Nn \l__mhchem_cg_replaceForSuperscript_result_tl
+ { \__mhchem_output_electronDot: }
+ }
+ \tl_set:Nn \l__mhchem_cg_replaceForSuperscript_state_tl { s }
+ \tl_put_right:Nn \l__mhchem_cg_replaceForSuperscript_result_tl
+ { \__mhchem_output_excited: }
+ \__mhchem_cg_replaceForSuperscript_loop:
+ }{
+ \peek_charcode_remove:NTF ,
+ {
+ \str_case:Vnn \l__mhchem_cg_replaceForSuperscript_state_tl
+ {
+ { 9. }
{
- \mode_if_math:TF { ##1 } { \exp_not:N \text{##1} }
+ \tl_put_right:Nn \l__mhchem_cg_replaceForSuperscript_result_tl
+ { \__mhchem_output_electronDot: }
}
- \cs_set:Npx \mhchem@mathOrText@ii ##1##2
+ { 9 }
{
- \mode_if_math:TF { ##1 } { ##2 }
- }
+ \tl_put_right:Nn \l__mhchem_cg_replaceForSuperscript_result_tl
+ { \__mhchem_output_commaAutoSmall: }
+ }
+ }
+ {
+ \tl_put_right:Nn \l__mhchem_cg_replaceForSuperscript_result_tl
+ { \__mhchem_output_commaEnumerationSmall: }
+ }
+ \tl_set:Nn \l__mhchem_cg_replaceForSuperscript_state_tl { s }
+ \__mhchem_cg_replaceForSuperscript_loop:
+ }{
+ \peek_catcode_remove:NTF \c_math_toggle_token
+ {
+ \str_if_eq:VnT \l__mhchem_cg_replaceForSuperscript_state_tl { 9. }
+ {
+ \tl_put_right:Nn \l__mhchem_cg_replaceForSuperscript_result_tl
+ { \__mhchem_output_electronDot: }
+ }
+ \tl_set:Nn \l__mhchem_cg_replaceForSuperscript_state_tl { s }
+ \__mhchem_loopHelper_appendMathB:nn
+ { l__mhchem_cg_replaceForSuperscript_result_tl }
+ { __mhchem_cg_replaceForSuperscript_loop: }
+ }{
+ \peek_catcode:NTF \c_group_begin_token
+ {
+ \str_if_eq:VnT \l__mhchem_cg_replaceForSuperscript_state_tl { 9. }
+ {
+ \tl_put_right:Nn \l__mhchem_cg_replaceForSuperscript_result_tl
+ { \__mhchem_output_electronDot: }
}
+ \tl_set:Nn \l__mhchem_cg_replaceForSuperscript_state_tl { s }
+ \__mhchem_loopHelper_appendNextGroup:NNn
+ \l__mhchem_cg_replaceForSuperscript_result_tl
+ \__mhchem_cg_replaceForSuperscript_loop:
}
% else
{
-
- \mhchem@option@textFont
- \cs_set:Npx \mhchem@mathOrText ##1 { \exp_not:N \text{##1} }
- \cs_set:Npx \mhchem@mathOrText@ii ##1##2 { ##2 }
+ \str_if_eq:VnT \l__mhchem_cg_replaceForSuperscript_state_tl { 9. }
+ {
+ \tl_put_right:Nn \l__mhchem_cg_replaceForSuperscript_result_tl
+ { \__mhchem_output_electronDot: }
+ }
+ \tl_set:Nn \l__mhchem_cg_replaceForSuperscript_state_tl { s }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \l__mhchem_cg_replaceForSuperscript_result_tl
+ \__mhchem_cg_replaceForSuperscript_loop:
}
+ }}}}}}}}
}
-%%%%%%%%%%%%%%%%%%%%%
-%%% @chemfive %%%
-%%%%%%%%%%%%%%%%%%%%%
-\cs_new_protected:Npn \__mhchem_chemfive:nnnnnn #1#2#3#4#5#6
- {
- \bool_if:NTF \__mhchem_option_superscriptsStacked_bool
- {
- \__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}}}%
- {\mhchem@mathOrText{#4#6}}%
- {\mhchem@mathOrText{#5}}%
- {}%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%% output %%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\bool_new:N \l__mhchem_output_isMathMode_bool
+\cs_new_protected:Npn \__mhchem_output_defMathOrText:
+ {
+ \bool_if:nTF
+ {
+ \mode_if_math_p: ||
+ ( \l__mhchem_ce_ceActive_bool && \int_compare_p:n { \l__mhchem_option_version_int < 2 } )
+ }
+ {
+ \bool_set_true:N \l__mhchem_output_isMathMode_bool
}
{
- \__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}}}%
- {\mhchem@mathOrText{#4}}%
- {\mhchem@mathOrText{#5}}%
- {\mhchem@mathOrText{#6}}%
+ \bool_set_false:N \l__mhchem_output_isMathMode_bool
+ \mhchem@option@textFont
}
}
-
-%%% @prepostscript
-\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
+\cs_new_protected:Npn \__mhchem_output_coreFive:nnnnnn #1#2#3#4#5#6
{
+ \group_begin:
+ \bool_if:nT
+ { \str_if_eq_p:nn {#6} {} && ! \str_if_eq_p:nn {#4} {} }
+ { \bool_set_true:N \l__mhchem_option_superscriptsStacked_bool }
\m@th
\ensuremath
{
- \hbox_set:Nn \l_tmpa_box { $#4#5$ }
- \dim_compare:nNnT { \box_wd:N \l_tmpa_box } > { 0pt }
+ \str_if_eq:nnF {#1#2} {}
{
- \hphantom { {}^{#4}\c_math_subscript_token{#5} }
- { \vphantom {#3#6} }
+ \hphantom { {}^{\__mhchem_output_withFont:n{#1}}\c_math_subscript_token{\__mhchem_output_withFont:n{#2}} }
+ { \vphantom { \__mhchem_output_withFont:n { X } } }
^ {
\mhchem@mathboxrightt
{
- \vphantom {#1}
- #4
+ \vphantom { \__mhchem_output_scriptWithFont:n { 2+ } }
+ \__mhchem_output_scriptWithFont:n {#1}
}
}
- \c_math_subscript_token {
- \mhchem@mathboxrightt
- {
- \vphantom {#2}
- #5
- }
+ \str_if_eq:nnF {#2} {}
+ {
+ \c_math_subscript_token {
+ \mhchem@mathboxrightt
+ {
+ \smash{\__mhchem_output_scriptWithFont:n {#2}}
+ }
+ }
}
- \mhchem@minispace %
+ \mhchem@minispace
}
- #6
- \hbox_set:Nn \l_tmpa_box { $#7#8#9$ }
- \dim_compare:nNnT { \box_wd:N \l_tmpa_box } > { 0pt }
+ \__mhchem_output_withFont:n {#3}
+ \str_if_eq:nnF {#4#6#5} {}
{
- \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 }
+ \bool_if:NTF \l__mhchem_option_superscriptsStacked_bool
{
- \c_math_subscript_token {
- \vphantom { \smash[b]{#2} }
- #8
+ { \vphantom { \__mhchem_output_withFont:n { X } } }
+ \str_if_eq:nnF {#5} {}
+ {
+ \c_math_subscript_token
+ {
+ \vphantom { \__mhchem_output_scriptWithFont:n { 2 } }
+ \smash[t] { \__mhchem_output_scriptWithFont:n {#5} }
+ }
}
- }
- \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] { \__mhchem_output_scriptWithFont:n { 2+ } } }
+ \__mhchem_output_scriptWithFont:n {#4#6}
}
}
+ % else
{
- ^ {
- \vphantom { \smash[t]{#1} }
- \hphantom {#8}
- #9
+ \bool_if:NTF \l__mhchem_option_subscriptsDeep_bool
+ {
+ { \vphantom { \__mhchem_output_withFont:n { X } } }
+ \str_if_eq:nnF {#5} {}
+ {
+ \c_math_subscript_token
+ {
+ \vphantom { \__mhchem_output_scriptWithFont:n { 2 } }
+ \smash[t] { \__mhchem_output_scriptWithFont:n {#5} }
+ }
+ }
+ \str_if_eq:nnTF {#4#6} {}
+ {
+ ^ {
+ \vphantom { \smash[t] { \__mhchem_output_scriptWithFont:n { 2+ } } }
+ }
+ }
+ {
+ ^ {
+ \vphantom { \smash[t] { \__mhchem_output_scriptWithFont:n { 2+ } } }
+ \hphantom { \__mhchem_output_scriptWithFont:n {#5} }
+ \__mhchem_output_scriptWithFont:n {#4#6}
+ }
+ }
+ }
+ {
+ \str_if_eq:nnF {#5} {}
+ {
+ { \vphantom { \__mhchem_output_withFont:n { X } } }
+ \c_math_subscript_token
+ {
+ \vphantom { \__mhchem_output_scriptWithFont:n { 2 } }
+ \smash[t] { \__mhchem_output_scriptWithFont:n {#5} }
+ }
+ }
+ \str_if_eq:nnF {#4#6} {}
+ {
+ { \vphantom { \__mhchem_output_withFont:n { X } } }
+ ^ {
+ \__mhchem_output_scriptWithFont:n {#4#6}
+ }
+ }
}
}
}
}
+ \group_end:
+ }
+\cs_new_protected:Npn \__mhchem_output_withFont:n #1
+ {
+ \bool_if:NTF \l__mhchem_output_isMathMode_bool
+ { \__mhchem_output_escapeFromMathToRomanMath:n {#1} }
+ { \__mhchem_output_escapeFromMathToText:n {#1} }
+ }
+\cs_new_protected:Npn \__mhchem_output_scriptWithFont:n #1
+ {
+ \int_compare:nT
+ { \l__mhchem_option_version_int > 3 }
+ {
+ \thinmuskip=0mu
+ \medmuskip=0mu
+ \thickmuskip=0mu
+ }
+ \bool_if:NTF \l__mhchem_output_isMathMode_bool
+ {
+ \int_compare:nTF
+ { \l__mhchem_option_version_int < 2 }
+ {#1}
+ { \__mhchem_output_escapeFromMathToRomanMath:n {#1} }
+ }
+ { \__mhchem_output_escapeFromMathToText:n {#1} }
+ }
+\cs_new_protected:Npn \__mhchem_output_escapeFromMathToText:n #1
+ { \text { \mhchem@hook@beforeText #1 } }
+\cs_new_protected:Npn \__mhchem_output_escapeToRomanMath:n #1
+ {
+ \bool_if:NTF \l__mhchem_output_isMathMode_bool
+ { \__mhchem_output_escapeFromMathToRomanMath:n {#1} }
+ { \__mhchem_output_escapeFromTextToRomanMath:n {#1} }
+ }
+\cs_new_protected:Npn \__mhchem_output_escapeFromTextToRomanMath:n #1
+ { \ensuremath { \__mhchem_output_escapeFromMathToRomanMath:n {#1} } }
+\cs_new_protected:Npn \__mhchem_output_escapeFromMathToRomanMath:n #1
+ { \mhchem@option@mathFont { \mhchem@hook@beforeRomanMath #1 } }
+\cs_new_protected:Npn \__mhchem_output_escapeFromTextToItalicText:n #1
+ { \group_begin: \itshape \mhchem@hook@beforeItalicText #1 \group_end: \/ }
+\cs_new_protected:Npn \__mhchem_output_escapeToItalicMath:n #1
+ {
+ \ensuremath { \__mhchem_output_escapeFromMathToItalicMath:n {#1} }
+ }
+\cs_new_protected:Npn \__mhchem_output_escapeFromMathToItalicMath:n #1
+ {
+ \text { \__mhchem_output_escapeFromTextToItalicMath:n {#1} }
+ }
+\cs_new_protected:Npn \__mhchem_output_escapeFromTextToItalicMath:n #1
+ {
+ \ensuremath
+ {
+ \mhchem@hook@beforeItalicMath
+ \bool_if:NT \l__mhchem_cg_isScript_bool
+ {
+ \medmuskip=0mu
+ \thinmuskip=0mu
+ \thickmuskip=0mu
+ }
+ #1
+ }
+ }
+\cs_new_protected:Npn \__mhchem_output_minus:
+ {
+ \bool_if:NTF \l__mhchem_output_isMathMode_bool
+ { - }
+ { \mhchem@option@textminus }
+ }
+\cs_new_protected:Npn \__mhchem_output_plus:
+ {
+ \bool_if:NTF \l__mhchem_output_isMathMode_bool
+ { {}+{} }
+ { \hspace{0.5ex} + \hspace{0.5ex} }
+ }
+\cs_new_protected:Npn \__mhchem_output_operatorPlus:
+ {
+ \int_compare:nTF { \l__mhchem_option_version_int < 4 }
+ { \ensuremath { {}+{} } }
+ { \__mhchem_output_plus: }
+ }
+\cs_new_protected:Npn \__mhchem_output_operatorEquals:
+ {
+ \int_compare:nTF { \l__mhchem_option_version_int < 4 }
+ { {}={} }
+ {
+ \bool_if:NTF \l__mhchem_output_isMathMode_bool
+ { {}={} }
+ { \hspace{0.5ex} = \hspace{0.5ex} }
+ }
+ }
+\cs_new_protected:Npn \__mhchem_output_electronDot:
+ {
+ \bool_if:NTF \l__mhchem_output_isMathMode_bool
+ { \mhchem@option@textElectronDot }
+ { \mhchem@option@textElectronDot }
+ }
+\cs_new_protected:Npn \__mhchem_output_additionCompound:
+ {
+ \ensuremath { \,{\mhchem@option@cdot}\, }
+ }
+\cs_new_protected:Npn \__mhchem_output_excited:
+ {
+ \bool_if:NTF \l__mhchem_output_isMathMode_bool
+ { \ast }
+ { \smash{\raisebox{-0.4em}{\scalebox{1.3}{*}}} }
+ }
+\cs_new_protected:Npn \__mhchem_output_commaDecimal:
+ { \__mhchem_output_withFont:n { , } }
+\cs_new_protected:Npn \__mhchem_output_commaEnumeration:
+ { \__mhchem_output_withFont:n { , } \ensuremath { \mkern3mu } }
+\cs_new_protected:Npn \__mhchem_output_commaAuto:
+ {
+ \__mhchem_regex_peek:nTF { [0-9] }
+ { \__mhchem_output_commaDecimal: }
+ { \__mhchem_output_commaEnumeration: }
+ }
+\cs_new_protected:Npn \__mhchem_output_commaEnumerationSmall:
+ { \__mhchem_output_withFont:n { , } \ensuremath { \mkern1mu } }
+\cs_new_protected:Npn \__mhchem_output_commaAutoSmall:
+ {
+ \__mhchem_regex_peek:nTF { [0-9] }
+ { \__mhchem_output_commaDecimal: }
+ { \__mhchem_output_commaEnumerationSmall: }
+ }
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%% bonds %%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\newlength\mhchem@bondwidth%
+\newlength\mhchem@bondheight%
+\newlength\mhchem@smallbondwidth@tmpA%
+\newlength\mhchem@smallbondwidth@tmpB%
+\newlength\mhchem@smallbondwidth%
+\newlength\mhchem@bondtmp@minussidebearingleft
+\newlength\mhchem@bondtmp@minussidebearingright
+
+\def\mhchem@setbondwidth{%
+ \int_compare:nTF { \l__mhchem_option_version_int < 4 }
+ {
+ \setlength\mhchem@bondtmp@minussidebearingleft{\mhchem@option@minusmathsidebearingleft}
+ \setlength\mhchem@bondtmp@minussidebearingright{\mhchem@option@minusmathsidebearingright}
+ }
+ {
+ \bool_if:NTF \l__mhchem_output_isMathMode_bool
+ {
+ \setlength\mhchem@bondtmp@minussidebearingleft{\mhchem@option@minusmathsidebearingleft}
+ \setlength\mhchem@bondtmp@minussidebearingright{\mhchem@option@minusmathsidebearingright}
+ }
+ {
+ \setlength\mhchem@bondtmp@minussidebearingleft{\mhchem@option@minustextsidebearingleft}
+ \setlength\mhchem@bondtmp@minussidebearingright{\mhchem@option@minustextsidebearingright}
+ }
+ }
+ \setlength\mhchem@bondwidth{\widthof{\sbond}}%
+ \setlength\mhchem@bondheight{\heightof{\sbond}}%
+ \setlength\mhchem@smallbondwidth@tmpA{%
+ \mhchem@bondwidth-\mhchem@bondtmp@minussidebearingleft-\mhchem@bondtmp@minussidebearingright}%
+ \setlength\mhchem@smallbondwidth@tmpB{%
+ \widthof{\sbond\sbond\sbond}-\mhchem@bondtmp@minussidebearingleft-%
+ \mhchem@bondtmp@minussidebearingright}%
+ \setlength\mhchem@smallbondwidth{\mhchem@bondwidth*%
+ \ratio{\mhchem@smallbondwidth@tmpA}{\mhchem@smallbondwidth@tmpB}}%
+}
+\def\mhchem@halfbond{\rlap{\hspace{\mhchem@bondtmp@minussidebearingleft}%
+ \resizebox{\mhchem@smallbondwidth}{\mhchem@bondheight}{\sbond}\unskip%
+ \resizebox{\mhchem@smallbondwidth}{\mhchem@bondheight}{\sbond}%
+ \resizebox{\mhchem@smallbondwidth}{\mhchem@bondheight}{\sbond}}%
+ \phantom{\sbond}}%
+
+\cs_new_protected:Npn \__mhchem_output_sbond:
+ {
+ \int_compare:nTF { \l__mhchem_option_version_int < 4 }
+ { {\ensuremath{-}} }
+ {
+ \bool_if:NTF \l__mhchem_output_isMathMode_bool
+ { {\ensuremath{-}} }
+ { \text{\mhchem@option@textminus} }
+ }
}
\ExplSyntaxOff
-%%% @mathbox
-\newcommand*\mhchem@mathbox[2][]{%
- \mathchoice%
- {\mhchem@mathbox@ii{\displaystyle}{#1}{#2}}%
- {\mhchem@mathbox@ii{\textstyle}{#1}{#2}}%
- {\mhchem@mathbox@ii{\scriptstyle}{#1}{#2}}%
- {\mhchem@mathbox@ii{\scriptscriptstyle}{#1}{#2}}}%
-\newlength\mhchem@mathbox@tmp@i
-\newlength\mhchem@mathbox@tmp@ii
-\newcommand*\mhchem@mathbox@ii[3]{%
- \setlength{\mhchem@mathbox@tmp@i}{\widthof{\ensuremath{#1#2}}}%
- \setlength{\mhchem@mathbox@tmp@ii}{\widthof{\ensuremath{#1#3}}}%
- \ifdim\mhchem@mathbox@tmp@i<\mhchem@mathbox@tmp@ii%
- \mhchem@mathbox@i{#3}%
- \else%
- \makebox[\mhchem@mathbox@tmp@i]{\ensuremath{#1#3}}%
- \fi}
-\newcommand*\mhchem@mathbox@i[1]{\mathchoice%
- {\mbox{\ensuremath{\displaystyle#1}}}%
- {\mbox{\ensuremath{\textstyle#1}}}%
- {\mbox{\ensuremath{\scriptstyle#1}}}%
- {\mbox{\ensuremath{\scriptscriptstyle#1}}}}
+\ExplSyntaxOn % with special tilde
+\char_set_catcode_letter:n { 126 } % tilde
+
+\cs_new_protected:Npn \mhchem@bond #1
+ {
+ \ensuremath
+ {
+ \str_case:nnn {#1}
+ {
+ { - } { \sbond }
+ { 1 } { \sbond }
+ { = } { \dbond }
+ { 2 } { \dbond }
+ { ## } { \tbond }
+ { 3 } { \tbond }
+ { ~ }
+ {
+ \mhchem@setbondwidth
+ \mhchem@halfbond
+ }
+ { ~- }
+ {
+ \mhchem@setbondwidth
+ \rlap{\protect\raisebox{.2ex}{\mhchem@halfbond}}
+ \protect\raisebox{-.2ex}{\sbond}
+ }
+ { ~-- }
+ {
+ \mhchem@setbondwidth
+ \rlap{\protect\raisebox{.4ex}{\mhchem@halfbond}}
+ \rlap{\sbond}
+ \protect\raisebox{-.4ex}{\sbond}
+ }
+ { ~= }
+ {
+ \mhchem@setbondwidth
+ \rlap{\protect\raisebox{.4ex}{\mhchem@halfbond}}
+ \rlap{\sbond}
+ \protect\raisebox{-.4ex}{\sbond}
+ }
+ { -~- }
+ {
+ \mhchem@setbondwidth
+ \rlap{\protect\raisebox{.4ex}{\sbond}}
+ \rlap{\mhchem@halfbond}
+ \protect\raisebox{-.4ex}{\sbond}
+ }
+ { ... } { {\cdot}{\cdot}{\cdot} }
+ { .... } { {\cdot}{\cdot}{\cdot}{\cdot} }
+ { -> } { {\rightarrow} }
+ { <- } { {\leftarrow} }
+ }
+ {
+ \PackageError{mhchem}{Unknown~bond~type~in~\string\bond~(#1)}%
+ }
+ }
+ }
+\ExplSyntaxOff % end of Expl with tilde
%%% @mathboxright
\newcommand*\mhchem@mathboxright[2]{\mathchoice%
@@ -2881,11 +3004,24 @@
\def\mhchem@option@mathFont{\mathrm}
\def\mhchem@option@textFont{}
-\bool_new:N \__mhchem_option_superscriptsStacked_bool
+\def\mhchem@hook@beforeCe{}
+\def\mhchem@hook@afterCe{}
+\def\mhchem@hook@beforeText{}
+\def\mhchem@hook@beforeItalicText{}
+\def\mhchem@hook@beforeRomanMath{}
+\def\mhchem@hook@beforeItalicMath{}
+\bool_new:N \l__mhchem_option_layoutWasSet
+\bool_set_false:N \l__mhchem_option_layoutWasSet
+\bool_new:N \l__mhchem_option_superscriptsStacked_bool
+\bool_new:N \l__mhchem_option_subscriptsDeep_bool
+\cs_new_protected:Npn \mhchem@option@textElectronDot {}
+\cs_new_protected:Npn \mhchem@option@cdot {}
+\bool_new:N \l__mhchem_option_greekSelectedByUser
+\bool_set_false:N \l__mhchem_option_greekSelectedByUser
\keys_define:nn {mhchem}
{
- version .int_set:N = \__mhchem_option_version_int,
+ version .int_set:N = \l__mhchem_option_version_int,
version .value_required:,
version .initial:n = { -1 },
version .default:n = { -1 },
@@ -2897,25 +3033,50 @@
font .choice:,
font / sf .code:n =
{
- \def\mhchem@option@textFont{\sffamily}%
- \def\mhchem@option@mathFont{\mathsf}%
+ \def\mhchem@option@textFont{\sffamily}
+ \def\mhchem@option@mathFont{\mathsf}
},
font / .code:n =
{
- \def\mhchem@option@textFont{}%
- \def\mhchem@option@mathFont{\mathrm}%
+ \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 },
+ layout .choice:,
+ layout / stacked .code:n =
+ {
+ \bool_set_true:N \l__mhchem_option_layoutWasSet
+ \bool_set_true:N \l__mhchem_option_superscriptsStacked_bool
+ },
+ layout / staggered-deep .code:n =
+ {
+ \bool_set_true:N \l__mhchem_option_layoutWasSet
+ \bool_set_false:N \l__mhchem_option_superscriptsStacked_bool
+ \bool_set_true:N \l__mhchem_option_subscriptsDeep_bool
+ },
+ layout / staggered-flat .code:n =
+ {
+ \bool_set_true:N \l__mhchem_option_layoutWasSet
+ \bool_set_false:N \l__mhchem_option_superscriptsStacked_bool
+ \bool_set_false:N \l__mhchem_option_subscriptsDeep_bool
+ },
+
+ minus-sidebearing-left .dim_set:N = \mhchem@option@minusmathsidebearingleft,
+ minus-sidebearing-right .dim_set:N = \mhchem@option@minusmathsidebearingright,
+ minus-math-sidebearing-left .dim_set:N = \mhchem@option@minusmathsidebearingleft,
+ minus-math-sidebearing-left .initial:n = { 0.06em },
+ minus-math-sidebearing-right .dim_set:N = \mhchem@option@minusmathsidebearingright,
+ minus-math-sidebearing-right .initial:n = { 0.11em },
+ minus-text-sidebearing-left .dim_set:N = \mhchem@option@minustextsidebearingleft,
+ minus-text-sidebearing-left .initial:n = { 0.10em },
+ minus-text-sidebearing-right .dim_set:N = \mhchem@option@minustextsidebearingright,
+ minus-text-sidebearing-right .initial:n = { 0.16em },
arrows .choice:,
arrows / font .code:n = { \mhchem@definearrows{#1} },
arrows / pgf .code:n =
{
- \bool_if:NT { \__mhchem_option_inPreamble_bool }
+ \bool_if:NT { \l__mhchem_option_inPreamble_bool }
{
\RequirePackage{pgf}
\RequirePackage{tikz}
@@ -2924,7 +3085,7 @@
},
arrows / pgf-filled .code:n =
{
- \bool_if:NT { \__mhchem_option_inPreamble_bool }
+ \bool_if:NT { \l__mhchem_option_inPreamble_bool }
{
\RequirePackage{pgf}
\RequirePackage{tikz}
@@ -2940,51 +3101,56 @@
skip-after-amount .initial:n = { \, },
textminus .code:n = { \def\mhchem@option@textminus{#1} },
- textminus .initial:n = { -- },
+ textminus .initial:n = { \hspace{0.3ex} -- \hspace{0.3ex} },
- textcdot .code:n = { \def\mhchem@option@textcdot{#1} },
- textcdot .initial:n = { \cdot },
+ cdot .code:n = { \def\mhchem@option@cdot{#1} },
+ cdot .initial:n = { \cdot },
+ textelectrondot .code:n = { \cs_set_protected:Npn \mhchem@option@textElectronDot {#1} },
+ textelectrondot .initial:n =
+ {
+ \int_compare:nTF { \l__mhchem_option_version_int < 4 }
+ { \ensuremath{\textbf{\fontfamily{cmr}\selectfont\textperiodcentered}} }
+ { \ensuremath { \bullet } }
+ },
- 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
+\bool_new:N \l__mhchem_option_inPreamble_bool
+\bool_set_true:N \l__mhchem_option_inPreamble_bool
\ProcessKeysPackageOptions{mhchem}
-\bool_set_false:N \__mhchem_option_inPreamble_bool
+\bool_set_false:N \l__mhchem_option_inPreamble_bool
-\int_compare:nT { -1 = \__mhchem_option_version_int }
+\int_compare:nT { -1 = \l__mhchem_option_version_int }
{
\msg_error:nn { mhchem } { options / no-version }
- \int_set:Nn \__mhchem_option_version_int { 3 }
+ \int_set:Nn \l__mhchem_option_version_int { 4 }
}
% else
{
- \int_compare:nT { \__mhchem_option_version_int > 3}
+ \int_compare:nT { \l__mhchem_option_version_int > 4 }
{
\msg_warning:nn { mhchem } { options / version-too-high }
}
}
+\bool_if:NF \l__mhchem_option_layoutWasSet
+ {
+ \int_compare:nTF { \l__mhchem_option_version_int < 4 }
+ { \mhchemoptions{layout=staggered-deep} }
+ { \mhchemoptions{layout=staggered-flat} }
+ }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%% legacy %%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\int_compare:nT { \__mhchem_option_version_int < 4 }
+\int_compare:nT { \l__mhchem_option_version_int < 4 }
{
- \newcommand*\mhchem@cmath[1]{\ensuremath{\text{\ensuremath{#1}}}}%
+ \newcommand*\mhchem@cmath[1]{\__mhchem_output_escapeFromMathToItalicMath:n{#1}}
\newcommand*\cmath[1]{\mhchem@cmath{#1}}
\DeclareRobustCommand\cf[2][]{\mhchem@cf[#1]{#2}}
+ \DeclareRobustCommand\cee[1]{\mhchem@cee{#1}}
}