diff options
author | Karl Berry <karl@freefriends.org> | 2012-02-20 23:31:10 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2012-02-20 23:31:10 +0000 |
commit | 96948f06651bb4a4bb0174bb28d9d6d443ada4e4 (patch) | |
tree | bc564db764d728bbd08c5726e606e82e95acb5f8 /Master/texmf-dist/tex/latex/chemmacros/chemformula.sty | |
parent | 1c39817dbba19c5ef1e95912dabb3805085871ac (diff) |
chemmacros (20feb12)
git-svn-id: svn://tug.org/texlive/trunk@25448 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/chemmacros/chemformula.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/chemmacros/chemformula.sty | 618 |
1 files changed, 309 insertions, 309 deletions
diff --git a/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty b/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty index b5e74df2f90..1c7c0f75735 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/10 - % +% - 2012/02/19 - % % --------------------------------------------------------------------------- % % - https://bitbucket.org/cgnieder/chemmacros/ - % % - contact@mychemistry.eu - % @@ -28,7 +28,11 @@ % - The Current Maintainer of this work is Clemens Niederberger. - % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \RequirePackage{ expl3 } -\ProvidesExplPackage {chemformula} {2012/02/10} {3.0d} {typeset chemical compounds and reactions} +\ProvidesExplPackage + {chemformula} + {2012/02/19} + {3.1} + {typeset chemical compounds and reactions} %-----------------------------------------------------------------------------% % WARNING AND ERROR MESSAGES @@ -52,6 +56,23 @@ \token_to_str:N \usepackage \{ chemmacros \}. } +\msg_set:nnnn { chemformula } { declare-arrow } + { + The~arrow~type~ \tl_to_str:n { #1 } \c_space_tl is~already~defined. + } + { + You've~tried~to~define~the~arrow~type~\tl_to_str:n { #1 } \c_space_tl with + ~\token_to_str:N \DeclareChemArrow \c_space_tl but~it~already~exists. + ~Choose~another~name. + } + +\msg_set:nnnn { chemformula } { renew-arrow } + { The~arrow~type~ \tl_to_str:n { #1 } \c_space_tl is~not~defined. } + { + You've~tried~to~renew~the~arrow~type~\tl_to_str:n { #1 } ~but~it~doesn't~ + exist. + } + %-----------------------------------------------------------------------------% % test, if we are loaded without the `chemmacros' package \cs_if_exist:cF { ver@chemmacros.sty } @@ -78,7 +99,8 @@ % Some basic internal commands: \cs_new:Nn \chemformula_plus: { - \bool_if:nTF { \l_chemmacros_circled_bool && !\l_chemmacros_circled_formal_bool } + \bool_if:nTF + { \l_chemmacros_circled_bool && !\l_chemmacros_circled_formal_bool } { \bool_if:NTF \l_chemmacros_circled_chem_bool { \chemmacros_fplus: } @@ -93,7 +115,8 @@ \cs_new:Nn \chemformula_minus: { - \bool_if:nTF { \l_chemmacros_circled_bool && !\l_chemmacros_circled_formal_bool } + \bool_if:nTF + { \l_chemmacros_circled_bool && !\l_chemmacros_circled_formal_bool } { \bool_if:NTF \l_chemmacros_circled_chem_bool { \chemmacros_fminus: } @@ -264,267 +287,178 @@ \tl_new:N \l_chemformula_arrow_label_style_tl \tl_set:Nn \l_chemformula_arrow_label_style_tl { \footnotesize } -% <-> -\NewDocumentCommand \chemformula_arrow_mesomeric:w { O{}O{} } +\prop_new:N \l_chemformula_arrows_code_prop +\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 + +% read optional arguments +\cs_new_nopar:Npn \l_chemformula_arrow_read_args:w { - \chemformula_determine_arrow_length:nn { #1 } { #2 } - \chemformula_tikz:nf { inner~sep=0, baseline=(chemformula_arrow_start.base) } - { - \chemformula_draw:xn - { \l_chemformula_arrow_head_tl-\l_chemformula_arrow_head_tl , \l_chemformula_arrow_style_tl } - { - coordinate (chemformula_arrow_start) (0,0) - ++ (\l_chemformula_compound_sep_dim,.3432em) ++ (0,\l_chemformula_arrow_yshift_dim) -- ++ - ( \dim_use:N \l_chemformula_arrow_length_dim , 0) - node - [ - pos=.5, - above=\l_chemformula_arrow_label_offset_dim, - font=\l_chemformula_arrow_label_style_tl, - butt~cap-butt~cap - ] { #1 } - node - [ - pos=.5, - below=\l_chemformula_arrow_label_offset_dim, - font=\l_chemformula_arrow_label_style_tl, - butt~cap-butt~cap - ] { #2 } - } - \chemformula_draw:nn {} - { - (\l_chemformula_compound_sep_dim,.3432em) ++ (0,\l_chemformula_arrow_yshift_dim) ++ - ( \l_chemformula_compound_sep_dim + \dim_use:N \l_chemformula_arrow_length_dim , 0) - } - } + \peek_meaning:NTF [ + { \l_chemformula_arrow_read_args_aux_i:w } + { \l_chemformula_arrow_read_args_aux_iii: } } -% -> -\NewDocumentCommand \chemformula_arrow_right:w { O{}O{} } +\cs_new_nopar:Npn \l_chemformula_arrow_read_args_aux_i:w [#1] { - \chemformula_determine_arrow_length:nn { #1 } { #2 } - \chemformula_tikz:nn { inner~sep=0, baseline=(chemformula_arrow_start.base) } - { - \chemformula_draw:xn { -\l_chemformula_arrow_head_tl , \l_chemformula_arrow_style_tl } - { - coordinate (chemformula_arrow_start) (0,0) - ++ (\l_chemformula_compound_sep_dim,.3432em) ++ (0,\l_chemformula_arrow_yshift_dim) -- ++ - ( \dim_use:N \l_chemformula_arrow_length_dim , 0) - node - [ - pos=.5, - above=\l_chemformula_arrow_label_offset_dim, - font=\l_chemformula_arrow_label_style_tl, - butt~cap-butt~cap - ] { #1 } - node - [ - pos=.5, - below=\l_chemformula_arrow_label_offset_dim, - font=\l_chemformula_arrow_label_style_tl, - butt~cap-butt~cap - ] { #2 } - } - \chemformula_draw:nn {} - { - (\l_chemformula_compound_sep_dim,.3432em) ++ (0,\l_chemformula_arrow_yshift_dim) ++ - ( \l_chemformula_compound_sep_dim + \dim_use:N \l_chemformula_arrow_length_dim , 0) - } - } + \tl_set:Nn \l_chemformula_arrow_arg_i_tl { #1 } + \peek_meaning:NTF [ + { \l_chemformula_arrow_read_args_aux_ii:w } + { \l_chemformula_arrow_read_args_aux_iii: } } -% <- -\NewDocumentCommand \chemformula_arrow_left:w { O{}O{} } +\cs_new_nopar:Npn \l_chemformula_arrow_read_args_aux_ii:w [#1] { - \chemformula_determine_arrow_length:nn { #1 } { #2 } - \chemformula_tikz:nn { inner~sep=0, baseline=(chemformula_arrow_start.base) } - { - \chemformula_draw:xn { \l_chemformula_arrow_head_tl- , \l_chemformula_arrow_style_tl } - { - coordinate (chemformula_arrow_start) (0,0) - ++ (\l_chemformula_compound_sep_dim,.3432em) ++ (0,\l_chemformula_arrow_yshift_dim) -- ++ - ( \dim_use:N \l_chemformula_arrow_length_dim , 0) - node - [ - pos=.5, - above=\l_chemformula_arrow_label_offset_dim, - font=\l_chemformula_arrow_label_style_tl, - butt~cap-butt~cap - ] { #1 } - node - [ - pos=.5, - below=\l_chemformula_arrow_label_offset_dim, - font=\l_chemformula_arrow_label_style_tl, - butt~cap-butt~cap - ] { #2 } - } - \chemformula_draw:nn {} - { - (\l_chemformula_compound_sep_dim,.3432em) ++ (0,\l_chemformula_arrow_yshift_dim)++ - ( \l_chemformula_compound_sep_dim + \dim_use:N \l_chemformula_arrow_length_dim , 0) - } - } + \tl_set:Nn \l_chemformula_arrow_arg_ii_tl { #1 } + \l_chemformula_arrow_read_args_aux_iii: } -% <=> -\NewDocumentCommand \chemformula_arrow_equilibrium:w { O{}O{} } +\cs_new_nopar:Npn \l_chemformula_arrow_read_args_aux_iii: { - \chemformula_determine_arrow_length:nn { #1 } { #2 } - \chemformula_tikz:nn { inner~sep=0, baseline=(chemformula_arrow_start.base) } - { - \chemformula_draw:xn { -left~\l_chemformula_arrow_head_tl , \l_chemformula_arrow_style_tl } - { - coordinate (chemformula_arrow_start) (0,0) - ++ (\l_chemformula_compound_sep_dim,.429em) ++ (0,\l_chemformula_arrow_yshift_dim) -- ++ - ( \dim_use:N \l_chemformula_arrow_length_dim , 0) - node - [ - pos=.5, - above=\l_chemformula_arrow_label_offset_dim, - font=\l_chemformula_arrow_label_style_tl, - butt~cap-butt~cap - ] { #1 } - } - \chemformula_draw:xn { left~\l_chemformula_arrow_head_tl- , \l_chemformula_arrow_style_tl } - { - (chemformula_arrow_start) ++ - (\l_chemformula_compound_sep_dim,.2574em) ++ (0,\l_chemformula_arrow_yshift_dim) -- ++ - ( \dim_use:N \l_chemformula_arrow_length_dim , 0) - node - [ - pos=.5, - below=\l_chemformula_arrow_label_offset_dim, - font=\l_chemformula_arrow_label_style_tl, - butt~cap-butt~cap - ] { #2 } - } - \chemformula_draw:nn {} - { - (\l_chemformula_compound_sep_dim,.3432em) ++ (0,\l_chemformula_arrow_yshift_dim) ++ - ( \l_chemformula_compound_sep_dim + \dim_use:N \l_chemformula_arrow_length_dim , 0) - } - } + % now we have both arguments do the actual drawing: + \prop_get:NVN \l_chemformula_arrows_code_prop + \l_chemformula_arrow_type_tl + \l_tmpb_tl + \chemformula_arrow_draw:V \l_tmpb_tl } -% <=>> -\NewDocumentCommand \chemformula_arrow_equilibrium_right:w { O{}O{} } +% get arrows (for the use in \ch to replace the symbol) +% #1: symbol +\cs_new_nopar:Npn \chemformula_arrows_get:n #1 { - \chemformula_determine_arrow_length:nn { #1 } { #2 } - \chemformula_tikz:nn { inner~sep=0, baseline=(chemformula_arrow_start.base) } - { - \chemformula_draw:xn { -left~\l_chemformula_arrow_head_tl , \l_chemformula_arrow_style_tl } - { - coordinate (chemformula_arrow_start) (0,0) - ++ (\l_chemformula_compound_sep_dim,.429em) ++ (0,\dim_use:N \l_chemformula_arrow_yshift_dim) -- ++ - ( \dim_use:N \l_chemformula_arrow_length_dim , 0) - node - [ - pos=.5, - above=\l_chemformula_arrow_label_offset_dim, - font=\l_chemformula_arrow_label_style_tl, - butt~cap-butt~cap - ] { #1 } - } - \chemformula_draw:xn { left~\l_chemformula_arrow_head_tl- , \l_chemformula_arrow_style_tl } - { - (chemformula_arrow_start) ++ - (\l_chemformula_compound_sep_dim + \l_chemformula_arrow_shortage_dim,.2574em) ++ (0,\l_chemformula_arrow_yshift_dim) -- ++ - ( \dim_use:N \l_chemformula_arrow_length_dim -2*\l_chemformula_arrow_shortage_dim , 0) - node - [ - pos=.5, - below=\l_chemformula_arrow_label_offset_dim, - font=\l_chemformula_arrow_label_style_tl, - butt~cap-butt~cap - ] { #2 } - } - \chemformula_draw:nn {} - { - (\l_chemformula_compound_sep_dim,.3432em) ++ (0,\l_chemformula_arrow_yshift_dim) ++ - ( \l_chemformula_compound_sep_dim + \dim_use:N \l_chemformula_arrow_length_dim , 0) - } - } + % first clear the arguments + \tl_clear:N \l_chemformula_arrow_arg_i_tl + \tl_clear:N \l_chemformula_arrow_arg_ii_tl + % then get the arrow type + \tl_set:Nn \l_chemformula_arrow_type_tl { #1 } + \l_chemformula_arrow_read_args:w } -% <<=> -\NewDocumentCommand \chemformula_arrow_equilibrium_left:w { O{}O{} } +% draw the arrows +\cs_new_nopar:Npn \chemformula_arrow_draw:n #1 { - \chemformula_determine_arrow_length:nn { #1 } { #2 } - \chemformula_tikz:nn { inner~sep=0, baseline=(chemformula_arrow_start.base) } + % prepare arrow code for drawing: + % TODO: flexible Pfeilspitzen, TikZ-Keys ermöglichen + \tl_set_rescan:Nnn \l_tmpc_tl { \char_set_catcode_letter:N \_ } { #1 } + % determine length of the arrow + \chemformula_determine_arrow_length:oo + { \l_chemformula_arrow_arg_i_tl } + { \l_chemformula_arrow_arg_ii_tl } + \chemformula_tikz:nf + { inner~sep=0, baseline=(chemformula_arrow_start.base) } { - \chemformula_draw:xn { -left~\l_chemformula_arrow_head_tl , \l_chemformula_arrow_style_tl } + % the coordinates + \chemformula_draw:xn + { \l_chemformula_arrow_style_tl } { coordinate (chemformula_arrow_start) (0,0) - ++ (\l_chemformula_compound_sep_dim + \l_chemformula_arrow_shortage_dim,.429em) ++ (0,\l_chemformula_arrow_yshift_dim) -- ++ - ( \dim_use:N \l_chemformula_arrow_length_dim - 2*\l_chemformula_arrow_shortage_dim , 0) + ++ (\l_chemformula_compound_sep_dim,.3432em) + ++ (0,\l_chemformula_arrow_yshift_dim) + coordinate (cf_arrow_start) + ++ ( .5 * \dim_use:N \l_chemformula_arrow_length_dim , 0) + coordinate (cf_arrow_mid) + ++ ( .5 * \dim_use:N \l_chemformula_arrow_length_dim , 0) + coordinate (cf_arrow_end) + ++ (\l_chemformula_compound_sep_dim,0) + (cf_arrow_start) ++ (\l_chemformula_arrow_shortage_dim,0) + coordinate (cf_arrow_mid_start) + (cf_arrow_end) ++ (-\l_chemformula_arrow_shortage_dim , 0) + coordinate (cf_arrow_mid_end) + } + % the arrow labels: + \draw node [ - pos=.5, above=\l_chemformula_arrow_label_offset_dim, font=\l_chemformula_arrow_label_style_tl, butt~cap-butt~cap - ] { #1 } - } - \chemformula_draw:xn { left~\l_chemformula_arrow_head_tl- , \l_chemformula_arrow_style_tl } - { - (chemformula_arrow_start) ++ (\l_chemformula_compound_sep_dim,.2574em) ++ (0,\l_chemformula_arrow_yshift_dim) -- ++ - ( \dim_use:N \l_chemformula_arrow_length_dim , 0) + ] at (cf_arrow_mid) { \l_chemformula_arrow_arg_i_tl } node [ - pos=.5, below=\l_chemformula_arrow_label_offset_dim, font=\l_chemformula_arrow_label_style_tl, butt~cap-butt~cap - ] { #2 } - } - \chemformula_draw:nn {} - { - (\l_chemformula_compound_sep_dim,.3432em) ++ (0,\l_chemformula_arrow_yshift_dim) ++ - ( \l_chemformula_compound_sep_dim + \dim_use:N \l_chemformula_arrow_length_dim , 0) - } + ] at (cf_arrow_mid) { \l_chemformula_arrow_arg_ii_tl } + ; + \tl_use:N \l_tmpc_tl } } +\cs_generate_variant:Nn \chemformula_arrow_draw:n { V } +\cs_generate_variant:Nn \chemformula_determine_arrow_length:nn { oo } -% <> -\NewDocumentCommand \chemformula_arrow_both:w { O{}O{} } +% commands to declare arrows (can also be used by users): +% #1: symbol, #2: code +\NewDocumentCommand \DeclareChemArrow { mm } { - \chemformula_determine_arrow_length:nn { #1 } { #2 } - \chemformula_tikz:nn { inner~sep=0, baseline=(chemformula_arrow_start.base) } - { - \chemformula_draw:xn { -\l_chemformula_arrow_head_tl , \l_chemformula_arrow_style_tl } - { - coordinate (chemformula_arrow_start) (0,0) - ++ (\l_chemformula_compound_sep_dim,.441em) ++ (0,\l_chemformula_arrow_yshift_dim) -- ++ - ( \dim_use:N \l_chemformula_arrow_length_dim , 0) - node - [ - pos=.5, - above=\l_chemformula_arrow_label_offset_dim, - font=\l_chemformula_arrow_label_style_tl, - butt~cap-butt~cap - ] { #1 } - } - \chemformula_draw:xn { \l_chemformula_arrow_head_tl- , \l_chemformula_arrow_style_tl } - { - (chemformula_arrow_start) ++ - (\l_chemformula_compound_sep_dim,.2454em) ++ (0,\l_chemformula_arrow_yshift_dim) -- ++ - ( \dim_use:N \l_chemformula_arrow_length_dim , 0) - node - [ - pos=.5, - below=\l_chemformula_arrow_label_offset_dim, - font=\l_chemformula_arrow_label_style_tl, - butt~cap-butt~cap - ] { #2 } - } - \chemformula_draw:nn {} - { - (\l_chemformula_compound_sep_dim,.3432em) ++ (0,\l_chemformula_arrow_yshift_dim) ++ - ( \l_chemformula_compound_sep_dim + \dim_use:N \l_chemformula_arrow_length_dim , 0) - } - } + \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 } } } + +\NewDocumentCommand \RenewChemArrow { mm } + { + \prop_if_in:NnTF \l_chemformula_arrows_code_prop { #1 } + { \prop_put:Nnn \l_chemformula_arrows_code_prop { #1 } { #2 } } + { \chemmacros_msg:nnxx { chemformula } { renew-arrow } { #1 } {} } + } + +\NewDocumentCommand \ShowChemArrow { m } + { + \prop_get:NnN \l_chemformula_arrows_code_prop { #1 } \l_tmpa_tl + \tl_to_str:N \l_tmpa_tl + } + +% declare arrows: +\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[-cf] ([yshift=.2ex]cf_arrow_start) -- ([yshift=.2ex]cf_arrow_end) ; + \draw[cf-,] ([yshift=-.2ex]cf_arrow_start) -- ([yshift=-.2ex]cf_arrow_end) ; + } +\DeclareChemArrow { <o> } + { + \draw[cf-cf] (cf_arrow_start) -- (cf_arrow_end) ; + \draw + (cf_arrow_mid) .. controls ++(-.9ex,-1.5ex) and + ++(.9ex,-1.5ex) .. (cf_arrow_mid) ; + } +\DeclareChemArrow { <=>> } + { + \draw[-left~cf] + ([yshift=.15ex]cf_arrow_start) -- ([yshift=.15ex]cf_arrow_end) ; + \draw[left~cf-] + ([yshift=-.15ex]cf_arrow_mid_start) -- ([yshift=-.15ex]cf_arrow_mid_end) ; + } +\DeclareChemArrow {<<=>} + { + \draw[-left~cf] + ([yshift=.15ex]cf_arrow_mid_start) -- ([yshift=.15ex]cf_arrow_mid_end) ; + \draw[left~cf-] + ([yshift=-.15ex]cf_arrow_start) -- ([yshift=-.15ex]cf_arrow_end) ; + } +\DeclareChemArrow { <=> } + { + \draw[-left~cf] + ([yshift=.15ex]cf_arrow_start) -- ([yshift=.15ex]cf_arrow_end) ; + \draw[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) ; + } +\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) ; + } + %-----------------------------------------------------------------------------% % arrow customization \keys_define:nn { chemmacros / chemformula } @@ -534,7 +468,7 @@ arrow-ratio .tl_set:N = \l_chemformula_arrow_ratio_tl , label-offset .dim_set:N = \l_chemformula_arrow_label_offset_dim , compound-sep .dim_set:N = \l_chemformula_compound_sep_dim , - arrow-tips .tl_set:N = \l_chemformula_arrow_head_tl , +% arrow-tips .tl_set:N = \l_chemformula_arrow_head_tl , arrow-style .tl_set:N = \l_chemformula_arrow_style_tl , label-style .tl_set:N = \l_chemformula_arrow_label_style_tl } @@ -544,9 +478,15 @@ \NewDocumentCommand \chemformula_ch_aux_iii:w { > { \SplitList { ~ } } m } { \group_begin: + \cs_set_eq:NN \xspace \scan_stop: + \cs_set_nopar:Npn \[ { [ } + \cs_set_nopar:Npn \] { ] } \bool_set_true:N \l_chemformula_inside_ch_bool \tl_if_blank:oF { \g_chemformula_options_tl } - { \keys_set:no { chemmacros / chemformula } { \g_chemformula_options_tl } } + { + \keys_set:no { chemmacros / chemformula } + { \g_chemformula_options_tl } + } \tl_map_function:nN { #1 } \chemformula_input:n \chemformula_generate_arrows:N \l_chemformula_input_tl \chemformula_generate_name:N \l_chemformula_output_tl @@ -560,7 +500,6 @@ \cs_new:Nn \chemformula_ch:nn { \group_align_safe_begin: - \cs_set:Npn \xspace {} \leavevmode \IfNoValueTF { #1 } { \tl_gclear:N \g_chemformula_options_tl } @@ -583,7 +522,8 @@ \cs_new:Npn \chemformula_ch_aux_ii:w #1 & #2 \q_stop { - \tl_gput_right:Nn \g_chemformula_output_tl { \chemformula_ch_aux_iii:w { #1 } } + \tl_gput_right:Nn \g_chemformula_output_tl + { \chemformula_ch_aux_iii:w { #1 } } \quark_if_no_value:nF { #2 } { \tl_gput_right:Nn \g_chemformula_output_tl { & } @@ -610,43 +550,49 @@ %-----------------------------------------------------------------------------% % arrow generation & detection -\cs_new:Npn \chemformula_generate_arrows:n #1 +% make sure to look for <->, <=>> and <<=> first! +\cs_set:Npn \chemformula_generate_arrows:n #1 { \tl_set:No \l_tmpa_tl { #1 } - \tl_if_in:onT { \l_tmpa_tl } { <-> } - { \tl_replace_all:Nnn \l_tmpa_tl { <-> } { \chemformula_arrow_mesomeric:w } } - \tl_if_in:onT { \l_tmpa_tl } { -> } - { \tl_replace_all:Nnn \l_tmpa_tl { -> } { \chemformula_arrow_right:w } } - \tl_if_in:onT { \l_tmpa_tl } { <- } - { \tl_replace_all:Nnn \l_tmpa_tl { <- } { \chemformula_arrow_left:w } } - \tl_if_in:onT { \l_tmpa_tl } { glgw_l } - { \tl_replace_all:Nnn \l_tmpa_tl { glgw_l } { \chemformula_arrow_equilibrium_left:w } } - \tl_if_in:onT { \l_tmpa_tl } { <=>> } - { \tl_replace_all:Nnn \l_tmpa_tl { <=>> } { \chemformula_arrow_equilibrium_right:w } } - \tl_if_in:onT { \l_tmpa_tl } { <=> } - { \tl_replace_all:Nnn \l_tmpa_tl { <=> } { \chemformula_arrow_equilibrium:w } } - \tl_if_in:onT { \l_tmpa_tl } { <> } - { \tl_replace_all:Nnn \l_tmpa_tl { <> } { \chemformula_arrow_both:w } } + \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 + { + \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 } } + } + \bool_set_false:N \l_chemformula_arrow_already_replaced_bool + } \cs_generate_variant:Nn \chemformula_generate_arrows:n { N } \cs_new:Npn \chemformula_detect_arrows:n #1 { \bool_set_false:N \l_chemformula_is_arrow_bool - \tl_set:No \l_tmpa_tl { #1 } - \tl_if_in:onT { \l_tmpa_tl } { <-> } - { \bool_set_true:N \l_chemformula_is_arrow_bool } - \tl_if_in:onT { \l_tmpa_tl } { -> } - { \bool_set_true:N \l_chemformula_is_arrow_bool } - \tl_if_in:onT { \l_tmpa_tl } { <- } - { \bool_set_true:N \l_chemformula_is_arrow_bool } - \tl_if_in:onT { \l_tmpa_tl } { <=>> } - { \bool_set_true:N \l_chemformula_is_arrow_bool } - \tl_if_in:onT { \l_tmpa_tl } { glgw_l } - { \bool_set_true:N \l_chemformula_is_arrow_bool } - \tl_if_in:onT { \l_tmpa_tl } { <=> } - { \bool_set_true:N \l_chemformula_is_arrow_bool } + \prop_map_inline:Nn \l_chemformula_arrows_code_prop + { + \tl_set_rescan:Nnn \l_tmpa_tl {} { ##1 } + \tl_if_in:noT { #1 } { \l_tmpa_tl } + { \bool_set_true:N \l_chemformula_is_arrow_bool } + } } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -654,7 +600,7 @@ \dim_new:N \l_chemformula_name_dim \cs_new:Npn \chemformula_name_cmpd:w - { \peek_meaning:NTF { ( } { \chemformula_name_cmpd_aux:w } { ! } } + { \peek_meaning:NTF ( { \chemformula_name_cmpd_aux:w } { ! } } \cs_new:Npn \chemformula_name_cmpd_aux:w (#1)(#2) { @@ -816,16 +762,26 @@ % behaviour in a charge \prop_new:N \l_chemformula_charge_prop -\prop_put:Nnn \l_chemformula_charge_prop { 0 } { \chemformula_charge_style:n { 0 } } -\prop_put:Nnn \l_chemformula_charge_prop { 1 } { \chemformula_charge_style:n { 1 } } -\prop_put:Nnn \l_chemformula_charge_prop { 2 } { \chemformula_charge_style:n { 2 } } -\prop_put:Nnn \l_chemformula_charge_prop { 3 } { \chemformula_charge_style:n { 3 } } -\prop_put:Nnn \l_chemformula_charge_prop { 4 } { \chemformula_charge_style:n { 4 } } -\prop_put:Nnn \l_chemformula_charge_prop { 5 } { \chemformula_charge_style:n { 5 } } -\prop_put:Nnn \l_chemformula_charge_prop { 6 } { \chemformula_charge_style:n { 6 } } -\prop_put:Nnn \l_chemformula_charge_prop { 7 } { \chemformula_charge_style:n { 7 } } -\prop_put:Nnn \l_chemformula_charge_prop { 8 } { \chemformula_charge_style:n { 8 } } -\prop_put:Nnn \l_chemformula_charge_prop { 9 } { \chemformula_charge_style:n { 9 } } +\prop_put:Nnn \l_chemformula_charge_prop { 0 } + { \chemformula_charge_style:n { 0 } } +\prop_put:Nnn \l_chemformula_charge_prop { 1 } + { \chemformula_charge_style:n { 1 } } +\prop_put:Nnn \l_chemformula_charge_prop { 2 } + { \chemformula_charge_style:n { 2 } } +\prop_put:Nnn \l_chemformula_charge_prop { 3 } + { \chemformula_charge_style:n { 3 } } +\prop_put:Nnn \l_chemformula_charge_prop { 4 } + { \chemformula_charge_style:n { 4 } } +\prop_put:Nnn \l_chemformula_charge_prop { 5 } + { \chemformula_charge_style:n { 5 } } +\prop_put:Nnn \l_chemformula_charge_prop { 6 } + { \chemformula_charge_style:n { 6 } } +\prop_put:Nnn \l_chemformula_charge_prop { 7 } + { \chemformula_charge_style:n { 7 } } +\prop_put:Nnn \l_chemformula_charge_prop { 8 } + { \chemformula_charge_style:n { 8 } } +\prop_put:Nnn \l_chemformula_charge_prop { 9 } + { \chemformula_charge_style:n { 9 } } \prop_put:Nnn \l_chemformula_charge_prop { + } { \chemformula_plus: } \prop_put:Nnn \l_chemformula_charge_prop { - } { \chemformula_minus: } \prop_put:Nnn \l_chemformula_charge_prop { . } { \chemformula_radical: } @@ -842,8 +798,10 @@ \prop_put:Nnn \l_chemformula_stoich_prop { 7 } { 7 } \prop_put:Nnn \l_chemformula_stoich_prop { 8 } { 8 } \prop_put:Nnn \l_chemformula_stoich_prop { 9 } { 9 } -\prop_put:Nnn \l_chemformula_stoich_prop { . } { { \l_chemformula_decimal_output_tl } } -\prop_put:Nnn \l_chemformula_stoich_prop { , } { { \l_chemformula_decimal_output_tl } } +\prop_put:Nnn \l_chemformula_stoich_prop { . } + { { \l_chemformula_decimal_output_tl } } +\prop_put:Nnn \l_chemformula_stoich_prop { , } + { { \l_chemformula_decimal_output_tl } } \prop_put:Nnn \l_chemformula_stoich_prop { / } { / } \prop_put:Nnn \l_chemformula_stoich_prop { _ } { _ } @@ -868,9 +826,14 @@ { \chemformula_tikz:nn { inner~sep=0, outer~sep=0 } { - \draw node[draw=none,minimum~height=1em,minimum~width=0] (chemformula-double-bond) at (0,0) {} ; - \draw[butt~cap-butt~cap] (chemformula-double-bond) ++ (0,-.0858em) -- ++( \l_chemformula_bond_dim ,0) ; - \draw[butt~cap-butt~cap] (chemformula-double-bond) ++ (0,-.2574em) -- ++( \l_chemformula_bond_dim ,0) ; + \draw node[draw=none,minimum~height=1em,minimum~width=0] + (chemformula-double-bond) at (0,0) {} ; + \draw[butt~cap-butt~cap] + (chemformula-double-bond) ++ (0,-.0858em) -- ++ + (\l_chemformula_bond_dim ,0) ; + \draw[butt~cap-butt~cap] + (chemformula-double-bond) ++ (0,-.2574em) -- ++ + (\l_chemformula_bond_dim ,0) ; } } @@ -878,10 +841,17 @@ { \chemformula_tikz:nn { inner~sep=0, outer~sep=0 } { - \draw node[draw=none,minimum~height=1em,minimum~width=0] (chemformula-triple-bond) at (0,0) {} ; - \draw[butt~cap-butt~cap] (chemformula-triple-bond) ++ (0,-.0429em) -- ++( \l_chemformula_bond_dim ,0) ; - \draw[butt~cap-butt~cap] (chemformula-triple-bond) ++ (0,-.1716em) -- ++( \l_chemformula_bond_dim ,0) ; - \draw[butt~cap-butt~cap](chemformula-triple-bond) ++ (0,-.3003em) -- ++( \l_chemformula_bond_dim ,0) ; + \draw node[draw=none,minimum~height=1em,minimum~width=0] + (chemformula-triple-bond) at (0,0) {} ; + \draw[butt~cap-butt~cap] + (chemformula-triple-bond) ++ (0,-.0429em) -- ++ + (\l_chemformula_bond_dim ,0) ; + \draw[butt~cap-butt~cap] + (chemformula-triple-bond) ++ (0,-.1716em) -- ++ + (\l_chemformula_bond_dim ,0) ; + \draw[butt~cap-butt~cap] + (chemformula-triple-bond) ++ (0,-.3003em) -- ++ + (\l_chemformula_bond_dim ,0) ; } } @@ -906,8 +876,10 @@ \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_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 @@ -924,8 +896,14 @@ } \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 } } $ } } - { \exp_args:NNo \hbox_set:Nn \l_tmpb_box { $ ^ { \chemformula_charge_style:n { \l_tmpc_tl } } $ } } + { + \exp_args:NNo \hbox_set:Nn \l_tmpb_box + { $ ^ { \chemformula_charge_style:n { \l_tmpa_tl } } $ } + } + { + \exp_args:NNo \hbox_set:Nn \l_tmpb_box + { $ ^ { \chemformula_charge_style: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 @@ -966,17 +944,26 @@ \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_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_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_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 } } $ } } + { + \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 } \box_clear:N \l_tmpa_box @@ -1089,7 +1076,6 @@ { \tl_set_rescan:Nnn \l_chemformula_tmpa_tl { -% \char_set_catcode_letter:N \_ \char_set_catcode_letter:N \{ \char_set_catcode_letter:N \} \char_set_catcode_letter:N \\ @@ -1099,12 +1085,10 @@ \chemformula_input_escape_text:o { \l_chemformula_tmpa_tl } \chemformula_input_escape_math:n { #1 } \chemformula_input_stoich:n { #1 } - % need to take care of <<=> arrow - \tl_if_in:onT { \l_chemformula_tmpa_tl } { <<=> } - { \tl_replace_all:Nnn \l_chemformula_tmpa_tl { <<=> } { glgw_l } } \chemformula_clean_chem_macros:o { \l_chemformula_tmpa_tl } - \chemformula_input_cmpd:oN { \l_chemformula_tmpa_tl } \l_chemformula_input_tl - \chemformula_input_arrow:o { \l_chemformula_tmpa_tl } + \chemformula_input_cmpd:oN + { \l_chemformula_tmpa_tl } \l_chemformula_input_tl + \chemformula_input_arrow:n { #1 } \chemformula_input_name:n { #1 } \chemformula_input_plus:n { #1 } \chemformula_input_up:n { #1 } @@ -1133,7 +1117,8 @@ \tl_set_rescan:Nno \l_chemformula_stoich_tl { \ExplSyntaxOn } { \l_chemformula_stoich_tl } - \exp_args:No \chemformula_parse_stoich:n { \l_chemformula_stoich_tl } + \exp_args:No \chemformula_parse_stoich:n + { \l_chemformula_stoich_tl } } } { \tl_clear:N \l_chemformula_stoich_tl } @@ -1159,7 +1144,10 @@ } \cs_new:Npn \chemformula_parse_stoich_frac:w #1/#2 \q_nil - { \tl_put_right:Nn \l_chemformula_input_tl { \chemformula_frac:nn { #1 } { #2 } } } + { + \tl_put_right:Nn \l_chemformula_input_tl + { \chemformula_frac:nn { #1 } { #2 } } + } \cs_new:Npn \chemformula_parse_stoich_misc_frac:w #1_#2/#3 \q_nil { @@ -1218,7 +1206,8 @@ } } { - \tl_put_right:Nn #2 { \skip_horizontal:N \l_chemformula_stoich_space_dim } + \tl_put_right:Nn #2 + { \skip_horizontal:N \l_chemformula_stoich_space_dim } \tl_clear:N \l_chemformula_stoich_tl } } @@ -1269,14 +1258,21 @@ \exp_args:Nx \tl_if_in:nnT { \tl_head:V \l_tmpa_tl } { ^ } { \bool_set_true:N \l_chemformula_first_is_sup_bool } \tl_if_in:VnT \l_tmpa_tl { ^ } - { \tl_replace_all:Nnn \l_tmpa_tl { ^ } { \chemformula_chief_supscript:n } } + { + \tl_replace_all:Nnn \l_tmpa_tl { ^ } + { \chemformula_chief_supscript:n } + } \tl_if_in:VnT \l_tmpa_tl { _ } - { \tl_replace_all:Nnn \l_tmpa_tl { _ } { \chemformula_chief_subscript:n } } + { + \tl_replace_all:Nnn \l_tmpa_tl { _ } + { \chemformula_chief_subscript:n } + } \int_zero:N \l_chemformula_count_tokens_int \tl_map_inline:Nn \l_tmpa_tl { \int_incr:N \l_chemformula_count_tokens_int - \int_compare:nTF { \l_chemformula_count_tokens_int = \tl_length:N \l_tmpa_tl } + \int_compare:nTF + { \l_chemformula_count_tokens_int = \tl_length:N \l_tmpa_tl } { \tl_if_eq:nnTF { ##1 } { + } { @@ -1528,7 +1524,10 @@ { \dim_set:Nn \l_chemformula_subscript_shift_additional_dim { #1 } \dim_set:Nn \l_chemformula_subscript_shift_dim - { \l_chemformula_subscript_shift_default_dim + \l_chemformula_subscript_shift_additional_dim } + { + \l_chemformula_subscript_shift_default_dim + + \l_chemformula_subscript_shift_additional_dim + } } , subscript-vshift .default:n = 0pt , subscript-style .choice: , @@ -1610,13 +1609,14 @@ VERSION HISTORY - bugfix: escaped text recognizes space by ~ again - * in superscript now gives excited state - new arrow type <> +2012/02/19 - version 3.1 - new functions in the chemmacros package + - new arrow types -/>, </- and <o> + - new commands \DeclareChemArrow, \RenewChemArrow and + \ShowChemArrow %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 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? -- the explicit definition of each arrow on its own is inefficient. - also these definitions abuse the `xparse' command \NewDocumentCommand - for internal commands => needs to be taken care of
\ No newline at end of file +- vertikaler shift für superskripte?
\ No newline at end of file |