summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/mhchem
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/texmf-dist/tex/latex/mhchem
parent48a19dc74b35f6b94debd3e82fd1ccbed71d6f76 (diff)
mhchem (7apr15)
git-svn-id: svn://tug.org/texlive/trunk@36738 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/mhchem')
-rw-r--r--Master/texmf-dist/tex/latex/mhchem/mhchem.sty3074
1 files changed, 1620 insertions, 1454 deletions
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}}
}