diff options
author | Karl Berry <karl@freefriends.org> | 2013-10-28 22:44:38 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2013-10-28 22:44:38 +0000 |
commit | 2d51c9ecf81c2731d82fb9c7973c5c143e8960af (patch) | |
tree | c0a61de895f3c09b2d3f78ae23de07153c178c8c /Master/texmf-dist/tex/latex/chemmacros | |
parent | 1cede05dc55dbfc5b1087d336d45984b2e595ac3 (diff) |
chemmacros (28oct13)
git-svn-id: svn://tug.org/texlive/trunk@32026 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/chemmacros')
-rw-r--r-- | Master/texmf-dist/tex/latex/chemmacros/chemformula.sty | 357 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty | 230 |
2 files changed, 433 insertions, 154 deletions
diff --git a/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty b/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty index d041025fe17..38408cde11b 100644 --- a/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty +++ b/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty @@ -27,8 +27,8 @@ % -------------------------------------------------------------------------- \RequirePackage{ expl3 , xparse , l3keys2e , tikz , amsmath , xfrac , nicefrac , scrlfile } \usetikzlibrary{arrows} -\def\chemformula@version{4.1} -\def\chemformula@date{2013/08/24} +\def\chemformula@version{4.2} +\def\chemformula@date{2013/10/24} \ProvidesExplPackage {chemformula} @@ -208,6 +208,8 @@ \box_new:N \l__chemformula_tmpa_box \box_new:N \l__chemformula_tmpb_box +\seq_new:N \l__chemformula_tmpa_seq + % booleans: % this one is officially used to detect wether we're in \ch or not: \bool_new:N \l_chemformula_inside_ch_bool @@ -287,6 +289,12 @@ \dim_set:Nn \l__chemformula_bond_dim { .5833em } \dim_new:N \l__chemformula_bond_space_dim \dim_set:Nn \l__chemformula_bond_space_dim { .07em } +\dim_new:N \l__chemformula_elspec_pair_distance_dim +\dim_set:Nn \l__chemformula_elspec_pair_distance_dim { 1ex } +\dim_new:N \l__chemformula_elspec_pair_line_length_dim +\dim_set:Nn \l__chemformula_elspec_pair_line_length_dim { 1.5ex } +\dim_new:N \l__chemformula_elspec_pair_width_dim +\dim_set:Nn \l__chemformula_elspec_pair_width_dim { 1pt } % skips: \skip_new:N \l__chemformula_stoich_space_skip @@ -299,6 +307,7 @@ % integers: \int_new:N \l__chemformula_count_tokens_int +\int_new:N \g__chemformula_lewis_int % token lists: \tl_new:N \l__chemformula_arrow_ratio_tl @@ -343,10 +352,15 @@ \tl_set:Nn \l__chemformula_subscript_shift_additional_tl { 0pt } \tl_new:N \l__chemformula_superscript_shift_additional_tl \tl_set:Nn \l__chemformula_superscript_shift_additional_tl { 0pt } -\tl_new:N \l__chemformula_bond_style_tl \tl_new:N \l__chemformula_subscript_tl \tl_new:N \l__chemformula_superscript_tl \tl_new:N \g__chemformula_input_up_tl +\tl_new:N \l__chemformula_elspec_angle_tl +\tl_new:N \l__chemformula_elspec_radius_tl +\tl_set:Nn \l__chemformula_elspec_radius_tl { .5ex } +\tl_new:N \l__chemformula_elspec_default_type_tl +\tl_set:Nn \l__chemformula_elspec_default_type_tl { pair } +\tl_const:Nx \c_chemformula_colon_tl { \token_to_str:N : } % property lists: \prop_new:N \l__chemformula_arrows_code_prop @@ -356,6 +370,7 @@ \prop_new:N \l__chemformula_charge_prop \prop_new:N \l__chemformula_numbers_prop \prop_new:N \l__chemformula_no_stoich_prop +\prop_new:N \l__chemformula_lewis_elspec_types_prop % sequences: \seq_new:N \l__chemformula_arrows_type_seq @@ -377,6 +392,14 @@ { \draw [ #1 ] #2 ; } \cs_generate_variant:Nn \chemformula_draw:nn { xn,nx,xx,xf } +\cs_new:Npn \chemformula_node:nn #1#2 + { \node [ #1 ] { #2 } ; } +\cs_generate_variant:Nn \chemformula_node:nn { x } + +\cs_new:Npn \chemformula_node:nnn #1#2#3 + { \node [ #1 ] ( #2 ) { #3 } ; } +\cs_generate_variant:Nn \chemformula_node:nnn { nx } + \cs_new:Npn \chemformula_allow_break: { \tex_penalty:D \c_zero } @@ -816,54 +839,59 @@ % 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) ; } +\DeclareChemArrow { <-> } + { \draw[chemarrow,cf-cf] (cf_arrow_start) -- (cf_arrow_end) ; } +\DeclareChemArrow { -> } + { \draw[chemarrow,-cf] (cf_arrow_start) -- (cf_arrow_end) ; } +\DeclareChemArrow { <- } + { \draw[chemarrow,cf-] (cf_arrow_start) -- (cf_arrow_end) ; } \DeclareChemArrow { <> } { - \draw[-cf] ([yshift=.2ex]cf_arrow_start) -- ([yshift=.2ex]cf_arrow_end) ; - \draw[cf-,] ([yshift=-.2ex]cf_arrow_start) -- ([yshift=-.2ex]cf_arrow_end) ; + \draw[chemarrow,-cf] + ([yshift=.2ex]cf_arrow_start) -- ([yshift=.2ex]cf_arrow_end) ; + \draw[chemarrow,cf-,] + ([yshift=-.2ex]cf_arrow_start) -- ([yshift=-.2ex]cf_arrow_end) ; } % isolobal arrow: \DeclareChemArrow { <o> } { - \draw[cf-cf] (cf_arrow_start) -- (cf_arrow_end) ; - \draw + \draw[chemarrow,cf-cf] (cf_arrow_start) -- (cf_arrow_end) ; + \draw[chemarrow] (cf_arrow_mid) .. controls ++(-.9ex,-1.5ex) and ++(.9ex,-1.5ex) .. (cf_arrow_mid) ; } \DeclareChemArrow { <=>> } { - \draw[-left~cf] + \draw[chemarrow,-left~cf] ([yshift=.15ex]cf_arrow_start) -- ([yshift=.15ex]cf_arrow_end) ; - \draw[left~cf-] + \draw[chemarrow,left~cf-] ([yshift=-.15ex]cf_arrow_mid_start) -- ([yshift=-.15ex]cf_arrow_mid_end) ; } \DeclareChemArrow {<<=>} { - \draw[-left~cf] + \draw[chemarrow,-left~cf] ([yshift=.15ex]cf_arrow_mid_start) -- ([yshift=.15ex]cf_arrow_mid_end) ; - \draw[left~cf-] + \draw[chemarrow,left~cf-] ([yshift=-.15ex]cf_arrow_start) -- ([yshift=-.15ex]cf_arrow_end) ; } \DeclareChemArrow { <=> } { - \draw[-left~cf] + \draw[chemarrow,-left~cf] ([yshift=.15ex]cf_arrow_start) -- ([yshift=.15ex]cf_arrow_end) ; - \draw[left~cf-] + \draw[chemarrow,left~cf-] ([yshift=-.15ex]cf_arrow_start) -- ([yshift=-.15ex]cf_arrow_end) ; } \DeclareChemArrow { -/> } { - \draw[-cf] (cf_arrow_start) -- (cf_arrow_end) ; - \draw (cf_arrow_mid) ++ (.2ex,.4ex) -- ++(-.4ex,-.8ex) ; - \draw (cf_arrow_mid) ++ (-.2ex,.4ex) -- ++(-.4ex,-.8ex) ; + \draw[chemarrow,-cf] (cf_arrow_start) -- (cf_arrow_end) ; + \draw[chemarrow] (cf_arrow_mid) ++ (.2ex,.4ex) -- ++(-.4ex,-.8ex) ; + \draw[chemarrow] (cf_arrow_mid) ++ (-.2ex,.4ex) -- ++(-.4ex,-.8ex) ; } \DeclareChemArrow { </- } { - \draw[cf-] (cf_arrow_start) -- (cf_arrow_end) ; - \draw (cf_arrow_mid) ++ (.2ex,.4ex) -- ++(-.4ex,-.8ex) ; - \draw (cf_arrow_mid) ++ (.6ex,.4ex) -- ++(-.4ex,-.8ex) ; + \draw[chemarrow,cf-] (cf_arrow_start) -- (cf_arrow_end) ; + \draw[chemarrow] (cf_arrow_mid) ++ (.2ex,.4ex) -- ++(-.4ex,-.8ex) ; + \draw[chemarrow] (cf_arrow_mid) ++ (.6ex,.4ex) -- ++(-.4ex,-.8ex) ; } % net reaction: \DeclareChemArrow { == } { \node at ([yshift=-.2ex]cf_arrow_mid) { = } ; } @@ -880,7 +908,8 @@ compound-sep .dim_set:N = \l__chemformula_compound_sep_dim , arrow-style .tl_set:N = \l__chemformula_arrow_style_tl , label-style .tl_set:N = \l__chemformula_arrow_label_style_tl , - arrow-penalty .tl_set:N = \l__chemformula_arrow_penalty_tl + arrow-penalty .tl_set:N = \l__chemformula_arrow_penalty_tl , + arrow-style .code:n = \tikzset { chemarrow/.style={#1} } , } % -------------------------------------------------------------------------- @@ -915,12 +944,12 @@ \mode_if_math:TF { \mathchoice - { \text { #1 } } - { \text { #1 } } - { \text { \scriptsize #1 } } - { \text { \tiny #1 } } + { \text { \chemformula_font_inner: #1 } } + { \text { \chemformula_font_inner: #1 } } + { \text { \scriptsize \chemformula_font_inner: #1 } } + { \text { \tiny \chemformula_font_inner: #1 } } } - { #1 } + { \chemformula_font_inner: #1 } } \cs_generate_variant:Nn \chemformula_write:n { V } @@ -1008,6 +1037,7 @@ { \group_begin: \keys_set:nn { chemmacros / chemformula } { #1 } + \chemformula_input_cmpd:nN { #2 } \l__chemformula_compound_tl \chemformula_write:V \l__chemformula_compound_tl \group_end: @@ -1212,8 +1242,6 @@ \l__chemformula_tmpa_tl } -\tikzset { chembond/.style={butt~cap-butt~cap,\l__chemformula_bond_style_tl} } - \NewDocumentCommand \DeclareChemBond { mm } { \cs_if_exist:cTF { chemformula_bond_type_#1 } @@ -1689,11 +1717,10 @@ { \tl_if_blank:VF \l__chemformula_stoich_tl { - \tl_put_left:Nn \l__chemformula_stoich_tl { \chemformula_font_inner: } - % TODO: is \ExplSyntaxOn needed here? - \tl_set_rescan:Nno \l__chemformula_stoich_tl - { \ExplSyntaxOn } - { \l__chemformula_stoich_tl } + \tl_put_left:Nn \l__chemformula_stoich_tl { \q_mark } + \__chemformula_sanitize:NV + \l__chemformula_stoich_tl + \l__chemformula_stoich_tl \__chemformula_parse_stoich:V \l__chemformula_stoich_tl } @@ -1707,9 +1734,8 @@ { \__chemformula_parse_stoich:w #1 \q_nil } \cs_generate_variant:Nn \__chemformula_parse_stoich:n { V } -\cs_new:Npn \__chemformula_parse_stoich:w \chemformula_font_inner: #1 \q_nil +\cs_new:Npn \__chemformula_parse_stoich:w \q_mark #1 \q_nil { - \tl_put_right:Nn \l__chemformula_input_tl { \chemformula_font_inner: } \__chemformula_bool_set_if_first_last:Nnnn \l__chemformula_stoich_is_iupac_bool { #1 } { ( } { ) } \bool_if:NTF \l__chemformula_stoich_is_iupac_bool @@ -1834,8 +1860,6 @@ !\l__chemformula_first_last_math_bool } { - \tl_put_right:Nn #2 - { \chemformula_font_inner: } \__chemformula_handle_sub_and_superscripts:nN { #1 } #2 \bool_if:NT \l__chemformula_options_bool { @@ -1980,11 +2004,7 @@ \cs_new_protected:Npn \__chemformula_clean_chemmacros:n #1 { \cs_set:Nn \chemmacros_text:n - { - \mode_if_math:TF - { \text { \chemformula_font_inner: ##1 } } - { \chemformula_font_inner: ##1 } - } + { \mode_if_math:TF { \text { ##1 } } { ##1 } } \cs_set:Npn \chemmacros_xspace: {} } \cs_generate_variant:Nn \__chemformula_clean_chemmacros:n { V } @@ -2277,7 +2297,8 @@ } , bond-length .dim_set:N = \l__chemformula_bond_dim , bond-offset .dim_set:N = \l__chemformula_bond_space_dim , - bond-style .tl_set:N = \l__chemformula_bond_style_tl , + bond-style .code:n = + \tikzset { chembond/.style={butt~cap-butt~cap,#1} } , bond-penalty .tl_set:N = \l__chemformula_bond_penalty_tl , font-family .code:n = \bool_set_true:N \l__chemformula_fss_bool @@ -2305,10 +2326,242 @@ } % -------------------------------------------------------------------------- +% \chlewis[opions]{el spec}{atom} + +\keys_define:nn { chemmacros / chemformula } + { + lewis-default .tl_set:N = \l__chemformula_elspec_default_type_tl , + lewis-distance .dim_set:N = \l__chemformula_elspec_pair_distance_dim , + lewis-line-length .dim_set:N = \l__chemformula_elspec_pair_line_length_dim , + lewis-line-width .dim_set:N = \l__chemformula_elspec_pair_width_dim , + lewis-offset .tl_set:N = \l__chemformula_elspec_radius_tl + } + +% #1: options +% #2- el spec +% #3: atom +\cs_new_protected:Npn \chemformula_lewis:nnn #1#2#3 + { + \group_begin: + \keys_set:nn { chemmacros / chemformula } { #1 } + \int_gincr:N \g__chemformula_lewis_int + \chemformula_get_lewis_sequence:n { #2 } + \chemformula_tikz:nn { baseline } + { + \chemformula_node:nxn { anchor=base , inner~sep=0pt } + { chlewis-\int_use:N \g__chemformula_lewis_int } + { + \bool_if:NTF \l_chemformula_inside_ch_bool + { #3 } + { \chemformula_chcpd:nn {} { #3 } } + } + \seq_map_inline:Nn \l__chemformula_tmpa_seq + { \chemformula_lewis_get_angle_and_spec:n { ##1 } } + } + \group_end: + } + +\cs_new_protected:Npn \chemformula_get_lewis_sequence:n #1 + { + \tl_set:Nn \l__chemformula_tmpa_tl { #1 } + \tl_replace_all:Nnn \l__chemformula_tmpa_tl { : } { \scan_stop: : , } + \tl_replace_all:NVn \l__chemformula_tmpa_tl \c_chemformula_colon_tl + { \scan_stop: : , } + \tl_replace_all:Nnn \l__chemformula_tmpa_tl { . } { \scan_stop: . , } + \tl_replace_all:Nnn \l__chemformula_tmpa_tl { | } { \scan_stop: | , } + \tl_replace_all:Nnn \l__chemformula_tmpa_tl { o } { \scan_stop: o , } + \seq_set_split:NnV \l__chemformula_tmpa_seq { , } \l__chemformula_tmpa_tl + } +\cs_generate_variant:Nn \tl_replace_all:Nnn { NV } + +\cs_new:Npn \chemformula_lewis_get_angle_and_spec:n #1 + { \__chemformula_lewis_get_angle_and_spec:w #1 \scan_stop: \scan_stop: \q_stop } + +\cs_new_protected:Npn + \__chemformula_lewis_get_angle_and_spec:w #1 \scan_stop: #2 \scan_stop: #3 \q_stop + { + \tl_if_blank:nF { #1 } + { + \tl_set:Nn \l__chemformula_elspec_angle_tl { #1 } + \tl_if_blank:nTF { #2 } + { + \tl_set_eq:NN + \l__chemformula_elspec_type_tl + \l__chemformula_elspec_default_type_tl + } + { \tl_set:Nn \l__chemformula_elspec_type_tl { #2 } } + \__chemformula_lewis_set_elspec_type:V \l__chemformula_elspec_type_tl + } + } + +\cs_new_protected:Npn \__chemformula_lewis_set_elspec_type:n #1 + { + \prop_get:NnNT \l__chemformula_lewis_elspec_types_prop { #1 } + \l__chemformula_tmpa_tl + { \tl_use:N \l__chemformula_tmpa_tl } + } +\cs_generate_variant:Nn \__chemformula_lewis_set_elspec_type:n { V } + +\prop_put:Nnn \l__chemformula_lewis_elspec_types_prop { | } + { \__chemformula_lewis_elspec_pair_line: } +\prop_put:Nnn \l__chemformula_lewis_elspec_types_prop { : } + { \__chemformula_lewis_elspec_pair_dots: } +\prop_put:Nnn \l__chemformula_lewis_elspec_types_prop { . } + { \__chemformula_lewis_elspec_single: } +\prop_put:Nnn \l__chemformula_lewis_elspec_types_prop { o } + { \__chemformula_lewis_elspec_empty: } +\prop_put:Nnn \l__chemformula_lewis_elspec_types_prop { pair } + { \__chemformula_lewis_elspec_pair_dots: } +\prop_put:Nnn \l__chemformula_lewis_elspec_types_prop { pair~(dotted) } + { \__chemformula_lewis_elspec_pair_dots: } +\prop_put:Nnn \l__chemformula_lewis_elspec_types_prop { pair~(line) } + { \__chemformula_lewis_elspec_pair_line: } +\prop_put:Nnn \l__chemformula_lewis_elspec_types_prop { single } + { \__chemformula_lewis_elspec_single: } +\prop_put:Nnn \l__chemformula_lewis_elspec_types_prop { empty } + { \__chemformula_lewis_elspec_empty: } + +\cs_new_protected:Npn \__chemformula_lewis_elspec_pair_dots: + { + \chemformula_draw:nn { fill } + { + (node~cs \c_chemformula_colon_tl + name = chlewis-\int_use:N \g__chemformula_lewis_int , + angle = \l__chemformula_elspec_angle_tl + ) + ++ + ( + \l__chemformula_elspec_angle_tl + \c_chemformula_colon_tl + \l__chemformula_elspec_radius_tl + ) + ++ + ( + \l__chemformula_elspec_angle_tl +90 + \c_chemformula_colon_tl + .5\l__chemformula_elspec_pair_distance_dim + ) + circle (\l__chemformula_radical_radius_dim) + ++ + ( + \l__chemformula_elspec_angle_tl -90 + \c_chemformula_colon_tl + \l__chemformula_elspec_pair_distance_dim + ) + circle (\l__chemformula_radical_radius_dim) + } + } + +\cs_new_protected:Npn \__chemformula_lewis_elspec_pair_line: + { + \chemformula_draw:nn + { line~width = \l__chemformula_elspec_pair_width_dim } + { + (node~cs \c_chemformula_colon_tl + name = chlewis-\int_use:N \g__chemformula_lewis_int , + angle = \l__chemformula_elspec_angle_tl + ) + ++ + ( + \l__chemformula_elspec_angle_tl + \c_chemformula_colon_tl + \l__chemformula_elspec_radius_tl + ) + ++ + ( + \l__chemformula_elspec_angle_tl +90 + \c_chemformula_colon_tl + .5\l__chemformula_elspec_pair_line_length_dim + ) + -- + ++ + ( + \l__chemformula_elspec_angle_tl -90 + \c_chemformula_colon_tl + \l__chemformula_elspec_pair_line_length_dim + ) + } + } + +\cs_new_protected:Npn \__chemformula_lewis_elspec_single: + { + \chemformula_draw:nn { fill } + { + (node~cs \c_chemformula_colon_tl + name = chlewis-\int_use:N \g__chemformula_lewis_int , + angle = \l__chemformula_elspec_angle_tl + ) + ++ + ( + \l__chemformula_elspec_angle_tl + \c_chemformula_colon_tl + \l__chemformula_elspec_radius_tl + ) + circle (\l__chemformula_radical_radius_dim) + } + } + +\cs_new_protected:Npn \__chemformula_lewis_elspec_empty: + { + \chemformula_draw:nn { } + { + (node~cs \c_chemformula_colon_tl + name = chlewis-\int_use:N \g__chemformula_lewis_int , + angle = \l__chemformula_elspec_angle_tl + ) + ++ + ( + \l__chemformula_elspec_angle_tl + \c_chemformula_colon_tl + \l__chemformula_elspec_radius_tl + ) + ++ + ( + \l__chemformula_elspec_angle_tl +90 + \c_chemformula_colon_tl + .5\l__chemformula_elspec_pair_line_length_dim + ) + coordinate (chlewis-tmp1) + ++ + ( + \l__chemformula_elspec_angle_tl -90 + \c_chemformula_colon_tl + \l__chemformula_elspec_pair_line_length_dim + ) + coordinate (chlewis-tmp2) + ++ + ( + \l__chemformula_elspec_angle_tl + \c_chemformula_colon_tl + .25\l__chemformula_elspec_pair_line_length_dim + ) + coordinate (chlewis-tmp3) + ++ + ( + \l__chemformula_elspec_angle_tl +90 + \c_chemformula_colon_tl + \l__chemformula_elspec_pair_line_length_dim + ) + coordinate (chlewis-tmp4) + (chlewis-tmp1) -- (chlewis-tmp2) -- + (chlewis-tmp3) -- (chlewis-tmp4) -- + cycle + } + } + +\NewDocumentCommand\chlewis{O{}mm} + { \chemformula_lewis:nnn { #1 } { #2 } { #3 } } + +% -------------------------------------------------------------------------- \NewDocumentCommand \setchemformula { m } { \keys_set:nn { chemmacros / chemformula } { #1 } } +\setchemformula{ + bond-style = {} , + arrow-style = {} +} + % -------------------------------------------------------------------------- % hyperref support \AfterPackage* { hyperref } @@ -2319,6 +2572,7 @@ \cs_set:Npn \charrow #1 { #1 } \cs_set:Npn \chname (#1)(#2) { #2~(#1) } \cs_set:Npn \ch #1 { #1 } + \cs_set:Npn \chlewis #1#2 { #2 } } } @@ -2431,13 +2685,16 @@ VERSION HISTORY reference - new option `tikz-external-disable' - new option `frac-math-cmd' +2013/10/24 - version 4.2 - \chemformula_font_inner: is only applied /once/ to + a formula, and at the beginning, fixes + https://bitbucket.org/cgnieder/chemmacros/issue/23 + - fixed wrong setting of the TikZ bond style + - new option `arrow-style' + - new command \chlewis % -------------------------------------------------------------------------- % TODO -- add \tikzexternaldisable and an option to disable it to \ch, \chcpd, - \charrow, and \bond +- https://bitbucket.org/cgnieder/chemmacros/issue/23/ - Addukte: Zahlen nach * und . automatisch erkennen? -- optionale Argumente von \\ nach außen weiterreichen? -- zu `frac-style' die Möglichkeit einbauen, statt \frac, \dfrac oder \tfrac zu - verwenden. +- optionale Argumente von \\ nach außen diff --git a/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty b/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty index 26cb76ea4ab..3b99d33eb9b 100644 --- a/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty +++ b/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty @@ -26,8 +26,8 @@ % - The Current Maintainer of this work is Clemens Niederberger. % -------------------------------------------------------------------------- \RequirePackage{ expl3 , xparse , l3keys2e } -\def\chemmacros@version{4.1} -\def\chemmacros@date{2013/08/24} +\def\chemmacros@version{4.2} +\def\chemmacros@date{2013/10/28} \ProvidesExplPackage {chemmacros} @@ -55,6 +55,8 @@ \cs_generate_variant:Nn \prop_put:Nnn { NV , NVx } \cs_generate_variant:Nn \prop_get:NnNTF { NV } \cs_generate_variant:Nn \tl_set_rescan:Nnn { NnV } +\cs_generate_variant:Nn \tl_if_eq:nnTF { V } +\cs_generate_variant:Nn \tl_const:cn { cV } % -------------------------------------------------------------------------- % load required packages @@ -127,6 +129,13 @@ { \msg_warning:nnxx { #1 } { #2 } { #3 } { #4 } } } +\cs_new_protected:Npn \chemmacros_msg:nn #1#2 + { + \bool_if:NTF \l_chemmacros_strict_bool + { \msg_error:nn { #1 } { #2 } } + { \msg_warning:nn { #1 } { #2 } } + } + \cs_new_protected:Npn \chemmacros_warning:nnxx #1#2#3#4 { \bool_if:NTF \l_chemmacros_strict_bool @@ -296,28 +305,35 @@ properly~ \msg_line_context: . } -\msg_new:nnnn { chemmacros } { DeclareChemState } +\msg_new:nnnn { chemmacros } { declare-state } { The~ state~ \exp_after:wN \token_to_str:N \cs:w #1 \cs_end: \c_space_tl already~ exists.~ You~ need~ to~ use~ \token_to_str:N \RenewChemState - \c_space_tl to~ alter~ it. + \c_space_tl to~ alter~ it~ \msg_line_context: . } { The~ state~ \exp_after:wN \token_to_str:N \cs:w #1 \cs_end: \c_space_tl already~ exists.~ You~ need~ to~ use~ \token_to_str:N \RenewChemState - \c_space_tl to~ alter~ it. + \c_space_tl to~ alter~ it~ \msg_line_context: . } -\msg_new:nnnn { chemmacros } { RenewChemState } +\msg_new:nnnn { chemmacros } { renew-state } { The~ state~ \exp_after:wN \token_to_str:N \cs:w #1 \cs_end: \c_space_tl isn't~ set~ up~ yet.~ You~ need~ to~ use~ \token_to_str:N - \DeclareChemState \c_space_tl to~ create~ it. + \DeclareChemState \c_space_tl to~ create~ it~ \msg_line_context: . } { The~ state~ \exp_after:wN \token_to_str:N \cs:w #1 \cs_end: \c_space_tl isn't~ set~ up~ yet.~ You~ need~ to~ use~ \token_to_str:N - \DeclareChemState \c_space_tl to~ create ~it. + \DeclareChemState \c_space_tl to~ create ~it~ \msg_line_context: . + } + +\msg_new:nnn { chemmacros } { state-syntax } + { + You're~ using~ a~ no~ longer~ recommended~ syntax~ to~ (re-)define~ a~ + state~ variable~ \msg_line_context: .~ This~ syntax~ may~ deprecate~ and~ + be~ removed~ in~ the~ future. } % declare an option as deprecated: @@ -614,6 +630,13 @@ \cs_new:Npn \chemmacros_remove_backslash:N #1 { \exp_after:wN \use_none:n \token_to_str:N #1 } +\prg_new_conditional:Npnn \chemmacros_if_is_cs:n #1 { T,F,TF } + { + \tl_set:Nx \l__chemmacros_tmpa_tl { \token_if_cs:NTF #1 { } { x } } + \tl_if_blank:VTF \l__chemmacros_tmpa_tl + { \prg_return_true: } + { \prg_return_false: } + } % detection and handling of bold face: \prg_new_conditional:Npnn \chemmacros_if_bold: { T,F,TF } @@ -909,10 +932,9 @@ \bool_if:NTF \l__chemmacros_chemfig_bool { \bool_if:NTF \l__chemmacros_elpair_dots_bool - { - { \chemmacros_inner_font: #1 \Lewis { 0: , { \vphantom { #1 } } } } - } - { { \chemmacros_inner_font: #1 \Lewis { 0 , \vphantom { #1 } } } } + { \chlewis { 0: } { #1 } } + { \chlewis { 0| } { #1 } } +% { { \chemmacros_inner_font: #1 \chlewis { 0=| } { \vphantom { #1 } } } } } { \chemmacros_msg:nnxx { chemmacros } { chemfig } { #1 } {} @@ -1038,10 +1060,11 @@ \protected\def\chemmacros@sconf#1% {% \begingroup - \tikz[baseline=(a.base),text height=1.5ex,text depth=.25ex] + \tikz[baseline,text height=1.5ex,text depth=.25ex] { - \node(a) {#1} ; - \draw[->,thick,rotate=90] ($(a.center)+(20:.8em)$) arc (20:340:.8em); + \node[anchor=base] (chemmacros@@Sconf) {#1} ; + \draw[->,thick,rotate=90] + ($(chemmacros@@Sconf.center)+(20:.8em)$) arc (20:340:.8em); }% \endgroup } @@ -1049,10 +1072,11 @@ \protected\def\chemmacros@rconf#1% {% \begingroup - \tikz[baseline=(a.base),text height=1.5ex,text depth=.25ex] + \tikz[baseline,text height=1.5ex,text depth=.25ex] { - \node(a) {#1} ; - \draw[<-,thick,rotate=90] ($(a.center)+(20:.8em)$) arc (20:340:.8em) ; + \node[anchor=base] (chemmacros@@Rconf) {#1} ; + \draw[<-,thick,rotate=90] + ($(chemmacros@@Rconf.center)+(20:.8em)$) arc (20:340:.8em) ; }% \endgroup } @@ -2337,18 +2361,10 @@ } \NewDocumentCommand \DeclareChemPhase { mom } - { - \IfNoValueTF { #2 } - { \chemmacros_declare_phase:Nn #1 { #3 } } - { \chemmacros_declare_phase:Nn #1 { #3 } } - } + { \chemmacros_declare_phase:Nn #1 { #3 } } \NewDocumentCommand \RenewChemPhase { mom } - { - \IfNoValueTF { #2 } - { \chemmacros_renew_phase:Nn #1 { #3 } } - { \chemmacros_renew_phase:Nn #1 { #3 } } - } + { \chemmacros_renew_phase:Nn #1 { #3 } } \cs_new_protected:Npn \__chemmacros_define_phase:Nn #1#2 { @@ -2620,10 +2636,13 @@ } } +\cs_new_protected:Npn \changestate + { \mathop{} \! \ChemDelta } + % -------------------------------------------------------------------------- % \State \tl_new:N \l__chemmacros_State_delta_tl -\tl_set:Nn \l__chemmacros_State_delta_tl { \Delta } +\tl_set:Nn \l__chemmacros_State_delta_tl { \changestate } \tl_new:N \l__chemmacros_State_exponent_tl \tl_set:Nn \l__chemmacros_State_exponent_tl { \standardstate } @@ -2667,8 +2686,7 @@ \cs_new_protected:Npn \chemmacros_state:nnn #1#2#3 { \group_begin: - \IfNoValueF { #1 } - { \keys_set:nn { chemmacros / state } { #1 } } + \keys_set:nn { chemmacros / state } { #1 } \ensuremath { \bool_if:NT \l__chemmacros_State_delta_bool @@ -2683,11 +2701,11 @@ } \group_end: } -\cs_generate_variant:Nn \chemmacros_state:nnn { fnn,xnn } +\cs_generate_variant:Nn \chemmacros_state:nnn { xnV } \bool_if:NF \l__chemmacros_version_one_bool { - \NewDocumentCommand \State { s o m G{} } + \NewDocumentCommand \State { s O{} m G{} } { \group_begin: \IfBooleanT { #1 } @@ -2711,7 +2729,7 @@ \tl_set:Nn \l__chemmacros_thermod_exponent_default_tl { \standardstate } \tl_new:N \l__chemmacros_thermod_delta_tl \tl_new:N \l__chemmacros_thermod_delta_default_tl -\tl_set:Nn \l__chemmacros_thermod_delta_default_tl { \Delta } +\tl_set:Nn \l__chemmacros_thermod_delta_default_tl { \changestate } \bool_new:N \l__chemmacros_renewstate_bool @@ -2738,25 +2756,31 @@ \l__chemmacros_thermod_delta_default_tl } -% \DeclareChemState[<keyval>]{<name>}{<symbol>}{<unit>} \bool_if:NF \l__chemmacros_version_one_bool { - \cs_new_protected:Npn \DeclareChemState + % \DeclareChemState{<name>}[<keyval>]{<symbol>}{<unit>} + \NewDocumentCommand \DeclareChemState { omO{}mm } { \bool_set_false:N \l__chemmacros_renewstate_bool \__chemmacros_setnewstate_reset: - \peek_meaning:NTF [ - { \__chemmacros_setnewstate:n } - { \__chemmacros_setnewstate_aux:nnn } + \IfNoValueTF { #1 } + { \chemmacros_define_state:nnnn { #3 } { #2 } { #4 } { #5 } } + { + \chemmacros_msg:nn { chemmacros } { state-syntax } + \chemmacros_define_state:nnnn { #1#3 } { #2 } { #4 } { #5 } + } } -% \RenewChemState[<keyval>]{<name>}{<symbol>}{<unit>} - \cs_new_protected:Npn \RenewChemState + % \RenewChemState{<name>}[<keyval>]{<symbol>}{<unit>} + \NewDocumentCommand \RenewChemState { omO{}mm } { \bool_set_true:N \l__chemmacros_renewstate_bool \__chemmacros_setnewstate_reset: - \peek_meaning:NTF [ - { \__chemmacros_setnewstate:n } - { \__chemmacros_setnewstate_aux:nnn } + \IfNoValueTF { #1 } + { \chemmacros_define_state:nnnn { #3 } { #2 } { #4 } { #5 } } + { + \chemmacros_msg:nn { chemmacros } { state-syntax } + \chemmacros_define_state:nnnn { #1#3 } { #2 } { #4 } { #5 } + } } \cs_set_protected:Npn \setnewstate { @@ -2777,27 +2801,32 @@ \tl_set:Nn \l__chemmacros_thermod_subscript_left_default_tl { true } \tl_clear:N \l__chemmacros_thermod_subscript_default_tl \tl_set:Nn \l__chemmacros_thermod_exponent_default_tl { \standardstate } - \tl_set:Nn \l__chemmacros_thermod_delta_default_tl { \Delta } + \tl_set:Nn \l__chemmacros_thermod_delta_default_tl { \changestate } } -\cs_new_protected:Npn \__chemmacros_setnewstate:n [#1] +\cs_new_protected:Npn \chemmacros_define_state:nnnn #1#2#3#4 { \keys_set:nn { chemmacros / setnewstate } { #1 } - \__chemmacros_setnewstate_aux:nnn + \chemmacros_if_is_cs:nTF { #2 } + { \__chemmacros_set_state:xnn { \cs_to_str:N #2 } { #3 } { #4 } } + { + \chemmacros_msg:nn { chemmacros } { state-syntax } + \__chemmacros_set_state:nnn { #2 } { #3 } { #4 } + } } -\cs_new_protected:Npn \__chemmacros_setnewstate_aux:nnn #1#2#3 +\cs_new_protected:Npn \__chemmacros_set_state:nnn #1#2#3 { \bool_if:NTF \l__chemmacros_renewstate_bool { \cs_if_exist:cF { #1 } - { \msg_error:nnx { chemmacros } { renewstate } { #1 } } + { \msg_error:nnx { chemmacros } { renew-state } { #1 } } \cs_undefine:c {chemmacros_ #1 _reset: } - \cs_undefine:c { l__chemmacros_ #1 _subscript_tl } - \cs_undefine:c { l__chemmacros_ #1 _exponent_tl } - \cs_undefine:c { l__chemmacros_ #1 _delta_tl } - \cs_undefine:c { l__chemmacros_ #1 _left_tl } - \cs_undefine:c { l__chemmacros_ #1 _unit_tl } + \cs_undefine:c { c__chemmacros_ #1 _subscript_tl } + \cs_undefine:c { c__chemmacros_ #1 _exponent_tl } + \cs_undefine:c { c__chemmacros_ #1 _delta_tl } + \cs_undefine:c { c__chemmacros_ #1 _left_tl } + \cs_undefine:c { c__chemmacros_ #1 _unit_tl } \cs_undefine:c { #1 } \cs_undefine:c { #1 _aux_i:n } \cs_undefine:c { #1 _aux_ii:n } @@ -2805,41 +2834,41 @@ } { \cs_if_exist:cT { #1 } - { \msg_error:nnx { chemmacros } { setnewstate } { #1 } } + { \msg_error:nnx { chemmacros } { declare-state } { #1 } } } \group_begin: - \exp_args:Nnf \tl_const:cn - { l__chemmacros_ #1 _subscript_tl } - { \tl_use:N \l__chemmacros_thermod_subscript_default_tl } - \exp_args:Nnf \tl_const:cn - { l__chemmacros_ #1 _exponent_tl } - { \tl_use:N \l__chemmacros_thermod_exponent_default_tl } - \exp_args:Nnf \tl_const:cn - { l__chemmacros_ #1 _delta_tl } - { \tl_use:N \l__chemmacros_thermod_delta_default_tl } - \exp_args:Nnf \tl_const:cn - { l__chemmacros_ #1 _left_tl } - { \tl_use:N \l__chemmacros_thermod_subscript_left_default_tl } + \tl_const:cV + { c__chemmacros_ #1 _subscript_tl } + \l__chemmacros_thermod_subscript_default_tl + \tl_const:cV + { c__chemmacros_ #1 _exponent_tl } + \l__chemmacros_thermod_exponent_default_tl + \tl_const:cV + { c__chemmacros_ #1 _delta_tl } + \l__chemmacros_thermod_delta_default_tl + \tl_const:cV + { c__chemmacros_ #1 _left_tl } + \l__chemmacros_thermod_subscript_left_default_tl \tl_const:cn - { l__chemmacros_ #1 _unit_tl } + { c__chemmacros_ #1 _unit_tl } { #3 } \cs_new_protected:cpn {chemmacros_ #1 _reset: } { \tl_set_eq:Nc \l__chemmacros_thermod_subscript_tl - { l__chemmacros_ #1 _subscript_tl } + { c__chemmacros_ #1 _subscript_tl } \tl_set_eq:Nc \l__chemmacros_thermod_exponent_tl - { l__chemmacros_ #1 _exponent_tl } + { c__chemmacros_ #1 _exponent_tl } \tl_set_eq:Nc \l__chemmacros_thermod_delta_tl - { l__chemmacros_ #1 _delta_tl } + { c__chemmacros_ #1 _delta_tl } \tl_set_eq:Nc \l__chemmacros_thermod_subscript_left_tl - { l__chemmacros_ #1 _left_tl } + { c__chemmacros_ #1 _left_tl } \tl_set_eq:Nc \l__chemmacros_thermod_unit_tl - { l__chemmacros_ #1 _unit_tl } + { c__chemmacros_ #1 _unit_tl } } \cs_new_protected:cpn { #1 } { @@ -2868,48 +2897,47 @@ { \ensuremath { - \exp_args:Nf \tl_if_eq:nnTF - { \tl_use:N \l__chemmacros_thermod_subscript_left_tl } { true } + \tl_if_eq:VnTF + \l__chemmacros_thermod_subscript_left_tl { true } { - \chemmacros_state:fnn + \chemmacros_state:xnV { subscript-left = true , exponent = - { \tl_use:N \l__chemmacros_thermod_exponent_tl } , + { \exp_not:V \l__chemmacros_thermod_exponent_tl } , delta = - { \tl_use:N \l__chemmacros_thermod_delta_tl } + { \exp_not:V \l__chemmacros_thermod_delta_tl } } { #2 } } { - \chemmacros_state:fnn + \chemmacros_state:xnV { subscript-left = false , exponent = - { \tl_use:N \l__chemmacros_thermod_exponent_tl } , + { \exp_not:V \l__chemmacros_thermod_exponent_tl } , delta = - { \tl_use:N \l__chemmacros_thermod_delta_tl } + { \exp_not:V \l__chemmacros_thermod_delta_tl } } { #2 } } - { \tl_use:N \l__chemmacros_thermod_subscript_tl } + \l__chemmacros_thermod_subscript_tl = - \exp_args:Nno \SI { ##1 } { \l__chemmacros_thermod_unit_tl } + \exp_args:NnV \SI { ##1 } \l__chemmacros_thermod_unit_tl } } \group_end: \ignorespaces } +\cs_generate_variant:Nn \__chemmacros_set_state:nnn { x } % predefined: \bool_if:NF \l__chemmacros_version_one_bool { - \DeclareChemState {Enthalpy} - {H} {\kilo\joule\per\mole} - \DeclareChemState [ delta=false, subscript-left=false ] {Entropy} + \DeclareChemState \Enthalpy {H} {\kilo\joule\per\mole} + \DeclareChemState \Entropy [ delta=false, subscript-left=false ] {S} {\joule\per\kelvin\per\mole} - \DeclareChemState {Gibbs} - {G} {\kilo\joule\per\mole} + \DeclareChemState \Gibbs {G} {\kilo\joule\per\mole} } % -------------------------------------------------------------------------- @@ -3732,7 +3760,7 @@ \NewDocumentCommand \chemsetup { o m } { \IfNoValueTF { #1 } - { \keys_set:nn { chemmacros } { #2 } } + { \keys_set:nn { chemmacros } { #2 } } { \bool_if:NTF \l__chemmacros_version_four_bool { @@ -3757,29 +3785,15 @@ { \pdfstringdefDisableCommands { - \cs_set:Npn \- { - }% myabe not a good idea... + % \cs_set:Npn \- { - } % maybe not a good idea... \cs_set:Npn \| { } \cs_set:Npn \pH { pH } \cs_set:Npn \pOH { pOH } \cs_set:Npn \iupac #1 { #1 } - % \cs_set:Npn \a { alpha } - % \cs_set:Npn \g { gamma } - % \cs_set:Npn \d { delta } - % \cs_set:Npn \m { mu } - % \cs_set:Npn \n { eta } - % \cs_set:Npn \w { omega } - % \cs_set:Npn \N { N } - % \cs_set:Npn \O { O } - % \cs_set:Npn \Sf { S } - % \cs_set:Npn \P { P } - % \cs_set:Npn \R { (R) } \cs_set:Npn \cip #1 { (#1) } - % \cs_set:Npn \E { (E) } - % \cs_set:Npn \Z { (Z) } \cs_set:Npn \cis { cis } \cs_set:Npn \trans { trans } \cs_set:Npn \tert { tert } - % \cs_set:Npn \D { D } \cs_set:Npn \ortho { o } \cs_set:Npn \meta { m } \cs_set:Npn \para { p } @@ -4020,6 +4034,14 @@ Version history see http://tex.stackexchange.com/q/128792/5049 and http://tex.stackexchange.com/q/118467/5049 for reference +2013/10/28 - version 4.2 - changed particles with electron pairs to use + \chlewis + - changed \Delta in thermodynamic state variables + into \ChemDelta for IUPAC compliance and defined + it as an operator + - change in the syntax of \DeclareChemState and + \RenewChemState and improved both internal + definition and user interface % --------------------------------------------------------------------------- % % TODO: |