summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/mhchem
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2015-03-13 23:23:06 +0000
committerKarl Berry <karl@freefriends.org>2015-03-13 23:23:06 +0000
commit92c0eccd62a3eb57e56ee44400ebe63fec446bf6 (patch)
tree841103e4b6f8af074da637e3ac5ca53f2aac2759 /Master/texmf-dist/tex/latex/mhchem
parent40a46f311d540329fb7fb15ed97a491a710333d3 (diff)
mhchem (13mar15)
git-svn-id: svn://tug.org/texlive/trunk@36504 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/mhchem')
-rw-r--r--Master/texmf-dist/tex/latex/mhchem/mhchem.sty1737
1 files changed, 1038 insertions, 699 deletions
diff --git a/Master/texmf-dist/tex/latex/mhchem/mhchem.sty b/Master/texmf-dist/tex/latex/mhchem/mhchem.sty
index aba1aec977d..571c78dda85 100644
--- a/Master/texmf-dist/tex/latex/mhchem/mhchem.sty
+++ b/Master/texmf-dist/tex/latex/mhchem/mhchem.sty
@@ -27,13 +27,14 @@
% This work consists of all files listed in manifest.txt.
%
%
-\ProvidesPackage{mhchem}[2015/02/09 v3.19 for typesetting chemical formulae]
-\RequirePackage{ifthen}
+\ProvidesPackage{mhchem}[2015/03/13 v3.21 for typesetting chemical formulae]
+\RequirePackage{expl3}
+\RequirePackage{l3keys2e}
+\RequirePackage{l3regex}
\RequirePackage{calc}[1998/07/07]
\RequirePackage{amsmath}
-\RequirePackage{keyval}
\RequirePackage{graphics}
-\RequirePackage{expl3}
+\RequirePackage{ifthen} %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%% misc %%%%%%%%%%
@@ -47,50 +48,62 @@
%%%%%%%%%% \cee %%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\newcommand*{\cee}[1]{%
- \def\mhchem@ce@out{}%
- {\mhchem@cee@i#1\\\mhchem@END\mhchem@ENDEND}%
- \ensuremath{%
- \mhchem@ce@out%
- }%
-}%
+\ExplSyntaxOn
-\def\mhchem@cee@i#1\\#2#3\mhchem@ENDEND{%
- \ifx\mhchem@END#2%
- \mhchem@cee@ii#1&\mhchem@END\mhchem@ENDEND%
- \else%
- \mhchem@cee@ii#1&\mhchem@END\mhchem@ENDEND%
- \g@addto@macro\mhchem@ce@out{\\}%
- \@ifnextchar[%
- \mhchem@cee@optArg%
- \mhchem@cee@i#2#3\mhchem@ENDEND%
- \fi%
-}
-\def\mhchem@cee@optArg[#1]{%
- \g@addto@macro\mhchem@ce@out{[#1]}\mhchem@cee@i%
-}
+\newcommand*{\cee}[1]
+ {
+ \cesplit
+ {
+ { \c{\\}(\[.*?\])? } { \0 }
+ { \& } { \0 }
+ }
+ {#1}
+ }
-\long\def\mhchem@cee@ii#1&#2#3\mhchem@ENDEND{%
- \ifx\mhchem@END#2%
- \g@addto@macro\mhchem@ce@out{\ce{#1}}%
- \else%
- \g@addto@macro\mhchem@ce@out{\ce{#1}}%
- \g@addto@macro\mhchem@ce@out{&}%
- \mhchem@cee@ii#2#3\mhchem@ENDEND%
- \fi%
-}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%% \cesplit %%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\cs_generate_variant:Nn \regex_replace_all:nnN { VnN }
+\bool_new:N \__mhchem_cesplit_odd_bool
+
+\newcommand\cesplit[2]
+ {
+ \bool_set_true:N \__mhchem_cesplit_odd_bool
+
+ \tl_set:Nn \l_tmpa_tl { \__mhchem_ce:n {#2} }
+
+ \tl_map_inline:nn {#1}
+ {
+ \bool_if:NTF \__mhchem_cesplit_odd_bool
+ {
+ \tl_set:Nn \__mhchem_cesplit_key_tl {##1}
+ \bool_set_false:N \__mhchem_cesplit_odd_bool
+ }
+ % else
+ {
+ \regex_replace_all:VnN
+ \__mhchem_cesplit_key_tl
+ { \cE] ##1 \c{__mhchem_ce:n}\cB[ }
+ \l_tmpa_tl
+ \bool_set_true:N \__mhchem_cesplit_odd_bool
+ }
+ }
+ \tl_use:N \l_tmpa_tl
+ }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%% global helpers %%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\ExplSyntaxOff
+
\def\mhchem@appendToks#1#2{%
#1=\expandafter{\the#1#2}%
}
\ExplSyntaxOn
-\int_new:N \__mhchem_option_version_int
\cs_generate_variant:Nn \str_if_eq:nnTF { Vn }
\cs_generate_variant:Nn \peek_catcode_remove:NTF { oTF }
\cs_generate_variant:Nn \peek_catcode:NTF { oTF }
@@ -191,6 +204,8 @@
Assertion~failed:~Unexpected~internal~state~'#1' (ce).~You~found~a~bug.~
Please~contact~the~package~author.
}
+\bool_new:N \__mhchem_ce_ceActive_bool
+\bool_set_false:N \__mhchem_ce_ceActive_bool
\tl_new:N \__mhchem_ce_state_tl
\tl_new:N \__mhchem_ce_arrowName_tl
@@ -198,6 +213,8 @@
\tl_new:N \__mhchem_ce_arrowTextOne_tl
\tl_new:N \__mhchem_ce_arrowTypeTwo_tl
\tl_new:N \__mhchem_ce_arrowTextTwo_tl
+\bool_new:N \__mhchem_ce_potentialSpacing_bool
+\bool_new:N \__mhchem_ce_potentialSpacing_future_bool
\newcommand*\mhchem@ce[1]{
\__mhchem_ce:n {#1}
@@ -205,13 +222,18 @@
\cs_new_protected:Npn \__mhchem_ce:n #1
{
\group_begin:
+ \bool_if:NF \__mhchem_cf_cfActive_bool
+ {
+ \bool_set_true:N \__mhchem_cf_cfActive_bool
+ \__mhchem_defMathOrText:
+ }
\def\hyphen{\mhchem@hyphen}%
\tl_clear_new:N \__mhchem_ce_result_tl
\tl_clear_new:N \__mhchem_ce_part_tl
+ \bool_set_false:N \__mhchem_ce_potentialSpacing_bool
\tl_set:Nn \__mhchem_ce_state_tl { c }
\__mhchem_ce_loop: #1 \q_recursion_stop
- \int_set:Nn \__mhchem_option_version_int { \mhchem@option@version }
- \int_compare:nTF { 1 < \__mhchem_option_version_int }
+ \int_compare:nTF { \__mhchem_option_version_int > 1 }
{ \tl_use:N \__mhchem_ce_result_tl }
{ \ensuremath{\tl_use:N \__mhchem_ce_result_tl} }
\group_end:
@@ -228,6 +250,7 @@
{
\tl_put_right:Nn \__mhchem_ce_result_tl { \ensuremath{{}+{}} }
\tl_clear:N \__mhchem_ce_part_tl
+ \tl_set:Nn \__mhchem_ce_state_tl { a-end }
}
{ -> }
{
@@ -280,6 +303,9 @@
\peek_charcode_remove:NTF \c_space_token
{
\__mhchem_ce_output:
+ \bool_if:NTF \__mhchem_ce_potentialSpacingAllowed_bool
+ { \bool_set_true:N \__mhchem_ce_potentialSpacing_bool }
+ { \bool_set_false:N \__mhchem_ce_potentialSpacing_bool }
\__mhchem_ce_loop:
}{
\peek_catcode_remove:NTF \c_math_toggle_token
@@ -360,6 +386,7 @@
% else
{
\__mhchem_ce_output:
+ \tl_set:Nn \__mhchem_ce_state_tl { a-end }
\__mhchem_ce_loop:
}
}
@@ -377,6 +404,7 @@
% else
{
\__mhchem_ce_output:
+ \tl_set:Nn \__mhchem_ce_state_tl { a-end }
\__mhchem_ce_loop:
}
}
@@ -384,6 +412,7 @@
% else
{
\__mhchem_ce_output:
+ \tl_set:Nn \__mhchem_ce_state_tl { a-end }
\__mhchem_ce_loop:
}
}
@@ -399,6 +428,7 @@
% else
{
\__mhchem_ce_output:
+ \tl_set:Nn \__mhchem_ce_state_tl { a-end }
\__mhchem_ce_loop:
}
}
@@ -470,6 +500,7 @@
% else
{
\__mhchem_ce_output:
+ \tl_set:Nn \__mhchem_ce_state_tl { a-end }
\__mhchem_ce_loop:
}
}}}}
@@ -484,6 +515,7 @@
% else
{
\__mhchem_ce_output:
+ \tl_set:Nn \__mhchem_ce_state_tl { a-end }
\__mhchem_ce_loop:
}
}
@@ -497,6 +529,7 @@
\peek_charcode:NTF ]
{
\__mhchem_ce_output:
+ \tl_set:Nn \__mhchem_ce_state_tl { a-end }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_ce_loop:
}{
\peek_catcode:NTF \c_group_begin_token
@@ -519,6 +552,19 @@
}
}}}
}
+ { a-end }
+ {
+ \bool_set_false:N \__mhchem_ce_potentialSpacing_bool
+ \tl_set:Nn \__mhchem_ce_state_tl { c }
+ \peek_charcode_remove:NTF \c_space_token
+ {
+ \__mhchem_ce_loop:
+ }
+ % else
+ {
+ \__mhchem_ce_loop:
+ }
+ }
}
{
\msg_error:nnx { mhchem } { ce/unexpected-state }
@@ -531,6 +577,7 @@
}
\cs_new_protected:Npn \__mhchem_ce_output:
{
+ \bool_set_true:N \__mhchem_ce_potentialSpacingAllowed_bool
\str_case:Vnn \__mhchem_ce_state_tl
{
{ c }
@@ -538,32 +585,42 @@
\str_if_eq:VnTF \__mhchem_ce_part_tl { - }
{
\tl_put_right:Nn \__mhchem_ce_result_tl { \ensuremath{{}-{}} }
+ \bool_set_false:N \__mhchem_ce_potentialSpacingAllowed_bool
}{
\str_if_eq:VnTF \__mhchem_ce_part_tl { (v) }
{
\tl_put_right:Nn \__mhchem_ce_result_tl
{ \ensuremath{{}\mathop{\downarrow}{}} }
+ \bool_set_false:N \__mhchem_ce_potentialSpacingAllowed_bool
}{
\str_if_eq:VnTF \__mhchem_ce_part_tl { v }
{
\tl_put_right:Nn \__mhchem_ce_result_tl
{ \ensuremath{{}\mathop{\downarrow}{}} }
+ \bool_set_false:N \__mhchem_ce_potentialSpacingAllowed_bool
}{
\str_if_eq:VnTF \__mhchem_ce_part_tl { (^) }
{
\tl_put_right:Nn \__mhchem_ce_result_tl
{ \ensuremath{{}\mathop{\uparrow}{}} }
+ \bool_set_false:N \__mhchem_ce_potentialSpacingAllowed_bool
}{
\str_if_eq:VnTF \__mhchem_ce_part_tl { ^ }
{
\tl_put_right:Nn \__mhchem_ce_result_tl
{ \ensuremath{{}\mathop{\uparrow}{}} }
+ \bool_set_false:N \__mhchem_ce_potentialSpacingAllowed_bool
}
% else
{
\tl_if_empty:NTF \__mhchem_ce_part_tl
{}
{
+ \bool_if:NT \__mhchem_ce_potentialSpacing_bool
+ {
+ \int_compare:nT { \__mhchem_option_version_int > 3 }
+ { \tl_put_right:Nn \__mhchem_ce_result_tl { \mhchem@option@skipAfterAmount } }
+ }
\tl_put_right:Nx \__mhchem_ce_result_tl
{
\exp_not:N \__mhchem_cf:nn
@@ -593,6 +650,7 @@
{}
\tl_set:NV \__mhchem_ce_part_tl \__mhchem_ce_arrowTypeOne_tl
\tl_set:Nn \__mhchem_ce_state_tl { c }
+ \bool_set_false:N \__mhchem_ce_potentialSpacing_bool
\__mhchem_ce_output:
}
{ a-]1 }
@@ -623,6 +681,7 @@
{}
\tl_set:NV \__mhchem_ce_part_tl \__mhchem_ce_arrowTypeTwo_tl
\tl_set:Nn \__mhchem_ce_state_tl { c }
+ \bool_set_false:N \__mhchem_ce_potentialSpacing_bool
\__mhchem_ce_output:
}
{ a-]2 }
@@ -638,6 +697,7 @@
{}
\tl_clear:N \__mhchem_ce_part_tl
\tl_set:Nn \__mhchem_ce_state_tl { c }
+ \bool_set_false:N \__mhchem_ce_potentialSpacing_bool
}
\cs_new_protected:Npn \__mhchem_ce_outputArrow:nnnnn #1#2#3#4#5
{
@@ -691,7 +751,7 @@
{
{ }
{
- \int_compare:nTF { 3 < \__mhchem_option_version_int }
+ \int_compare:nTF { \__mhchem_option_version_int > 3 }
{ \cs:w mhchem@arrow@#1T \cs_end: {#3}{#5} }
{ \cs:w mhchem@arrow@#1M \cs_end: {#3}{#5} }
}
@@ -910,7 +970,10 @@
\mathop{\makebox[#7]{#8\displaystyle}}%
\limits%
\@ifnotempty{#3}{^{\mkern#1mu#3\mkern#2mu}}%
- \@ifnotempty{#6}{_{\mkern#4mu#6\mkern#5mu}}%
+ \@ifnotempty{#6}{_{%
+ \makebox{\raisebox{1.25ex-\heightof{$\scriptstyle\mkern#4mu#6\mkern#5mu$}}[0pt]%
+ {$\scriptstyle\mkern#4mu#6\mkern#5mu$}}
+ }}%
}%
}
\def\mhchem@rightharpoonupfill@{\arrowfill@\relbar\relbar\rightharpoonup}
@@ -1126,17 +1189,17 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ExplSyntaxOn
-\msg_new:nnn { mhchem } { cf/unexpected-input }
+\msg_new:nnn { mhchem } { cf / unexpected-input }
{
Assertion~failed:~Unexpected~input~character.~You~found~a~bug.~
Please~contact~the~package~author.
}
-\msg_new:nnn { mhchem } { cf/unexpected-state }
+\msg_new:nnn { mhchem } { cf / unexpected-state }
{
Assertion~failed:~Unexpected~internal~state~'#1' (cf).~You~found~a~bug.~
Please~contact~the~package~author.
}
-\msg_new:nnn { mhchem } { cf/unexpected-two-superscripts }
+\msg_new:nnn { mhchem } { cf / unexpected-two-superscripts }
{
Assertion~failed:~Two~superscripts.~You~entered~an~invalid~formula.~
Or~you~found~a~bug,~in~which~case~you~should~contact~the~package~author.
@@ -1166,64 +1229,61 @@
\newcommand*\mhchem@cf[2][]{
\__mhchem_cf:nn {#1} {#2}
}
-\tl_new:N \__mhchem_cf_state_tl
+
\bool_new:N \__mhchem_cf_startedWithBond_bool
+
+\tl_new:N \__mhchem_cf_state_tl
+\tl_new:N \__mhchem_cf_presup_tl
+\tl_new:N \__mhchem_cf_presub_tl
+\tl_new:N \__mhchem_cf_presupState_tl
+\tl_new:N \__mhchem_cf_presubState_tl
+\tl_new:N \__mhchem_cf_element_tl
+\tl_new:N \__mhchem_cf_supA_tl
+\tl_new:N \__mhchem_cf_sub_tl
+\tl_new:N \__mhchem_cf_sup_tl
+\tl_new:N \__mhchem_cf_supState_tl
+\tl_new:N \__mhchem_cf_subState_tl
+\cs_new_protected:Npn \__mhchem_cf_resetOutput:
+ {
+ \tl_clear:N \__mhchem_cf_presup_tl
+ \tl_clear:N \__mhchem_cf_presub_tl
+ \tl_set:Nn \__mhchem_cf_presupState_tl { - }
+ \tl_set:Nn \__mhchem_cf_presubState_tl { - }
+ \tl_clear:N \__mhchem_cf_element_tl
+ \tl_clear:N \__mhchem_cf_supA_tl
+ \tl_clear:N \__mhchem_cf_sub_tl
+ \tl_clear:N \__mhchem_cf_sup_tl
+ \tl_set:Nn \__mhchem_cf_supState_tl { - }
+ \tl_set:Nn \__mhchem_cf_subState_tl { - }
+ }
+
\bool_new:N \__mhchem_cf_cfActive_bool
\bool_set_false:N \__mhchem_cf_cfActive_bool
\cs_new_protected:Npn \__mhchem_cf:nn #1#2
{
\group_begin:
- \int_set:Nn \__mhchem_option_version_int { \mhchem@option@version }
\def\sbond{{\ensuremath{-}}}
- \ifnum 2=\mhchem@option@version
- \let\bond\sbond
- \else\ifnum 2<\mhchem@option@version
- \def\bond{\mhchem@bond}
- \fi\fi
+ \int_compare:nTF { 2 = \__mhchem_option_version_int }
+ {
+ \let\bond\sbond
+ }
+ % else
+ {
+ \int_compare:nT { \__mhchem_option_version_int > 2 }
+ {
+ \def\bond{\mhchem@bond}
+ }
+ }
\def\dbond{\rlap{\protect\raisebox{.2ex}{\sbond}}\protect\raisebox{-.2ex}{\sbond}}
\def\tbond{\rlap{\protect\raisebox{.4ex}{\sbond}}
\rlap{\sbond}\protect\raisebox{-.4ex}{\sbond}}
\def\hyphen{\mhchem@hyphen}
- \bool_if:NF \__mhchem_cf_cfActive_bool
- {
- \bool_set_true:N \__mhchem_cf_cfActive_bool
- \mode_if_math:F
- {
- \def\mhchem@option@alwaystextmode{1}
- \mhchem@option@textFont
- }
- \str_if_eq:nnTF { 1 } { \mhchem@option@alwaystextmode }
- {
- \cs_set:Npx \mhchem@mathOrText ##1 { \exp_not:N \text{##1} }
- \cs_set:Npx \mhchem@mathOrText@ii ##1##2 { ##2 }
- }
- {
- \int_compare:nTF { 1 < \__mhchem_option_version_int }
- {
- \cs_set:Npx \mhchem@mathOrText ##1
- {
- \mode_if_math:TF
- { \exp_not:N \mhchem@option@mathFont{##1} }
- { \exp_not:N \text{##1} }
- }
- \cs_set:Npx \mhchem@mathOrText@ii ##1##2
- {
- \mode_if_math:TF
- { \exp_not:N \mhchem@option@mathFont{##1} }
- { ##2 }
- }
- }
- {
- \cs_set:Npx \mhchem@mathOrText ##1
- {
- \mode_if_math:TF { ##1 } { \exp_not:N \text{##1} }
- }
- \cs_set:Npx \mhchem@mathOrText@ii ##1##2
- {
- \mode_if_math:TF { ##1 } { ##2 }
- }
- }
- }
+ \bool_if:NF \__mhchem_ce_ceActive_bool {
+ \bool_if:NF \__mhchem_cf_cfActive_bool
+ {
+ \bool_set_true:N \__mhchem_cf_cfActive_bool
+ \__mhchem_defMathOrText:
+ }
}
\tl_set:Nn \__mhchem_cf_state_tl { s }
\bool_set_false:N \__mhchem_cf_startedWithBond_bool
@@ -1233,7 +1293,6 @@
\str_if_eq:nnTF {#1} {}
{ \ensuremath{\tl_use:N \__mhchem_cf_result_tl} }
{ \ensuremath{\overset{#1}{\tl_use:N \__mhchem_cf_result_tl}} }
- \bool_set_false:N \__mhchem_cf_cfActive_bool
\group_end:
}
\cs_new_protected:Npn \__mhchem_cf_loop:
@@ -1247,9 +1306,9 @@
\bool_if:NTF \__mhchem_cf_startedWithBond_bool
{
\__mhchem_cf_outputAndReset:
- \tl_put_right:Nn \__mhchem_cf_result_tl {\sbond}
+ \tl_put_right:Nn \__mhchem_cf_result_tl { \sbond }
}
- { \tl_put_right:Nn \__mhchem_cf_sup_tl {-} }
+ { \tl_put_right:Nn \__mhchem_cf_sup_tl { - } }
}
{ 1 }
{ \tl_set:Nn \__mhchem_cf_state_tl {9} }
@@ -1267,27 +1326,30 @@
{
\__mhchem_cf_outputAndReset:
\tl_put_right:Nn \__mhchem_cf_result_tl {\sbond}
- \tl_set:Nn \__mhchem_cf_state_tl { + }
+ \tl_set:Nn \__mhchem_cf_state_tl { a }
\__mhchem_cf_loop:
}
{ s }
{
\peek_charcode:NTF -
{
- \int_compare:nTF { 1 < \__mhchem_option_version_int }
+ \__mhchem_cf_outputAndReset:
+ \int_compare:nTF { \__mhchem_option_version_int > 1 }
{
\tl_set:Nn \__mhchem_cf_state_tl { - }
\bool_set_true:N \__mhchem_cf_startedWithBond_bool
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
}
+ % else
{
- \tl_set:Nn \__mhchem_cf_state_tl { + }
- \tl_put_right:Nn \__mhchem_cf_sup_tl { - }
+ \tl_set:Nn \__mhchem_cf_state_tl { a }
+ \tl_put_right:Nn \__mhchem_cf_sup_tl { - } % z. B. \cmath{mu}-Cl
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
}
}{
\peek_charcode:NTF =
{
+ \__mhchem_cf_outputAndReset:
\__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn
{ \dbond }
{ s }
@@ -1295,6 +1357,7 @@
}{
\peek_charcode:NTF ##
{
+ \__mhchem_cf_outputAndReset:
\__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn
{ \tbond }
{ s }
@@ -1302,21 +1365,31 @@
}{
\peek_charcode:NTF ^
{
+ \str_if_eq:VnF \__mhchem_cf_presupState_tl { - }
+ { \__mhchem_cf_outputAndReset: }
+ \tl_set:Nn \__mhchem_cf_presupState_tl { d }
\tl_set:Nn \__mhchem_cf_state_tl { p }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
}{
\peek_charcode:NTF _
{
+ \str_if_eq:VnF \__mhchem_cf_presubState_tl { - }
+ { \__mhchem_cf_outputAndReset: }
+ \tl_set:Nn \__mhchem_cf_presubState_tl { d }
\tl_set:Nn \__mhchem_cf_state_tl { q }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
}{
\peek_charcode:NTF `
{
- \int_compare:nTF { 4 > \__mhchem_option_version_int }
+ \int_compare:nTF { \__mhchem_option_version_int < 4 }
{
- \tl_set:Nn \__mhchem_cf_state_tl { P }
+ \str_if_eq:VnF \__mhchem_cf_presupState_tl { - }
+ { \__mhchem_cf_outputAndReset: }
+ \tl_set:Nn \__mhchem_cf_presupState_tl { rm }
+ \tl_set:Nn \__mhchem_cf_state_tl { p }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
}
+ % else
{
\tl_set:Nn \__mhchem_cf_state_tl { a }
\__mhchem_loopHelper_appendNextToken:NNn
@@ -1326,23 +1399,27 @@
}{
\peek_charcode:NTF ,
{
- \int_compare:nTF { 4 > \__mhchem_option_version_int }
+ \int_compare:nTF { \__mhchem_option_version_int < 4 }
{
- \tl_set:Nn \__mhchem_cf_state_tl { Q }
+ \str_if_eq:VnF \__mhchem_cf_presubState_tl { - }
+ { \__mhchem_cf_outputAndReset: }
+ \tl_set:Nn \__mhchem_cf_presubState_tl { rm }
+ \tl_set:Nn \__mhchem_cf_state_tl { q }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
}
+ % else
{
+ \__mhchem_cf_outputAndReset:
\tl_set:Nn \__mhchem_cf_state_tl { 1 }
- \tl_put_right:Nn \__mhchem_cf_sub_tl { {,} }
- \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
+ \__mhchem_cf_loop:
}
}{
\peek_charcode:NTF .
{
- \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn
- { \mhchem@mathOrText@ii{{}\cdot{}}{\mhchem@option@textcdot} }
- { s }
- \__mhchem_cf_loop:
+
+ \__mhchem_cf_outputAndReset:
+ \tl_set:Nn \__mhchem_cf_state_tl { 1 }
+ \__mhchem_cf_loop:
}{
\peek_charcode:NTF *
{
@@ -1353,10 +1430,11 @@
}{
\peek_charcode:NTF +
{
- \tl_set:Nn \__mhchem_cf_state_tl { + }
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
- \__mhchem_cf_loop:
+ \str_if_eq:VnF \__mhchem_cf_presupState_tl { - }
+ { \__mhchem_cf_outputAndReset: }
+ \tl_set:Nn \__mhchem_cf_presupState_tl { d }
+ \tl_set:Nn \__mhchem_cf_state_tl { p }
+ \__mhchem_cf_loop:
}{
\peek_charcode:NTF |
{
@@ -1388,6 +1466,7 @@
}{
\peek_catcode:NTF \mhchem@macro
{
+ \__mhchem_cf_outputAndReset:
\tl_set:Nn \__mhchem_cf_state_tl { c }
\__mhchem_loopHelper_appendNextToken:NNn
\__mhchem_cf_result_tl
@@ -1402,6 +1481,7 @@
}{
\peek_catcode:NTF 1
{
+ \__mhchem_cf_outputAndReset:
\tl_set:Nn \__mhchem_cf_state_tl { 1 }
\__mhchem_loopHelper_appendNextToken:NNn
\__mhchem_cf_element_tl
@@ -1409,37 +1489,20 @@
}{
\peek_catcode:NTF \c_group_begin_token
{
- \int_compare:nTF { 4 > \__mhchem_option_version_int }
- {
- \__mhchem_loopHelper_appendNextGroup:NNn
- \__mhchem_cf_result_tl
- \__mhchem_cf_loop:
- }
- {
- \tl_set:Nn \__mhchem_cf_state_tl { 1 }
- \__mhchem_loopHelper_appendNextGroup:NNn
- \__mhchem_cf_sub_tl
- \__mhchem_cf_loop:
- }
+ \__mhchem_cf_outputAndReset:
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_result_tl
+ \__mhchem_cf_loop:
}{
\peek_catcode_remove:NTF \c_math_toggle_token
{
- \int_compare:nTF { 4 > \__mhchem_option_version_int }
- {
- \tl_set:Nn \__mhchem_cf_state_tl { a }
- \__mhchem_loopHelper_appendMathB:NNw
- \__mhchem_cf_element_tl
- \__mhchem_cf_loop:
- }
- {
- \tl_set:Nn \__mhchem_cf_state_tl { 1 }
- \__mhchem_loopHelper_appendMathB:NNw
- \__mhchem_cf_element_tl
- \__mhchem_cf_loop:
- }
+ \tl_set:Nn \__mhchem_cf_state_tl { a }
+ \__mhchem_loopHelper_appendMathB:NNw
+ \__mhchem_cf_element_tl
+ \__mhchem_cf_loop:
}
% else
- { \msg_error:nnn { mhchem } { cf/unexpected-input } }
+ { \msg_error:nnn { mhchem } { cf / unexpected-input } }
}}}}}}}}}}}}}}}}}}}
}
{ c }
@@ -1450,6 +1513,7 @@
\__mhchem_cf_result_tl
\__mhchem_cf_loop:
}
+ % else
{
\tl_set:Nn \__mhchem_cf_state_tl { a }
\__mhchem_cf_loop:
@@ -1577,22 +1641,38 @@
}{
\peek_charcode:NTF ^
{
- \tl_set:Nn \__mhchem_cf_state_tl { k }
+ \str_if_eq:VnF \__mhchem_cf_supState_tl { - }
+ { \__mhchem_cf_outputAndReset: }
+ \str_if_eq:VnTF \__mhchem_cf_subState_tl { - }
+ { \tl_set:Nn \__mhchem_cf_supState_tl { kv } }
+ { \tl_set:Nn \__mhchem_cf_supState_tl { d } }
+ \tl_set:Nn \__mhchem_cf_state_tl { e }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
}{
\peek_charcode:NTF _
{
+ \str_if_eq:VnF \__mhchem_cf_subState_tl { - }
+ { \__mhchem_cf_outputAndReset: }
+ \tl_set:Nn \__mhchem_cf_subState_tl { d }
\tl_set:Nn \__mhchem_cf_state_tl { f }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
}{
\peek_charcode:NTF `
{
- \int_compare:nTF { 4 > \__mhchem_option_version_int }
+ \int_compare:nTF { \__mhchem_option_version_int < 4 }
{
- \tl_set:Nn \__mhchem_cf_state_tl { E }
+ \str_if_eq:VnF \__mhchem_cf_supState_tl { - }
+ { \__mhchem_cf_outputAndReset: }
+ \tl_set:Nn \__mhchem_cf_supState_tl { rm }
+ \tl_set:Nn \__mhchem_cf_state_tl { e }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
}
+ % else
{
+ \str_if_eq:VnF \__mhchem_cf_supState_tl { - }
+ { \__mhchem_cf_outputAndReset: }
+ \str_if_eq:VnF \__mhchem_cf_subState_tl { - }
+ { \__mhchem_cf_outputAndReset: }
\__mhchem_loopHelper_appendNextToken:NNn
\__mhchem_cf_element_tl
\__mhchem_cf_loop:
@@ -1600,15 +1680,20 @@
}{
\peek_charcode:NTF ,
{
- \int_compare:nTF { 4 > \__mhchem_option_version_int }
+ \int_compare:nTF { \__mhchem_option_version_int < 4 }
{
- \tl_set:Nn \__mhchem_cf_state_tl { F }
+ \str_if_eq:VnF \__mhchem_cf_subState_tl { - }
+ { \__mhchem_cf_outputAndReset: }
+ \tl_set:Nn \__mhchem_cf_subState_tl { rm }
+ \tl_set:Nn \__mhchem_cf_state_tl { f }
\__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
}
+ % else
{
- \tl_set:Nn \__mhchem_cf_state_tl { 1 }
- \tl_put_right:Nn \__mhchem_cf_sub_tl { , }
- \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
+ \__mhchem_cf_outputAndReset:
+ \tl_put_right:Nn \__mhchem_cf_result_tl { {,} }
+ \__mhchem_loopHelper_ignoreNextToken:Nn
+ \__mhchem_cf_loop:
}
}{
\peek_charcode:NTF .
@@ -1627,10 +1712,11 @@
}{
\peek_charcode:NTF +
{
- \tl_set:Nn \__mhchem_cf_state_tl { + }
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
- \__mhchem_cf_loop:
+ \str_if_eq:VnF \__mhchem_cf_supState_tl { - }
+ { \__mhchem_cf_outputAndReset: }
+ \tl_set:Nn \__mhchem_cf_supState_tl { d }
+ \tl_set:Nn \__mhchem_cf_state_tl { e }
+ \__mhchem_cf_loop:
}{
\peek_charcode:NTF |
{
@@ -1669,18 +1755,23 @@
\__mhchem_cf_result_tl
\__mhchem_cf_loop:
}{
- \peek_catcode:NTF a
+ \peek_catcode:NTF a % letter
{
+ \str_if_eq:VnF \__mhchem_cf_supState_tl { - }
+ { \__mhchem_cf_outputAndReset: }
+ \str_if_eq:VnF \__mhchem_cf_subState_tl { - }
+ { \__mhchem_cf_outputAndReset: }
\__mhchem_loopHelper_appendNextToken:NNn
\__mhchem_cf_element_tl
\__mhchem_cf_loop:
}{
- \peek_catcode:NTF 1
+ \peek_catcode:NTF 1 % number
{
- \tl_set:Nn \__mhchem_cf_state_tl { 2 }
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sub_tl
- \__mhchem_cf_loop:
+ \str_if_eq:VnF \__mhchem_cf_subState_tl { - }
+ { \__mhchem_cf_outputAndReset: }
+ \tl_set:Nn \__mhchem_cf_subState_tl { d }
+ \tl_set:Nn \__mhchem_cf_state_tl { f }
+ \__mhchem_cf_loop:
}{
\peek_catcode:NTF \c_group_begin_token
{
@@ -1691,519 +1782,663 @@
}{
\peek_catcode_remove:NTF \c_math_toggle_token
{
+ \str_if_eq:VnF \__mhchem_cf_supState_tl { - }
+ { \__mhchem_cf_outputAndReset: }
+ \str_if_eq:VnF \__mhchem_cf_subState_tl { - }
+ { \__mhchem_cf_outputAndReset: }
\__mhchem_loopHelper_appendMathB:NNw
\__mhchem_cf_element_tl
\__mhchem_cf_loop:
}
% else
- { \msg_error:nnn { mhchem } { cf/unexpected-input } }
+ {
+ \__mhchem_cf_outputAndReset:
+ \tl_set:Nn \__mhchem_cf_state_tl { s }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_result_tl
+ \__mhchem_cf_loop:
+ }
}}}}}}}}}}}}}}}}}}}
}
- { 2 }
+ { e }
{
- \peek_charcode:NTF -
+ \peek_charcode:NTF 1
{
- \tl_set:Nn \__mhchem_cf_state_tl { - }
- \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
+ \tl_set:Nn \__mhchem_cf_state_tl { e+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sup_tl
+ \__mhchem_cf_loop:
}{
- \peek_charcode:NTF =
+ \peek_charcode:NTF 2
{
- \__mhchem_cf_outputAndReset:
- \tl_put_right:Nn \__mhchem_cf_result_tl {\dbond}
- \tl_set:Nn \__mhchem_cf_state_tl { s }
- \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
+ \tl_set:Nn \__mhchem_cf_state_tl { e+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sup_tl
+ \__mhchem_cf_loop:
}{
- \peek_charcode:NTF ##
+ \peek_charcode:NTF 3
{
- \__mhchem_cf_outputAndReset:
- \tl_put_right:Nn \__mhchem_cf_result_tl {\tbond}
- \tl_set:Nn \__mhchem_cf_state_tl { s }
- \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
+ \tl_set:Nn \__mhchem_cf_state_tl { e+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sup_tl
+ \__mhchem_cf_loop:
}{
- \peek_charcode:NTF ^
+ \peek_charcode:NTF 4
{
- \tl_set:Nn \__mhchem_cf_state_tl { e }
- \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
+ \tl_set:Nn \__mhchem_cf_state_tl { e+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sup_tl
+ \__mhchem_cf_loop:
}{
- \peek_charcode:NTF _
+ \peek_charcode:NTF 5
{
- \tl_set:Nn \__mhchem_cf_state_tl { f }
- \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
+ \tl_set:Nn \__mhchem_cf_state_tl { e+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sup_tl
+ \__mhchem_cf_loop:
}{
- \peek_charcode:NTF `
+ \peek_charcode:NTF 6
{
- \int_compare:nTF { 4 > \__mhchem_option_version_int }
- {
- \tl_set:Nn \__mhchem_cf_state_tl { E }
- \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
- }
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sub_tl
- \__mhchem_cf_loop:
- }
+ \tl_set:Nn \__mhchem_cf_state_tl { e+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sup_tl
+ \__mhchem_cf_loop:
}{
- \peek_charcode:NTF ,
+ \peek_charcode:NTF 7
{
- \int_compare:nTF { 4 > \__mhchem_option_version_int }
- {
- \tl_set:Nn \__mhchem_cf_state_tl { F }
- \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
- }
- {
- \tl_put_right:Nn \__mhchem_cf_sub_tl { , }
- \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
- }
+ \tl_set:Nn \__mhchem_cf_state_tl { e+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sup_tl
+ \__mhchem_cf_loop:
}{
- \peek_charcode:NTF .
+ \peek_charcode:NTF 8
{
- \int_compare:nTF { 4 > \__mhchem_option_version_int }
- {
- \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn
- { \mhchem@mathOrText@ii{{}\cdot{}}{\mhchem@option@textcdot} }
- { s }
- \__mhchem_cf_loop:
- }
- {
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sub_tl
- \__mhchem_cf_loop:
- }
+ \tl_set:Nn \__mhchem_cf_state_tl { e+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sup_tl
+ \__mhchem_cf_loop:
}{
- \peek_charcode:NTF *
+ \peek_charcode:NTF 9
{
- \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn
- { \mhchem@mathOrText@ii{{}\cdot{}}{\mhchem@option@textcdot} }
- { s }
+ \tl_set:Nn \__mhchem_cf_state_tl { e+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sup_tl
\__mhchem_cf_loop:
}{
- \peek_charcode:NTF +
+ \peek_charcode:NTF 0
{
- \tl_set:Nn \__mhchem_cf_state_tl { + }
+ \tl_set:Nn \__mhchem_cf_state_tl { e+ }
\__mhchem_loopHelper_appendNextToken:NNn
\__mhchem_cf_sup_tl
\__mhchem_cf_loop:
}{
- \peek_charcode:NTF |
+ \peek_catcode_remove:NTF \c_math_toggle_token
{
- \PackageWarning{mhchem}{The symbol | is not allowed here}
- \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
- }{
- \peek_charcode:NTF (
+ \tl_set:Nn \__mhchem_cf_state_tl { a }
+ \__mhchem_loopHelper_appendMathAsGroup:NNw
+ \__mhchem_cf_sup_tl
+ \__mhchem_cf_loop:
+ }
+ % else
{
- \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn
- { s }
+ \tl_set:Nn \__mhchem_cf_state_tl { a }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sup_tl
+ \__mhchem_cf_loop:
+ }
+ }}}}}}}}}}
+ }
+ { e+ }
+ {
+ \peek_charcode:NTF 1
+ {
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sup_tl
\__mhchem_cf_loop:
}{
- \peek_charcode:NTF )
+ \peek_charcode:NTF 2
{
- \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn
- { a }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sup_tl
\__mhchem_cf_loop:
}{
- \peek_charcode:NTF [
+ \peek_charcode:NTF 3
{
- \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn
- { s }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sup_tl
\__mhchem_cf_loop:
}{
- \peek_charcode:NTF ]
+ \peek_charcode:NTF 4
{
- \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn
- { a }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sup_tl
\__mhchem_cf_loop:
}{
- \peek_catcode:NTF \mhchem@macro
+ \peek_charcode:NTF 5
{
- \__mhchem_cf_outputAndReset:
- \tl_set:Nn \__mhchem_cf_state_tl { c }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_result_tl
+ \__mhchem_cf_sup_tl
\__mhchem_cf_loop:
}{
- \peek_catcode:NTF a
+ \peek_charcode:NTF 6
{
- \__mhchem_cf_outputAndReset:
- \tl_set:Nn \__mhchem_cf_state_tl { a }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_element_tl
+ \__mhchem_cf_sup_tl
\__mhchem_cf_loop:
}{
- \peek_catcode:NTF 1
+ \peek_charcode:NTF 7
{
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sub_tl
+ \__mhchem_cf_sup_tl
\__mhchem_cf_loop:
}{
- \peek_catcode:NTF \c_group_begin_token
+ \peek_charcode:NTF 8
{
- \int_compare:nTF { 4 > \__mhchem_option_version_int }
- {
- \__mhchem_cf_outputAndReset:
- \tl_set:Nn \__mhchem_cf_state_tl { s }
- \__mhchem_loopHelper_appendNextGroup:NNn
- \__mhchem_cf_result_tl
- \__mhchem_cf_loop:
- }
- {
- \__mhchem_cf_outputAndReset:
- \tl_set:Nn \__mhchem_cf_state_tl { a }
- \__mhchem_loopHelper_appendNextGroup:NNn
- \__mhchem_cf_element_tl
- \__mhchem_cf_loop:
- }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sup_tl
+ \__mhchem_cf_loop:
}{
- \peek_catcode_remove:NTF \c_math_toggle_token
+ \peek_charcode:NTF 9
{
- \__mhchem_cf_outputAndReset:
- \tl_set:Nn \__mhchem_cf_state_tl { a }
- \__mhchem_loopHelper_appendMathB:NNw
- \__mhchem_cf_element_tl
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sup_tl
\__mhchem_cf_loop:
- }
- % else
+ }{
+ \peek_charcode:NTF 0
{
- \__mhchem_cf_outputAndReset:
- \tl_set:Nn \__mhchem_cf_state_tl { s }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_result_tl
+ \__mhchem_cf_sup_tl
\__mhchem_cf_loop:
- }
- }}}}}}}}}}}}}}}}}}}
- }
- { e }
- {
- \tl_set:Nn \__mhchem_cf_state_tl { + }
- \peek_catcode_remove:NTF \c_math_toggle_token
+ }{
+ \peek_charcode:NTF +
{
- \__mhchem_loopHelper_appendMathAsGroup:NNw
+ \__mhchem_loopHelper_appendNextToken:NNn
\__mhchem_cf_sup_tl
\__mhchem_cf_loop:
- }
+ }{
+ \peek_charcode:NTF -
{
\__mhchem_loopHelper_appendNextToken:NNn
\__mhchem_cf_sup_tl
\__mhchem_cf_loop:
}
+ % else
+ {
+ \tl_set:Nn \__mhchem_cf_state_tl { a }
+ \__mhchem_cf_loop:
+ }
+ }}}}}}}}}}}
}
- { k }
+ { f }
{
- \tl_set:Nn \__mhchem_cf_state_tl { + }
+ \peek_charcode:NTF 1
+ {
+ \tl_set:Nn \__mhchem_cf_state_tl { f+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sub_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 2
+ {
+ \tl_set:Nn \__mhchem_cf_state_tl { f+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sub_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 3
+ {
+ \tl_set:Nn \__mhchem_cf_state_tl { f+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sub_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 4
+ {
+ \tl_set:Nn \__mhchem_cf_state_tl { f+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sub_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 5
+ {
+ \tl_set:Nn \__mhchem_cf_state_tl { f+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sub_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 6
+ {
+ \tl_set:Nn \__mhchem_cf_state_tl { f+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sub_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 7
+ {
+ \tl_set:Nn \__mhchem_cf_state_tl { f+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sub_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 8
+ {
+ \tl_set:Nn \__mhchem_cf_state_tl { f+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sub_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 9
+ {
+ \tl_set:Nn \__mhchem_cf_state_tl { f+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sub_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 0
+ {
+ \tl_set:Nn \__mhchem_cf_state_tl { f+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sub_tl
+ \__mhchem_cf_loop:
+ }{
\peek_catcode_remove:NTF \c_math_toggle_token
{
+ \tl_set:Nn \__mhchem_cf_state_tl { a }
\__mhchem_loopHelper_appendMathAsGroup:NNw
- \__mhchem_cf_supA_tl
+ \__mhchem_cf_sub_tl
\__mhchem_cf_loop:
}
+ % else
{
+ \tl_set:Nn \__mhchem_cf_state_tl { a }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_supA_tl
+ \__mhchem_cf_sub_tl
\__mhchem_cf_loop:
}
+ }}}}}}}}}}
}
- { f }
+ { f+ }
{
- \tl_set:Nn \__mhchem_cf_state_tl { + }
- \peek_catcode_remove:NTF \c_math_toggle_token
+ \peek_charcode:NTF 1
{
- \__mhchem_loopHelper_appendMathAsGroup:NNw
+ \__mhchem_loopHelper_appendNextToken:NNn
\__mhchem_cf_sub_tl
\__mhchem_cf_loop:
- }
+ }{
+ \peek_charcode:NTF 2
+ {
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sub_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 3
+ {
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sub_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 4
+ {
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sub_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 5
+ {
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sub_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 6
+ {
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sub_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 7
+ {
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sub_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 8
+ {
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sub_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 9
+ {
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_sub_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 0
{
\__mhchem_loopHelper_appendNextToken:NNn
\__mhchem_cf_sub_tl
\__mhchem_cf_loop:
}
+ % else
+ {
+ \tl_set:Nn \__mhchem_cf_state_tl { a }
+ \__mhchem_cf_loop:
+ }
+ }}}}}}}}}
}
{ p }
{
- \tl_set:Nn \__mhchem_cf_state_tl { * }
- \peek_catcode_remove:NTF \c_math_toggle_token
+ \peek_charcode:NTF 1
{
- \__mhchem_loopHelper_appendMathAsGroup:NNw
+ \tl_set:Nn \__mhchem_cf_state_tl { p+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
\__mhchem_cf_presup_tl
\__mhchem_cf_loop:
- }
+ }{
+ \peek_charcode:NTF 2
{
+ \tl_set:Nn \__mhchem_cf_state_tl { p+ }
\__mhchem_loopHelper_appendNextToken:NNn
\__mhchem_cf_presup_tl
\__mhchem_cf_loop:
- }
- }
- { q }
- {
- \tl_set:Nn \__mhchem_cf_state_tl { * }
+ }{
+ \peek_charcode:NTF 3
+ {
+ \tl_set:Nn \__mhchem_cf_state_tl { p+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presup_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 4
+ {
+ \tl_set:Nn \__mhchem_cf_state_tl { p+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presup_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 5
+ {
+ \tl_set:Nn \__mhchem_cf_state_tl { p+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presup_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 6
+ {
+ \tl_set:Nn \__mhchem_cf_state_tl { p+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presup_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 7
+ {
+ \tl_set:Nn \__mhchem_cf_state_tl { p+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presup_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 8
+ {
+ \tl_set:Nn \__mhchem_cf_state_tl { p+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presup_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 9
+ {
+ \tl_set:Nn \__mhchem_cf_state_tl { p+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presup_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 0
+ {
+ \tl_set:Nn \__mhchem_cf_state_tl { p+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presup_tl
+ \__mhchem_cf_loop:
+ }{
\peek_catcode_remove:NTF \c_math_toggle_token
{
+ \tl_set:Nn \__mhchem_cf_state_tl { s }
\__mhchem_loopHelper_appendMathAsGroup:NNw
- \__mhchem_cf_presub_tl
+ \__mhchem_cf_presup_tl
\__mhchem_cf_loop:
}
+ % else
{
+ \tl_set:Nn \__mhchem_cf_state_tl { s }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_presub_tl
+ \__mhchem_cf_presup_tl
\__mhchem_cf_loop:
- }
- }
- { E }
- {
- \tl_set:Nn \__mhchem_cf_state_tl { + }
- \__mhchem_loopHelper_appendNextTokenAsMathrm:NNn
- \__mhchem_cf_sup_tl
- \__mhchem_cf_loop:
- }
- { F }
- {
- \tl_set:Nn \__mhchem_cf_state_tl { + }
- \__mhchem_loopHelper_appendNextTokenAsMathrm:NNn
- \__mhchem_cf_sub_tl
- \__mhchem_cf_loop:
+ }}}}}}}}}}}
}
- { P }
+ { p+ }
{
- \tl_set:Nn \__mhchem_cf_state_tl { * }
- \__mhchem_loopHelper_appendNextTokenAsMathrm:NNn
- \__mhchem_cf_presup_tl
- \__mhchem_cf_loop:
- }
- { Q }
- {
- \tl_set:Nn \__mhchem_cf_state_tl { * }
- \__mhchem_loopHelper_appendNextTokenAsMathrm:NNn
- \__mhchem_cf_presub_tl
- \__mhchem_cf_loop:
- }
- { + }
- {
- \peek_charcode:NTF -
+ \peek_charcode:NTF 1
{
- \tl_set:Nn \__mhchem_cf_state_tl { - }
- \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presup_tl
+ \__mhchem_cf_loop:
}{
- \peek_charcode:NTF =
+ \peek_charcode:NTF 2
{
- \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn
- { \dbond }
- { s }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presup_tl
\__mhchem_cf_loop:
}{
- \peek_charcode:NTF ##
+ \peek_charcode:NTF 3
{
- \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn
- { \tbond }
- { s }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presup_tl
\__mhchem_cf_loop:
}{
- \peek_charcode:NTF ^
+ \peek_charcode:NTF 4
{
- \tl_set:Nn \__mhchem_cf_state_tl { e }
- \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presup_tl
+ \__mhchem_cf_loop:
}{
- \peek_charcode:NTF _
+ \peek_charcode:NTF 5
{
- \tl_set:Nn \__mhchem_cf_state_tl { f }
- \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presup_tl
+ \__mhchem_cf_loop:
}{
- \peek_charcode:NTF `
+ \peek_charcode:NTF 6
{
- \int_compare:nTF { 4 > \__mhchem_option_version_int }
- {
- \tl_set:Nn \__mhchem_cf_state_tl { E }
- \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
- }
- {
- \__mhchem_cf_outputAndReset:
- \tl_set:Nn \__mhchem_cf_state_tl { a }
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_element_tl
- \__mhchem_cf_loop:
- }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presup_tl
+ \__mhchem_cf_loop:
}{
- \peek_charcode:NTF ,
+ \peek_charcode:NTF 7
{
- \int_compare:nTF { 4 > \__mhchem_option_version_int }
- {
- \tl_set:Nn \__mhchem_cf_state_tl { F }
- \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
- }
- {
- \__mhchem_cf_outputAndReset:
- \tl_set:Nn \__mhchem_cf_state_tl { a }
- \tl_put_right:Nn \__mhchem_cf_element_tl { , }
- \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
- }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presup_tl
+ \__mhchem_cf_loop:
}{
- \peek_charcode:NTF .
+ \peek_charcode:NTF 8
{
- \int_compare:nTF { 4 > \__mhchem_option_version_int }
- {
- \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn
- { \mhchem@mathOrText@ii{{}\cdot{}}{\mhchem@option@textcdot} }
- { s }
- \__mhchem_cf_loop:
- }
- {
- \__mhchem_cf_outputAndReset:
- \tl_set:Nn \__mhchem_cf_state_tl { a }
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_element_tl
- \__mhchem_cf_loop:
- }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presup_tl
+ \__mhchem_cf_loop:
}{
- \peek_charcode:NTF *
+ \peek_charcode:NTF 9
{
- \__mhchem_loopHelper_outputAndReset_appendToResult_setState_useNone:NNn
- { \mhchem@mathOrText@ii{{}\cdot{}}{\mhchem@option@textcdot} }
- { s }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presup_tl
\__mhchem_cf_loop:
}{
- \peek_charcode:NTF +
+ \peek_charcode:NTF 0
{
- \tl_set:Nn \__mhchem_cf_state_tl { + }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_sup_tl
+ \__mhchem_cf_presup_tl
+ \__mhchem_cf_loop:
+ }
+ % else
+ {
+ \tl_set:Nn \__mhchem_cf_state_tl { s }
+ \__mhchem_cf_loop:
+ }}}}}}}}}}
+ }
+ { q }
+ {
+ \peek_charcode:NTF 1
+ {
+ \tl_set:Nn \__mhchem_cf_state_tl { q+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presub_tl
\__mhchem_cf_loop:
}{
- \peek_charcode:NTF |
+ \peek_charcode:NTF 2
{
- \PackageWarning{mhchem}{The symbol | is not allowed here}
- \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
+ \tl_set:Nn \__mhchem_cf_state_tl { q+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presub_tl
+ \__mhchem_cf_loop:
}{
- \peek_charcode:NTF (
+ \peek_charcode:NTF 3
{
- \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn
- { s }
+ \tl_set:Nn \__mhchem_cf_state_tl { q+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presub_tl
\__mhchem_cf_loop:
}{
- \peek_charcode:NTF )
+ \peek_charcode:NTF 4
{
- \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn
- { a }
+ \tl_set:Nn \__mhchem_cf_state_tl { q+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presub_tl
\__mhchem_cf_loop:
}{
- \peek_charcode:NTF [
+ \peek_charcode:NTF 5
{
- \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn
- { s }
+ \tl_set:Nn \__mhchem_cf_state_tl { q+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presub_tl
\__mhchem_cf_loop:
}{
- \peek_charcode:NTF ]
+ \peek_charcode:NTF 6
{
- \__mhchem_loopHelper_outputAndReset_appendNextTokenToResult_setState:NNn
- { a }
+ \tl_set:Nn \__mhchem_cf_state_tl { q+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presub_tl
\__mhchem_cf_loop:
}{
- \peek_catcode:NTF \mhchem@macro
+ \peek_charcode:NTF 7
{
- \__mhchem_cf_outputAndReset:
- \tl_set:Nn \__mhchem_cf_state_tl { c }
+ \tl_set:Nn \__mhchem_cf_state_tl { q+ }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_result_tl
+ \__mhchem_cf_presub_tl
\__mhchem_cf_loop:
}{
- \peek_catcode:NTF a
+ \peek_charcode:NTF 8
{
- \__mhchem_cf_outputAndReset:
- \tl_set:Nn \__mhchem_cf_state_tl { a }
+ \tl_set:Nn \__mhchem_cf_state_tl { q+ }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_element_tl
+ \__mhchem_cf_presub_tl
\__mhchem_cf_loop:
}{
- \peek_catcode:NTF 1
+ \peek_charcode:NTF 9
{
- \__mhchem_cf_outputAndReset:
- \tl_set:Nn \__mhchem_cf_state_tl { a }
+ \tl_set:Nn \__mhchem_cf_state_tl { q+ }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_element_tl
+ \__mhchem_cf_presub_tl
\__mhchem_cf_loop:
}{
- \peek_catcode:NTF \c_group_begin_token
+ \peek_charcode:NTF 0
{
- \int_compare:nTF { 4 > \__mhchem_option_version_int }
- {
- \__mhchem_cf_outputAndReset:
- \tl_set:Nn \__mhchem_cf_state_tl { s }
- \__mhchem_loopHelper_appendNextGroup:NNn
- \__mhchem_cf_result_tl
- \__mhchem_cf_loop:
- }
- {
- \__mhchem_cf_outputAndReset:
- \tl_set:Nn \__mhchem_cf_state_tl { a }
- \__mhchem_loopHelper_appendNextGroup:NNn
- \__mhchem_cf_element_tl
- \__mhchem_cf_loop:
- }
+ \tl_set:Nn \__mhchem_cf_state_tl { q+ }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presub_tl
+ \__mhchem_cf_loop:
}{
\peek_catcode_remove:NTF \c_math_toggle_token
{
- \__mhchem_cf_outputAndReset:
- \tl_set:Nn \__mhchem_cf_state_tl { a }
- \__mhchem_loopHelper_appendMathB:NNw
- \__mhchem_cf_element_tl
+ \tl_set:Nn \__mhchem_cf_state_tl { s }
+ \__mhchem_loopHelper_appendMathAsGroup:NNw
+ \__mhchem_cf_presub_tl
\__mhchem_cf_loop:
}
% else
{
- \__mhchem_cf_outputAndReset:
\tl_set:Nn \__mhchem_cf_state_tl { s }
\__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_result_tl
+ \__mhchem_cf_presub_tl
\__mhchem_cf_loop:
- }
- }}}}}}}}}}}}}}}}}}}
+ }}}}}}}}}}}
}
- { * }
+ { q+ }
{
- \peek_charcode:NTF ^
+ \peek_charcode:NTF 1
{
- \tl_set:Nn \__mhchem_cf_state_tl { p }
- \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presub_tl
+ \__mhchem_cf_loop:
}{
- \peek_charcode:NTF _
+ \peek_charcode:NTF 2
{
- \tl_set:Nn \__mhchem_cf_state_tl { q }
- \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presub_tl
+ \__mhchem_cf_loop:
}{
- \peek_charcode:NTF `
+ \peek_charcode:NTF 3
{
- \int_compare:nTF { 4 > \__mhchem_option_version_int }
- {
- \tl_set:Nn \__mhchem_cf_state_tl { P }
- \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
- }
- {
- \tl_set:Nn \__mhchem_cf_state_tl { a }
- \__mhchem_loopHelper_appendNextToken:NNn
- \__mhchem_cf_element_tl
- \__mhchem_cf_loop:
- }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presub_tl
+ \__mhchem_cf_loop:
}{
- \peek_charcode:NTF ,
+ \peek_charcode:NTF 4
{
- \int_compare:nTF { 4 > \__mhchem_option_version_int }
- {
- \tl_set:Nn \__mhchem_cf_state_tl { Q }
- \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
- }
- {
- \tl_set:Nn \__mhchem_cf_state_tl { a }
- \tl_put_right:Nn \__mhchem_cf_element_tl { , }
- \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop:
- }
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presub_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 5
+ {
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presub_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 6
+ {
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presub_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 7
+ {
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presub_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 8
+ {
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presub_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 9
+ {
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presub_tl
+ \__mhchem_cf_loop:
+ }{
+ \peek_charcode:NTF 0
+ {
+ \__mhchem_loopHelper_appendNextToken:NNn
+ \__mhchem_cf_presub_tl
+ \__mhchem_cf_loop:
}
% else
{
- \__mhchem_cf_outputAndReset:
\tl_set:Nn \__mhchem_cf_state_tl { s }
\__mhchem_cf_loop:
- }
- }}}
+ }}}}}}}}}}
}
}
{
- \msg_error:nnx { mhchem } { cf/unexpected-state }
+ \msg_error:nnx { mhchem } { cf / unexpected-state }
{ \__mhchem_cf_state_tl }
\__mhchem_loopHelper_appendNextToken:NNn
\__mhchem_cf_result_tl
@@ -2220,92 +2455,119 @@
\mhchem@cf@continue%
}%
-\tl_new:N \__mhchem_cf_presup_tl
-\tl_new:N \__mhchem_cf_presub_tl
-\tl_new:N \__mhchem_cf_element_tl
-\tl_new:N \__mhchem_cf_supA_tl
-\tl_new:N \__mhchem_cf_sub_tl
-\tl_new:N \__mhchem_cf_sup_tl
\cs_new_protected:Npn \__mhchem_cf_output:
{
- \str_case:Vnn \__mhchem_cf_state_tl
+ \str_if_eq:nnTF
{
- { s } { }
- { 1 }
+ \__mhchem_cf_presup_tl
+ \__mhchem_cf_presub_tl
+ \__mhchem_cf_element_tl
+ \__mhchem_cf_supA_tl%todo remove
+ \__mhchem_cf_sub_tl
+ \__mhchem_cf_sup_tl
+ }
+ {} % is empty?
+ {
+ }
+ {
+ \str_case:Vnn \__mhchem_cf_state_tl
{
- \tl_put_right:Nx \__mhchem_cf_result_tl
+ { 1 }
{
- \exp_not:N \mhchem@mathOrText {
- \exp_not:N \mhchem@cf@frac
- \exp_not:V \__mhchem_cf_element_tl / \exp_not:N \mhchem@END
- { \mhchem@option@skipAfterFracAmount } }
+ \tl_put_right:Nx \__mhchem_cf_result_tl
+ {
+ \exp_not:N \mhchem@mathOrText {
+ \exp_not:N \mhchem@cf@frac
+ \exp_not:V \__mhchem_cf_element_tl / \exp_not:N \mhchem@END
+ { \exp_not:N \mhchem@option@skipAfterAmount } }
+ }
}
- }
- { 9 }
- {
- \tl_put_right:Nx \__mhchem_cf_result_tl
+ { 9 }
{
- \exp_not:N \mhchem@mathOrText {
- \exp_not:N \mhchem@cf@frac
- \exp_not:V \__mhchem_cf_element_tl /
- \exp_not:N \mhchem@END
- {} }
+ \tl_put_right:Nx \__mhchem_cf_result_tl
+ {
+ \exp_not:N \mhchem@mathOrText {
+ \exp_not:N \mhchem@cf@frac
+ \exp_not:V \__mhchem_cf_element_tl /
+ \exp_not:N \mhchem@END
+ {} }
+ }
}
}
- }
- {
- \tl_if_empty:NTF \__mhchem_cf_sub_tl
- {
- \tl_put_right:NV \__mhchem_cf_supA_tl \__mhchem_cf_sup_tl
- \tl_clear:N \__mhchem_cf_sup_tl
- }
{
- \tl_if_empty:NTF \__mhchem_cf_sup_tl
- { }
+ \str_if_eq:VnTF \__mhchem_cf_supState_tl { rm }
{
- \tl_if_empty:NTF \__mhchem_cf_supA_tl
- { }
- {
- \msg_error:nnn { mhchem } { cf/unexpected-two-superscripts }
- }
+ \tl_set:Nx \__mhchem_cf_sup_tl { \exp_not:N \ensuremath { \exp_not:N \mathrm { \exp_not:V \__mhchem_cf_sup_tl } } }
}
- }
- \tl_put_right:Nx \__mhchem_cf_result_tl
- {
- \exp_not:N \__mhchem_chemfive:nnnnnn
+ {}
+ \str_if_eq:VnT \__mhchem_cf_subState_tl { rm }
{
- \exp_not:N \__mhchem_cf_replaceMath:n
- { \exp_not:V \__mhchem_cf_presup_tl }
+ \tl_set:Nx \__mhchem_cf_sub_tl { \exp_not:N \ensuremath { \exp_not:N \mathrm { \exp_not:V \__mhchem_cf_sub_tl } } }
}
+ \str_if_eq:VnTF \__mhchem_cf_presupState_tl { rm }
{
- \exp_not:N \__mhchem_cf_replaceMath:n
- { \exp_not:V \__mhchem_cf_presub_tl }
+ \tl_set:Nx \__mhchem_cf_presup_tl { \exp_not:N \ensuremath { \exp_not:N \mathrm { \exp_not:V \__mhchem_cf_presup_tl } } }
}
- { \exp_not:V \__mhchem_cf_element_tl }
+ {}
+ \str_if_eq:VnT \__mhchem_cf_presubState_tl { rm }
{
- \exp_not:N \__mhchem_cf_replaceMathMinusDot:n
- { \exp_not:V \__mhchem_cf_supA_tl }
+ \tl_set:Nx \__mhchem_cf_presub_tl { \exp_not:N \ensuremath { \exp_not:N \mathrm { \exp_not:V \__mhchem_cf_presub_tl } } }
}
+ \str_case:Vnn \__mhchem_cf_supState_tl
{
- \exp_not:N \__mhchem_cf_replaceMath:n
- { \exp_not:V \__mhchem_cf_sub_tl }
+ { kv }
+ {
+ \tl_put_right:Nx \__mhchem_cf_result_tl
+ {
+ \exp_not:N \__mhchem_chemfive:nnnnnn
+ {
+ \exp_not:N \__mhchem_cf_replaceMath:n
+ { \exp_not:V \__mhchem_cf_presup_tl }
+ }
+ {
+ \exp_not:N \__mhchem_cf_replaceMath:n
+ { \exp_not:V \__mhchem_cf_presub_tl }
+ }
+ { \exp_not:V \__mhchem_cf_element_tl }
+ {
+ \exp_not:N \__mhchem_cf_replaceMathMinusDot:n
+ { \exp_not:V \__mhchem_cf_sup_tl }
+ }
+ {
+ \exp_not:N \__mhchem_cf_replaceMath:n
+ { \exp_not:V \__mhchem_cf_sub_tl }
+ }
+ {}
+ }
+ }
}
{
- \exp_not:N \__mhchem_cf_replaceMathMinusDot:n
- { \exp_not:V \__mhchem_cf_sup_tl }
+ \tl_put_right:Nx \__mhchem_cf_result_tl
+ {
+ \exp_not:N \__mhchem_chemfive:nnnnnn
+ {
+ \exp_not:N \__mhchem_cf_replaceMath:n
+ { \exp_not:V \__mhchem_cf_presup_tl }
+ }
+ {
+ \exp_not:N \__mhchem_cf_replaceMath:n
+ { \exp_not:V \__mhchem_cf_presub_tl }
+ }
+ { \exp_not:V \__mhchem_cf_element_tl }
+ {}
+ {
+ \exp_not:N \__mhchem_cf_replaceMath:n
+ { \exp_not:V \__mhchem_cf_sub_tl }
+ }
+ {
+ \exp_not:N \__mhchem_cf_replaceMathMinusDot:n
+ { \exp_not:V \__mhchem_cf_sup_tl }
+ }
+ }
}
- }
+ }
}
}
-\cs_new_protected:Npn \__mhchem_cf_resetOutput:
- {
- \tl_clear:N \__mhchem_cf_presup_tl
- \tl_clear:N \__mhchem_cf_presub_tl
- \tl_clear:N \__mhchem_cf_element_tl
- \tl_clear:N \__mhchem_cf_supA_tl
- \tl_clear:N \__mhchem_cf_sub_tl
- \tl_clear:N \__mhchem_cf_sup_tl
- }
\cs_new_protected:Npn \__mhchem_cf_outputAndReset:
{
\__mhchem_cf_output:
@@ -2410,16 +2672,56 @@
}}}}
}
+\cs_new_protected:Npn \__mhchem_defMathOrText:
+ {
+ \mode_if_math:TF
+ {
+ \int_compare:nTF { \__mhchem_option_version_int > 1 }
+ {
+ \cs_set:Npx \mhchem@mathOrText ##1
+ {
+ \mode_if_math:TF
+ { \exp_not:N \mhchem@option@mathFont{##1} }
+ { \exp_not:N \text{##1} }
+ }
+ \cs_set:Npx \mhchem@mathOrText@ii ##1##2
+ {
+ \mode_if_math:TF
+ { \exp_not:N \mhchem@option@mathFont{##1} }
+ { ##2 }
+ }
+ }
+ % else
+ {
+ \cs_set:Npx \mhchem@mathOrText ##1
+ {
+ \mode_if_math:TF { ##1 } { \exp_not:N \text{##1} }
+ }
+ \cs_set:Npx \mhchem@mathOrText@ii ##1##2
+ {
+ \mode_if_math:TF { ##1 } { ##2 }
+ }
+ }
+ }
+ % else
+ {
+
+ \mhchem@option@textFont
+ \cs_set:Npx \mhchem@mathOrText ##1 { \exp_not:N \text{##1} }
+ \cs_set:Npx \mhchem@mathOrText@ii ##1##2 { ##2 }
+ }
+ }
%%%%%%%%%%%%%%%%%%%%%
%%% @chemfive %%%
%%%%%%%%%%%%%%%%%%%%%
\cs_new_protected:Npn \__mhchem_chemfive:nnnnnn #1#2#3#4#5#6
{
- \str_if_eq:VnTF \mhchem@option@superscriptstacked { true }
+ \bool_if:NTF \__mhchem_option_superscriptsStacked_bool
{
- \mhchem@prepostscript%
- {\mhchem@mathOrText{\smash[t]{2+}}}%
- {\mhchem@mathOrText{\smash[t]{2}}}%
+ \__mhchem_prepostscript:nnnnnnnnn%
+ {\mhchem@mathOrText{2+}}%
+ {\mhchem@mathOrText{2}}%
+ {\mhchem@mathOrText{X}}%
{\mhchem@mathOrText{#1}}%
{\mhchem@mathOrText{#2}}%
{\mhchem@mathOrText@ii{\mhchem@option@mathFont{#3}}{\text{#3}}}%
@@ -2428,9 +2730,10 @@
{}%
}
{
- \mhchem@prepostscript%
- {\mhchem@mathOrText{\smash[t]{2+}}}%
- {\mhchem@mathOrText{\smash[t]{2}}}%
+ \__mhchem_prepostscript:nnnnnnnnn%
+ {\mhchem@mathOrText{2+}}%
+ {\mhchem@mathOrText{2}}%
+ {\mhchem@mathOrText{X}}%
{\mhchem@mathOrText{#1}}%
{\mhchem@mathOrText{#2}}%
{\mhchem@mathOrText@ii{\mhchem@option@mathFont{#3}}{\text{#3}}}%
@@ -2439,68 +2742,72 @@
{\mhchem@mathOrText{#6}}%
}
}
-\ExplSyntaxOff
%%% @prepostscript
-\newlength\mhchem@prepostscript@tmp@i%
-\newlength\mhchem@prepostscript@tmp@ii%
-\newcommand*\mhchem@prepostscript[8]{%
- \m@th%
- \ensuremath{%
- \setlength{\mhchem@prepostscript@tmp@i}{\widthof{$#3#4$}}%
- \ifdim\mhchem@prepostscript@tmp@i>0pt%
- \setlength{\mhchem@prepostscript@tmp@i}{\widthof{${}^{#3}$}}%
- \setlength{\mhchem@prepostscript@tmp@ii}{\widthof{${}_{#4}$}}%
- \ifdim\mhchem@prepostscript@tmp@i<\mhchem@prepostscript@tmp@ii%
- \setlength{\mhchem@prepostscript@tmp@i}{\mhchem@prepostscript@tmp@ii}\fi%
- \vphantom{#5}%
- {}%
- ^{%
- \mhchem@mathboxright{\mhchem@prepostscript@tmp@i}{%
- \vphantom{#6#8}%
- \vphantom{#1}%
- #3%
- }%
- }%
- _{%
- \mhchem@mathboxright{\mhchem@prepostscript@tmp@i}{%
- \vphantom{#7}%
- \vphantom{#2}%
- #4%
- }%
- }%
- \mhchem@minispace%
- \fi%
- #5%
- \setlength{\mhchem@prepostscript@tmp@i}{\widthof{$#7#6$}}%
- \ifdim\mhchem@prepostscript@tmp@i>0pt%
- _{%
- \vphantom{#4}%
- \vphantom{#2}%
- #7%
- }%
- ^{%
- \vphantom{#3#8}%
- \vphantom{#1}%
- #6%
- }%
- \fi%
- \setlength{\mhchem@prepostscript@tmp@i}{\widthof{$#8$}}%
- \ifdim\mhchem@prepostscript@tmp@i>0pt%
- \mhchem@minispace%
- {}%
- _{%
- \vphantom{#4#7}%
- \vphantom{#2}%
- }%
- ^{%
- \vphantom{#3#6}%
- \vphantom{#1}%
- #8%
- }%
- \fi%
- }%
-}
+\newlength\__mhchem_prepostscript_leftwidth%
+\newlength\__mhchem_prepostscript_leftwidth_ii%
+\cs_new_protected:Npn \__mhchem_prepostscript:nnnnnnnnn #1#2#3#4#5#6#7#8#9
+ {
+ \m@th
+ \ensuremath
+ {
+ \hbox_set:Nn \l_tmpa_box { $#4#5$ }
+ \dim_compare:nNnT { \box_wd:N \l_tmpa_box } > { 0pt }
+ {
+ \hphantom { {}^{#4}\c_math_subscript_token{#5} }
+ { \vphantom {#3#6} }
+ ^ {
+ \mhchem@mathboxrightt
+ {
+ \vphantom {#1}
+ #4
+ }
+ }
+ \c_math_subscript_token {
+ \mhchem@mathboxrightt
+ {
+ \vphantom {#2}
+ #5
+ }
+ }
+ \mhchem@minispace %
+ }
+ #6
+ \hbox_set:Nn \l_tmpa_box { $#7#8#9$ }
+ \dim_compare:nNnT { \box_wd:N \l_tmpa_box } > { 0pt }
+ {
+ \hbox_set:Nn \l_tmpa_box { $#6$ }
+ \dim_compare:nNnTF { \box_wd:N \l_tmpa_box } > { 0pt }
+ { { \vphantom {#3#6} } }
+ { \mhchem@minibackspace { \vphantom {#3} } }
+ \hbox_set:Nn \l_tmpa_box { $#8$ }
+ \dim_compare:nNnT { \box_wd:N \l_tmpa_box } > { 0pt }
+ {
+ \c_math_subscript_token {
+ \vphantom { \smash[b]{#2} }
+ #8
+ }
+ }
+ \hbox_set:Nn \l_tmpa_box { $#9$ }
+ \dim_compare:nNnTF { \box_wd:N \l_tmpa_box } = { 0pt }
+ {
+ ^ {
+ \vphantom { \smash[t]{#1} }
+ #7
+ }
+ }
+ {
+ ^ {
+ \vphantom { \smash[t]{#1} }
+ \hphantom {#8}
+ #9
+ }
+ }
+ }
+ }
+ }
+
+\ExplSyntaxOff
%%% @mathbox
\newcommand*\mhchem@mathbox[2][]{%
@@ -2531,6 +2838,11 @@
{\makebox[#1][r]{\ensuremath{\textstyle#2}}}%
{\makebox[#1][r]{\ensuremath{\scriptstyle#2}}}%
{\makebox[#1][r]{\ensuremath{\scriptscriptstyle#2}}}}
+\newcommand*\mhchem@mathboxrightt[1]{\mathchoice%
+ {\ensuremath{\displaystyle\llap{\ensuremath{\displaystyle#1}}}}%
+ {\ensuremath{\textstyle\llap{\ensuremath{\textstyle#1}}}}%
+ {\ensuremath{\scriptstyle\llap{\ensuremath{\scriptstyle#1}}}}%
+ {\ensuremath{\scriptscriptstyle\llap{\ensuremath{\scriptscriptstyle#1}}}}}%
%%% @minispace
\newlength\mhchem@minispace@tmp
@@ -2539,113 +2851,140 @@
\widthof{$\text{C}^8_8$}-\widthof{$\text{C}^{}_{}$}}%
\kern\mhchem@minispace@tmp%
}
+%%% @minibackspace
+\newlength\mhchem@minibackspace@tmp
+\newcommand*\mhchem@minibackspace{%
+ \setlength{\mhchem@minibackspace@tmp}{0pt-\widthof{${}_{2}{}_{2}$}+\widthof{${}_{22}$}}%
+ \kern\mhchem@minibackspace@tmp%
+}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%% Package Options %%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\def\mhchem@option@version{0}
-\define@key{mhchem}{version}{\def\mhchem@option@version{#1}}
+\ExplSyntaxOn
+
+\msg_new:nnn { mhchem } { options / no-version }
+ {
+ You~did~not~specify~a~'version'~option~for~the~mhchem~package.~
+ Please~write~
+ \string\usepackage[version=3]{mhchem}~in~your~preamble~
+ (or~any~lower~number~for~compatibility~mode).
+ }
+\msg_new:nnn { mhchem } { options / version-too-high }
+ {
+ You~are~using~version~3.xx~of~mhchem,
+ but~you~entered~a~higher~version~number.~
+ This~means,~you~are~using~some~beta~features~of~mhchem~
+ that~are~subject~to~change~without~notice.
+ }
\def\mhchem@option@mathFont{\mathrm}
\def\mhchem@option@textFont{}
-\define@key{mhchem}{textfontcommand}{\def\mhchem@option@textFont{#1}}
-\define@key{mhchem}{textfontname}{\def\mhchem@option@textFont{\csname#1\endcsname}}
-\define@key{mhchem}{mathfontcommand}{\def\mhchem@option@mathFont{#1}}
-\define@key{mhchem}{mathfontname}{\def\mhchem@option@mathFont{\csname#1\endcsname}}
-\define@key{mhchem}{font}{%
- \ifthenelse{\equal{sf}{#1}}{%
- \def\mhchem@option@textFont{\sffamily}%
- \def\mhchem@option@mathFont{\mathsf}%
- }{\ifthenelse{\equal{}{#1}}{%
- \def\mhchem@option@textFont{}%
- \def\mhchem@option@mathFont{\mathrm}%
- }{\PackageError{mhchem}{Font option `#1' unknown}}}%
-}
+\bool_new:N \__mhchem_option_superscriptsStacked_bool
-\def\mhchem@option@alwaystextmode{0}%
-
-\newlength\mhchem@option@minussidebearingleft
-\newlength\mhchem@option@minussidebearingright
-\setlength\mhchem@option@minussidebearingleft{0.06em}
-\setlength\mhchem@option@minussidebearingright{0.11em}
-\define@key{mhchem}{minus-sidebearing-left}{\setlength\mhchem@option@minussidebearingleft{#1}}
-\define@key{mhchem}{minus-sidebearing-right}{\setlength\mhchem@option@minussidebearingright{#1}}
-
-\mhchem@definearrows{font}
-\define@key{mhchem}{arrows}{%
- \ifthenelse{\equal{pgf}{#1} \or \equal{pgf-filled}{#1}}{%
- \RequirePackage{pgf}% for finding the tikz package more easily
- \RequirePackage{tikz}%
- }{}%
- \mhchem@definearrows{#1}%
-}
+\keys_define:nn {mhchem}
+ {
+ version .int_set:N = \__mhchem_option_version_int,
+ version .value_required:,
+ version .initial:n = { -1 },
+ version .default:n = { -1 },
-\def\mhchem@option@skipAfterAmount{\,}
-\define@key{mhchem}{skip-after-amount}{\def\mhchem@option@skipAfterAmount{#1}\def\mhchem@option@skipAfterFracAmount{#1}}
-\def\mhchem@option@skipAfterFracAmount{\,}
-\define@key{mhchem}{skip-after-frac-amount}{\def\mhchem@option@skipAfterFracAmount{#1}}
-
-\def\mhchem@option@textminus{--}
-\define@key{mhchem}{textminus}{\def\mhchem@option@textminus{#1}}
-
-\def\mhchem@option@textcdot{\cdot}
-\define@key{mhchem}{textcdot}{\def\mhchem@option@textcdot{#1}}
-
-\def\mhchem@option@superscriptstacked{0}
-\define@key{mhchem}{superscriptstacked}[true]{\def\mhchem@option@superscriptstacked{#1}}%
-
-%%% begin: standard keyval handling as in many other packages
-\def\ProcessOptionsWithKV#1{%
- \let\@tempc\relax%
- \let\mhchem@tempa\@empty%
- \@for\CurrentOption:=\@classoptionslist\do{%
- \@ifundefined{KV@#1@\CurrentOption}%
- {}%
- {%
- \edef\mhchem@tempa{\mhchem@tempa,\CurrentOption,}%
- \@expandtwoargs\@removeelement\CurrentOption%
- \@unusedoptionlist\@unusedoptionlist%
- }%
- }%
- \edef\mhchem@tempa{%
- \noexpand\setkeys{#1}{%
- \mhchem@tempa\@ptionlist{\@currname.\@currext}%
- }%
- }%
- \mhchem@tempa%
- \let\CurrentOption\@empty%
- \AtEndOfPackage{\let\@unprocessedoptions\relax}%
-}
-\ProcessOptionsWithKV{mhchem}\relax
-%%% end:
-
-\define@key{mhchem}{arrows}{\mhchem@definearrows{#1}}%
-
-\newcommand*\mhchemoptions[1]{\setkeys{mhchem}{#1}}
-
-\ifnum 0=\mhchem@option@version%
- \PackageWarningNoLine{mhchem}{%
- You did not specify a 'version' option for the mhchem\MessageBreak
- package. If you are about to create a new document,\MessageBreak
- please write \string\usepackage[version=3]{mhchem} in your\MessageBreak
- preamble in order to use the most recent version of\MessageBreak
- mhchem}%
- \def\mhchem@option@version{3}%
-\else\ifnum 4=\mhchem@option@version%
- \PackageWarningNoLine{mhchem}{%
- You are using version 3.xx of mhchem. You entered\MessageBreak
- the parameter version=4. This means, you are using\MessageBreak
- some beta features of mhchem that are subject\MessageBreak
- to change without notice}%
-\fi\fi%
+ textfontcommand .code:n = { \def\mhchem@option@textFont{#1} },
+ textfontname .code:n = { \def\mhchem@option@textFont{\csname#1\endcsname} },
+ mathfontcommand .code:n = { \def\mhchem@option@mathFont{#1} },
+ mathfontname .code:n = { \def\mhchem@option@mathFont{\csname#1\endcsname} },
+ font .choice:,
+ font / sf .code:n =
+ {
+ \def\mhchem@option@textFont{\sffamily}%
+ \def\mhchem@option@mathFont{\mathsf}%
+ },
+ font / .code:n =
+ {
+ \def\mhchem@option@textFont{}%
+ \def\mhchem@option@mathFont{\mathrm}%
+ },
+
+ minus-sidebearing-left .dim_set:N = \mhchem@option@minussidebearingleft,
+ minus-sidebearing-left .initial:n = { 0.06em },
+ minus-sidebearing-right .dim_set:N = \mhchem@option@minussidebearingright,
+ minus-sidebearing-right .initial:n = { 0.11em },
+
+ arrows .choice:,
+ arrows / font .code:n = { \mhchem@definearrows{#1} },
+ arrows / pgf .code:n =
+ {
+ \bool_if:NT { \__mhchem_option_inPreamble_bool }
+ {
+ \RequirePackage{pgf}
+ \RequirePackage{tikz}
+ }
+ \mhchem@definearrows{#1}
+ },
+ arrows / pgf-filled .code:n =
+ {
+ \bool_if:NT { \__mhchem_option_inPreamble_bool }
+ {
+ \RequirePackage{pgf}
+ \RequirePackage{tikz}
+ }
+ \mhchem@definearrows{#1}
+ },
+ arrows .initial:n = { font },
+
+ skip-after-amount .code:n =
+ {
+ \def\mhchem@option@skipAfterAmount{#1}
+ },
+ skip-after-amount .initial:n = { \, },
+
+ textminus .code:n = { \def\mhchem@option@textminus{#1} },
+ textminus .initial:n = { -- },
+
+ textcdot .code:n = { \def\mhchem@option@textcdot{#1} },
+ textcdot .initial:n = { \cdot },
+
+ superscripts .choice:,
+ superscripts / stacked .code:n =
+ { \bool_set_true:N \__mhchem_option_superscriptsStacked_bool },
+ superscripts / shifted .code:n =
+ { \bool_set_true:N \__mhchem_option_superscriptsStacked_bool },
+ superscripts / .code:n =
+ { \bool_set_true:N \__mhchem_option_superscriptsStacked_bool },
+ superscripts .initial:n .code:n =
+ { \bool_set_true:N \__mhchem_option_superscriptsStacked_bool },
+ }
+
+\newcommand*\mhchemoptions[1]
+ { \keys_set:nn { mhchem } {#1} }
+
+\bool_new:N \__mhchem_option_inPreamble_bool
+\bool_set_true:N \__mhchem_option_inPreamble_bool
+\ProcessKeysPackageOptions{mhchem}
+\bool_set_false:N \__mhchem_option_inPreamble_bool
+
+\int_compare:nT { -1 = \__mhchem_option_version_int }
+ {
+ \msg_error:nn { mhchem } { options / no-version }
+ \int_set:Nn \__mhchem_option_version_int { 3 }
+ }
+% else
+ {
+ \int_compare:nT { \__mhchem_option_version_int > 3}
+ {
+ \msg_warning:nn { mhchem } { options / version-too-high }
+ }
+ }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%% legacy %%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\ifnum 4>\mhchem@option@version
- \newcommand*\mhchem@cmath[1]{\ensuremath{\text{\ensuremath{#1}}}}%
- \newcommand*\cmath[1]{\mhchem@cmath{#1}}
- \DeclareRobustCommand\cf[2][]{\mhchem@cf[#1]{#2}}
-\fi
+\int_compare:nT { \__mhchem_option_version_int < 4 }
+ {
+ \newcommand*\mhchem@cmath[1]{\ensuremath{\text{\ensuremath{#1}}}}%
+ \newcommand*\cmath[1]{\mhchem@cmath{#1}}
+ \DeclareRobustCommand\cf[2][]{\mhchem@cf[#1]{#2}}
+ }
+