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.sty510
1 files changed, 297 insertions, 213 deletions
diff --git a/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty b/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty
index 1c7c0f75735..a5555476e0d 100644
--- a/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty
+++ b/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty
@@ -5,7 +5,7 @@
% - macros and commands for chemists - %
% --------------------------------------------------------------------------- %
% - Clemens Niederberger - %
-% - 2012/02/19 - %
+% - 2012/03/03 - %
% --------------------------------------------------------------------------- %
% - https://bitbucket.org/cgnieder/chemmacros/ - %
% - contact@mychemistry.eu - %
@@ -30,8 +30,8 @@
\RequirePackage{ expl3 }
\ProvidesExplPackage
{chemformula}
- {2012/02/19}
- {3.1}
+ {2012/03/03}
+ {3.1b}
{typeset chemical compounds and reactions}
%-----------------------------------------------------------------------------%
@@ -288,6 +288,7 @@
\tl_set:Nn \l_chemformula_arrow_label_style_tl { \footnotesize }
\prop_new:N \l_chemformula_arrows_code_prop
+\seq_new:N \l_chemformula_arrows_type_seq
\tl_new:N \l_chemformula_arrow_type_tl
\tl_new:N \l_chemformula_arrow_arg_i_tl
\tl_new:N \l_chemformula_arrow_arg_ii_tl
@@ -393,7 +394,11 @@
{
\prop_if_in:NnTF \l_chemformula_arrows_code_prop { #1 }
{ \chemmacros_msg:nnxx { chemformula } { declare-arrow } { #1 } {} }
- { \prop_put:Nnn \l_chemformula_arrows_code_prop { #1 } { #2 } }
+ {
+ % store type in the sequence and code in the property list
+ \seq_put_right:Nn \l_chemformula_arrows_type_seq { #1 }
+ \prop_put:Nnn \l_chemformula_arrows_code_prop { #1 } { #2 }
+ }
}
\NewDocumentCommand \RenewChemArrow { mm }
@@ -409,7 +414,9 @@
\tl_to_str:N \l_tmpa_tl
}
-% declare arrows:
+% declare arrows in the right order
+% e.g. <-> must be declared before -> in order to search & replace it first
+% resonance arrow:
\DeclareChemArrow { <-> } { \draw[cf-cf] (cf_arrow_start) -- (cf_arrow_end) ; }
\DeclareChemArrow { -> } { \draw[-cf] (cf_arrow_start) -- (cf_arrow_end) ; }
\DeclareChemArrow { <- } { \draw[cf-] (cf_arrow_start) -- (cf_arrow_end) ; }
@@ -418,6 +425,7 @@
\draw[-cf] ([yshift=.2ex]cf_arrow_start) -- ([yshift=.2ex]cf_arrow_end) ;
\draw[cf-,] ([yshift=-.2ex]cf_arrow_start) -- ([yshift=-.2ex]cf_arrow_end) ;
}
+% isolobal arrow:
\DeclareChemArrow { <o> }
{
\draw[cf-cf] (cf_arrow_start) -- (cf_arrow_end) ;
@@ -458,6 +466,8 @@
\draw (cf_arrow_mid) ++ (.2ex,.4ex) -- ++(-.4ex,-.8ex) ;
\draw (cf_arrow_mid) ++ (.6ex,.4ex) -- ++(-.4ex,-.8ex) ;
}
+% net reaction:
+\DeclareChemArrow { == } { \node at ([yshift=-.2ex]cf_arrow_mid) { = } ; }
%-----------------------------------------------------------------------------%
% arrow customization
@@ -550,37 +560,15 @@
%-----------------------------------------------------------------------------%
% arrow generation & detection
-% make sure to look for <->, <=>> and <<=> first!
\cs_set:Npn \chemformula_generate_arrows:n #1
{
\tl_set:No \l_tmpa_tl { #1 }
- \tl_replace_all:Nnn \l_tmpa_tl { <-> }
- { \chemformula_arrows_get:n { <-> } }
- \tl_replace_all:Nnn \l_tmpa_tl { <=>> }
- { \chemformula_arrows_get:n { <=>> } }
- \tl_replace_all:Nnn \l_tmpa_tl { <<=> }
- { \chemformula_arrows_get:n { <<=> } }
- \prop_map_function:NN \l_chemformula_arrows_code_prop
- \chemformula_replace_arrows:nn
- \tl_set_eq:NN \l_chemformula_output_tl \l_tmpa_tl
- }
-
-\bool_new:N \l_chemformula_arrow_already_replaced_bool
-\cs_new:Npn \chemformula_replace_arrows:nn #1#2
- {
- \tl_if_eq:nnT { #1 } { <-> }
- { \bool_set_true:N \l_chemformula_arrow_already_replaced_bool }
- \tl_if_eq:nnT { #1 } { <=>> }
- { \bool_set_true:N \l_chemformula_arrow_already_replaced_bool }
- \tl_if_eq:nnT { #1 } { <<=> }
- { \bool_set_true:N \l_chemformula_arrow_already_replaced_bool }
- \bool_if:NF \l_chemformula_arrow_already_replaced_bool
+ \seq_map_inline:Nn \l_chemformula_arrows_type_seq
{
- \tl_set_rescan:Nnn \l_tmpb_tl {} { #1 }
- \exp_args:NNo \tl_replace_all:Nnn \l_tmpa_tl
- { \l_tmpb_tl } { \chemformula_arrows_get:n { #1 } }
+ \tl_replace_all:Nnn \l_tmpa_tl
+ { ##1 } { \chemformula_arrows_get:n { ##1 } }
}
- \bool_set_false:N \l_chemformula_arrow_already_replaced_bool
+ \tl_set_eq:NN \l_chemformula_output_tl \l_tmpa_tl
}
\cs_generate_variant:Nn \chemformula_generate_arrows:n { N }
@@ -663,7 +651,7 @@
\bool_new:N \l_chemformula_charge_style_math_bool
\bool_new:N \l_chemformula_sub_bool
\bool_new:N \l_chemformula_sup_bool
-\bool_new:N \l_chemformula_first_is_sup_bool
+\bool_new:N \l_chemformula_is_isotope_bool
\bool_new:N \l_chemformula_xfrac_bool
\bool_new:N \l_chemformula_nicefrac_bool
\bool_new:N \l_chemformula_mathfrac_bool
@@ -674,7 +662,7 @@
\bool_new:N \l_chemformula_fss_series_bool
\bool_new:N \l_chemformula_fss_shape_bool
\bool_new:N \l_chemformula_name_width_bool
-\bool_new:N \l_chemformula_charge_shift_bool
+\bool_new:N \l_chemformula_charge_full_shift_bool
% token lists:
\tl_new:N \l_chemformula_tmpa_tl
@@ -696,6 +684,7 @@
\tl_new:N \l_chemformula_fontspec_argument_tl
\tl_new:N \l_chemformula_name_format_tl
\tl_set:Nn \l_chemformula_name_format_tl { \scriptsize\centering }
+\tl_new:N \l_chemormula_sup_super_factor_tl
% dimensions:
\dim_new:N \l_chemformula_stoich_space_dim
@@ -707,19 +696,25 @@
\dim_new:N \l_chemformula_cdot_space_dim
\dim_set:Nn \l_chemformula_cdot_space_dim { .1333em }
\dim_new:N \l_chemformula_charge_shift_dim
- \dim_set:Nn \l_chemformula_charge_shift_dim { 1ex }
+ \dim_set:Nn \l_chemformula_charge_shift_dim { .5ex }
\dim_new:N \l_chemformula_subscript_shift_default_dim
- \dim_set:Nn \l_chemformula_subscript_shift_default_dim { -.6ex }
+ \dim_set:Nn \l_chemformula_subscript_shift_default_dim { -.65ex }
\dim_new:N \l_chemformula_subscript_shift_dim
\dim_set_eq:NN
\l_chemformula_subscript_shift_dim
\l_chemformula_subscript_shift_default_dim
\dim_new:N \l_chemformula_subscript_shift_additional_dim
+\dim_new:N \l_chemformula_superscript_shift_default_dim
+ \dim_set:Nn \l_chemformula_superscript_shift_default_dim { .8ex }
+\dim_new:N \l_chemformula_superscript_shift_dim
+ \dim_set_eq:NN
+ \l_chemformula_superscript_shift_dim
+ \l_chemformula_superscript_shift_default_dim
+\dim_new:N \l_chemformula_superscript_shift_additional_dim
\dim_new:N \l_chemformula_subscript_dim
\dim_zero:N \l_chemformula_subscript_dim
-\dim_new:N \l_chemformula_supscript_dim
- \dim_zero:N \l_chemformula_supscript_dim
-\dim_new:N \l_chemformula_subscript_compare_dim
+\dim_new:N \l_chemformula_superscript_dim
+ \dim_zero:N \l_chemformula_superscript_dim
\dim_new:N \l_chemformula_bond_dim
\hbox_set:Nn \l_tmpa_box { \textendash }
\dim_set:Nn \l_chemformula_bond_dim { \box_wd:N \l_tmpa_box }
@@ -804,6 +799,8 @@
{ { \l_chemformula_decimal_output_tl } }
\prop_put:Nnn \l_chemformula_stoich_prop { / } { / }
\prop_put:Nnn \l_chemformula_stoich_prop { _ } { _ }
+\prop_put:Nnn \l_chemformula_stoich_prop { ( } { ( }
+\prop_put:Nnn \l_chemformula_stoich_prop { ) } { ) }
%-----------------------------------------------------------------------------%
% bonds:
@@ -871,203 +868,252 @@
{ \ensuremath { \text { #1 } } }
}
-\cs_new:Npn \chemformula_subscript:n #1
+% subscripts
+\tl_new:N \l_chemformula_subscript_tl
+\box_new:N \l_chemformula_subscript_box
+
+% remove double or nested sub- and superscripts
+\cs_new:Nn \chemformula_subscript:n
{
- \bool_set_true:N \l_chemformula_sub_bool
- % clean up wrong input
- \tl_set:Nn \l_tmpc_tl { #1 }
- \tl_replace_all:Nnn \l_tmpc_tl
- { \chemformula_single_bond: } { \chemformula_minus: }
- \tl_replace_all:Nnn \l_tmpc_tl
- { \chemformula_triple_bond: } {\chemformula_plus: }
- \tl_replace_all:Nnn \l_tmpc_tl { \chemformula_adduct: } { . }
- \tl_replace_all:Nnn \l_tmpc_tl { \chemformula_star_adduct: } { * }
- % measure width and save it
- \hbox_set:Nn \l_tmpa_box
- {
- $\mathchoice
- { \scriptstyle }
- { \scriptstyle }
- { \scriptscriptstyle }
- { \scriptscriptstyle }
- \prop_get:NnNTF \l_chemformula_numbers_prop { #1 } \l_tmpa_tl
- { \chemformula_number_style:n { \l_tmpa_tl } }
- { \chemformula_number_style:n { \l_tmpc_tl } }$
- }
- \dim_set:Nn \l_chemformula_subscript_dim { -\box_wd:N \l_tmpa_box }
- \prop_get:NnNTF \l_chemformula_charge_prop { #1 } \l_tmpa_tl
- {
- \exp_args:NNo \hbox_set:Nn \l_tmpb_box
- { $ ^ { \chemformula_charge_style:n { \l_tmpa_tl } } $ }
- }
+ \tl_if_eq:nnTF { #1 }{ \chemformula_superscript:n }
+ { \chemformula_subscript_aux:n }
{
- \exp_args:NNo \hbox_set:Nn \l_tmpb_box
- { $ ^ { \chemformula_charge_style:n { \l_tmpc_tl } } $ }
+ \tl_if_eq:nnTF { #1 }{ \chemformula_subscript:n }
+ { \chemformula_subscript_aux:n }
+ {
+ \tl_set:Nn \l_tmpc_tl { #1 }
+ \tl_if_in:nnT { #1 } { \chemformula_subscript:n }
+ { \tl_remove_all:Nn \l_tmpc_tl { \chemformula_subscript:n } }
+ \tl_if_in:nnT { #1 } { \chemformula_superscript:n }
+ { \tl_remove_all:Nn \l_tmpc_tl { \chemformula_superscript:n } }
+ \exp_args:No \chemformula_subscript_aux:n { \l_tmpc_tl }
+ }
}
- \dim_set:Nn \l_chemformula_subscript_compare_dim { -\box_wd:N \l_tmpb_box }
- \box_clear:N \l_tmpa_box
- \box_clear:N \l_tmpb_box
- \bool_if:NT \l_chemformula_sup_bool
+ }
+
+% handle subscripts
+\cs_new:Nn \chemformula_subscript_aux:n
+ {
+ \tl_put_right:Nn \l_chemformula_subscript_tl { #1 }
+ \chemformula_clean_subscript:
+ % if a subscript follows just store and do nothing else
+ \peek_meaning:NF \chemformula_subscript:n
{
- \chemformula_sub_or_supscript_skip:
- \bool_if:NT \l_chemformula_charge_shift_bool
+ % if a superscript follows store and do nothing else
+ % if something else follows both sub- and superscript
+ \peek_meaning:NF \chemformula_superscript:n
{
- \skip_horizontal:N \l_chemformula_charge_shift_dim
- \bool_set_false:N \l_chemformula_charge_shift_bool
+ \chemformula_measure_subscript:V \l_chemformula_subscript_tl
+ \chemformula_measure_superscript:V \l_chemformula_superscript_tl
+ \chemformula_use_sub_and_superscript:
}
- \dim_zero:N \l_chemformula_supscript_dim
}
- % typeset subscript
- \tex_raise:D \l_chemformula_subscript_shift_dim
+ }
+
+\cs_new:Npn \chemformula_clean_subscript:
+ {
+ \tl_replace_all:Nnn \l_chemformula_subscript_tl
+ { \chemformula_single_bond: } { \chemformula_minus: }
+ \tl_replace_all:Nnn \l_chemformula_subscript_tl
+ { \chemformula_triple_bond: } {\chemformula_plus: }
+ \tl_replace_all:Nnn \l_chemformula_subscript_tl
+ { \chemformula_adduct: } { . }
+ \tl_replace_all:Nnn \l_chemformula_subscript_tl
+ { \chemformula_star_adduct: } { * }
+ }
+
+\cs_new:Nn \chemformula_subscript_write:nV
+ {
+ \exp_args:No \dim_set:Nn \l_tmpa_dim
+ { \l_chemformula_subscript_shift_dim * #1 }
+ \tex_raise:D \l_tmpa_dim
\hbox:n
{
- $\mathchoice
- { \scriptstyle }
- { \scriptstyle }
- { \scriptscriptstyle }
- { \scriptscriptstyle }
- \prop_get:NnNTF \l_chemformula_numbers_prop { #1 } \l_tmpa_tl
+ $\scriptstyle
+ \prop_get:NoNTF \l_chemformula_numbers_prop
+ { #2 } \l_tmpa_tl
{ \chemformula_number_style:n { \l_tmpa_tl } }
- { \chemformula_number_style:n { \l_tmpc_tl } }$
- }
- % look ahead what's coming next and set boolean accordingly
- \peek_meaning:NTF \chemformula_supscript:n
- { \bool_set_true:N \l_chemformula_sub_bool }
- {
- \peek_meaning:NTF \chemformula_chief_supscript:n
- { \bool_set_true:N \l_chemformula_sub_bool }
- { \bool_set_false:N \l_chemformula_sub_bool }
+ { \chemformula_number_style:n { #2 } }$
}
}
-\cs_new:Npn \chemformula_supscript:n #1
+
+\cs_new:Nn \chemformula_measure_subscript:V
{
- \bool_set_true:N \l_chemformula_sup_bool
- % clean up wrong input
- \tl_set:Nn \l_tmpc_tl { #1 }
- \tl_replace_all:Nnn \l_tmpc_tl { \chemformula_single_bond: }
- { \chemformula_minus: }
- \tl_replace_all:Nnn \l_tmpc_tl { - } { \chemformula_minus: }
- \tl_replace_all:Nnn \l_tmpc_tl { \chemformula_triple_bond: }
- { \chemformula_plus: }
- \tl_replace_all:Nnn \l_tmpc_tl { + } { \chemformula_plus: }
- \tl_replace_all:Nnn \l_tmpc_tl { \chemformula_adduct: }
- { \chemformula_radical: }
- \tl_replace_all:Nnn \l_tmpc_tl { \chemformula_star_adduct: } { * }
- \tl_replace_all:Nnn \l_tmpc_tl { . } { \chemformula_radical: }
- % measure width and save it
- \prop_get:NnNTF \l_chemformula_charge_prop { #1 } \l_tmpa_tl
- {
- \exp_args:NNo \hbox_set:Nn \l_tmpa_box
- { $ ^ { \chemformula_charge_style:n { \l_tmpa_tl } } $ }
- }
- {
- \exp_args:NNo \hbox_set:Nn \l_tmpa_box
- { $ ^ { \chemformula_charge_style:n { \l_tmpc_tl } } $ }
- }
- \dim_set:Nn \l_chemformula_supscript_dim
- { -\box_wd:N \l_tmpa_box }
+ \hbox_set:Nn \l_tmpa_box
+ { \chemformula_subscript_write:nV { 1 } \l_chemformula_subscript_tl }
+ \dim_set:Nn \l_chemformula_subscript_dim { -\box_wd:N \l_tmpa_box }
\box_clear:N \l_tmpa_box
- \bool_if:NT \l_chemformula_sub_bool
- {
- \chemformula_sub_or_supscript_skip:
- \skip_horizontal:n \l_chemformula_charge_shift_dim
- \bool_set_true:N \l_chemformula_charge_shift_bool
- \dim_zero:N \l_chemformula_subscript_dim
- }
- % typeset superscript
- \prop_get:NnNTF \l_chemformula_charge_prop { #1 } \l_tmpa_tl
- { $ ^ { \chemformula_charge_style:n { \l_tmpa_tl } } $ }
- { $ ^ { \chemformula_charge_style:n { \l_tmpc_tl } } $ }
- % look ahead what's coming next and set boolean accordingly
- \peek_meaning:NTF \chemformula_subscript:n
- { \bool_set_true:N \l_chemformula_sup_bool }
- {
- \peek_meaning:NTF \chemformula_chief_subscript:n
- { \bool_set_true:N \l_chemformula_sup_bool }
- { \bool_set_false:N \l_chemformula_sup_bool }
- }
}
-\cs_new:Npn \chemformula_sub_or_supscript_skip:
- {
- \bool_if:NTF \l_chemformula_first_is_sup_bool
- {
- % when compound starts with a superscript only shift back
- % by the width of the subscript to align them left
- \bool_set_false:N \l_chemformula_first_is_sup_bool
- \skip_horizontal:N \l_chemformula_subscript_compare_dim
- \bool_set_false:N \l_chemformula_sup_bool
- \bool_set_false:N \l_chemformula_sub_bool
- }
- {
- \dim_compare:nTF
- {
- \dim_abs:n { \l_chemformula_subscript_compare_dim }
- <=
- \dim_abs:n { \l_chemformula_supscript_dim }
- }
- { \skip_horizontal:N \l_chemformula_subscript_compare_dim }
- { \skip_horizontal:N \l_chemformula_supscript_dim }
- \bool_set_false:N \l_chemformula_sup_bool
- \bool_set_false:N \l_chemformula_sub_bool
- }
- }
+% superscripts
+\tl_new:N \l_chemformula_superscript_tl
+\box_new:N \l_chemformula_superscript_box
-% handle sub- in superscripts and vice versa
-\cs_new:Npn \chemformula_chief_supscript:n #1
+% remove double or nested sub- and superscripts
+\cs_new:Npn \chemformula_superscript:n #1
{
- \tl_if_eq:nnTF { #1 } { \chemformula_supscript:n }
- { \chemformula_supscript:n }
+ \tl_if_eq:nnTF { #1 } { \chemformula_superscript:n }
+ { \chemformula_superscript_aux:n }
{
\tl_if_eq:nnTF { #1 } { \chemformula_subscript:n }
- { \chemformula_supscript:n }
+ { \chemformula_superscript_aux:n }
{
\tl_set:Nn \l_tmpc_tl { #1 }
\tl_if_in:nnT { #1 } { \chemformula_subscript:n }
{ \tl_remove_all:Nn \l_tmpc_tl { \chemformula_subscript:n } }
- \tl_if_in:nnT { #1 } { \chemformula_supscript:n }
- { \tl_remove_all:Nn \l_tmpc_tl { \chemformula_supscript:n } }
- \exp_args:No \chemformula_supscript:n { \l_tmpc_tl }
+ \tl_if_in:nnT { #1 } { \chemformula_superscript:n }
+ { \tl_remove_all:Nn \l_tmpc_tl { \chemformula_superscript:n } }
+ \exp_args:No \chemformula_superscript_aux:n { \l_tmpc_tl }
}
}
}
-\cs_new:Npn \chemformula_chief_subscript:n #1
+% handle superscripts
+\cs_new:Nn \chemformula_superscript_aux:n
{
- \tl_if_eq:nnTF { #1 }{ \chemformula_supscript:n }
- { \chemformula_subscript:n }
+ \tl_put_right:Nn \l_chemformula_superscript_tl { #1 }
+ \chemformula_clean_superscript:
+ \peek_meaning:NF \chemformula_superscript:n
{
- \tl_if_eq:nnTF { #1 }{ \chemformula_subscript:n }
- { \chemformula_subscript:n }
+ \peek_meaning:NF \chemformula_subscript:n
{
- \tl_set:Nn \l_tmpc_tl { #1 }
- \tl_if_in:nnT { #1 } { \chemformula_subscript:n }
- { \tl_remove_all:Nn \l_tmpc_tl { \chemformula_subscript:n } }
- \tl_if_in:nnT { #1 } { \chemformula_supscript:n }
- { \tl_remove_all:Nn \l_tmpc_tl { \chemformula_supscript:n } }
- \exp_args:No \chemformula_subscript:n { \l_tmpc_tl }
+ \chemformula_measure_subscript:V \l_chemformula_subscript_tl
+ \chemformula_measure_superscript:V \l_chemformula_superscript_tl
+ \chemformula_use_sub_and_superscript:
}
}
}
-\cs_new:Npn \chemformula_test_for_subscript:n #1
+\cs_new:Npn \chemformula_clean_superscript:
{
- \peek_meaning:NT \chemformula_subscript:n
+ \tl_replace_all:Nnn \l_chemformula_superscript_tl
+ { \chemformula_single_bond: } { \chemformula_minus: }
+ \tl_replace_all:Nnn \l_chemformula_superscript_tl
+ { - } { \chemformula_minus: }
+ \tl_replace_all:Nnn \l_chemformula_superscript_tl
+ { \chemformula_triple_bond: } { \chemformula_plus: }
+ \tl_replace_all:Nnn \l_chemformula_superscript_tl
+ { + } { \chemformula_plus: }
+ \tl_replace_all:Nnn \l_chemformula_superscript_tl
+ { \chemformula_adduct: } { \chemformula_radical: }
+ \tl_replace_all:Nnn \l_chemformula_superscript_tl
+ { \chemformula_star_adduct: } { * }
+ \tl_replace_all:Nnn \l_chemformula_superscript_tl
+ { . } { \chemformula_radical: }
+ }
+
+\cs_new:Nn \chemformula_superscript_write:nV
+ {
+ \exp_args:No \dim_set:Nn \l_tmpa_dim
+ { \l_chemformula_superscript_shift_dim * #1 }
+ \tex_raise:D \l_tmpa_dim
+ \hbox:n
{
- \bool_if:NT \l_chemformula_sup_bool
- { \skip_horizontal:N #1 }
- \bool_set_false:N \l_chemformula_sup_bool
+ $\scriptstyle
+ \prop_get:NoNTF \l_chemformula_charge_prop
+ { #2 } \l_tmpa_tl
+ { \chemformula_charge_style:n { \l_tmpa_tl } }
+ { \chemformula_charge_style:n { #2 } }$
}
}
-\cs_new:Npn \chemformula_test_for_supscript:n #1
+\cs_new:Nn \chemformula_measure_superscript:V
+ {
+ \hbox_set:Nn \l_tmpa_box
+ { \chemformula_superscript_write:nV { 1 } \l_chemformula_superscript_tl }
+ \dim_set:Nn \l_chemformula_superscript_dim
+ { -\box_wd:N \l_tmpa_box }
+ \box_clear:N \l_tmpa_box
+ }
+
+% typeset both sub- and superscripts
+\cs_new:Npn \chemformula_use_sub_and_superscript:
{
- \peek_meaning:NT \chemformula_subscript:n
+ \group_begin:
+ % No shift for excited state
+ \exp_args:No \tl_if_eq:nnT { \l_chemformula_superscript_tl } { * }
+ {
+ \bool_set_false:N \l_chemformula_charge_full_shift_bool
+ \dim_zero:N \l_chemformula_charge_shift_dim
+ }
+ % align to the right if isotope else to the left
+ \bool_if:NTF \l_chemformula_is_isotope_bool
{
- \bool_if:NT \l_chemformula_sup_bool
- { \skip_horizontal:N #1 }
- \bool_set_false:N \l_chemformula_sup_bool
+ \tl_if_blank:VF \l_chemformula_superscript_tl
+ {
+ \dim_compare:nT
+ { \l_chemformula_subscript_dim < \l_chemformula_superscript_dim }
+ {
+ \skip_horizontal:n { -\l_chemformula_subscript_dim }
+ \skip_horizontal:N \l_chemformula_superscript_dim
+ }
+ }
}
+ {
+ % add hshift to the superscript if there also is a subscript
+ \tl_if_blank:VF \l_chemformula_superscript_tl
+ {
+ \tl_if_blank:VF \l_chemformula_subscript_tl
+ {
+ \bool_if:NTF \l_chemformula_charge_full_shift_bool
+ { \skip_horizontal:n { -\l_chemformula_subscript_dim } }
+ { \skip_horizontal:N \l_chemformula_charge_shift_dim }
+ }
+ }
+ }
+ % typeset superscript
+ \tl_if_blank:VF \l_chemformula_superscript_tl
+ {
+ \chemformula_superscript_write:nV { 1 } \l_chemformula_superscript_tl
+ % skip back for the subscript
+ \tl_if_blank:VF \l_chemformula_subscript_tl
+ {
+ \bool_if:NTF \l_chemformula_is_isotope_bool
+ { \skip_horizontal:N \l_chemformula_subscript_dim }
+ {
+ \skip_horizontal:N \l_chemformula_superscript_dim
+ \bool_if:NTF \l_chemformula_charge_full_shift_bool
+ { \skip_horizontal:N \l_chemformula_subscript_dim }
+ {
+ \skip_horizontal:n
+ { -\l_chemformula_charge_shift_dim }
+ }
+ }
+ }
+ }
+ % typeset subscript
+ \tl_if_blank:VF \l_chemformula_subscript_tl
+ { \chemformula_subscript_write:nV { 1 } \l_chemformula_subscript_tl }
+ \bool_if:NF \l_chemformula_is_isotope_bool
+ {
+ \dim_zero:N \l_tmpa_dim
+ \bool_if:NTF \l_chemformula_charge_full_shift_bool
+ {
+ \tl_if_blank:VF \l_chemformula_subscript_tl
+ { \dim_set:Nn \l_tmpa_dim { - \l_chemformula_superscript_dim } }
+ }
+ {
+ \tl_if_blank:VF \l_chemformula_superscript_tl
+ {
+ \tl_if_blank:VF \l_chemformula_subscript_tl
+ {
+ \dim_set:Nn \l_tmpa_dim
+ {
+ \l_chemformula_charge_shift_dim
+ - \l_chemformula_superscript_dim
+ + \l_chemformula_subscript_dim
+ }
+ }
+ }
+ }
+ \dim_compare:nT { \l_tmpa_dim > 0pt }
+ { \skip_horizontal:N \l_tmpa_dim }
+ }
+ \group_end:
+ % clean up
+ \bool_set_false:N \l_chemformula_is_isotope_bool
+ \tl_clear:N \l_chemformula_subscript_tl
+ \tl_clear:N \l_chemformula_superscript_tl
}
%-----------------------------------------------------------------------------%
@@ -1128,12 +1174,17 @@
\cs_new:Npn \chemformula_parse_stoich:n #1
{
- \tl_if_in:nnTF { #1 } { _ }
- { \chemformula_parse_stoich_misc_frac:w #1 \q_nil }
+ % TODO add support for missing leading 0
+ \tl_if_in:nnTF { #1 } { ( }
+ { \tl_put_right:Nn \l_chemformula_input_tl { #1 } }
{
- \tl_if_in:nnTF { #1 } { / }
- { \chemformula_parse_stoich_frac:w #1 \q_nil }
- { \tl_put_right:Nn \l_chemformula_input_tl { #1 } }
+ \tl_if_in:nnTF { #1 } { _ }
+ { \chemformula_parse_stoich_misc_frac:w #1 \q_nil }
+ {
+ \tl_if_in:nnTF { #1 } { / }
+ { \chemformula_parse_stoich_frac:w #1 \q_nil }
+ { \tl_put_right:Nn \l_chemformula_input_tl { #1 } }
+ }
}
}
@@ -1202,7 +1253,7 @@
{
\tl_put_right:Nn #2
{ \chemformula_font_inner: }
- \chemformula_handle_sub_and_supscripts:nN { #1 } #2
+ \chemformula_handle_sub_and_superscripts:nN { #1 } #2
}
}
{
@@ -1244,7 +1295,7 @@
\cs_new:Npn \chemformula_fontspec_aux:w [#1]#2 \q_stop
{ \newfontfamily \chemformula_font: [ #1 ] { #2 } }
-\cs_new:Nn \chemformula_handle_sub_and_supscripts:nN
+\cs_new:Nn \chemformula_handle_sub_and_superscripts:nN
{
\tl_set_rescan:Nnn \l_tmpa_tl
{
@@ -1254,18 +1305,26 @@
\char_set_catcode_letter:N \\
}
{ #1 }
- % let's see if the compound starts with a superscript:
+ % let's see if the compound starts with a sub- or superscript:
+% \exp_args:Nx \tl_show:n { \tl_head:V \l_tmpa_tl }
\exp_args:Nx \tl_if_in:nnT { \tl_head:V \l_tmpa_tl } { ^ }
- { \bool_set_true:N \l_chemformula_first_is_sup_bool }
+ { \bool_set_true:N \l_chemformula_is_isotope_bool }
+ \exp_args:Nx \tl_if_in:nnT { \tl_head:V \l_tmpa_tl } { _ }
+ { \bool_set_true:N \l_chemformula_is_isotope_bool }
+ \exp_args:NNx \prop_if_in:NnT \l_chemformula_numbers_prop
+ { \tl_head:V \l_tmpa_tl }
+ { \bool_set_true:N \l_chemformula_is_isotope_bool }
+% \bool_if:NT \l_chemformula_is_isotope_bool
+% { \exp_args:Nx \tl_show:n { \tl_head:V \l_tmpa_tl } }
\tl_if_in:VnT \l_tmpa_tl { ^ }
{
\tl_replace_all:Nnn \l_tmpa_tl { ^ }
- { \chemformula_chief_supscript:n }
+ { \chemformula_superscript:n }
}
\tl_if_in:VnT \l_tmpa_tl { _ }
{
\tl_replace_all:Nnn \l_tmpa_tl { _ }
- { \chemformula_chief_subscript:n }
+ { \chemformula_subscript:n }
}
\int_zero:N \l_chemformula_count_tokens_int
\tl_map_inline:Nn \l_tmpa_tl
@@ -1277,13 +1336,13 @@
\tl_if_eq:nnTF { ##1 } { + }
{
\tl_put_right:Nn #2
- { \chemformula_supscript:n { \chemformula_plus: } }
+ { \chemformula_superscript:n { \chemformula_plus: } }
}
{
\tl_if_eq:nnTF { ##1 } { - }
{
\tl_put_right:Nn #2
- { \chemformula_supscript:n { \chemformula_minus: } }
+ { \chemformula_superscript:n { \chemformula_minus: } }
}
{
\prop_get:NnNTF \l_chemformula_cmpd_prop { ##1 } \l_tmpb_tl
@@ -1399,7 +1458,7 @@
{
\tl_set_rescan:Nnn \l_tmpa_tl
{ \ExplSyntaxNamesOn \char_set_catcode_other:N \: }
- { #1 }
+ { { #1 } }
\tl_replace_all:Nnn \l_tmpa_tl { \_ } { chemformulaplaceholder }
\tl_replace_all:Nnn \l_tmpa_tl { _ } { \sb }
\tl_replace_all:Nnn \l_tmpa_tl { chemformulaplaceholder } { \_ }
@@ -1410,7 +1469,7 @@
\cs_new:Npn \chemformula_read_escape_single:w '#1' \q_nil
{
\tl_set_rescan:Nnn \l_tmpa_tl
- { \ExplSyntaxOn \char_set_catcode_other:N \: }
+ { \ExplSyntaxNamesOn \char_set_catcode_other:N \: }
{ { #1 } }
\tl_replace_all:Nnn \l_tmpa_tl { \_ } { chemformulaplaceholder }
\tl_replace_all:Nnn \l_tmpa_tl { _ } { \sb }
@@ -1513,12 +1572,27 @@
% customization of output other than arrows
\keys_define:nn { chemmacros / chemformula }
{
- charge-hshift .dim_set:N = \l_chemformula_charge_shift_dim ,
- charge-hshift .default:n = 1ex ,
+ charge-hshift .code:n =
+ \tl_if_eq:nnTF { #1 } { full }
+ { \bool_set_true:N \l_chemformula_charge_full_shift_bool }
+ {
+ \bool_set_false:N \l_chemformula_charge_full_shift_bool
+ \dim_set:Nn \l_chemformula_charge_shift_dim { #1 }
+ } ,
+ charge-hshift .default:n = .5ex ,
+ charge-vshift .code:n =
+ {
+ \dim_set:Nn \l_chemformula_superscript_shift_additional_dim { #1 }
+ \dim_set:Nn \l_chemformula_superscript_shift_dim
+ {
+ \l_chemformula_superscript_shift_default_dim +
+ \l_chemformula_superscript_shift_additional_dim
+ }
+ } ,
charge-style .choice: ,
- charge-style / text .code:n =
+ charge-style / text .code:n =
\bool_set_false:N \l_chemformula_charge_style_math_bool ,
- charge-style / math .code:n =
+ charge-style / math .code:n =
\bool_set_true:N \l_chemformula_charge_style_math_bool ,
subscript-vshift .code:n =
{
@@ -1612,11 +1686,21 @@ VERSION HISTORY
2012/02/19 - version 3.1 - new functions in the chemmacros package
- new arrow types -/>, </- and <o>
- new commands \DeclareChemArrow, \RenewChemArrow and
- \ShowChemArrow
+ \ShowChemArrow
+2012/02/26 - version 3.1a - changes in the chemmacros package
+2012/03/03 - version 3.1b - arrow types are stored in a sequence to automate the
+ search and replace in the right order
+ - new arrow type ==
+ - IUPAC compliance for stoichiometric factors
+ - new handling of super- and subscripts to correct
+ various flaws: clear distinction between isotope and
+ formula
+ - new option charge-vshift
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TODO
- Addukte: Zahlen nach * und . automatisch erkennen?
- allow fractions in subscripts: _{$\frac{1}{2}$} ?
- optionale argumente von \\ nach außen weiterreichen?
-- vertikaler shift für superskripte? \ No newline at end of file
+- vertikalen Shift der Hoch- und Tiefstellungen mit \mathchoice anpassen:
+ \( K = \frac{[\ch{Na+}]^2[\ch{SO4^2-}]}{[\ch{Na2SO4}]} \) \ No newline at end of file