From 6151df96e3052187573221b5851211dd5bae6657 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 5 Mar 2012 00:55:20 +0000 Subject: chemmacros 3.1b (4mar12) git-svn-id: svn://tug.org/texlive/trunk@25561 c570f23f-e606-0410-a88d-b1316a301751 --- .../tex/latex/chemmacros/chemformula.sty | 510 ++++++++++++--------- .../texmf-dist/tex/latex/chemmacros/chemmacros.sty | 155 ++++--- .../texmf-dist/tex/latex/chemmacros/ghsystem.sty | 9 +- 3 files changed, 404 insertions(+), 270 deletions(-) (limited to 'Master/texmf-dist/tex/latex/chemmacros') 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 { } { \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 -/>, - 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 diff --git a/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty b/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty index 9f0569be67f..c12b04033ca 100644 --- a/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty +++ b/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty @@ -5,7 +5,7 @@ % - macros and commands for chemists - % % --------------------------------------------------------------------------- % % - Clemens Niederberger - % -% - 2012/02/26 - % +% - 2012/03/03 - % % --------------------------------------------------------------------------- % % - https://bitbucket.org/cgnieder/chemmacros/ - % % - contact@mychemistry.eu - % @@ -33,8 +33,8 @@ \ProvidesExplPackage {chemmacros} - {2012/02/26} - {3.1a} + {2012/03/03} + {3.1b} {macros and commands for chemists} \@ifpackageloaded { chemformula } {} { \RequirePackage { chemformula } } @@ -82,24 +82,28 @@ % --------------------------------------------------------------------------- % % package options -% xspace => add an \xspace after a whole bunch of macros % bpchem => use \IUPAC inside for \NMR command % circled => circle charges % detect-bold => behaviour when font series bold % EZ => cool or chemmacros version of \E % german => change pKA => pKS etc +% iupac => behaviour of nomenclature commands % ngerman => an alias :) % ghsystem => load ghsystem or don't % method => use `chemformula' or `mhchem' % strict => errors or warnings % synchronize => let particles et.al. adapt chemformula's font selection -% iupac => behaviour of nomenclature commands +% ugreek => behaviour of \ChemDelta, \Chemalpha, ... % version=1 => compatibility for documents set with v1.* +% xspace => add an \xspace after a whole bunch of macros \bool_new:N \l_chemmacros_strict_bool \bool_new:N \l_chemmacros_detect_bold_bool \bool_set_true:N \l_chemmacros_detect_bold_bool +\bool_new:N \l_chemmacros_use_upgreek_bool +\bool_new:N \l_chemmacros_use_textgreek_bool + \cs_new:Nn \chemmacros_inner_font: {} \keys_define:nn { chemmacros / option } @@ -137,6 +141,16 @@ german .default:n = true , ghsystem .bool_set:N = \l_chemmacros_ghsystem_bool , ghsystem .default:n = true , + iupac .choice: , + iupac / restricted .code:n = + \bool_set_true:N \l_chemmacros_iupac_restricted_bool + \bool_set_false:N \l_chemmacros_iupac_strict_bool , + iupac / auto .code:n = + \bool_set_false:N \l_chemmacros_iupac_restricted_bool + \bool_set_false:N \l_chemmacros_iupac_strict_bool , + iupac / strict .code:n = + \bool_set_false:N \l_chemmacros_iupac_restricted_bool + \bool_set_true:N \l_chemmacros_iupac_strict_bool , method .choice: , method / chemformula .code:n = \bool_set_false:N \l_chemmacros_use_mhchem_bool , @@ -152,29 +166,30 @@ strict .bool_set:N = \l_chemmacros_strict_bool , strict .default:n = true , synchronize .choice: , - synchronize / true .code:n = + synchronize / true .code:n = \cs_set_eq:NN \chemmacros_inner_font: \chemformula_font_inner: , synchronize / false .code:n = \cs_set:Nn \chemmacros_inner_font: {} , synchronize .default:n = true , - iupac .choice: , - iupac / restricted .code:n = - \bool_set_true:N \l_chemmacros_iupac_restricted_bool - \bool_set_false:N \l_chemmacros_iupac_strict_bool , - iupac / auto .code:n = - \bool_set_false:N \l_chemmacros_iupac_restricted_bool - \bool_set_false:N \l_chemmacros_iupac_strict_bool , - iupac / strict .code:n = - \bool_set_false:N \l_chemmacros_iupac_restricted_bool - \bool_set_true:N \l_chemmacros_iupac_strict_bool , - xspace .bool_set:N = \l_chemmacros_xspace_bool , - xspace .default:n = true , + upgreek .choice: , + upgreek / upgreek .code:n = + \bool_set_true:N \l_chemmacros_use_upgreek_bool + \bool_set_false:N \l_chemmacros_use_textgreek_bool , + upgreek / textgreek .code:n = + \bool_set_false:N \l_chemmacros_use_upgreek_bool + \bool_set_true:N \l_chemmacros_use_textgreek_bool , + upgreek / none .code:n = + \bool_set_false:N \l_chemmacros_use_upgreek_bool + \bool_set_false:N \l_chemmacros_use_textgreek_bool , + upgreek .default:n = upgreek , version .choice: , version / 1 .code:n = { \bool_set_true:N \l_chemmacros_version_one_bool } , version / 2 .code:n = { \bool_set_false:N \l_chemmacros_version_one_bool } , version / bundle .code:n = - { \bool_set_false:N \l_chemmacros_version_one_bool } + { \bool_set_false:N \l_chemmacros_version_one_bool } , + xspace .bool_set:N = \l_chemmacros_xspace_bool , + xspace .default:n = true } \ProcessKeysOptions { chemmacros / option } @@ -190,7 +205,47 @@ { \RequirePackage { xspace } } \bool_if:NT \l_chemmacros_use_mhchem_bool { \RequirePackage[ version=3 ]{ mhchem } } - } + \@ifpackageloaded { upgreek } + { \bool_set_true:N \l_chemmacros_use_upgreek_bool } + { + \@ifpackageloaded { textgreek } + { \bool_set_true:N \l_chemmacros_use_textgreek_bool } + {} + } + \bool_if:NTF \l_chemmacros_use_upgreek_bool + { + \cs_set_nopar:Npn \Chemalpha { \ensuremath { \upalpha } } + \cs_set_nopar:Npn \Chembeta { \ensuremath { \upbeta } } + \cs_set_nopar:Npn \Chemgamma { \ensuremath { \upgamma } } + \cs_set_nopar:Npn \Chemdelta { \ensuremath { \updelta } } + \cs_set_nopar:Npn \Chemomega { \ensuremath { \upomega } } + \cs_set_nopar:Npn \ChemDelta { \ensuremath { \Updelta } } + } + { + \bool_if:NT \l_chemmacros_use_textgreek_bool + { + \cs_set_nopar:Npn \Chemalpha + { \ensuremath { \text { \textalpha } } } + \cs_set_nopar:Npn \Chembeta + { \ensuremath { \text { \textbeta } } } + \cs_set_nopar:Npn \Chemgamma + { \ensuremath { \text { \textgamma } } } + \cs_set_nopar:Npn \Chemdelta + { \ensuremath { \text { \textdelta } } } + \cs_set_nopar:Npn \Chemomega + { \ensuremath { \text { \textomega } } } + \cs_set_nopar:Npn \ChemDelta + { \ensuremath { \text { \textDelta } } } + } + } + } + +\cs_new_nopar:Npn \Chemalpha { \ensuremath { \alpha } } +\cs_new_nopar:Npn \Chembeta { \ensuremath { \beta } } +\cs_new_nopar:Npn \Chemgamma { \ensuremath { \gamma } } +\cs_new_nopar:Npn \Chemdelta { \ensuremath { \delta } } +\cs_new_nopar:Npn \Chemomega { \ensuremath { \omega } } +\cs_new_nopar:Npn \ChemDelta { \ensuremath { \Delta } } \cs_new_nopar:Npn \chemmacros_xspace: { @@ -226,6 +281,9 @@ \token_to_str:N #2 \c_space_tl instead. } +\msg_set:nnn { chemmacros } { command-dropped } + { The~command~\token_to_str:N #1 \c_space_tl has~been~dropped.~I'm~sorry. } + \msg_set:nnnn { chemmacros } { declare-particle } { The~command~sequence~ \token_to_str:N #1 \c_space_tl is~already~defined. @@ -582,6 +640,13 @@ { #1 } } +\NewDocumentCommand \Rad { O{}G{} } + { + \chemmacros_msg:nnxx { chemmacros } { command-dropped } + { \Rad } { } + #1#2 + } + % charges \cs_new_nopar:Npn \chemmacros_charge:n #1 { @@ -873,6 +938,20 @@ \DeclareChemIUPAC \syn { \textit { syn } } \DeclareChemIUPAC \anti { \textit { anti } } +% attachments to heteroatoms / added hydrogen +\DeclareChemIUPAC \H { \textit { H } } +\DeclareChemIUPAC \O { \textit { O } } +\DeclareChemIUPAC \N { \textit { N } } +\DeclareChemIUPAC \Sf { \textit { S } } +\DeclareChemIUPAC \P { \textit { P } } + +% greek letters +\DeclareChemIUPAC\a{\Chemalpha} +\DeclareChemIUPAC\b{\Chembeta} +\DeclareChemIUPAC\g{\Chemgamma} +\DeclareChemIUPAC\d{\Chemdelta} +\DeclareChemIUPAC\w{\Chemomega} + % \iupac (basically the same as bpchem's \IUPAC) % - allows multiple breaking points as compound names can get really long and % especially in multicolumn documents can span more than two lines @@ -899,7 +978,7 @@ \tex_ignorespaces:D \cs_set_eq:NN \- \chemmacros_break_point_hyphen: \cs_set_eq:NN \| \chemmacros_break_point: - \cs_set_eq:NN \^ \chemformula_supscript:n + \cs_set_eq:NN \^ \chemformula_superscript:n #1 \group_end: } @@ -1006,36 +1085,6 @@ \chemmacros_xspace: } -\char_set_catcode_letter:N \@ - -% --------------------------------------------------------------------------- % -% substituents -% \Rad[]{} - -\char_set_catcode_math_subscript:N \@ -\NewDocumentCommand \Rad { o g } - { - \chemmacros_atom:n - { - R - $ - \IfNoValueF { #2 } { @ { \mathrm { #2 } } } - ^ { - \IfNoValueF { #1 } - { - \tl_if_eq:nnTF { #1 } { + } - { \chemmacros_plus: } - { - \tl_if_eq:nnT { #1 } { - } - { \chemmacros_minus: } - } - } - } - $ - } - } -\char_set_catcode_letter:N \@ - % --------------------------------------------------------------------------- % % units \DeclareSIUnit { \atm } { atm } @@ -1138,9 +1187,7 @@ \fp_new:N \l_chemmacros_ox_number_fp \bool_new:N \l_chemmacros_ox_side_bool -\bool_set_false:N \l_chemmacros_ox_side_bool \bool_new:N \l_chemmacros_ox_super_bool -\bool_set_false:N \l_chemmacros_ox_super_bool \bool_new:N \l_chemmacros_ox_top_bool \bool_set_true:N \l_chemmacros_ox_top_bool @@ -3208,6 +3255,8 @@ Version history recommendations - new option "acid-base/p-style" - deprecated option: "option/detect-bold" +2012/03/03 - version 3.1b - changes in the chemformula package + - IUPAC compliance for \Delta and \ox % --------------------------------------------------------------------------- % % TODO: diff --git a/Master/texmf-dist/tex/latex/chemmacros/ghsystem.sty b/Master/texmf-dist/tex/latex/chemmacros/ghsystem.sty index 0e729748933..43a250ef30a 100644 --- a/Master/texmf-dist/tex/latex/chemmacros/ghsystem.sty +++ b/Master/texmf-dist/tex/latex/chemmacros/ghsystem.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 {ghsystem} - {2012/02/19} - {3.1} + {2012/03/03} + {3.1b} {globally harmonised system} % --------------------------------------------------------------------------- % @@ -452,7 +452,8 @@ VERSION HISTORY 2012/02/19 - version 3.1 - new functions in the chemmacros package - new arrow types and functions in the chemformula package - +2012/02/26 - version 3.1a - changes in the chemmacros package +2012/03/03 - version 3.1b - changes in packages chemformula and chemmacros %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % TODO: -- cgit v1.2.3