diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/chemmacros/chemformula.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/chemmacros/chemformula.sty | 357 |
1 files changed, 307 insertions, 50 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 |