summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/latex/chemmacros/chemformula.sty')
-rw-r--r--Master/texmf-dist/tex/latex/chemmacros/chemformula.sty326
1 files changed, 177 insertions, 149 deletions
diff --git a/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty b/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty
index c8c81b62add..715ff06b1ad 100644
--- a/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty
+++ b/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty
@@ -156,13 +156,13 @@
\dim_new:N \l__chemformula_radical_radius_dim
\dim_set:Nn \l__chemformula_radical_radius_dim { .2ex }
\dim_new:N \l__chemformula_radical_hshift_dim
-\dim_set:Nn \l__chemformula_radical_hshift_dim { .3ex }
+\dim_set:Nn \l__chemformula_radical_hshift_dim { .15em }
\dim_new:N \l__chemformula_radical_vshift_dim
-\dim_set:Nn \l__chemformula_radical_vshift_dim { .7ex }
+\dim_set:Nn \l__chemformula_radical_vshift_dim { .5ex }
\dim_new:N \l__chemformula_radical_space_dim
-\dim_set:Nn \l__chemformula_radical_space_dim { .3ex }
+\dim_set:Nn \l__chemformula_radical_space_dim { .15em }
-\cs_new:Npn \chemformula_radical:
+\cs_new_protected:Npn \chemformula_radical:
{
\chemformula_tikz:xn
{
@@ -314,7 +314,7 @@
\tl_set:Nn \l__chemformula_arrow_ratio_tl { .6 }
% determine length in dependency of labels
-\cs_new_protected:Npn \chemformula_determine_arrow_length:NN #1#2
+\cs_new_protected:Npn \__chemformula_determine_arrow_length:NN #1#2
{
\box_set_eq:NN \l__chemformula_tmpa_box #1
\dim_set:Nn \l__chemformula_tmpa_dim { \box_wd:N \l__chemformula_tmpa_box }
@@ -359,59 +359,59 @@
\box_new:N \l__chemformula_arrow_arg_ii_box
% read optional arguments
-\cs_new:Npn \l__chemformula_arrow_read_args:w
+\cs_new:Npn \__chemformula_arrow_read_args:w
{
\peek_meaning:NTF [
- { \l__chemformula_arrow_read_args_aux_i:w }
- { \l__chemformula_arrow_read_args_aux_iii: }
+ { \__chemformula_arrow_read_args_aux_i:w }
+ { \__chemformula_arrow_read_args_aux_iii: }
}
-\cs_new_protected:Npn \l__chemformula_arrow_read_args_aux_i:w [#1]
+\cs_new_protected:Npn \__chemformula_arrow_read_args_aux_i:w [#1]
{
\hbox_set:Nn \l__chemformula_arrow_arg_i_box
{ \tl_use:N \l__chemformula_arrow_label_style_tl #1 }
\peek_meaning:NTF [
- { \l__chemformula_arrow_read_args_aux_ii:w }
- { \l__chemformula_arrow_read_args_aux_iii: }
+ { \__chemformula_arrow_read_args_aux_ii:w }
+ { \__chemformula_arrow_read_args_aux_iii: }
}
-\cs_new_protected:Npn \l__chemformula_arrow_read_args_aux_ii:w [#1]
+\cs_new_protected:Npn \__chemformula_arrow_read_args_aux_ii:w [#1]
{
\hbox_set:Nn \l__chemformula_arrow_arg_ii_box
{ \tl_use:N \l__chemformula_arrow_label_style_tl #1 }
- \l__chemformula_arrow_read_args_aux_iii:
+ \__chemformula_arrow_read_args_aux_iii:
}
-\cs_new:Npn \l__chemformula_arrow_read_args_aux_iii:
+\cs_new:Npn \__chemformula_arrow_read_args_aux_iii:
{
% now we have both arguments do the actual drawing:
\prop_get:NVN \l__chemformula_arrows_code_prop
\l__chemformula_arrow_type_tl
\l__chemformula_tmpb_tl
- \chemformula_arrow_draw:V \l__chemformula_tmpb_tl
+ \__chemformula_arrow_draw:V \l__chemformula_tmpb_tl
}
% get arrows (for the use in \ch to replace the symbol)
% #1: symbol
-\cs_new_protected:Npn \chemformula_arrows_get:n #1
+\cs_new_protected:Npn \__chemformula_arrows_get:n #1
{
% first clear the arguments
\box_clear:N \l__chemformula_arrow_arg_i_box
\box_clear:N \l__chemformula_arrow_arg_ii_box
% then get the arrow type
\tl_set:Nn \l__chemformula_arrow_type_tl { #1 }
- \l__chemformula_arrow_read_args:w
+ \__chemformula_arrow_read_args:w
}
% draw the arrows
-\cs_new:Npn \chemformula_arrow_draw:n #1
+\cs_new:Npn \__chemformula_arrow_draw:n #1
{
\chemmacros_allow_break:
% prepare arrow code for drawing:
\tl_set_rescan:Nnn \l__chemformula_tmpc_tl
{ \char_set_catcode_letter:N \_ } { #1 }
% determine length of the arrow
- \chemformula_determine_arrow_length:NN
+ \__chemformula_determine_arrow_length:NN
\l__chemformula_arrow_arg_i_box
\l__chemformula_arrow_arg_ii_box
\chemformula_tikz:nf
@@ -448,7 +448,7 @@
}
\chemmacros_allow_break:
}
-\cs_generate_variant:Nn \chemformula_arrow_draw:n { V }
+\cs_generate_variant:Nn \__chemformula_arrow_draw:n { V }
% commands to declare arrows (can also be used by users):
% #1: symbol, #2: code
@@ -548,7 +548,7 @@
%-----------------------------------------------------------------------------%
\seq_new:N \l__chemformula_input_seq
% MAIN COMMAND
-\cs_new_protected:Npn \chemformula_ch_main:n #1
+\cs_new_protected:Npn \__chemformula_ch_main:n #1
{
\group_begin:
\seq_set_split:Nnn \l__chemformula_input_seq { ~ } { #1 }
@@ -564,8 +564,8 @@
\seq_map_function:NN
\l__chemformula_input_seq
\chemformula_input:n
- \chemformula_generate_arrows:V \l__chemformula_input_tl
- \chemformula_generate_name:V \l__chemformula_output_tl
+ \__chemformula_generate_arrows:V \l__chemformula_input_tl
+ \__chemformula_generate_name:V \l__chemformula_output_tl
\tl_set_rescan:Nno \l__chemformula_output_tl
{ \ExplSyntaxOn \makeatletter }
{ \l__chemformula_output_tl }
@@ -573,6 +573,7 @@
\group_end:
}
+% internal version of \ch command:
\cs_new_protected:Npn \chemformula_ch:nn #1#2
{
\group_align_safe_begin:
@@ -580,7 +581,7 @@
\IfNoValueTF { #1 }
{ \tl_gclear:N \g__chemformula_options_tl }
{ \tl_gset:Nn \g__chemformula_options_tl { #1 } }
- \chemformula_ch_aux_i:w #2 \\ \q_no_value \q_stop
+ \__chemformula_ch_aux_i:w #2 \\ \q_no_value \q_stop
\group_align_safe_end:
\tl_use:N \g__chemformula_output_tl
\tl_gclear:N \g__chemformula_output_tl
@@ -588,58 +589,58 @@
% Trickery to use \ch inside align environment:
% bypass \\:
-\cs_new_protected:Npn \chemformula_ch_aux_i:w #1 \\ #2 \q_stop
+\cs_new_protected:Npn \__chemformula_ch_aux_i:w #1 \\ #2 \q_stop
{
- \chemformula_ch_aux_ii:w #1 & \q_no_value \q_stop
+ \__chemformula_ch_aux_ii:w #1 & \q_no_value \q_stop
\quark_if_no_value:nF { #2 }
{
\tl_gput_right:Nn \g__chemformula_output_tl { \\ }
- \chemformula_ch_aux_i:w #2 \q_stop
+ \__chemformula_ch_aux_i:w #2 \q_stop
}
}
% bypass &:
-\cs_new_protected:Npn \chemformula_ch_aux_ii:w #1 & #2 \q_stop
+\cs_new_protected:Npn \__chemformula_ch_aux_ii:w #1 & #2 \q_stop
{
- \chemformula_ch_aux_iii:w #1 \label{} \q_no_value \q_stop
+ \__chemformula_ch_aux_iii:w #1 \label{} \q_no_value \q_stop
\quark_if_no_value:nF { #2 }
{
\tl_gput_right:Nn \g__chemformula_output_tl { & }
- \chemformula_ch_aux_ii:w #2 \q_stop
+ \__chemformula_ch_aux_ii:w #2 \q_stop
}
}
% bypass \label:
-\cs_new_protected:Npn \chemformula_ch_aux_iii:w #1 \label#2 #3 \q_stop
+\cs_new_protected:Npn \__chemformula_ch_aux_iii:w #1 \label#2 #3 \q_stop
{
- \chemformula_ch_aux_iv:w #1 \tag{} \q_no_value \q_stop
+ \__chemformula_ch_aux_iv:w #1 \tag{} \q_no_value \q_stop
\quark_if_no_value:nF { #3 }
{
\tl_gput_right:Nn \g__chemformula_output_tl { \label{#2} }
- \chemformula_ch_aux_iii:w #3 \q_stop
+ \__chemformula_ch_aux_iii:w #3 \q_stop
}
}
% bypass \tag:
-\cs_new_protected:Npn \chemformula_ch_aux_iv:w #1 \tag#2 #3 \q_stop
+\cs_new_protected:Npn \__chemformula_ch_aux_iv:w #1 \tag#2 #3 \q_stop
{
- \chemformula_ch_aux_v:w #1 \intertext{} \q_no_value \q_stop
+ \__chemformula_ch_aux_v:w #1 \intertext{} \q_no_value \q_stop
\quark_if_no_value:nF { #3 }
{
\tl_gput_right:Nn \g__chemformula_output_tl { \tag{#2} }
- \chemformula_ch_aux_iv:w #3 \q_stop
+ \__chemformula_ch_aux_iv:w #3 \q_stop
}
}
% bypass \intertext:
-\cs_new_protected:Npn \chemformula_ch_aux_v:w #1 \intertext#2 #3 \q_stop
+\cs_new_protected:Npn \__chemformula_ch_aux_v:w #1 \intertext#2 #3 \q_stop
{
\tl_gput_right:Nn \g__chemformula_output_tl
- { \chemformula_ch_main:n { #1 } }
+ { \__chemformula_ch_main:n { #1 } }
\quark_if_no_value:nF { #3 }
{
\tl_gput_right:Nn \g__chemformula_output_tl { \intertext{#2} }
- \chemformula_ch_aux_v:w #3 \q_stop
+ \__chemformula_ch_aux_v:w #3 \q_stop
}
}
@@ -663,19 +664,19 @@
%-----------------------------------------------------------------------------%
% arrow generation & detection
-\cs_new:Npn \chemformula_generate_arrows:n #1
+\cs_new:Npn \__chemformula_generate_arrows:n #1
{
\tl_set:Nn \l__chemformula_tmpa_tl { #1 }
\seq_map_inline:Nn \l__chemformula_arrows_type_seq
{
\tl_replace_all:Nnn \l__chemformula_tmpa_tl
- { ##1 } { \chemformula_arrows_get:n { ##1 } }
+ { ##1 } { \__chemformula_arrows_get:n { ##1 } }
}
\tl_set_eq:NN \l__chemformula_output_tl \l__chemformula_tmpa_tl
}
-\cs_generate_variant:Nn \chemformula_generate_arrows:n { V }
+\cs_generate_variant:Nn \__chemformula_generate_arrows:n { V }
-\cs_new_protected:Npn \chemformula_detect_arrows:n #1
+\cs_new_protected:Npn \__chemformula_detect_arrows:n #1
{
\bool_set_false:N \l__chemformula_is_arrow_bool
\prop_map_inline:Nn \l__chemformula_arrows_code_prop
@@ -690,12 +691,12 @@
% compound names
\dim_new:N \l__chemformula_name_dim
-\cs_new:Npn \chemformula_name_cmpd:w
- { \peek_meaning:NTF ( { \chemformula_name_cmpd_aux:w } { ! } }
+\cs_new:Npn \__chemformula_name_cmpd:w
+ { \peek_meaning:NTF ( { \__chemformula_name_cmpd_aux:w } { ! } }
% TODO
% this is no document command -- but now nesting of brackets is possible
-\NewDocumentCommand \chemformula_name_cmpd_aux:w {r()r()}
+\NewDocumentCommand \__chemformula_name_cmpd_aux:w {r()r()}
{
\(
\underset
@@ -713,16 +714,16 @@
\)
}
-\cs_new_protected:Npn \chemformula_generate_name:n #1
+\cs_new_protected:Npn \__chemformula_generate_name:n #1
{
\tl_set:Nn \l__chemformula_tmpa_tl { #1 }
\tl_if_in:VnT \l__chemformula_tmpa_tl { ! }
- { \tl_replace_all:Nnn \l__chemformula_tmpa_tl { ! } { \chemformula_name_cmpd:w } }
+ { \tl_replace_all:Nnn \l__chemformula_tmpa_tl { ! } { \__chemformula_name_cmpd:w } }
\tl_set_eq:NN \l__chemformula_output_tl \l__chemformula_tmpa_tl
}
-\cs_generate_variant:Nn \chemformula_generate_name:n { V }
+\cs_generate_variant:Nn \__chemformula_generate_name:n { V }
-\cs_new_protected:Npn \chemformula_detect_name:n #1
+\cs_new_protected:Npn \__chemformula_detect_name:n #1
{
\bool_set_false:N \l__chemformula_is_name_bool
\tl_set:Nn \l__chemformula_tmpa_tl { #1 }
@@ -737,11 +738,13 @@
\bool_new:N \l__chemformula_options_bool
\bool_new:N \l__chemformula_is_option_bool
\bool_new:N \l__chemformula_stoich_bool
+\bool_new:N \l__chemformula_no_stoich_bool
\bool_new:N \l__chemformula_is_plus_bool
\bool_new:N \l__chemformula_is_up_bool
\bool_new:N \l__chemformula_is_down_bool
\bool_new:N \l__chemformula_is_arrow_bool
\bool_new:N \l__chemformula_is_name_bool
+\bool_new:N \l__chemformula_stoich_is_iupac_bool
\bool_new:N \l__chemformula_stoich_parse_iupac_bool
\bool_new:N \l__chemformula_first_last_text_bool
\bool_new:N \l__chemformula_first_last_double_bool
@@ -850,16 +853,16 @@
% behaviour in a charge
\prop_new:N \l__chemformula_charge_prop
-\prop_put:Nnn \l__chemformula_charge_prop { 0 } { \chemformula_charge_style:n { 0 } }
-\prop_put:Nnn \l__chemformula_charge_prop { 1 } { \chemformula_charge_style:n { 1 } }
-\prop_put:Nnn \l__chemformula_charge_prop { 2 } { \chemformula_charge_style:n { 2 } }
-\prop_put:Nnn \l__chemformula_charge_prop { 3 } { \chemformula_charge_style:n { 3 } }
-\prop_put:Nnn \l__chemformula_charge_prop { 4 } { \chemformula_charge_style:n { 4 } }
-\prop_put:Nnn \l__chemformula_charge_prop { 5 } { \chemformula_charge_style:n { 5 } }
-\prop_put:Nnn \l__chemformula_charge_prop { 6 } { \chemformula_charge_style:n { 6 } }
-\prop_put:Nnn \l__chemformula_charge_prop { 7 } { \chemformula_charge_style:n { 7 } }
-\prop_put:Nnn \l__chemformula_charge_prop { 8 } { \chemformula_charge_style:n { 8 } }
-\prop_put:Nnn \l__chemformula_charge_prop { 9 } { \chemformula_charge_style:n { 9 } }
+\prop_put:Nnn \l__chemformula_charge_prop { 0 } { \__chemformula_charge_style:n { 0 } }
+\prop_put:Nnn \l__chemformula_charge_prop { 1 } { \__chemformula_charge_style:n { 1 } }
+\prop_put:Nnn \l__chemformula_charge_prop { 2 } { \__chemformula_charge_style:n { 2 } }
+\prop_put:Nnn \l__chemformula_charge_prop { 3 } { \__chemformula_charge_style:n { 3 } }
+\prop_put:Nnn \l__chemformula_charge_prop { 4 } { \__chemformula_charge_style:n { 4 } }
+\prop_put:Nnn \l__chemformula_charge_prop { 5 } { \__chemformula_charge_style:n { 5 } }
+\prop_put:Nnn \l__chemformula_charge_prop { 6 } { \__chemformula_charge_style:n { 6 } }
+\prop_put:Nnn \l__chemformula_charge_prop { 7 } { \__chemformula_charge_style:n { 7 } }
+\prop_put:Nnn \l__chemformula_charge_prop { 8 } { \__chemformula_charge_style:n { 8 } }
+\prop_put:Nnn \l__chemformula_charge_prop { 9 } { \__chemformula_charge_style:n { 9 } }
\prop_put:Nnn \l__chemformula_charge_prop { + } { \chemformula_plus: }
\prop_put:Nnn \l__chemformula_charge_prop { - } { \chemformula_minus: }
\prop_put:Nnn \l__chemformula_charge_prop { . } { \chemformula_radical: }
@@ -883,6 +886,14 @@
\prop_put:Nnn \l__chemformula_stoich_prop { ( } { ( }
\prop_put:Nnn \l__chemformula_stoich_prop { ) } { ) }
+\prop_new:N \l__chemformula_no_stoich_prop
+\prop_put:Nnn \l__chemformula_no_stoich_prop { . } { }
+\prop_put:Nnn \l__chemformula_no_stoich_prop { , } { }
+\prop_put:Nnn \l__chemformula_no_stoich_prop { / } { }
+\prop_put:Nnn \l__chemformula_no_stoich_prop { _ } { }
+\prop_put:Nnn \l__chemformula_no_stoich_prop { ( } { }
+\prop_put:Nnn \l__chemformula_no_stoich_prop { ) } { }
+
%-----------------------------------------------------------------------------%
% bonds:
\dim_new:N \l__chemformula_bond_space_dim
@@ -923,13 +934,13 @@
\draw (chemformula-bond-start) ++(\l__chemformula_bond_dim ,0)
coordinate (chemformula-bond-end) ;
\tl_if_blank:nTF { #1 }
- { \chemformula_bond_draw:n { single } }
- { \chemformula_bond_draw:n { #1 } }
+ { \__chemformula_bond_draw:n { single } }
+ { \__chemformula_bond_draw:n { #1 } }
}
\chemmacros_skip_nobreak:N \l__chemformula_bond_space_dim
}
-\cs_new_protected:Npn \chemformula_bond_draw:n #1
+\cs_new_protected:Npn \__chemformula_bond_draw:n #1
{
\tl_set_rescan:Nnn \l__chemformula_tmpa_tl {} { #1 }
\exp_args:NNo \prop_get:Nn \l__chemformula_bonds_prop
@@ -1046,20 +1057,20 @@
%-----------------------------------------------------------------------------%
% sub- and superscripts
-\cs_new:Npn \chemformula_number_style:n #1
+\cs_new:Npn \__chemformula_number_style:n #1
{
\bool_if:NTF \l__chemformula_number_style_math_bool
{ \ensuremath { #1 } }
{ \ensuremath { \text { #1 } } }
}
-\cs_new:Npn \chemformula_charge_style:n #1
+\cs_new:Npn \__chemformula_charge_style:n #1
{
\bool_if:NTF \l__chemformula_charge_style_math_bool
{ \ensuremath { #1 } }
{ \ensuremath { \text { #1 } } }
}
-\cs_generate_variant:Nn \chemformula_charge_style:n { V }
+\cs_generate_variant:Nn \__chemformula_charge_style:n { V }
% subscripts
\tl_new:N \l__chemformula_subscript_tl
@@ -1069,26 +1080,26 @@
\cs_new_protected:Npn \chemformula_subscript:n #1
{
\tl_if_eq:nnTF { #1 }{ \chemformula_superscript:n }
- { \chemformula_subscript_aux:n }
+ { \__chemformula_subscript:n }
{
\tl_if_eq:nnTF { #1 }{ \chemformula_subscript:n }
- { \chemformula_subscript_aux:n }
+ { \__chemformula_subscript:n }
{
\tl_set:Nn \l__chemformula_tmpc_tl { #1 }
\tl_if_in:nnT { #1 } { \chemformula_subscript:n }
{ \tl_remove_all:Nn \l__chemformula_tmpc_tl { \chemformula_subscript:n } }
\tl_if_in:nnT { #1 } { \chemformula_superscript:n }
{ \tl_remove_all:Nn \l__chemformula_tmpc_tl { \chemformula_superscript:n } }
- \chemformula_subscript_aux:V \l__chemformula_tmpc_tl
+ \__chemformula_subscript:V \l__chemformula_tmpc_tl
}
}
}
% handle subscripts
-\cs_new_protected:Npn \chemformula_subscript_aux:n #1
+\cs_new_protected:Npn \__chemformula_subscript:n #1
{
\tl_put_right:Nn \l__chemformula_subscript_tl { #1 }
- \chemformula_clean_subscript:
+ \__chemformula_clean_subscript:
% if a subscript follows just store and do nothing else
\peek_meaning:NF \chemformula_subscript:n
{
@@ -1096,15 +1107,15 @@
% if something else follows both sub- and superscript
\peek_meaning:NF \chemformula_superscript:n
{
- \chemformula_measure_subscript:V \l__chemformula_subscript_tl
- \chemformula_measure_superscript:V \l__chemformula_superscript_tl
- \chemformula_use_sub_and_superscript:
+ \__chemformula_measure_subscript:V \l__chemformula_subscript_tl
+ \__chemformula_measure_superscript:V \l__chemformula_superscript_tl
+ \__chemformula_use_sub_and_superscript:
}
}
}
-\cs_generate_variant:Nn \chemformula_subscript_aux:n { o,V }
+\cs_generate_variant:Nn \__chemformula_subscript:n { o,V }
-\cs_new_protected:Npn \chemformula_clean_subscript:
+\cs_new_protected:Npn \__chemformula_clean_subscript:
{
\tl_replace_all:Nnn \l__chemformula_subscript_tl
{ \chemformula_single_bond: } { \chemformula_minus: }
@@ -1116,7 +1127,7 @@
{ \chemformula_star_adduct: } { * }
}
-\cs_new_protected:Npn \chemformula_subscript_raise:N #1
+\cs_new_protected:Npn \__chemformula_subscript_raise:N #1
{
\hbox_set:Nn \l__chemformula_tmpa_box
{ $\scriptstyle Hg$ }
@@ -1130,29 +1141,29 @@
\tex_raise:D #1
}
-\cs_new:Npn \chemformula_subscript_write:n #1
+\cs_new:Npn \__chemformula_subscript_write:n #1
{
- \chemformula_subscript_raise:N \l__chemformula_subscript_shift_dim
+ \__chemformula_subscript_raise:N \l__chemformula_subscript_shift_dim
\hbox:n
{
$\scriptstyle
\prop_get:NoNTF \l__chemformula_numbers_prop
{ #1 } \l__chemformula_tmpa_tl
- { \chemformula_number_style:n { \l__chemformula_tmpa_tl } }
- { \chemformula_number_style:n { #1 } }$
+ { \__chemformula_number_style:n { \l__chemformula_tmpa_tl } }
+ { \__chemformula_number_style:n { #1 } }$
}
}
-\cs_generate_variant:Nn \chemformula_subscript_write:n { V }
+\cs_generate_variant:Nn \__chemformula_subscript_write:n { V }
-\cs_new_protected:Npn \chemformula_measure_subscript:n #1
+\cs_new_protected:Npn \__chemformula_measure_subscript:n #1
{
\hbox_set:Nn \l__chemformula_tmpa_box
- { \chemformula_subscript_write:n { #1 } }
+ { \__chemformula_subscript_write:n { #1 } }
\dim_set:Nn \l__chemformula_subscript_dim
{ -\box_wd:N \l__chemformula_tmpa_box }
\box_clear:N \l__chemformula_tmpa_box
}
-\cs_generate_variant:Nn \chemformula_measure_subscript:n { V }
+\cs_generate_variant:Nn \__chemformula_measure_subscript:n { V }
% superscripts
\tl_new:N \l__chemformula_superscript_tl
@@ -1162,39 +1173,39 @@
\cs_new_protected:Npn \chemformula_superscript:n #1
{
\tl_if_eq:nnTF { #1 } { \chemformula_superscript:n }
- { \chemformula_superscript_aux:n }
+ { \__chemformula_superscript:n }
{
\tl_if_eq:nnTF { #1 } { \chemformula_subscript:n }
- { \chemformula_superscript_aux:n }
+ { \__chemformula_superscript:n }
{
\tl_set:Nn \l__chemformula_tmpc_tl { #1 }
\tl_if_in:nnT { #1 } { \chemformula_subscript:n }
{ \tl_remove_all:Nn \l__chemformula_tmpc_tl { \chemformula_subscript:n } }
\tl_if_in:nnT { #1 } { \chemformula_superscript:n }
{ \tl_remove_all:Nn \l__chemformula_tmpc_tl { \chemformula_superscript:n } }
- \chemformula_superscript_aux:V \l__chemformula_tmpc_tl
+ \__chemformula_superscript:V \l__chemformula_tmpc_tl
}
}
}
% handle superscripts
-\cs_new_protected:Npn \chemformula_superscript_aux:n #1
+\cs_new_protected:Npn \__chemformula_superscript:n #1
{
\tl_put_right:Nn \l__chemformula_superscript_tl { #1 }
- \chemformula_clean_superscript:
+ \__chemformula_clean_superscript:
\peek_meaning:NF \chemformula_superscript:n
{
\peek_meaning:NF \chemformula_subscript:n
{
- \chemformula_measure_subscript:V \l__chemformula_subscript_tl
- \chemformula_measure_superscript:V \l__chemformula_superscript_tl
- \chemformula_use_sub_and_superscript:
+ \__chemformula_measure_subscript:V \l__chemformula_subscript_tl
+ \__chemformula_measure_superscript:V \l__chemformula_superscript_tl
+ \__chemformula_use_sub_and_superscript:
}
}
}
-\cs_generate_variant:Nn \chemformula_superscript_aux:n { o,V }
+\cs_generate_variant:Nn \__chemformula_superscript:n { o,V }
-\cs_new_protected:Npn \chemformula_clean_superscript:
+\cs_new_protected:Npn \__chemformula_clean_superscript:
{
\tl_replace_all:Nnn \l__chemformula_superscript_tl
{ \chemformula_single_bond: } { \chemformula_minus: }
@@ -1212,7 +1223,7 @@
{ . } { \chemformula_radical: }
}
-\cs_new_protected:Npn \chemformula_superscript_raise:N #1
+\cs_new_protected:Npn \__chemformula_superscript_raise:N #1
{
\hbox_set:Nn \l__chemformula_tmpa_box
{ $\scriptstyle Hg$ }
@@ -1226,32 +1237,32 @@
\tex_raise:D #1
}
-\cs_new:Npn \chemformula_superscript_write:n #1
+\cs_new:Npn \__chemformula_superscript_write:n #1
{
- \chemformula_superscript_raise:N \l__chemformula_superscript_shift_dim
+ \__chemformula_superscript_raise:N \l__chemformula_superscript_shift_dim
\hbox:n
{
$\scriptstyle
\prop_get:NoNTF \l__chemformula_charge_prop
{ #1 } \l__chemformula_tmpa_tl
- { \chemformula_charge_style:V \l__chemformula_tmpa_tl }
- { \chemformula_charge_style:n { #1 } }$
+ { \__chemformula_charge_style:V \l__chemformula_tmpa_tl }
+ { \__chemformula_charge_style:n { #1 } }$
}
}
-\cs_generate_variant:Nn \chemformula_superscript_write:n { V }
+\cs_generate_variant:Nn \__chemformula_superscript_write:n { V }
-\cs_new_protected:Npn \chemformula_measure_superscript:n #1
+\cs_new_protected:Npn \__chemformula_measure_superscript:n #1
{
\hbox_set:Nn \l__chemformula_tmpa_box
- { \chemformula_superscript_write:n { #1 } }
+ { \__chemformula_superscript_write:n { #1 } }
\dim_set:Nn \l__chemformula_superscript_dim
{ -\box_wd:N \l__chemformula_tmpa_box }
\box_clear:N \l__chemformula_tmpa_box
}
-\cs_generate_variant:Nn \chemformula_measure_superscript:n { V }
+\cs_generate_variant:Nn \__chemformula_measure_superscript:n { V }
% typeset both sub- and superscripts
-\cs_new_protected:Npn \chemformula_use_sub_and_superscript:
+\cs_new_protected:Npn \__chemformula_use_sub_and_superscript:
{
\group_begin:
% No shift for excited state
@@ -1288,7 +1299,7 @@
% typeset superscript
\tl_if_blank:VF \l__chemformula_superscript_tl
{
- \chemformula_superscript_write:V \l__chemformula_superscript_tl
+ \__chemformula_superscript_write:V \l__chemformula_superscript_tl
% skip back for the subscript
\tl_if_blank:VF \l__chemformula_subscript_tl
{
@@ -1307,7 +1318,7 @@
}
% typeset subscript
\tl_if_blank:VF \l__chemformula_subscript_tl
- { \chemformula_subscript_write:V \l__chemformula_subscript_tl }
+ { \__chemformula_subscript_write:V \l__chemformula_subscript_tl }
\bool_if:NF \l__chemformula_is_isotope_bool
{
\dim_zero:N \l__chemformula_tmpa_dim
@@ -1356,7 +1367,7 @@
\chemformula_input_escape_text:V \l__chemformula_chemformula_tmpa_tl
\chemformula_input_escape_math:n { #1 }
\chemformula_input_stoich:n { #1 }
- \chemformula_clean_chem_macros:V \l__chemformula_chemformula_tmpa_tl
+ \__chemformula_clean_chem_macros:V \l__chemformula_chemformula_tmpa_tl
\chemformula_input_cmpd:VN
\l__chemformula_chemformula_tmpa_tl \l__chemformula_input_tl
\chemformula_input_arrow:n { #1 }
@@ -1390,24 +1401,34 @@
\cs_new_protected:Npn \chemformula_input_stoich:n #1
{
\bool_set_true:N \l__chemformula_stoich_bool
- \tl_put_right:Nn \l__chemformula_stoich_tl { \chemformula_font_inner: }
+ % the factor consists only of a parenthesis or a decimal marcer:
+ \bool_set_true:N \l__chemformula_no_stoich_bool
\tl_map_inline:nn { #1 }
{
- \prop_get:NnNTF \l__chemformula_stoich_prop { ##1 } \l__chemformula_tmpa_tl
+ \prop_get:NnNF \l__chemformula_no_stoich_prop { ##1 } \l__chemformula_tmpa_tl
+ { \bool_set_false:N \l__chemformula_no_stoich_bool }
+ }
+ \bool_if:NF \l__chemformula_no_stoich_bool
+ {
+ \tl_map_inline:nn { #1 }
{
- \bool_if:NT \l__chemformula_stoich_bool
- { \tl_put_right:Nx \l__chemformula_stoich_tl { \l__chemformula_tmpa_tl } }
+ \prop_get:NnNTF \l__chemformula_stoich_prop { ##1 } \l__chemformula_tmpa_tl
+ {
+ \bool_if:NT \l__chemformula_stoich_bool
+ { \tl_put_right:NV \l__chemformula_stoich_tl \l__chemformula_tmpa_tl }
+ }
+ { \bool_set_false:N \l__chemformula_stoich_bool }
}
- { \bool_set_false:N \l__chemformula_stoich_bool }
}
\bool_if:NTF \l__chemformula_stoich_bool
{
\tl_if_blank:VF \l__chemformula_stoich_tl
{
+ \tl_put_left:Nn \l__chemformula_stoich_tl { \chemformula_font_inner: }
\tl_set_rescan:Nno \l__chemformula_stoich_tl
{ \ExplSyntaxOn }
{ \l__chemformula_stoich_tl }
- \chemformula_parse_stoich:V
+ \__chemformula_parse_stoich:V
\l__chemformula_stoich_tl
}
}
@@ -1416,14 +1437,16 @@
\cs_new:Npn \chemformula_bm:n #1 { #1 }
-\cs_new_protected:Npn \chemformula_parse_stoich:n #1
+\cs_new_protected:Npn \__chemformula_parse_stoich:n #1
{ \__chemformula_parse_stoich:w #1 \q_nil }
-\cs_generate_variant:Nn \chemformula_parse_stoich:n { V }
+\cs_generate_variant:Nn \__chemformula_parse_stoich:n { V }
\cs_new:Npn \__chemformula_parse_stoich:w \chemformula_font_inner: #1 \q_nil
{
\tl_put_right:Nn \l__chemformula_input_tl { \chemformula_font_inner: }
- \tl_if_in:nnTF { #1 } { ( }
+ \__chemformula_bool_set_if_first_last:Nnnn
+ \l__chemformula_stoich_is_iupac_bool { #1 } { ( } { ) }
+ \bool_if:NTF \l__chemformula_stoich_is_iupac_bool
{ \__chemformula_parse_stoich_iupac:n { #1 } }
{ \__chemformula_parse_stoich_regular:n { #1 } }
}
@@ -1445,7 +1468,7 @@
{
% get head:
\tl_set:Nx \l__chemformula_tmpa_tl { \tl_head:n { #1 } }
- \tl_set:Nx \l__chemformula_tmpb_tl { \l__chemformula_decimal_output_tl }
+ \tl_set:Nn \l__chemformula_tmpb_tl { \l__chemformula_decimal_output_tl }
% check if stoich starts with decimal-marker and add leading 0 if so:
\tl_if_eq:NNTF \l__chemformula_tmpa_tl \l__chemformula_tmpb_tl
{ \tl_put_right:Nn \l__chemformula_input_tl { 0#1 } }
@@ -1462,13 +1485,13 @@
\cs_new_protected:Npn \__chemformula_parse_stoich_frac:w #1/#2 \q_nil
{
\tl_put_right:Nn \l__chemformula_input_tl
- { \chemformula_frac:nn { #1 } { #2 } }
+ { \__chemformula_frac:nn { #1 } { #2 } }
}
\cs_new_protected:Npn \__chemformula_parse_stoich_misc_frac:w #1_#2/#3 \q_nil
{
\tl_put_right:Nn \l__chemformula_input_tl
- { \chemformula_misc_frac:nnn { #1 } { #2 } { #3 } }
+ { \__chemformula_misc_frac:nnn { #1 } { #2 } { #3 } }
}
\cs_new_protected:Npn \__chemformula_parse_stoich_iupac:n #1
@@ -1485,7 +1508,7 @@
\tl_put_right:Nn \l__chemformula_input_tl { ) }
}
-\cs_new:Npn \chemformula_frac:nn #1#2
+\cs_new:Npn \__chemformula_frac:nn #1#2
{
\bool_if:NT \l__chemformula_xfrac_bool
{ \sfrac[chemformula-text-frac]{#1}{#2} }
@@ -1495,7 +1518,7 @@
{ $ \frac{ \text { #1 } } { \text { #2 } } $ }
}
-\cs_new:Npn \chemformula_misc_frac:nnn #1#2#3
+\cs_new:Npn \__chemformula_misc_frac:nnn #1#2#3
{
\bool_if:NT \l__chemformula_xfrac_bool
{ #1\sfrac[chemformula-text-frac]{#2}{#3} }
@@ -1517,8 +1540,8 @@
{ \bool_set_true:N \l__chemformula_is_down_bool }
\tl_if_eq:nnT { #1 } { ^ }
{ \bool_set_true:N \l__chemformula_is_up_bool }
- \chemformula_detect_arrows:n { #1 }
- \chemformula_detect_name:n { #1 }
+ \__chemformula_detect_arrows:n { #1 }
+ \__chemformula_detect_name:n { #1 }
\chemformula_input_options:n { #1 }
\bool_if:NT \l__chemformula_is_option_bool
{
@@ -1543,7 +1566,7 @@
{
\tl_put_right:Nn #2
{ \chemformula_font_inner: }
- \chemformula_handle_sub_and_superscripts:nN { #1 } #2
+ \__chemformula_handle_sub_and_superscripts:nN { #1 } #2
\bool_if:NT \l__chemformula_options_bool
{
\tl_put_right:Nn #2
@@ -1584,34 +1607,39 @@
}
\cs_new:Npn \chemformula_font: {}
-\cs_new:Npn \chemformula_fontspec:n #1
+\cs_new:Npn \__chemformula_fontspec:n #1
{
\tl_if_in:nnTF { #1 } { [ }
- { \chemformula_fontspec_aux:w #1 \q_stop }
- { \chemformula_fontspec_aux:w [] #1 \q_stop }
+ { \__chemformula_fontspec_aux:w #1 \q_stop }
+ { \__chemformula_fontspec_aux:w [] #1 \q_stop }
}
-\cs_new:Npn \chemformula_fontspec_aux:w [#1]#2 \q_stop
+\cs_new:Npn \__chemformula_fontspec_aux:w [#1]#2 \q_stop
{ \newfontfamily \chemformula_font: [ #1 ] { #2 } }
-\cs_new_protected:Npn \chemformula_sanitize:Nn #1#2
+\cs_new_protected:Npn \__chemformula_sanitize:Nn #1#2
{
\tl_set_rescan:Nnn #1
{
+ % expl3 catcodes:
\char_set_catcode_letter:N \_
\char_set_catcode_math_superscript:N \^
+ % disable some of the specials:
\char_set_catcode_letter:N \{
\char_set_catcode_letter:N \}
\char_set_catcode_letter:N \\
\char_set_catcode_letter:N \#
+ % make the naming work with babel languages like French that make
+ % ! active:
+ \char_set_catcode_other:N \!
}
{ #2 }
}
\cs_generate_variant:Nn \tl_if_in:nnT { x }
-\cs_new_protected:Npn \chemformula_handle_sub_and_superscripts:nN #1#2
+\cs_new_protected:Npn \__chemformula_handle_sub_and_superscripts:nN #1#2
{
- \chemformula_sanitize:Nn \l__chemformula_tmpa_tl { #1 }
+ \__chemformula_sanitize:Nn \l__chemformula_tmpa_tl { #1 }
% let's see if the compound starts with a sub- or superscript:
\tl_if_in:xnT { \tl_head:V \l__chemformula_tmpa_tl } { ^ }
{
@@ -1674,7 +1702,7 @@
%-----------------------------------------------------------------------------%
% clean up chemmacros commands:
-\cs_new_protected:Npn \chemformula_clean_chem_macros:n #1
+\cs_new_protected:Npn \__chemformula_clean_chem_macros:n #1
{
\cs_set:Nn \chemmacros_text:n
{
@@ -1684,7 +1712,7 @@
}
\cs_set:Npn \chemmacros_xspace: {}
}
-\cs_generate_variant:Nn \chemformula_clean_chem_macros:n { V }
+\cs_generate_variant:Nn \__chemformula_clean_chem_macros:n { V }
%-----------------------------------------------------------------------------%
% input "and" sign
@@ -1710,7 +1738,7 @@
\group_begin:
% ensure ^ has catcode 7
% (else chemmacros wouldn't work with e.g. `breqn')
- \chemformula_sanitize:Nn \g__chemformula_input_up_tl { #1 }
+ \__chemformula_sanitize:Nn \g__chemformula_input_up_tl { #1 }
\char_set_catcode_math_superscript:N \^
\__chemformula_input_up:V \g__chemformula_input_up_tl
}
@@ -1790,16 +1818,16 @@
\cs_new_protected:Npn \chemformula_input_escape_text:n #1
{
- \chemformula_first_last_text:n { #1 }
+ \__chemformula_first_last_text:n { #1 }
\bool_if:NT \l__chemformula_first_last_double_bool
{
\bool_set_true:N \l__chemformula_first_last_text_bool
- \chemformula_read_escape_double:w #1 \q_nil
+ \__chemformula_read_escape_double:w #1 \q_nil
}
\bool_if:NT \l__chemformula_first_last_single_bool
{
\bool_set_true:N \l__chemformula_first_last_text_bool
- \chemformula_read_escape_single:w #1 \q_nil
+ \__chemformula_read_escape_single:w #1 \q_nil
}
}
\cs_generate_variant:Nn \chemformula_input_escape_text:n { V }
@@ -1824,13 +1852,13 @@
\tl_put_right:NV \l__chemformula_input_tl \l__chemformula_tmpa_tl
}
-\cs_new:Npn \chemformula_read_escape_double:w "#1" \q_nil
+\cs_new:Npn \__chemformula_read_escape_double:w "#1" \q_nil
{ \__chemformula_read_escape_text:n { #1 } }
-\cs_new:Npn \chemformula_read_escape_single:w '#1' \q_nil
+\cs_new:Npn \__chemformula_read_escape_single:w '#1' \q_nil
{ \__chemformula_read_escape_text:n { #1 } }
-\cs_new_protected:Npn \chemformula_first_last_text:n #1
+\cs_new_protected:Npn \__chemformula_first_last_text:n #1
{
\bool_set_false:N \l__chemformula_first_last_double_bool
\bool_set_false:N \l__chemformula_first_last_single_bool
@@ -1852,16 +1880,16 @@
% input escaped math
\cs_new_protected:Npn \chemformula_input_escape_math:n #1
{
- \chemformula_first_last_math:n { #1 }
+ \__chemformula_first_last_math:n { #1 }
\bool_if:NT \l__chemformula_first_last_dollar_bool
{
\bool_set_true:N \l__chemformula_first_last_math_bool
- \chemformula_read_escape_dollar:w #1 \q_nil
+ \__chemformula_read_escape_dollar:w #1 \q_nil
}
\bool_if:NT \l__chemformula_first_last_mathbraces_bool
{
\bool_set_true:N \l__chemformula_first_last_math_bool
- \chemformula_read_escape_mathbraces:w #1 \q_nil
+ \__chemformula_read_escape_mathbraces:w #1 \q_nil
}
}
@@ -1887,13 +1915,13 @@
{ \skip_horizontal:N \l__chemformula_math_space_skip }
}
-\cs_new:Npn \chemformula_read_escape_dollar:w $#1$ \q_nil
+\cs_new:Npn \__chemformula_read_escape_dollar:w $#1$ \q_nil
{ \__chemformula_read_escape_math:n { #1 } }
-\cs_new:Npn \chemformula_read_escape_mathbraces:w \(#1\) \q_nil
+\cs_new:Npn \__chemformula_read_escape_mathbraces:w \(#1\) \q_nil
{ \__chemformula_read_escape_math:n { #1 } }
-\cs_new_protected:Npn \chemformula_first_last_math:n #1
+\cs_new_protected:Npn \__chemformula_first_last_math:n #1
{
\bool_set_false:N \l__chemformula_first_last_math_bool
\bool_set_false:N \l__chemformula_first_last_dollar_bool
@@ -1952,7 +1980,7 @@
\bool_set_false:N \l__chemformula_xfrac_bool
\bool_set_true:N \l__chemformula_nicefrac_bool
\bool_set_false:N \l__chemformula_mathfrac_bool ,
- stoich-iupac-parse .bool_set:N = \l__chemformula_stoich_parse_iupac_bool ,
+ stoich-paren-parse .bool_set:N = \l__chemformula_stoich_parse_iupac_bool ,
stoich-space .skip_set:N = \l__chemformula_stoich_space_skip ,
adduct-space .dim_set:N = \l__chemformula_cdot_space_dim ,
plus-space .skip_set:N = \l__chemformula_plus_space_skip ,
@@ -1988,7 +2016,7 @@
font-spec .code:n =
\bool_set_false:N \l__chemformula_fss_bool
\bool_set_true:N \l__chemformula_fontspec_bool
- \chemformula_fontspec:n { #1 } ,
+ \__chemformula_fontspec:n { #1 } ,
format .code:n =
\bool_set_false:N \l__chemformula_fss_bool
\bool_set_false:N \l__chemformula_fontspec_bool