diff options
author | Karl Berry <karl@freefriends.org> | 2016-08-09 22:39:41 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2016-08-09 22:39:41 +0000 |
commit | a5e307fda7603294be920676f6214104743fbea4 (patch) | |
tree | 21ad220230a3ec1588a12e3b0a28538b217efc0e /Master/texmf-dist/tex | |
parent | 6be2c32cff4adda12cf9068b51d5208782c4b3fc (diff) |
mhchem (9aug16)
git-svn-id: svn://tug.org/texlive/trunk@41829 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/latex/mhchem/mhchem.sty | 384 |
1 files changed, 233 insertions, 151 deletions
diff --git a/Master/texmf-dist/tex/latex/mhchem/mhchem.sty b/Master/texmf-dist/tex/latex/mhchem/mhchem.sty index 8a1879aafc0..0c9c343ea37 100644 --- a/Master/texmf-dist/tex/latex/mhchem/mhchem.sty +++ b/Master/texmf-dist/tex/latex/mhchem/mhchem.sty @@ -27,13 +27,13 @@ % This work consists of all files listed in manifest.txt. % % -\ProvidesPackage{mhchem}[2016/02/07 v4.04 for typesetting chemical formulae] +\ProvidesPackage{mhchem}[2016/08/07 v4.05 for typesetting chemical formulae] \RequirePackage{expl3} \RequirePackage{l3keys2e} \RequirePackage{l3regex} \RequirePackage{calc}[1998/07/07] \RequirePackage{amsmath} -\RequirePackage{chemgreek}[2015/04/09] +\RequirePackage{chemgreek}[2016/02/10] \RequirePackage{graphics} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -47,22 +47,16 @@ %%%%%%%%%% global helpers %%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\def\mhchem@appendToks#1#2{% - #1=\expandafter{\the#1#2}% -} - \ExplSyntaxOn \cs_generate_variant:Nn \str_if_eq:nnTF { Vn } \cs_generate_variant:Nn \str_case:nnF { VnF } -\cs_generate_variant:Nn \regex_match:nnTF { nV } -\cs_generate_variant:Nn \regex_match:nnTF { no } \cs_generate_variant:Nn \regex_match:NnTF { NV } \cs_generate_variant:Nn \regex_match:NnTF { No } \cs_new_protected:Npn \__mhchem_regex_peek_compile:Nn #1#2 { \regex_const:Nn #1 { \A the\ (character|letter)\ (#2) \Z } -} + } \cs_new_protected:Npn \__mhchem_regex_peek:NTF #1#2#3 { @@ -75,43 +69,48 @@ } } -\regex_const:Nn \l__mhchem_regex_digitCommaDigit_regex { \d\,\d } -\regex_const:Nn \l__mhchem_regex_oneLetter_regex { [nmptx] } +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%% RegExp helpers %%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\regex_const:Nn \l__mhchem_regex_oneLowercaseLetter_regex { [a-z] } \regex_const:Nn \l__mhchem_regex_hyphen_regex { - } \regex_const:Nn \l__mhchem_regex_letters_regex { [a-zA-Z]+ } \regex_const:Nn \l__mhchem_regex_spaces_regex { [\ ]+ } \regex_const:Nn \l__mhchem_regex_digits_fregex { \A [0-9]+ \Z} -\regex_const:Nn \l__mhchem_regex_oneToThreeLetters_fregex { \A (.+) (\([a-z]{1,3}\)) \Z } -\regex_const:Nn \l__mhchem_regex_oneLetter_fregex { \A [nmptx] \Z } -\regex_const:Nn \l__mhchem_regex_oneLetterPlus_fregex - { \A ([nmptx]|\c{eta|mu|kappa}|\c{__mhchem_cg_withinMathTokens:n}\cB.[nmptx]\cE.|[0-9]+|[0-9]+\/[0-9]+) \Z } +\regex_const:Nn \l__mhchem_regex_stateOfAggregationAtEnd_fregex { \A (.+) (\([a-z]{1,3}\)) \Z } +\regex_const:Nn \l__mhchem_regex_oneLowercaseLetter_fregex { \A [a-z] \Z } +\regex_const:Nn \l__mhchem_regex_oneLowercaseLetterPlus_fregex + { \A ( (\c{__mhchem_cg_withinMathTokens:n}\cB.)? ([a-z]|\c{alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|lambda|mu|nu|xi|omicron|pi|rho|sigma|tau|upsilon|phi|chi|psi|omega}) (\cE.)? | \(?[0-9]+ | \(?[0-9]+\/[0-9]+ ) \Z } \regex_const:Nn \l__mhchem_regex_romanNumeral_fregex { \A [IVX]+ \Z } \regex_const:Nn \l__mhchem_regex_bracedGroup_fregex { \A \cB. [^\cE.]* \cE. \Z } \regex_const:Nn \l__mhchem_regex_oneGreekLetter_fregex { \A \c{alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|lambda|mu|nu|xi|omicron|pi|rho|sigma|tau|upsilon|phi|chi|psi|omega|Alpha|Beta|Gamma|Delta|Epsilon|Zeta|Eta|Theta|Iota|Kappa|Lambda|Mu|Nu|Xi|Omicron|Pi|Rho|Sigma|Tau|Upsilon|Phi|Chi|Psi|Omega} \Z } \regex_const:Nn \l__mhchem_regex_digitOrLetterOrGreek_fregex { \A [1-9a-zA-Z\ \~\+\-\,\.\(\)\c{alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|lambda|mu|nu|xi|omicron|pi|rho|sigma|tau|upsilon|phi|chi|psi|omega|Alpha|Beta|Gamma|Delta|Epsilon|Zeta|Eta|Theta|Iota|Kappa|Lambda|Mu|Nu|Xi|Omicron|Pi|Rho|Sigma|Tau|Upsilon|Phi|Chi|Psi|Omega}]+ \Z } +\regex_const:Nn \l__mhchem_regex_nonFormula_fregex { \A \( [a-z]+ \) \Z } \regex_const:Nn \l__mhchem_regex_formula_fregex - { \A ([0-9\ \+\-\,\.\(\)]* [nmptx] [0-9\ \+\-\,\.\(\)]*)+ \Z } + { \A ( [a-z] | ([0-9\ \+\-\,\.\(\)]+ [a-z])+ [0-9\ \+\-\,\.\(\)]* | ([a-z][0-9\ \+\-\,\.\(\)]+)+[a-z]? ) \Z } \regex_const:Nn \l__mhchem_regex_formulaAmount_fregex - { \A \c{__mhchem_cg_withinMathTokens:n}\cB. (([0-9nmptx]+ [\+\-])? [nmptx] ([\+\-] [0-9nmptx]+)?) \cE. \Z } + { \A \c{__mhchem_cg_withinMathTokens:n}\cB. (([0-9]*[a-z]? [\+\-])? [a-z] ([\+\-] [0-9]+[a-z]?)?) \cE. \Z } \regex_const:Nn \l__mhchem_regex_fraction_fregex { \A ([0-9]+)\/([0-9]+) \Z } \regex_const:Nn \l__mhchem_regex_fracMacro_fregex { \A \c{frac} \Z } - -\__mhchem_regex_peek_compile:Nn \l__mhchem_regex_digit_pregex { [ 0-9 ] } -\__mhchem_regex_peek_compile:Nn \l__mhchem_regex_digitOrPlus_pregex { [ 0-9 \+ ] } -\__mhchem_regex_peek_compile:Nn \l__mhchem_regex_digitOrMinus_pregex { [ 0-9 \-] } -\__mhchem_regex_peek_compile:Nn \l__mhchem_regex_digitOrDot_pregex { [ 0-9 . ] } -\__mhchem_regex_peek_compile:Nn \l__mhchem_regex_digitOrSlash_pregex { [ 0-9 \/ ] } -\__mhchem_regex_peek_compile:Nn \l__mhchem_regex_digitOrDotPlus_pregex { [ 0-9 \) \. \/ ] } -\__mhchem_regex_peek_compile:Nn \l__mhchem_regex_dotOrAsterisk_pregex { [ \. \* ] } -\__mhchem_regex_peek_compile:Nn \l__mhchem_regex_letter_pregex { [ a-zA-Z ] } -\__mhchem_regex_peek_compile:Nn \l__mhchem_regex_uppercaseLetterOrParenthesis_pregex { [ A-Z( ] } +\regex_const:Nn \l__mhchem_regex_ceOperator_fregex { \A ( \+ | - | = | \c{pm} | \$\c{pm}\$ | \(v\) | v | \(\^\) | \^ | \. | \* ) \Z } + +\__mhchem_regex_peek_compile:Nn \l__mhchem_regex_digit_pregex { [0-9] } +\__mhchem_regex_peek_compile:Nn \l__mhchem_regex_digitOrPlus_pregex { [0-9 \+] } +\__mhchem_regex_peek_compile:Nn \l__mhchem_regex_digitOrMinus_pregex { [0-9 \-] } +\__mhchem_regex_peek_compile:Nn \l__mhchem_regex_digitOrDot_pregex { [0-9 .] } +\__mhchem_regex_peek_compile:Nn \l__mhchem_regex_digitOrSlash_pregex { [0-9 \/] } +\__mhchem_regex_peek_compile:Nn \l__mhchem_regex_digitOrDotPlus_pregex { [0-9 \) \. \/] } +\__mhchem_regex_peek_compile:Nn \l__mhchem_regex_dotOrAsterisk_pregex { [\. \*] } +\__mhchem_regex_peek_compile:Nn \l__mhchem_regex_letter_pregex { [a-zA-Z] } +\__mhchem_regex_peek_compile:Nn \l__mhchem_regex_uppercaseLetterOrParenthesis_pregex { [ A-Z \( \[ ] } \__mhchem_regex_peek_compile:Nn \l__mhchem_regex_openingBracket_pregex { [ \( \[ ] } \__mhchem_regex_peek_compile:Nn \l__mhchem_regex_closingBracket_pregex { [ \) \] \/ ] } -\__mhchem_regex_peek_compile:Nn \l__mhchem_regex_oneLetter_pregex { [ nmptx ] } +\__mhchem_regex_peek_compile:Nn \l__mhchem_regex_oneLowercaseLetter_pregex { [a-z] } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%% loop helpers %%%%%%%%%% @@ -172,6 +171,9 @@ \cs_new_protected:Npn \__mhchem_loopHelper_ignoreNextToken:Nn #1#2 { #1 } +\cs_new_protected:Npn \__mhchem_loopHelper_breakLoop:w #1#2\q_recursion_stop + { #1 } + \ExplSyntaxOff %%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -232,7 +234,7 @@ \bool_new:N \l__mhchem_cesplit_odd_bool \tl_new:N \l__mhchem_cesplit_tmpa_tl -\newcommand\cesplit[2] +\newcommand*\cesplit[2] { \bool_set_true:N \l__mhchem_cesplit_odd_bool \tl_set:Nn \l__mhchem_cesplit_tmpa_tl { \__mhchem_ce:n {#2} } @@ -260,12 +262,7 @@ %%%%%%%%%% \cee %%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\newcommand*\mhchem@cee[1]{ - \__mhchem_cee:n {#1} -} - -\ExplSyntaxOn -\cs_new_protected:Npn \__mhchem_cee:n #1 +\cs_new_protected:Npn \mhchem@cee #1 % \__mhchem_cee:n { \cesplit { @@ -295,8 +292,6 @@ \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_potentialSpacingAllowed_bool \cs_new_protected:Npn \__mhchem_ce:n #1 { @@ -407,9 +402,8 @@ \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 + \tl_clear:N \l__mhchem_cf_lastNonIsotopeElement_tl \__mhchem_ce_loop: #1 \q_recursion_stop \int_compare:nTF { \l__mhchem_option_version_int > 1 } { \tl_use:N \l__mhchem_ce_result_tl } @@ -427,19 +421,9 @@ \str_case:VnF \l__mhchem_ce_part_tl { { + } - { - \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 } - } + { \__mhchem_ce_output:nn { 0 } { 0 } } { \pm } - { - \tl_put_right:Nn \l__mhchem_ce_result_tl - { \__mhchem_output_operatorPlusMinus: } - \tl_clear:N \l__mhchem_ce_part_tl - \tl_set:Nn \l__mhchem_ce_state_tl { a-end } - } + { \__mhchem_ce_output:nn { 0 } { 0 } } { -> } { \tl_set:Nn \l__mhchem_ce_arrowName_tl { yields } @@ -482,7 +466,7 @@ {} \peek_meaning_remove:NTF \q_recursion_stop { - \__mhchem_ce_output: + \__mhchem_ce_output:nn { 1 } { 0 } }{ \str_case:VnF \l__mhchem_ce_state_tl { @@ -512,14 +496,10 @@ { \int_compare:nTF { \l__mhchem_ce_distanceFromLastComma_int = 1 } { - \__mhchem_ce_output: - \bool_set_false:N \l__mhchem_ce_potentialSpacing_bool + \__mhchem_ce_output:nn { 1 } { 0 } } { - \__mhchem_ce_output: - \bool_if:NTF \l__mhchem_ce_potentialSpacingAllowed_bool - { \bool_set_true:N \l__mhchem_ce_potentialSpacing_bool } - { \bool_set_false:N \l__mhchem_ce_potentialSpacing_bool } + \__mhchem_ce_output:nn { 1 } { 1 } } \__mhchem_ce_loop: }{ @@ -542,7 +522,7 @@ { \peek_charcode_remove:NTF \c_space_token { - \__mhchem_ce_output: + \__mhchem_ce_output:nn { 0 } { 0 } \__mhchem_ce_loop: }{ \peek_charcode:NTF T @@ -595,7 +575,7 @@ } % else { - \__mhchem_ce_output: + \__mhchem_ce_output:nn { 0 } { 0 } \tl_set:Nn \l__mhchem_ce_state_tl { a-end } \__mhchem_ce_loop: } @@ -613,7 +593,7 @@ } % else { - \__mhchem_ce_output: + \__mhchem_ce_output:nn { 0 } { 0 } \tl_set:Nn \l__mhchem_ce_state_tl { a-end } \__mhchem_ce_loop: } @@ -621,7 +601,7 @@ } % else { - \__mhchem_ce_output: + \__mhchem_ce_output:nn { 0 } { 0 } \tl_set:Nn \l__mhchem_ce_state_tl { a-end } \__mhchem_ce_loop: } @@ -637,7 +617,7 @@ } % else { - \__mhchem_ce_output: + \__mhchem_ce_output:nn { 0 } { 0 } \tl_set:Nn \l__mhchem_ce_state_tl { a-end } \__mhchem_ce_loop: } @@ -678,7 +658,7 @@ { \peek_charcode_remove:NTF \c_space_token { - \__mhchem_ce_output: + \__mhchem_ce_output:nn { 0 } { 0 } \__mhchem_ce_loop: }{ \peek_charcode:NTF T @@ -709,7 +689,7 @@ } % else { - \__mhchem_ce_output: + \__mhchem_ce_output:nn { 0 } { 0 } \tl_set:Nn \l__mhchem_ce_state_tl { a-end } \__mhchem_ce_loop: } @@ -724,7 +704,7 @@ } % else { - \__mhchem_ce_output: + \__mhchem_ce_output:nn { 0 } { 0 } \tl_set:Nn \l__mhchem_ce_state_tl { a-end } \__mhchem_ce_loop: } @@ -750,7 +730,7 @@ }{ \peek_charcode:NTF ] { - \__mhchem_ce_output: + \__mhchem_ce_output:nn { 0 } { 0 } \tl_set:Nn \l__mhchem_ce_state_tl { a-end } \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_ce_loop: } @@ -764,7 +744,6 @@ } { a-end } { - \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 { @@ -785,68 +764,110 @@ } } } -\cs_new_protected:Npn \__mhchem_ce_output: +\tl_new:N \l__mhchem_ce_output_cache_part_tl +\tl_new:N \l__mhchem_ce_output_cache_state_tl +\cs_new_protected:Npn \__mhchem_ce_output:nn #1#2 % #1 0/1 can be connected with previous to a cf phrase, #2 0/1 can be connected with following to a cf phrase { - \bool_set_true:N \l__mhchem_ce_potentialSpacingAllowed_bool - \str_case:VnF \l__mhchem_ce_state_tl + \regex_match:NVTF \l__mhchem_regex_ceOperator_fregex \l__mhchem_ce_part_tl + { + \__mhchem_ce_output_cache: + \tl_set:NV \l__mhchem_ce_output_cache_state_tl \l__mhchem_ce_state_tl + \tl_set:NV \l__mhchem_ce_output_cache_part_tl \l__mhchem_ce_part_tl + \__mhchem_ce_output_cache: + } + { + \bool_if:nTF + { + \str_if_eq_p:nn { #1 } { 0 } || + ( ! \tl_if_empty_p:N \l__mhchem_ce_output_cache_state_tl && + ! \str_if_eq_p:VV \l__mhchem_ce_output_cache_state_tl \l__mhchem_ce_state_tl ) + } + { + \__mhchem_ce_output_cache: + \tl_set:NV \l__mhchem_ce_output_cache_state_tl \l__mhchem_ce_state_tl + \tl_set:NV \l__mhchem_ce_output_cache_part_tl \l__mhchem_ce_part_tl + \str_if_eq:nnT { #2 } { 0 } + { + \__mhchem_ce_output_cache: + } + } + { + \tl_if_empty:NF \l__mhchem_ce_output_cache_part_tl + { + \tl_if_empty:NF \l__mhchem_ce_part_tl + { \tl_put_right:Nn \l__mhchem_ce_output_cache_part_tl { ~ } } + } + \tl_put_right:NV \l__mhchem_ce_output_cache_part_tl \l__mhchem_ce_part_tl + \tl_set:NV \l__mhchem_ce_output_cache_state_tl \l__mhchem_ce_state_tl + \str_if_eq:nnT { #2 } { 0 } + { \__mhchem_ce_output_cache: } + } + } + \tl_clear:N \l__mhchem_ce_part_tl + \tl_set:Nn \l__mhchem_ce_state_tl { c } + } +\cs_new_protected:Npn \__mhchem_ce_output_cache: + { + \str_case:VnF \l__mhchem_ce_output_cache_state_tl { { c } { - \str_case:VnF \l__mhchem_ce_part_tl + \str_case:VnF \l__mhchem_ce_output_cache_part_tl { + { + } + { + \tl_put_right:Nn \l__mhchem_ce_result_tl + { \__mhchem_output_operatorPlus: } + } { - } { \tl_put_right:Nn \l__mhchem_ce_result_tl { \__mhchem_output_operatorMinus: } - \bool_set_false:N \l__mhchem_ce_potentialSpacingAllowed_bool } { = } { \tl_put_right:Nn \l__mhchem_ce_result_tl { \__mhchem_output_operatorEquals: } - \bool_set_false:N \l__mhchem_ce_potentialSpacingAllowed_bool + } + { \pm } + { + \tl_put_right:Nn \l__mhchem_ce_result_tl + { \__mhchem_output_operatorPlusMinus: } } { $\pm$ } { \tl_put_right:Nn \l__mhchem_ce_result_tl { \__mhchem_output_operatorPlusMinus: } - \bool_set_false:N \l__mhchem_ce_potentialSpacingAllowed_bool } { (v) } { \tl_put_right:Nn \l__mhchem_ce_result_tl { \ensuremath{{}\mathop{\downarrow}{}} } - \bool_set_false:N \l__mhchem_ce_potentialSpacingAllowed_bool } { v } { \tl_put_right:Nn \l__mhchem_ce_result_tl { \ensuremath{{}\mathop{\downarrow}{}} } - \bool_set_false:N \l__mhchem_ce_potentialSpacingAllowed_bool } { (^) } { \tl_put_right:Nn \l__mhchem_ce_result_tl { \ensuremath{{}\mathop{\uparrow}{}} } - \bool_set_false:N \l__mhchem_ce_potentialSpacingAllowed_bool } { ^ } { \tl_put_right:Nn \l__mhchem_ce_result_tl { \ensuremath{{}\mathop{\uparrow}{}} } - \bool_set_false:N \l__mhchem_ce_potentialSpacingAllowed_bool } { . } { \tl_put_right:Nn \l__mhchem_ce_result_tl { \__mhchem_output_additionCompound: } - \bool_set_false:N \l__mhchem_ce_potentialSpacingAllowed_bool } { * } { \tl_put_right:Nn \l__mhchem_ce_result_tl { \__mhchem_output_additionCompound: } - \bool_set_false:N \l__mhchem_ce_potentialSpacingAllowed_bool } { } { @@ -856,29 +877,27 @@ { \int_compare:nTF { \l__mhchem_option_version_int > 3 } { - \bool_if:NT \l__mhchem_ce_potentialSpacing_bool - { \tl_put_right:Nn \l__mhchem_ce_result_tl { \__mhchem_output_skipAfterAmount: } } \regex_match:NVTF - \l__mhchem_regex_oneToThreeLetters_fregex - \l__mhchem_ce_part_tl + \l__mhchem_regex_stateOfAggregationAtEnd_fregex + \l__mhchem_ce_output_cache_part_tl { \regex_replace_once:NnN - \l__mhchem_regex_oneToThreeLetters_fregex + \l__mhchem_regex_stateOfAggregationAtEnd_fregex { \c{__mhchem_cf:nn}\cB[\cE]\cB[ \1 \cE] \c{__mhchem_output_skipBeforeStateOfAggregation:} \c{__mhchem_cf:nn}\cB[\cE]\cB[ \2 \cE] } - \l__mhchem_ce_part_tl + \l__mhchem_ce_output_cache_part_tl \tl_put_right:Nx \l__mhchem_ce_result_tl - { \exp_not:V \l__mhchem_ce_part_tl } + { \exp_not:V \l__mhchem_ce_output_cache_part_tl } } { \tl_put_right:Nx \l__mhchem_ce_result_tl { \exp_not:N \__mhchem_cf:nn {} - { \exp_not:V \l__mhchem_ce_part_tl } + { \exp_not:V \l__mhchem_ce_output_cache_part_tl } } } } @@ -887,7 +906,7 @@ { \exp_not:N \__mhchem_cf:nn {} - { \exp_not:V \l__mhchem_ce_part_tl } + { \exp_not:V \l__mhchem_ce_output_cache_part_tl } } } } @@ -909,10 +928,9 @@ {} {} {} - \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: + \tl_set:NV \l__mhchem_ce_output_cache_part_tl \l__mhchem_ce_arrowTypeOne_tl + \tl_set:Nn \l__mhchem_ce_output_cache_state_tl { c } + \__mhchem_ce_output_cache: } { a-]1 } { @@ -940,10 +958,9 @@ { \l__mhchem_ce_arrowTextOne_tl } {} {} - \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: + \tl_set:NV \l__mhchem_ce_output_cache_part_tl \l__mhchem_ce_arrowTypeTwo_tl + \tl_set:Nn \l__mhchem_ce_output_cache_state_tl { c } + \__mhchem_ce_output_cache: } { a-]2 } { @@ -956,9 +973,8 @@ } } {} - \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 + \tl_clear:N \l__mhchem_ce_output_cache_state_tl + \tl_clear:N \l__mhchem_ce_output_cache_part_tl } \cs_new_protected:Npn \__mhchem_ce_outputArrow:nnnnn #1#2#3#4#5 { @@ -1357,7 +1373,7 @@ \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 +\tl_new:N \l__mhchem_cf_lastNonIsotopeElement_tl \bool_new:N \g__mhchem_cf_lastElementWithScript_bool \cs_new_protected:Npn \__mhchem_cf_resetOutput: { @@ -1399,19 +1415,11 @@ \tl_set:Nn \l__mhchem_cf_state_tl { s } \bool_set_false:N \l__mhchem_cf_startedWithBond_bool \__mhchem_cf_resetOutput: - \tl_set:Nn \l__mhchem_cf_result_tl {#2} - \regex_replace_once:NnNTF - \l__mhchem_regex_oneLetter_fregex - { \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 - } - \tl_if_empty:nTF {#1} - { \ensuremath{\tl_use:N \l__mhchem_cf_result_tl} } - { \ensuremath{\overset{#1}{\tl_use:N \l__mhchem_cf_result_tl}} } + \tl_clear:N \l__mhchem_cf_result_tl + \__mhchem_cf_loop: #2 \q_recursion_stop + \tl_if_empty:nTF {#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 @@ -1438,6 +1446,46 @@ {} \__mhchem_cf_outputAndReset: }{ + \peek_charcode_remove:NTF \c_space_token + { + \str_case:VnF \l__mhchem_cf_state_tl + { + { - } + { + \bool_if:NTF \l__mhchem_cf_startedWithBond_bool + { \__mhchem_cf_outputRaw:n { \__mhchem_output_bond_single: } } + { \tl_put_right:Nn \l__mhchem_cf_sup_tl { - } } + } + { 1 } + { \tl_set:Nn \l__mhchem_cf_state_tl {9} } + { frac2 } + { \__mhchem_cf_outputRawElementAndReset: } + { a } + { + \bool_if:nT + { + \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_sub_tl && + \tl_if_empty_p:N \l__mhchem_cf_sup_tl + } + { + \regex_replace_once:NnNTF + \l__mhchem_regex_oneLowercaseLetter_fregex + { \c{__mhchem_output_withFont:n}\cB[ \c{__mhchem_cg_itshape:n}\cB[ \0 \cE]\cE] } + \l__mhchem_cf_element_tl + {} + {} + } + } + } + {} + \__mhchem_cf_outputAndReset: + \int_compare:nT { \l__mhchem_option_version_int > 3 } + { \__mhchem_cf_outputRaw:n { \__mhchem_output_skipAfterAmount: } } + \tl_set:Nn \l__mhchem_cf_state_tl { s } + \__mhchem_cf_loop: + }{ \peek_meaning:NTF \relax { \__mhchem_loopHelper_ignoreNextToken:Nn \__mhchem_cf_loop: }{ \peek_meaning:NTF \protect @@ -1447,16 +1495,18 @@ { - } { \__mhchem_cf_outputAndReset: - \regex_match:NVTF - \l__mhchem_regex_oneLetterPlus_fregex - \l__mhchem_cf_lastElement_tl - { - \__mhchem_cf_outputRaw:n - { \__mhchem_cg_escapeFromMathToTextOrFaketext:n { - } } - } + \int_compare:nTF { \l__mhchem_option_version_int > 3 } { - \__mhchem_cf_outputRaw:n { \__mhchem_output_bond_single: } + \regex_match:NVTF + \l__mhchem_regex_oneLowercaseLetterPlus_fregex + \l__mhchem_cf_lastNonIsotopeElement_tl + { + \__mhchem_cf_outputRaw:n + { \__mhchem_cg_escapeFromMathToTextOrFaketext:n { - } } + } + { \__mhchem_cf_outputRaw:n { \__mhchem_output_bond_single: } } } + { \__mhchem_cf_outputRaw:n { \__mhchem_output_bond_single: } } \tl_set:Nn \l__mhchem_cf_state_tl { s } \__mhchem_cf_loop: } @@ -1478,13 +1528,13 @@ } { ps } { - \__mhchem_cf_outputAndReset: \__mhchem_regex_peek:NTF \l__mhchem_regex_uppercaseLetterOrParenthesis_pregex { \regex_match:NVTF \l__mhchem_regex_formulaAmount_fregex - \l__mhchem_cf_lastElement_tl + \l__mhchem_cf_element_tl { + \__mhchem_cf_outputAndReset: \tl_put_right:Nn \l__mhchem_cf_result_tl { \__mhchem_output_skipAfterAmount: } @@ -1675,7 +1725,10 @@ \__mhchem_cf_loop: } % else - { \msg_error:nnn { mhchem } { cf / unexpected-input } } + { + \__mhchem_loopHelper_breakLoop:w + { \msg_error:nnn { mhchem } { cf / unexpected-input } } + } }}}}}}}}}}}}}}}}} } { c } @@ -1973,7 +2026,7 @@ \peek_charcode:NTF - { \regex_match:NVTF - \l__mhchem_regex_oneLetterPlus_fregex + \l__mhchem_regex_oneLowercaseLetterPlus_fregex \l__mhchem_cf_element_tl { \tl_set:Nn \l__mhchem_cf_state_tl { - } @@ -2118,7 +2171,7 @@ \l__mhchem_cf_result_tl \__mhchem_cf_loop: } - }}} + }}}} } \cs_new_protected:Npn \__mhchem_cf_output: @@ -2134,7 +2187,13 @@ { } { - \tl_set:NV \l__mhchem_cf_lastElement_tl \l__mhchem_cf_element_tl + \bool_if:nT + { + \tl_if_empty_p:N \l__mhchem_cf_presup_tl && + \tl_if_empty_p:N \l__mhchem_cf_presub_tl + } + { \tl_set:NV \l__mhchem_cf_lastNonIsotopeElement_tl \l__mhchem_cf_element_tl } + { \tl_clear:N \l__mhchem_cf_lastNonIsotopeElement_tl } \bool_gset:Nn \g__mhchem_cf_lastElementWithScript_bool { ! \tl_if_empty_p:N \l__mhchem_cf_sub_tl || @@ -2240,7 +2299,7 @@ } \cs_new_protected:Npn \__mhchem_cf_outputRawElement: { - \tl_set:NV \l__mhchem_cf_lastElement_tl \l__mhchem_cf_element_tl + \tl_set:NV \l__mhchem_cf_lastNonIsotopeElement_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: @@ -2413,28 +2472,35 @@ \int_compare:nTF { \l__mhchem_option_version_int > 3} { \regex_match:NVTF - \l__mhchem_regex_formula_fregex + \l__mhchem_regex_nonFormula_fregex #1 { - \regex_replace_all:NnN - \l__mhchem_regex_oneLetter_regex - { \c{__mhchem_output_withFont:n}\cB[ \c{__mhchem_cg_itshape:n}\cB[ \0 \cE]\cE] } - #1 - \regex_replace_all:NnN - \l__mhchem_regex_hyphen_regex - { \c{__mhchem_output_minus:} } - #1 - \regex_replace_all:NnN - \l__mhchem_regex_digitCommaDigit_regex - { \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 } + { + \regex_match:NVTF + \l__mhchem_regex_formula_fregex + #1 + { + \regex_replace_all:NnN + \l__mhchem_regex_oneLowercaseLetter_regex + { \c{__mhchem_output_withFont:n}\cB[ \c{__mhchem_cg_itshape:n}\cB[ \0 \cE]\cE] } + #1 + \regex_replace_all:NnN + \l__mhchem_regex_hyphen_regex + { \c{__mhchem_output_minus:} } + #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 { @@ -2510,8 +2576,14 @@ \tl_new:N \l__mhchem_cg_replaceForSuperscript_result_tl \tl_new:N \l__mhchem_cg_replaceForSuperscript_state_tl +\bool_new:N \l__mhchem_cg_replaceForSuperscript_isFormula_bool \cs_new_protected:Npn \__mhchem_cg_replaceForSuperscript:N #1 { + \regex_match:NVTF + \l__mhchem_regex_formula_fregex + #1 + { \bool_set_true:N \l__mhchem_cg_replaceForSuperscript_isFormula_bool } + { \bool_set_false:N \l__mhchem_cg_replaceForSuperscript_isFormula_bool } \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 @@ -2583,7 +2655,7 @@ } \__mhchem_cg_replaceForSuperscript_loop: }{ - \__mhchem_regex_peek:NTF \l__mhchem_regex_oneLetter_pregex + \__mhchem_regex_peek:NTF \l__mhchem_regex_oneLowercaseLetter_pregex { \str_if_eq:VnT \l__mhchem_cg_replaceForSuperscript_state_tl { 9. } { @@ -2591,11 +2663,20 @@ { \__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: + \bool_if:NTF + \l__mhchem_cg_replaceForSuperscript_isFormula_bool + { + \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_loopHelper_appendNextToken:NNn + \l__mhchem_cg_replaceForSuperscript_result_tl + \__mhchem_cg_replaceForSuperscript_loop: + } }{ \__mhchem_regex_peek:NTF \l__mhchem_regex_digit_pregex { @@ -3350,3 +3431,4 @@ \DeclareRobustCommand\cf[2][]{\mhchem@cf[#1]{#2}} \DeclareRobustCommand\cee[1]{\mhchem@cee{#1}} } + |