diff options
author | Karl Berry <karl@freefriends.org> | 2014-01-25 22:33:11 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2014-01-25 22:33:11 +0000 |
commit | 00162491a0a38dd40e88a84e63192f10868f0df4 (patch) | |
tree | e42dd812872b36f33a7d245b206e65d0d79f4b5a /Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty | |
parent | ca3052a995aa72637d7cc9132e4ba1d2f6f3b8a5 (diff) |
chemmacros (25jan14)
git-svn-id: svn://tug.org/texlive/trunk@32786 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty | 1044 |
1 files changed, 593 insertions, 451 deletions
diff --git a/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty b/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty index 4f393c2b2a1..fd13bbf4440 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.2e} -\def\chemmacros@date{2014/01/09} +\def\chemmacros@version{4.3} +\def\chemmacros@date{2014/01/24} \ProvidesExplPackage {chemmacros} @@ -52,7 +52,7 @@ % -------------------------------------------------------------------------- % variants of kernel commands: \cs_generate_variant:Nn \prop_if_in:NnTF { NV , Nx } -\cs_generate_variant:Nn \prop_put:Nnn { NV , NVx } +\cs_generate_variant:Nn \prop_put:Nnn { NV , NVV , 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 } @@ -74,12 +74,6 @@ % -------------------------------------------------------------------------- % boolean variables for the package options -% versioning: -\bool_new:N \l__chemmacros_version_one_bool -\bool_new:N \l__chemmacros_version_three_bool -\bool_new:N \l__chemmacros_version_four_bool -\bool_set_true:N \l__chemmacros_version_four_bool - \bool_new:N \l__chemmacros_xspace_bool \bool_set_true:N \l__chemmacros_xspace_bool @@ -122,27 +116,6 @@ % -------------------------------------------------------------------------- % warning / error messages -\cs_new_protected:Npn \chemmacros_msg:nnxx #1#2#3#4 - { - \bool_if:NTF \l_chemmacros_strict_bool - { \msg_error:nnxx { #1 } { #2 } { #3 } { #4 } } - { \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 - { \msg_warning:nnxx { #1 } { #2 } { #3 } { #4 } } - { \msg_info:nnxx { #1 } { #2 } { #3 } { #4 } } - } - \msg_new:nnnn { chemmacros } { language-not-defined } { The~ language~ `#1'~ is~ not~ defined~ by~ chemmacros. } { @@ -152,11 +125,17 @@ } \msg_new:nnnn { chemmacros } { already-defined } - { The~ command~ #1~ has~ also~ been~ defined~ by~ another~ package. } + { The~ command~ #1~ is~ already~ defined. } + { + The~ command~ #1~ has~ already~ been~ otherwise.~ chemmacros~ also~ tries~ + to~ define~ it~ and~ fails.~ + } + +\msg_new:nnnn { chemmacros } { not-defined } + { The~ command~ #1~ is~ not~ defined,~ yet. } { - The~ command~ #1~ has~ also~ been~ defined~ by~ another~ package.~ - chemmacros~ provides~ an~ alternative~ definition.~ See~ the~ - documentation~ for~ more~ information. + The~ command~ #1~ is~ not~ defined,~ yet.~ chemmacros~ tries~ to~ + redefine~ it~ and~ fails.~ } \msg_new:nnnn { chemmacros } { option-deprecated } @@ -186,14 +165,14 @@ sorry. } -\msg_new:nnnn { chemmacros } { declare-particle } +\msg_new:nnnn { chemmacros } { new-particle } { The~ command~ sequence~ \token_to_str:N #1 \c_space_tl is~ already~ defined. } { You've~ tried~ to~ define~ a~ particle~ with~ \token_to_str:N - \DeclareChemParticle ,~ but~ the~ command~ sequence~ \token_to_str:N #1 + \NewChemParticle ,~ but~ the~ command~ sequence~ \token_to_str:N #1 \c_space_tl already~ exists.~ Please~ choose~ another~ name. } @@ -204,14 +183,14 @@ doesn't~ exist. } -\msg_new:nnnn { chemmacros } { declare-latin } +\msg_new:nnnn { chemmacros } { new-latin } { The~ command~ sequence~ \token_to_str:N #1 \c_space_tl is~ already~ defined. } { You've~ tried~ to~ define~ a~ latin~ phrase~ with~\token_to_str:N - \DeclareChemLatin ,~ but~ the~ command~ sequence~ \token_to_str:N #1 + \NewChemLatin ,~ but~ the~ command~ sequence~ \token_to_str:N #1 \c_space_tl already~ exists.~ Please~ choose~ another~ name. } @@ -222,14 +201,14 @@ it~ doesn't~ exist. } -\msg_new:nnnn { chemmacros } { declare-nmr } +\msg_new:nnnn { chemmacros } { new-nmr } { The~ command~ sequence~ \token_to_str:N #1 \c_space_tl is~ already~ defined. } { You've~ tried~ to~ define~ a~ NMR~ command~ with~\token_to_str:N - \DeclareChemParticle ,~ but~ the~ command~ sequence~ \token_to_str:N #1 + \NewChemParticle ,~ but~ the~ command~ sequence~ \token_to_str:N #1 \c_space_tl already~ exists.~ Please~ choose~ another~ name. } @@ -240,14 +219,14 @@ it~ doesn't~ exist. } -\msg_new:nnnn { chemmacros } { declare-phase } +\msg_new:nnnn { chemmacros } { new-phase } { The~ command~ sequence~ \token_to_str:N #1 \c_space_tl is~ already~ defined. } { You've~ tried~ to~ define~ a~ phase~ with~ \token_to_str:N - \DeclareChemPhase ,~ but~ the~ command~ sequence~ \token_to_str:N #1 + \NewChemPhase ,~ but~ the~ command~ sequence~ \token_to_str:N #1 \c_space_tl already~ exists.~ Please~ choose~ another~ name. } @@ -258,14 +237,14 @@ doesn't~ exist. } -\msg_new:nnnn { chemmacros } { declare-iupac } +\msg_new:nnnn { chemmacros } { new-iupac } { The~ iupac~ naming~ command~ \token_to_str:N #1 \c_space_tl is~ already~ defined. } { You've~ tried~ to~ define~ a~ iupac~ naming~ command~ with~ - \token_to_str:N \DeclareChemIUPAC ,~ but~ the~ iupac~ command~ + \token_to_str:N \NewChemIUPAC ,~ but~ the~ iupac~ command~ \token_to_str:N #1 \c_space_tl already~ exists.~ Choose~ another~ name~ or~ use~ \token_to_str:N \RenewChemIUPAC . } @@ -277,10 +256,22 @@ } { You've~ tried~ to~ renew~ the~ iupac~ command~ \token_to_str:N #1 ,~ but~ - it~ doesn't~ exist.~ Use~ \token_to_str:N \DeclareChemIUPAC \c_space_tl + it~ doesn't~ exist.~ Use~ \token_to_str:N \NewChemIUPAC \c_space_tl instead. } +\msg_new:nnnn { chemmacros } { let-iupac } + { + The~ iupac~ naming~ command~ \token_to_str:N #2 \c_space_tl is~ not~ + defined. + } + { + You've~ tried~ to~ let~ the~ iupac~ command~ \token_to_str:N #1 ~ to~ the~ + iupac~ command~ \token_to_str:N #2 ,~ but~ the~ latter~ doesn't~ exist.~ + Use~ \token_to_str:N \NewChemIUPAC \c_space_tl instead~ or~declare~ + \token_to_str:N #2 \c_space_tl first. + } + \msg_new:nnnn { chemmacros } { ox } { \token_to_str:N \ox \c_space_tl : ~ #1 ~ \msg_line_context: . } { \token_to_str:N \ox \c_space_tl : ~ #1 ~ \msg_line_context: . } @@ -305,7 +296,7 @@ properly~ \msg_line_context: . } -\msg_new:nnnn { chemmacros } { declare-state } +\msg_new:nnnn { chemmacros } { new-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 @@ -321,12 +312,12 @@ { 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~ \msg_line_context: . + \NewChemState \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~ \msg_line_context: . + \NewChemState \c_space_tl to~ create ~it~ \msg_line_context: . } \msg_new:nnn { chemmacros } { state-syntax } @@ -338,27 +329,27 @@ % declare an option as deprecated: \cs_new_protected:Npn \chemmacros_option_deprecated:n #1 - { \chemmacros_msg:nnn { chemmacros } { option-deprecated } { #1 } } + { \msg_warning:nnn { chemmacros } { option-deprecated } { #1 } } % define a deprecated command with hints to the corresponding new one: -\cs_new_protected:Npn \chemmacros_define_deprecated:NNn #1#2#3 +\cs_new_protected:Npn \chemmacros_define_deprecated:NN #1#2 { \cs_new_protected:Npn #1 { - \chemmacros_msg:nnxx { chemmacros } { command-deprecated } + \msg_warning:nnxx { chemmacros } { command-deprecated } { #1 } { #2 } - #3 + #2 } } -\NewDocumentCommand \DeclareChemDeprecated { mmm } - { \chemmacros_define_deprecated:NNn #1 #2 { #3 } } +\NewDocumentCommand \DeclareChemDeprecated { mm } + { \chemmacros_define_deprecated:NN #1 #2 } % define a command as dropped! \cs_new_protected:Npn \chemmacros_define_dropped:N #1 { \cs_new_protected:Npn #1 - { \chemmacros_msg:nnxx { chemmacros } { command-dropped } { #1 } { } } + { \msg_error:nnn { chemmacros } { command-dropped } { #1 } } } \NewDocumentCommand \DeclareChemDropped { m } @@ -404,20 +395,6 @@ } % -------------------------------------------------------------------------- -% version management: -\tl_const:Nn \c__chemmacros_versions_tl { {one} {three} {four} } - -\cs_new_protected:Npn \chemmacros_set_version:n #1 - { - \tl_map_inline:Nn \c__chemmacros_versions_tl - { - \tl_if_eq:nnTF { #1 } { ##1 } - { \bool_set_true:c { l__chemmacros_version_##1_bool } } - { \bool_set_false:c { l__chemmacros_version_##1_bool } } - } - } - -% -------------------------------------------------------------------------- % package options % circled => circle charges % detect-bold => behaviour when font series bold @@ -429,13 +406,12 @@ % method => use `chemformula' or `mhchem' % strict => errors or warnings % synchronize => let particles et.al. adapt chemformula's font selection -% ugreek => behaviour of \ChemDelta, \Chemalpha, ... +% ugreek => behaviour of \chemDelta, \chemalpha, ... % version=1 => compatibility for documents set with v1.* % xspace => add an \xspace after a whole bunch of macros % this boolean has to be public since the other packages of the bundle may % want to know its value -\bool_new:N \l_chemmacros_strict_bool \bool_new:N \l__chemmacros_detect_bold_bool \bool_set_true:N \l__chemmacros_detect_bold_bool @@ -508,8 +484,8 @@ \bool_set_true:N \l__chemmacros_Nu_mathspec_bool , Nu / chemmacros .code:n = \bool_set_false:N \l__chemmacros_Nu_mathspec_bool , - strict .bool_set:N = \l_chemmacros_strict_bool , - strict .default:n = true , + strict .code:n = + \chemmacros_option_deprecated:n { strict } , synchronize .choice: , synchronize / true .code:n = \cs_set_eq:NN \chemmacros_inner_font: \chemformula_font_inner: , @@ -521,31 +497,32 @@ \bool_set_true:N \l__chemmacros_option_greek_set_bool , greek / textgreek .code:n = \chemgreek_activate_mapping:n { textgreek } - \bool_set_true:N \l__chemmacros_option_greek_set_bool, + \bool_set_true:N \l__chemmacros_option_greek_set_bool , greek / kpfonts .code:n = \chemgreek_activate_mapping:n { kpfonts } - \bool_set_true:N \l__chemmacros_option_greek_set_bool, - greek / newtx .code:n = + \bool_set_true:N \l__chemmacros_option_greek_set_bool , + greek / newtx .code:n = \chemgreek_activate_mapping:n { newtx } - \bool_set_true:N \l__chemmacros_option_greek_set_bool, + \bool_set_true:N \l__chemmacros_option_greek_set_bool , + greek / mathdesign .code:n = + \chemgreek_activate_mapping:n { mathdesign } + \bool_set_true:N \l__chemmacros_option_greek_set_bool , + greek / fourier .code:n = + \chemgreek_activate_mapping:n { fourier } + \bool_set_true:N \l__chemmacros_option_greek_set_bool , + greek / textalpha .code:n = + \chemgreek_activate_mapping:n { textalpha } + \bool_set_true:N \l__chemmacros_option_greek_set_bool , greek / math .code:n = \chemgreek_activate_mapping:n { default } - \bool_set_true:N \l__chemmacros_option_greek_set_bool, + \bool_set_true:N \l__chemmacros_option_greek_set_bool , greek / auto .code:n = - \bool_set_false:N \l__chemmacros_option_greek_set_bool, + \bool_set_false:N \l__chemmacros_option_greek_set_bool , greek .default:n = auto , upgreek .code:n = \chemmacros_option_deprecated:n { upgreek } , - % dummy version for compatibility with KOMA's global option and backwards - % compatibility of chemmacros version .code:n = \chemmacros_option_deprecated:n { version } , + cmversion .code:n = \chemmacros_option_deprecated:n { cmversion } , cmversion .choice: , - cmversion / 1 .code:n = \chemmacros_set_version:n { one } , - cmversion / 2 .code:n = \chemmacros_set_version:n { three } , - cmversion / 3 .code:n = \chemmacros_set_version:n { three } , - cmversion / 4 .code:n = \chemmacros_set_version:n { four } , - cmversion / newest .code:n = \chemmacros_set_version:n { four } , - cmversion / bundle .code:n = - \chemmacros_option_deprecated:n { cmversion/bundle } , xspace .bool_set:N = \l__chemmacros_xspace_bool , xspace .default:n = true } @@ -559,38 +536,53 @@ % - is `ghsystem' requested? % - do we need `xspace'? % - what about the greek letters? -\AtEndPreamble + +\seq_new:N \l__chemmacros_greek_packages_seq +\prop_new:N \l__chemmacros_greek_mapping_prop + +\cs_new_protected:Npn \chemmacros_add_greek_package_mapping:nn #1#2 + { + \seq_put_right:Nn \l__chemmacros_greek_packages_seq {#1} + \prop_put:Nnn \l__chemmacros_greek_mapping_prop {#1} {#2} + } + +\cs_generate_variant:Nn \chemgreek_activate_mapping:n { V } + +\cs_new_protected:Npn \__chemmacros_select_greek_mapping:n #1 { - \bool_if:NT \l__chemmacros_ghsystem_bool - { \RequirePackage { ghsystem } } - \bool_if:NT \l__chemmacros_xspace_bool - { \RequirePackage { xspace } } \bool_if:NF \l__chemmacros_option_greek_set_bool { - \@ifpackageloaded { upgreek } - { \bool_set_true:N \l__chemmacros_use_upgreek_bool } + \@ifpackageloaded { #1 } { - \@ifpackageloaded { textgreek } - { \bool_set_true:N \l__chemmacros_use_textgreek_bool } - { - \@ifpackageloaded { kpfonts } - { \bool_set_true:N \l__chemmacros_use_kpfonts_bool } - { - \@ifpackageloaded { newtxmath } - { \bool_set_true:N \l__chemmacros_use_newtx_bool } - { } - } - } + \prop_get:NnN + \l__chemmacros_greek_mapping_prop + { #1 } + \l__chemmacros_tmpa_tl + \chemgreek_activate_mapping:V \l__chemmacros_tmpa_tl + \bool_set_true:N \l__chemmacros_option_greek_set_bool + \seq_map_break: } + { } } - \bool_if:NT \l__chemmacros_use_upgreek_bool - { \chemgreek_activate_mapping:n { upgreek } } - \bool_if:NT \l__chemmacros_use_textgreek_bool - { \chemgreek_activate_mapping:n { textgreek } } - \bool_if:NT \l__chemmacros_use_kpfonts_bool - { \chemgreek_activate_mapping:n { kpfonts } } - \bool_if:NT \l__chemmacros_use_newtx_bool - { \chemgreek_activate_mapping:n { newtx } } + } + +\chemmacros_add_greek_package_mapping:nn {upgreek} {upgreek} +\chemmacros_add_greek_package_mapping:nn {textgreek} {textgreek} +\chemmacros_add_greek_package_mapping:nn {mathdesign} {mathdesign} +\chemmacros_add_greek_package_mapping:nn {kpfonts} {kpfonts} +\chemmacros_add_greek_package_mapping:nn {newtxmath} {newtx} +\chemmacros_add_greek_package_mapping:nn {fourier} {fourier} +\chemmacros_add_greek_package_mapping:nn {textalpha} {textalpha} + +\AtEndPreamble + { + \bool_if:NT \l__chemmacros_ghsystem_bool + { \RequirePackage { ghsystem } } + \bool_if:NT \l__chemmacros_xspace_bool + { \RequirePackage { xspace } } + \seq_map_function:NN + \l__chemmacros_greek_packages_seq + \__chemmacros_select_greek_mapping:n } \cs_new_protected:Npn \chemmacros_xspace: @@ -632,7 +624,7 @@ \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 } +\prg_new_protected_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 @@ -641,7 +633,7 @@ } % detection and handling of bold face: -\prg_new_conditional:Npnn \chemmacros_if_bold: { T,F,TF } +\prg_new_protected_conditional:Npnn \chemmacros_if_bold: { T,F,TF } { \seq_if_in:NVTF \l__chemmacros_if_bf_seq \f@series { \prg_return_true: } @@ -740,21 +732,24 @@ % -------------------------------------------------------------------------- % particles, charges -\NewDocumentCommand \DeclareChemParticle { mm } +\NewDocumentCommand \NewChemParticle { mm } { \cs_if_free:NTF #1 - { \chemmacros_new_particle:Nn #1 { #2 } } - { \chemmacros_msg:nnxx { chemmacros } { declare-particle } { #1 } {} } + { \chemmacros_define_particle:Nn #1 { #2 } } + { \msg_error:nnn { chemmacros } { new-particle } { #1 } } } \NewDocumentCommand \RenewChemParticle { mm } { \cs_if_free:NTF #1 - { \chemmacros_msg:nnxx { chemmacros } { renew-particle } { #1 } {} } - { \chemmacros_new_particle:Nn #1 { #2 } } + { \msg_error:nnn { chemmacros } { renew-particle } { #1 } } + { \chemmacros_define_particle:Nn #1 { #2 } } } -\cs_new_protected:Nn \chemmacros_new_particle:Nn +\NewDocumentCommand \DeclareChemParticle { mm } + { \chemmacros_define_particle:Nn #1 { #2 } } + +\cs_new_protected:Nn \chemmacros_define_particle:Nn { \cs_set_protected:Npn #1 { @@ -763,9 +758,9 @@ } } -\DeclareChemParticle \el { e- } -\DeclareChemParticle \prt { p+ } -\DeclareChemParticle \ntr { n^0 } +\NewChemParticle \el { e- } +\NewChemParticle \prt { p+ } +\NewChemParticle \ntr { n^0 } \DeclareChemDropped \Rad @@ -891,11 +886,11 @@ % -------------------------------------------------------------------------- % ions, molecules % proton, hydroxide, hydronium/oxonium, water, nucleophile, electrophile -\DeclareChemParticle \Hpl { H+ } -\DeclareChemParticle \Hyd { OH- } -\DeclareChemParticle \HtO { H3O+ } -\DeclareChemParticle \El { E+ } -\DeclareChemParticle \water { H2O } +\NewChemParticle \Hpl { H+ } +\NewChemParticle \Hyd { OH- } +\NewChemParticle \HtO { H3O+ } +\NewChemParticle \El { E+ } +\NewChemParticle \water { H2O } \NewDocumentCommand \chemmacros_Nu:w { o } { @@ -939,7 +934,7 @@ % { { \chemmacros_inner_font: #1 \chlewis { 0=| } { \vphantom { #1 } } } } } { - \chemmacros_msg:nnxx { chemmacros } { chemfig } { #1 } {} + \msg_error:nnn { chemmacros } { chemfig } { #1 } \chemmacros_atom:n { #1 } } } @@ -969,12 +964,12 @@ % IUPAC \prop_new:N \l__chemmacros_iupac_prop -\cs_new_protected:Npn \chemmacros_declare_iupac:Nn #1#2 +\cs_new_protected:Npn \chemmacros_new_iupac:Nn #1#2 { \tl_set:Nx \l__chemmacros_tmpa_tl { \chemmacros_remove_backslash:N #1 } \prop_if_in:NVTF \l__chemmacros_iupac_prop \l__chemmacros_tmpa_tl - { \chemmacros_msg:nnxx { chemmacros } { declare-iupac } { #1 } { } } + { \msg_error:nnn { chemmacros } { new-iupac } { #1 } } { \prop_put:NVn \l__chemmacros_iupac_prop \l__chemmacros_tmpa_tl @@ -983,23 +978,59 @@ \chemmacros_make_iupac: } +\cs_new_protected:Npn \chemmacros_define_iupac:Nn #1#2 + { + \tl_set:Nx \l__chemmacros_tmpa_tl + { \chemmacros_remove_backslash:N #1 } + \prop_put:NVn \l__chemmacros_iupac_prop + \l__chemmacros_tmpa_tl + { #2 } + \chemmacros_make_iupac: + } + \cs_new_protected:Npn \chemmacros_renew_iupac:Nn #1#2 { - \tl_set_rescan:Nnn \l__chemmacros_tmpa_tl - { \char_set_catcode_letter:N \\ } - { #1 } - \tl_set:Nf \l__chemmacros_tmpa_tl - { \tl_tail:V \l__chemmacros_tmpa_tl } + \tl_set:Nx \l__chemmacros_tmpa_tl + { \chemmacros_remove_backslash:N #1 } \prop_if_in:NVTF \l__chemmacros_iupac_prop \l__chemmacros_tmpa_tl { \prop_put:NVn \l__chemmacros_iupac_prop \l__chemmacros_tmpa_tl { #2 } } - { \chemmacros_msg:nnxx { chemmacros } { renew-iupac } { #1 } { } } + { \msg_error:nnn { chemmacros } { renew-iupac } { #1 } } \chemmacros_make_iupac: } +\cs_new_protected:Npn \chemmacros_let_iupac:NN #1#2 + { + \tl_set:Nx \l__chemmacros_tmpa_tl + { \chemmacros_remove_backslash:N #1 } + \tl_set:Nx \l__chemmacros_tmpb_tl + { \chemmacros_remove_backslash:N #2 } + \prop_get:NVNTF \l__chemmacros_iupac_prop + \l__chemmacros_tmpb_tl + \l__chemmacros_tmpc_tl + { + \prop_put:NVV \l__chemmacros_iupac_prop + \l__chemmacros_tmpa_tl + \l__chemmacros_tmpc_tl + } + { \msg_error:nnnn { chemmacros } { let-iupac } { #1 } { #2 } } + \chemmacros_make_iupac: + } + +\cs_new_protected:Npn \chemmacros_define_deprecated_iupac:NN #1#2 + { + \chemmacros_define_iupac:Nn #1 + { + \msg_warning:nnnn { chemmacros } { command-deprecated } + { #1 } { #2 } + #2 + } + } + + \cs_new_protected:Npn \chemmacros_make_iupac: { \bool_if:NT \l__chemmacros_in_document_bool @@ -1032,11 +1063,20 @@ \AtBeginDocument { \chemmacros_make_iupac: } \NewDocumentCommand \DeclareChemIUPAC { mm } - { \chemmacros_declare_iupac:Nn #1 { #2 } } + { \chemmacros_define_iupac:Nn #1 { #2 } } + +\NewDocumentCommand \NewChemIUPAC { mm } + { \chemmacros_new_iupac:Nn #1 { #2 } } \NewDocumentCommand \RenewChemIUPAC { mm } { \chemmacros_renew_iupac:Nn #1 { #2 } } +\NewDocumentCommand \LetChemIUPAC { mm } + { \chemmacros_let_iupac:NN #1 #2 } + +\NewDocumentCommand \DeprecateChemIUPAC { mm } + { \chemmacros_define_deprecated_iupac:NN #1 #2 } + % stereo descriptors and other nomenclature commands % Cahn-Ingold-Prelog \dim_new:N \l__chemmacros_cip_kern_dim @@ -1051,11 +1091,14 @@ \cs_new_protected:Npn \chemmacros_cip:n #1 { ( \textit{#1} \tex_kern:D \l__chemmacros_cip_kern_dim ) } -\DeclareChemDeprecated \Rcip \R { \cip { R } } -\DeclareChemDeprecated \Scip \S { \cip { S } } +\DeprecateChemIUPAC \Rcip \rectus +\DeprecateChemIUPAC \Scip \sinister -\DeclareChemIUPAC \R { \cip { R } } -\DeclareChemIUPAC \S { \cip { S } } +\NewChemIUPAC \rectus { \cip { R } } +\NewChemIUPAC \sinister { \cip { S } } + +\LetChemIUPAC \R \rectus +\LetChemIUPAC \S \sinister % TikZ needs : to be other \ExplSyntaxOff @@ -1088,35 +1131,41 @@ \NewDocumentCommand \Rconf { O{R} } { \chemmacros@rconf { #1 } } % E(ntgegen)/Z(usammen) -\DeclareChemIUPAC \E { \cip { E } } -\DeclareChemIUPAC \Z { \cip { Z } } +\NewChemIUPAC \entgegen { \cip { E } } +\NewChemIUPAC \zusammen { \cip { Z } } + +\LetChemIUPAC \E \entgegen +\LetChemIUPAC \Z \zusammen % cis/trans -\DeclareChemIUPAC \cis { \textit { cis } } -\DeclareChemIUPAC \trans { \textit { trans } } +\NewChemIUPAC \cis { \textit { cis } } +\NewChemIUPAC \trans { \textit { trans } } % fac/mer -\DeclareChemIUPAC \fac { \textit { fac } } -\DeclareChemIUPAC \mer { \textit { mer } } +\NewChemIUPAC \fac { \textit { fac } } +\NewChemIUPAC \mer { \textit { mer } } % tert -\DeclareChemIUPAC \tert { \textit { tert } } +\NewChemIUPAC \tert { \textit { tert } } % Fischer \DeclareChemDropped \Dfi \DeclareChemDropped \Lfi -\DeclareChemIUPAC \D { \textsc { d } } -\DeclareChemIUPAC \L { \textsc { l } } +\NewChemIUPAC \dexter { \textsc { d } } +\NewChemIUPAC \laevus { \textsc { l } } + +\LetChemIUPAC \D \dexter +\LetChemIUPAC \L \laevus % ortho/meta/para -\DeclareChemIUPAC \ortho { \textit { o } } -\DeclareChemIUPAC \meta { \textit { m } } -\DeclareChemIUPAC \para { \textit { p } } +\NewChemIUPAC \ortho { \textit { o } } +\NewChemIUPAC \meta { \textit { m } } +\NewChemIUPAC \para { \textit { p } } % syn/anti -\DeclareChemIUPAC \syn { \textit { syn } } -\DeclareChemIUPAC \anti { \textit { anti } } +\NewChemIUPAC \syn { \textit { syn } } +\NewChemIUPAC \anti { \textit { anti } } % coordination chemistry \bool_new:N \l__chemmacros_bridge_super_bool @@ -1134,14 +1183,21 @@ \cs_new_protected:Npn \chemformula_hapto:n #1 { - \Chemeta \chemformula_superscript:n { #1 } + \chemeta \chemformula_superscript:n { #1 } + \bool_if:NT \l__chemmacros_coord_use_hyphen_bool + { \chemmacros_break_point_hyphen: } + } + +\cs_new_protected:Npn \chemformula_dento:n #1 + { + \chemkappa \chemformula_superscript:n { #1 } \bool_if:NT \l__chemmacros_coord_use_hyphen_bool { \chemmacros_break_point_hyphen: } } \cs_new_protected:Npn \chemformula_bridge:n #1 { - \Chemmu + \chemmu \tl_if_blank:nF { #1 } { \bool_if:NTF \l__chemmacros_bridge_super_bool @@ -1152,35 +1208,42 @@ { \chemmacros_break_point_hyphen: } } -\DeclareChemIUPAC \hapto { \chemformula_hapto:n } -\DeclareChemIUPAC \bridge { \chemformula_bridge:n } +\NewChemIUPAC \hapto { \chemformula_hapto:n } +\NewChemIUPAC \dento { \chemformula_dento:n } +\NewChemIUPAC \bridge { \chemformula_bridge:n } % 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 } } +\NewChemIUPAC \hydrogen { \textit { H } } +\NewChemIUPAC \oxygen { \textit { O } } +\NewChemIUPAC \nitrogen { \textit { N } } +\NewChemIUPAC \sulfur { \textit { S } } +\NewChemIUPAC \phosphorus { \textit { P } } + +\LetChemIUPAC \H \hydrogen +\LetChemIUPAC \O \oxygen +\LetChemIUPAC \N \nitrogen +\LetChemIUPAC \Sf \sulfur +\LetChemIUPAC \P \phosphorus % language specific settings \AtBeginDocument { \bool_if:NT \l__chemmacros_italian_bool { - \DeclareChemIUPAC \sin { \textit { sin } } - \DeclareChemIUPAC \ter { \textit { ter } } + \NewChemIUPAC \sin { \textit { sin } } + \NewChemIUPAC \ter { \textit { ter } } } } % greek letters -\DeclareChemIUPAC \a { \Chemalpha } -\DeclareChemIUPAC \b { \Chembeta } -\DeclareChemIUPAC \g { \Chemgamma } -\DeclareChemIUPAC \d { \Chemdelta } -\DeclareChemIUPAC \k { \Chemkappa } -\DeclareChemIUPAC \m { \Chemmu } -\DeclareChemIUPAC \n { \Chemeta } -\DeclareChemIUPAC \w { \Chemomega } +\NewChemIUPAC \a { \chemalpha } +\NewChemIUPAC \b { \chembeta } +\NewChemIUPAC \g { \chemgamma } +\NewChemIUPAC \d { \chemdelta } +\NewChemIUPAC \k { \chemkappa } +\NewChemIUPAC \m { \chemmu } +\NewChemIUPAC \n { \chemeta } +\NewChemIUPAC \w { \chemomega } % \iupac (basically the same as bpchem's \IUPAC) % - allows multiple breaking points as compound names can get really long and @@ -1267,7 +1330,7 @@ \prop_new:N \l__chemmacros_latin_prop -\cs_new_protected:Npn \chemmacros_declare_latin:Nn #1#2 +\cs_new_protected:Npn \chemmacros_new_latin:Nn #1#2 { \cs_if_free:NTF #1 { @@ -1275,22 +1338,40 @@ { \chemmacros_latin:n { #2 } \chemmacros_xspace: } \prop_put:Nnn \l__chemmacros_latin_prop { #1 } { #2 } } - { \chemmacros_msg:nnxx { chemmacros } { declare-latin } { #1 } { } } + { \msg_error:nnn { chemmacros } { new-latin } { #1 } } + } + +\cs_new_protected:Npn \chemmacros_define_latin:Nn #1#2 + { + \cs_if_free:NTF #1 + { + \cs_new_protected:Npn #1 + { \chemmacros_latin:n { #2 } \chemmacros_xspace: } + \prop_put:Nnn \l__chemmacros_latin_prop { #1 } { #2 } + } + { + \cs_set_protected:Npn #1 + { \chemmacros_latin:n { #2 } \chemmacros_xspace: } + \prop_put:Nnn \l__chemmacros_latin_prop { #1 } { #2 } + } } \cs_new_protected:Npn \chemmacros_renew_latin:Nn #1#2 { \prop_if_in:NnTF \l__chemmacros_latin_prop { #1 } { \cs_set:Npn #1 { \chemmacros_latin:n { #2 } \chemmacros_xspace: } } - { \chemmacros_msg:nnxx { chemmacros } { renew-latin } { #1 } { } } + { \msg_error:nnn { chemmacros } { renew-latin } { #1 } } } -\NewDocumentCommand \DeclareChemLatin { mm } - { \chemmacros_declare_latin:Nn #1 { #2 } } +\NewDocumentCommand \NewChemLatin { mm } + { \chemmacros_new_latin:Nn #1 { #2 } } \NewDocumentCommand \RenewChemLatin { mm } { \chemmacros_renew_latin:Nn #1 { #2 } } +\NewDocumentCommand \DeclareChemLatin { mm } + { \chemmacros_define_latin:Nn #1 { #2 } } + \AtBeginDocument { \bool_if:NTF \l__chemmacros_chemstyle_bool @@ -1304,9 +1385,9 @@ { \cs_new_eq:NN \latin \chemmacros_latin:n } - \DeclareChemLatin \insitu { in~situ } - \DeclareChemLatin \abinitio { ab~initio } - \DeclareChemLatin \invacuo { in~vacuo } + \NewChemLatin \insitu { in~situ } + \NewChemLatin \abinitio { ab~initio } + \NewChemLatin \invacuo { in~vacuo } } % --------------------------------------------------------------------------- % @@ -1760,9 +1841,7 @@ { \group_begin: \tl_if_blank:nF { #1 } { \__chemmacros_ox_pos_super: } - \bool_if:NTF \l__chemmacros_version_one_bool - { \keys_set:nn { chemmacros / ox } { parse = false } } - { \tl_if_blank:nF { #2 } { \keys_set:nn { chemmacros / ox } { #2 } } } + \keys_set:nn { chemmacros / ox } { #2 } \__chemmacros_ox_write:nn { #3 } { #4 } \group_end: } @@ -1907,23 +1986,22 @@ sep .default:n = { .2em } } -\bool_if:NT \l__chemmacros_version_one_bool - { - \NewDocumentCommand \setredoxdist { m } - { - \tl_if_blank:nTF { #1 } - { \dim_set:Nn \l__chemmacros_redox_dist_dim { .6em } } - { \dim_set:Nn \l__chemmacros_redox_dist_dim { #1 } } - } - } - % --------------------------------------------------------------------------- % % spectroscopy \tl_new:N \g__chemmacros_nmr_isotope_tl \tl_new:N \l__chemmacros_nmr_isotope_default_tl \tl_set:Nn \l__chemmacros_nmr_isotope_default_tl { 1 } \tl_new:N \l__chemmacros_nmr_coupling_nuclei_tl +\tl_new:N \l__chemmacros_nmr_coupling_nuclei_pre_tl +\tl_set:Nn \l__chemmacros_nmr_coupling_nuclei_pre_tl { ( } +\tl_new:N \l__chemmacros_nmr_coupling_nuclei_post_tl +\tl_set:Nn \l__chemmacros_nmr_coupling_nuclei_post_tl { ) } \tl_new:N \l__chemmacros_nmr_coupling_bonds_tl +\tl_new:N \l__chemmacros_nmr_coupling_bonds_pre_tl +\tl_set:Nn \l__chemmacros_nmr_coupling_bonds_pre_tl { ( } +\tl_set:Nn \l__chemmacros_nmr_coupling_bonds_post_tl { \! } +\tl_new:N \l__chemmacros_nmr_coupling_symbol_tl +\tl_set:Nn \l__chemmacros_nmr_coupling_symbol_tl { J } \tl_new:N \g__chemmacros_nmr_element_coupled_tl \tl_new:N \g__chemmacros_nmr_element_tl \tl_new:N \l__chemmacros_nmr_element_default_tl @@ -1941,13 +2019,15 @@ \itemsep\z@ \parsep\z@ \itemindent\z@ \leftmargin\z@ } +\tl_new:N \l__chemmacros_nmr_position_tl +\bool_new:N \l__chemmacros_nmr_coupling_nuclei_sub_bool \bool_new:N \l__chemmacros_nmr_frequency_bool \bool_new:N \l__chemmacros_nmr_solvent_bool \bool_new:N \l__chemmacros_nmr_delimiters_bool \bool_new:N \l__chemmacros_nmr_comma_bool \bool_new:N \l__chemmacros_nmr_inner_bool -\bool_new:N \l__chemmacros_nmr_position_sub_bool +\bool_new:N \l__chemmacros_nmr_position_side_bool \bool_new:N \l__chemmacros_nmr_parse_bool \bool_set_true:N \l__chemmacros_nmr_parse_bool \bool_new:N \l__chemmacros_nmr_list_bool @@ -2009,34 +2089,59 @@ \keys_define:nn { chemmacros / nmr } { - unit .tl_set:N = \l__chemmacros_nmr_unit_tl , - unit .default:n = \mega\hertz , - nucleus .code:n = + unit .tl_set:N = \l__chemmacros_nmr_unit_tl , + unit .default:n = \mega\hertz , + nucleus .code:n = { \__chemmacros_nmr_default_nucleus:w #1 \q_stop } , - nucleus .default:n = { 1,H } , - format .tl_set:N = \l__chemmacros_nmr_format_tl , - pos-number .choice: , + nucleus .default:n = { 1,H } , + format .tl_set:N = \l__chemmacros_nmr_format_tl , + pos-number .choice: , pos-number / sub .code:n = - \bool_set_true:N \l__chemmacros_nmr_position_sub_bool , + \tl_set:Nn \l__chemmacros_nmr_position_tl { _ } + \bool_set_false:N \l__chemmacros_nmr_position_side_bool , + pos-number / super .code:n = + \tl_set:Nn \l__chemmacros_nmr_position_tl { ^ } + \bool_set_false:N \l__chemmacros_nmr_position_side_bool , pos-number / side .code:n = - \bool_set_false:N \l__chemmacros_nmr_position_sub_bool , + \tl_set:Nn \l__chemmacros_nmr_position_tl { - } + \bool_set_true:N \l__chemmacros_nmr_position_side_bool , coupling-unit .tl_set:N = \l__chemmacros_nmr_coupling_unit_tl , - parse .bool_set:N = \l__chemmacros_nmr_parse_bool , - delta .code:n = + coupling-pos .choice: , + coupling-pos / sub .code:n = + \bool_set_true:N \l__chemmacros_nmr_coupling_nuclei_sub_bool , + coupling-pos / side .code:n = + \bool_set_false:N \l__chemmacros_nmr_coupling_nuclei_sub_bool , + coupling-nuclei-pre .tl_set:N = + \l__chemmacros_nmr_coupling_nuclei_pre_tl , + coupling-nuclei-post .tl_set:N = + \l__chemmacros_nmr_coupling_nuclei_post_tl , + coupling-bonds-pre .tl_set:N = + \l__chemmacros_nmr_coupling_bonds_pre_tl , + coupling-bonds-post .tl_set:N = + \l__chemmacros_nmr_coupling_bonds_post_tl , + coupling-symbol .tl_set:N = + \l__chemmacros_nmr_coupling_symbol_tl , + parse .bool_set:N = \l__chemmacros_nmr_parse_bool , + delta .code:n = \tl_set:Nn \l__chemmacros_nmr_delta_tl { \, #1 } , - list .bool_set:N = \l__chemmacros_nmr_list_bool , - list .default:n = true , - list-setup .tl_set:N = \l__chemmacros_nmr_list_setup_tl , - use-equal .bool_set:N = \l__chemmacros_nmr_use_equal_bool , - use-equal .default:n = true + list .bool_set:N = \l__chemmacros_nmr_list_bool , + list .default:n = true , + list-setup .tl_set:N = \l__chemmacros_nmr_list_setup_tl , + use-equal .bool_set:N = \l__chemmacros_nmr_use_equal_bool , + use-equal .default:n = true } \prop_new:N \l__chemmacros_nmr_prop -\cs_new_protected:Npn \chemmacros_declare_nmr:Nn #1#2 +\cs_new_protected:Npn \chemmacros_new_nmr:Nn #1#2 { - \prop_if_in:NnTF \l__chemmacros_nmr_prop { #1 } - { \chemmacros_msg:nnxx { chemmacros } { declare-nmr } { #1 } { } } + \bool_if:nTF + { + \prop_if_in_p:Nn \l__chemmacros_nmr_prop { #1 } + || + \cs_if_exist_p:N #1 + } + { \msg_error:nnn { chemmacros } { new-nmr } { #1 } } { \prop_put:Nnn \l__chemmacros_nmr_prop { #1 } { #2 } \NewDocumentCommand #1 { s } @@ -2044,23 +2149,45 @@ } } +\cs_new_protected:Npn \chemmacros_define_nmr:Nn #1#2 + { + \prop_put:Nnn \l__chemmacros_nmr_prop { #1 } { #2 } + \cs_if_exist:NTF #1 + { + \RenewDocumentCommand #1 { s } + { \IfBooleanTF {##1} { \NMR*{#2} } { \NMR{#2} } } + } + { + \NewDocumentCommand #1 { s } + { \IfBooleanTF {##1} { \NMR*{#2} } { \NMR{#2} } } + } + } + \cs_new_protected:Npn \chemmacros_renew_nmr:Nn #1#2 { - \prop_if_in:NnTF \l__chemmacros_nmr_prop { #1 } + \bool_if:nTF + { + \prop_if_in_p:Nn \l__chemmacros_nmr_prop { #1 } + && + \cs_if_exist_p:N #1 + } { \prop_put:Nnn \l__chemmacros_nmr_prop { #1 } { #2 } - \NewDocumentCommand #1 { s } + \RenewDocumentCommand #1 { s } { \IfBooleanTF {##1} { \NMR*{#2} } { \NMR{#2} } } } - { \chemmacros_msg:nnxx { chemmacros } { renew-nmr } { #1 } { } } + { \msg_error:nnn { chemmacros } { renew-nmr } { #1 } } } -\NewDocumentCommand \DeclareChemNMR { mm } - { \chemmacros_declare_nmr:Nn #1 { #2 } } +\NewDocumentCommand \NewChemNMR { mm } + { \chemmacros_new_nmr:Nn #1 { #2 } } \NewDocumentCommand \RenewChemNMR { mm } { \chemmacros_renew_nmr:Nn #1 { #2 } } +\NewDocumentCommand \DeclareChemNMR { mm } + { \chemmacros_define_nmr:Nn #1 { #2 } } + \NewDocumentCommand \NMR { s G{} D(){} O{} } { \IfBooleanTF { #1 } @@ -2214,9 +2341,17 @@ \cs_new_protected:Npn \chemmacros_nmr_position:n #1 { - \bool_if:NTF \l__chemmacros_nmr_position_sub_bool - { \chemmacros_chemformula:x { \g__chemmacros_nmr_element_tl _ #1 } } - { \chemmacros_atom:V \g__chemmacros_nmr_element_tl - #1 } + \chemmacros_chemformula:x + { + \exp_not:V \g__chemmacros_nmr_element_tl + \bool_if:NF \l__chemmacros_nmr_position_side_bool + { + \exp_not:V \l__chemmacros_nmr_position_tl + \exp_not:n { {#1} } + } + } + \bool_if:NT \l__chemmacros_nmr_position_side_bool + { \tl_use:N \l__chemmacros_nmr_position_tl #1 } } \cs_new_protected:Npn \chemmacros_nmr_coupling:w @@ -2230,10 +2365,28 @@ \cs_new_protected:Npn \__chemmacros_nmr_coupling:w (#1;#2) { - \tl_set:Nn \l__chemmacros_nmr_coupling_bonds_tl { #1 } - \tl_set:Nn \l__chemmacros_nmr_coupling_nuclei_tl { #2 } - \tl_put_right:Nn \l__chemmacros_nmr_coupling_nuclei_tl { ) } - \tl_put_left:Nn \l__chemmacros_nmr_coupling_nuclei_tl { ( } + \tl_set:Nn \l__chemmacros_nmr_coupling_bonds_tl + { + \l__chemmacros_nmr_coupling_bonds_pre_tl + #1 + \l__chemmacros_nmr_coupling_bonds_post_tl + } + \bool_if:NTF \l__chemmacros_nmr_coupling_nuclei_sub_bool + { + \tl_set:Nn \l__chemmacros_nmr_coupling_nuclei_tl + { + \c_math_subscript_token + { \chemmacros_chemformula:n {#2} } + } + } + { + \tl_set:Nn \l__chemmacros_nmr_coupling_nuclei_tl + { + \l__chemmacros_nmr_coupling_nuclei_pre_tl + \chemmacros_chemformula:n {#2} + \l__chemmacros_nmr_coupling_nuclei_post_tl + } + } \__chemmacros_nmr_coupling_aux_i:w } @@ -2254,7 +2407,8 @@ list-units=single } \( - ^{ \l__chemmacros_nmr_coupling_bonds_tl } J + ^{ \l__chemmacros_nmr_coupling_bonds_tl } + \l__chemmacros_nmr_coupling_symbol_tl \l__chemmacros_nmr_coupling_nuclei_tl = \SIlist{#2}{#1} \) \group_end: @@ -2278,63 +2432,9 @@ } % -------------------------------------------------------------------------- -% placing text below atom/molecule -- only for `mhchem' users or users of -% version 1 -\cs_new_eq:NN \chemmacros_dim_to_width:Nn \chemformula_dim_to_width:Nn - -\bool_new:N \l__chemmacros_mhname_width_bool -\bool_set_false:N \l__chemmacros_mhname_width_bool -\dim_new:N \l__chemmacros_mhname_width_dim - -\tl_new:N \l__chemmacros_mhname_align_tl -\tl_set:Nn \l__chemmacros_mhname_align_tl { \centering } -\tl_new:N \l__chemmacros_mhname_format_tl -\tl_new:N \l__chemmacros_mhname_fontsize_tl -\tl_set:Nn \l__chemmacros_mhname_fontsize_tl { \tiny } - -\keys_define:nn { chemmacros / mhName } - { - align .tl_set:N = \l__chemmacros_mhname_align_tl , - format .tl_set:N = \l__chemmacros_mhname_format_tl , - fontsize .tl_set:N = \l__chemmacros_mhname_fontsize_tl , - width .code:n = - { - \tl_if_eq:nnTF { #1 } { auto } - { \bool_set_false:N \l__chemmacros_mhname_width_bool } - { - \bool_set_true:N \l__chemmacros_mhname_width_bool - \dim_set:Nn \l__chemmacros_mhname_width_dim { #1 } - } - } - } - -% \mhName[<keyval>]{<chemformula>}{<text>} -\bool_if:NF \l__chemmacros_version_one_bool - { - \NewDocumentCommand \mhName { o m m } - { - \group_begin: - \IfNoValueF { #1 } { \keys_set:nn { chemmacros / mhName } { #1 } } - \ensuremath - { - \underset - { - \bool_if:NF \l__chemmacros_mhname_width_bool - { \chemmacros_dim_to_width:Nn \l__chemmacros_mhname_width_dim { #2 } } - \parbox - { \dim_use:N \l__chemmacros_mhname_width_dim } - { - \tl_use:N \l__chemmacros_mhname_align_tl - \tl_use:N \l__chemmacros_mhname_format_tl - \tl_use:N \l__chemmacros_mhname_fontsize_tl - #3 - } - } - { \cf { #2 } } - } - \group_end: - } - } +% deprecated mhName: +\keys_define:nn { chemmacros } + { mhName .code:n = \chemmacros_option_deprecated:n { mhName } } % --------------------------------------------------------------------------- % % - phases @@ -2352,12 +2452,24 @@ space .dim_set:N = \l__chemmacros_phases_space_dim } -\cs_new_protected:Npn \chemmacros_declare_phase:Nn #1#2 +\cs_new_protected:Npn \chemmacros_new_phase:Nn #1#2 { \tl_set:Nx \l__chemmacros_tmpa_tl { \chemmacros_remove_backslash:N #1 } \cs_if_free:NF #1 - { \chemmacros_msg:nnxx { chemmacros } { declare-phase } { #1 } {} } + { \msg_error:nnn { chemmacros } { new-phase } { #1 } } + \DeclareTranslationFallback { phase-\l__chemmacros_tmpa_tl } { #2 } + \__chemmacros_define_phase:Nx #1 + { + \exp_not:N \chemmacros_translate:n + { phase-\l__chemmacros_tmpa_tl } + } + } + +\cs_new_protected:Npn \chemmacros_define_phase:Nn #1#2 + { + \tl_set:Nx \l__chemmacros_tmpa_tl + { \chemmacros_remove_backslash:N #1 } \DeclareTranslationFallback { phase-\l__chemmacros_tmpa_tl } { #2 } \__chemmacros_define_phase:Nx #1 { @@ -2371,7 +2483,7 @@ \tl_set:Nx \l__chemmacros_tmpa_tl { \chemmacros_remove_backslash:N #1 } \cs_if_free:NT #1 - { \chemmacros_msg:nnxx { chemmacros } { renew-phase } { #1 } {} } + { \msg_error:nnn { chemmacros } { renew-phase } { #1 } } \DeclareTranslationFallback { phase-\l__chemmacros_tmpa_tl } { #2 } \__chemmacros_define_phase:Nx #1 { @@ -2380,8 +2492,11 @@ } } +\NewDocumentCommand \NewChemPhase { mom } + { \chemmacros_new_phase:Nn #1 { #3 } } + \NewDocumentCommand \DeclareChemPhase { mom } - { \chemmacros_declare_phase:Nn #1 { #3 } } + { \chemmacros_define_phase:Nn #1 { #3 } } \NewDocumentCommand \RenewChemPhase { mom } { \chemmacros_renew_phase:Nn #1 { #3 } } @@ -2407,10 +2522,10 @@ } \cs_generate_variant:Nn \__chemmacros_define_phase:Nn { Nx } -\DeclareChemPhase\sld{ s } -\DeclareChemPhase\lqd{ l } -\DeclareChemPhase\gas{ g } -\DeclareChemPhase\aq { aq } +\NewChemPhase\sld{ s } +\NewChemPhase\lqd{ l } +\NewChemPhase\gas{ g } +\NewChemPhase\aq { aq } \cs_new_protected:Npn \chemmacros_phase:n #1 { @@ -2428,12 +2543,6 @@ \NewDocumentCommand \phase { m } { \chemmacros_phase:n { #1 } } -\bool_if:NT \l__chemmacros_version_one_bool - { - \cs_new_eq:NN \solid \sld - \cs_new_eq:NN \liquid \lqd - } - % -------------------------------------------------------------------------- % reaction environments \cs_new_protected:Npn \__chemmacros_record_for_lor:nnnnn #1#2#3#4#5 @@ -2489,10 +2598,10 @@ % define \listofreactions \tl_new:N \l__chemmacros_reaction_lorname_tl \tl_new:N \reactionlistname +\tl_new:N \l__chemmacros_reaction_heading_tl -% TODO: add option \cs_new:Npn \__chemmacros_reaction_heading:n #1 - { \section* { #1 } } + { \l__chemmacros_reaction_heading_tl { #1 } } \cs_generate_variant:Nn \__chemmacros_reaction_heading:n { V } \cs_new_protected:Npn \listofreactions @@ -2505,9 +2614,7 @@ { \@dottedtocline { 1 } { 1.5em } { 2.3em } { #1 } { #2 } } % create tagform -\bool_if:NTF \l__chemmacros_version_one_bool - { \newtagform { CMreaction } { \{ } { \} } } - { \newtagform { reaction } { \{ } { \} } } +\newtagform { reaction } { \{ } { \} } \newcounter { chemmacros_save_reaction } \newcounter { reaction } @@ -2525,9 +2632,7 @@ { \cs_set_eq:NN \p@equation \p@reaction } \setcounter { chemmacros_save_reaction } { \value { equation } } \setcounter { equation } { \value { reaction } } - \bool_if:NTF \l__chemmacros_version_one_bool - { \usetagform { CMreaction } } - { \usetagform { reaction } } + \usetagform { reaction } } % switch back to equation tags @@ -2550,86 +2655,95 @@ list-name .tl_set:N = \reactionlistname , list-entry .code:n = \tl_set:Nn \l__chemmacros_reaction_lorname_tl { #1 } , - list-heading .code:n = - \cs_set:Npn \__chemmacros_reaction_heading:n ##1 { #1 { ##1 } } + list-heading .tl_set:N = \l__chemmacros_reaction_heading_tl } % \DeclareChemReaction[<keyval>]{<name>}{<type>} -\cs_new_protected:Npn \chemmacros_new_reaction:nnn #1#2#3 +\cs_new_protected:Npn \__chemmacros_define_reaction:Nnnn #1#2#3#4 { - \cs_if_exist:cTF { #2 } - { \msg_error:nnx { chemmacros } { already-defined } { #2 } } + \bool_set_false:N \l__chemmacros_reactions_star_bool + \bool_set_false:N \l__chemmacros_reactions_args_bool + \keys_set:nn { chemmacros / reaction } { #2 } + \bool_if:NTF \l__chemmacros_reactions_args_bool { - \bool_set_false:N \l__chemmacros_reactions_star_bool - \bool_set_false:N \l__chemmacros_reactions_args_bool - \keys_set:nn { chemmacros / reaction } { #1 } - \bool_if:NTF \l__chemmacros_reactions_args_bool + #1 { #3 } [ 2 ] [] { - \NewEnviron { #2 } [ 2 ] [] + \__chemmacros_begin_reaction: + \AddRxnDesc { ##1 } + \begin { #4 } { ##2 } + \chemmacros_equation_chemformula:V \BODY + \end{ #4 } + \__chemmacros_end_reaction: + } + \bool_if:NT \l__chemmacros_reactions_star_bool + { + #1 { #3* } [ 1 ] { - \__chemmacros_begin_reaction: - \AddRxnDesc { ##1 } - \begin { #3 } { ##2 } + \begin { #4* } { ##1 } \chemmacros_equation_chemformula:V \BODY - \end{ #3 } - \__chemmacros_end_reaction: - } - \bool_if:NT \l__chemmacros_reactions_star_bool - { - \NewEnviron { #2* } [ 1 ] - { - \begin { #3* } { ##1 } - \chemmacros_equation_chemformula:V \BODY - \end { #3* } - } + \end { #4* } } } + } + { + #1 { #3 } [ 1 ] [] { - \NewEnviron { #2 } [ 1 ] [] + \__chemmacros_begin_reaction: + \AddRxnDesc { ##1 } + \begin { #4 } + \chemmacros_equation_chemformula:V \BODY + \end { #4 } + \__chemmacros_end_reaction: + } + \bool_if:NT \l__chemmacros_reactions_star_bool + { + #1 { #3* } { - \__chemmacros_begin_reaction: - \AddRxnDesc { ##1 } - \begin { #3 } + \begin { #4* } \chemmacros_equation_chemformula:V \BODY - \end { #3 } - \__chemmacros_end_reaction: - } - \bool_if:NT \l__chemmacros_reactions_star_bool - { - \NewEnviron { #2* } - { - \begin { #3* } - \chemmacros_equation_chemformula:V \BODY - \end { #3* } - } + \end { #4* } } } } \ignorespaces } -\bool_if:NF \l__chemmacros_version_one_bool +\cs_new_protected:Npn \chemmacros_define_reaction:nnn #1#2#3 { - \NewDocumentCommand \DeclareChemReaction { o m m } - { - \IfNoValueTF { #1 } - { \chemmacros_new_reaction:nnn { } { #2 } { #3 } } - { \chemmacros_new_reaction:nnn { #1 } { #2 } { #3 } } - } - \DeclareChemDeprecated \newreaction \DeclareChemReaction - { \DeclareChemReaction } + \cs_if_exist:cTF { #2 } + { \__chemmacros_define_reaction:Nnnn \RenewEnviron { #1 } { #2 } { #3 } } + { \__chemmacros_define_reaction:Nnnn \NewEnviron { #1 } { #2 } { #3 } } } +\cs_new_protected:Npn \chemmacros_new_reaction:nnn #1#2#3 + { + \cs_if_exist:cTF { #2 } + { \msg_error:nnx { chemmacros } { already-defined } { #2 } } + { \__chemmacros_define_reaction:Nnnn \NewEnviron { #1 } { #2 } { #3 } } + } + +\cs_new_protected:Npn \chemmacros_renew_reaction:nnn #1#2#3 + { + \cs_if_exist:cTF { #2 } + { \__chemmacros_define_reaction:Nnnn \RenewEnviron { #1 } { #2 } { #3 } } + { \msg_error:nnx { chemmacros } { not-defined } { #2 } } + } + +\NewDocumentCommand \NewChemReaction { O{} m m } + { \chemmacros_new_reaction:nnn { #1 } { #2 } { #3 } } +\NewDocumentCommand \RenewChemReaction { O{} m m } + { \chemmacros_renew_reaction:nnn { #1 } { #2 } { #3 } } +\NewDocumentCommand \DeclareChemReaction { O{} m m } + { \chemmacros_declare_reaction:nnn { #1 } { #2 } { #3 } } +\DeclareChemDeprecated \newreaction \NewChemReaction + \cs_new_protected:Npn \chemmacros_equation_chemformula:n #1 { \chemformula_ch:nn { } { #1 } } \cs_generate_variant:Nn \chemmacros_equation_chemformula:n { V } % predefined: -\bool_if:NF \l__chemmacros_version_one_bool - { - \DeclareChemReaction [ star ] { reaction } { equation } - \DeclareChemReaction [ star ] { reactions } { align } - } +\NewChemReaction [ star ] { reaction } { equation } +\NewChemReaction [ star ] { reactions } { align } % -------------------------------------------------------------------------- % thermodynamics et.al. @@ -2658,7 +2772,7 @@ } \cs_new_protected:Npn \changestate - { \mathop{} \! \ChemDelta } + { \mathop{} \! \chemDelta } % -------------------------------------------------------------------------- % \State @@ -2724,19 +2838,16 @@ } \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 } - { - \keys_set:nn { chemmacros / state } - { subscript-left = false , exponent = } - } - \chemmacros_state:nnn { #2 } { #3 } { #4 } - \group_end: - } + \group_begin: + \IfBooleanT { #1 } + { + \keys_set:nn { chemmacros / state } + { subscript-left = false , exponent = } + } + \chemmacros_state:nnn { #2 } { #3 } { #4 } + \group_end: } % -------------------------------------------------------------------------- @@ -2753,6 +2864,7 @@ \tl_set:Nn \l__chemmacros_thermod_delta_default_tl { \changestate } \bool_new:N \l__chemmacros_renewstate_bool +\bool_new:N \l__chemmacros_state_overwrite_error_bool \keys_define:nn { chemmacros } { @@ -2777,45 +2889,58 @@ \l__chemmacros_thermod_delta_default_tl } -\bool_if:NF \l__chemmacros_version_one_bool +% \NewChemState{<name>}[<keyval>]{<symbol>}{<unit>} +\NewDocumentCommand \NewChemState { omO{}mm } { - % \DeclareChemState{<name>}[<keyval>]{<symbol>}{<unit>} - \NewDocumentCommand \DeclareChemState { omO{}mm } - { - \bool_set_false:N \l__chemmacros_renewstate_bool - \__chemmacros_setnewstate_reset: - \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{<name>}[<keyval>]{<symbol>}{<unit>} - \NewDocumentCommand \RenewChemState { omO{}mm } + \bool_set_false:N \l__chemmacros_renewstate_bool + \bool_set_true:N \l__chemmacros_state_overwrite_error_bool + \__chemmacros_setnewstate_reset: + \IfNoValueTF { #1 } + { \chemmacros_define_state:nnnn { #3 } { #2 } { #4 } { #5 } } { - \bool_set_true:N \l__chemmacros_renewstate_bool - \__chemmacros_setnewstate_reset: - \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 } - } + \msg_warning:nn { chemmacros } { state-syntax } + \chemmacros_define_state:nnnn { #1#3 } { #2 } { #4 } { #5 } } - \cs_set_protected:Npn \setnewstate + } +% \DeclareChemState{<name>}[<keyval>]{<symbol>}{<unit>} +\NewDocumentCommand \DeclareChemState { omO{}mm } + { + \bool_set_false:N \l__chemmacros_renewstate_bool + \bool_set_false:N \l__chemmacros_state_overwrite_error_bool + \__chemmacros_setnewstate_reset: + \IfNoValueTF { #1 } + { \chemmacros_define_state:nnnn { #3 } { #2 } { #4 } { #5 } } { - \chemmacros_msg:nnxx { chemmacros } { command-deprecated } - { \setnewstate } { \DeclareChemState } - \DeclareChemState + \msg_warning:nn { chemmacros } { state-syntax } + \chemmacros_define_state:nnnn { #1#3 } { #2 } { #4 } { #5 } } - \cs_set_protected:Npn \renewstate + } +% \RenewChemState{<name>}[<keyval>]{<symbol>}{<unit>} +\NewDocumentCommand \RenewChemState { omO{}mm } + { + \bool_set_true:N \l__chemmacros_renewstate_bool + \bool_set_true:N \l__chemmacros_state_overwrite_error_bool + \__chemmacros_setnewstate_reset: + \IfNoValueTF { #1 } + { \chemmacros_define_state:nnnn { #3 } { #2 } { #4 } { #5 } } { - \chemmacros_msg:nnxx { chemmacros } { command-deprecated } - { \renewstate } { \RenewChemState } - \RenewChemState + \msg_warning:nn { chemmacros } { state-syntax } + \chemmacros_define_state:nnnn { #1#3 } { #2 } { #4 } { #5 } } } +% TODO +\cs_set_protected:Npn \setnewstate + { + \msg_warning:nnnn { chemmacros } { command-deprecated } + { \setnewstate } { \NewChemState } + \NewChemState + } +\cs_set_protected:Npn \renewstate + { + \msg_warning:nnnn { chemmacros } { command-deprecated } + { \renewstate } { \RenewChemState } + \RenewChemState + } \cs_new_protected:Npn \__chemmacros_setnewstate_reset: { @@ -2831,32 +2956,35 @@ \chemmacros_if_is_cs:nTF { #2 } { \__chemmacros_set_state:xnn { \cs_to_str:N #2 } { #3 } { #4 } } { - \chemmacros_msg:nn { chemmacros } { state-syntax } + \msg_warning:nn { chemmacros } { state-syntax } \__chemmacros_set_state:nnn { #2 } { #3 } { #4 } } } \cs_new_protected:Npn \__chemmacros_set_state:nnn #1#2#3 { - \bool_if:NTF \l__chemmacros_renewstate_bool + \bool_if:NT \l__chemmacros_state_overwrite_error_bool { - \cs_if_exist:cF { #1 } - { \msg_error:nnx { chemmacros } { renew-state } { #1 } } - \cs_undefine:c {chemmacros_ #1 _reset: } - \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 } - \cs_undefine:c { #1 _aux_iii:n } - } - { - \cs_if_exist:cT { #1 } - { \msg_error:nnx { chemmacros } { declare-state } { #1 } } + \bool_if:NTF \l__chemmacros_renewstate_bool + { + \cs_if_exist:cF { #1 } + { \msg_error:nnx { chemmacros } { nenew-state } { #1 } } + } + { + \cs_if_exist:cT { #1 } + { \msg_error:nnx { chemmacros } { new-state } { #1 } } + } } + \cs_undefine:c { chemmacros_ #1 _reset: } + \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 } + \cs_undefine:c { #1 _aux_iii:n } \group_begin: \tl_const:cV { c__chemmacros_ #1 _subscript_tl } @@ -2953,13 +3081,10 @@ \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 \Entropy [ delta=false, subscript-left=false ] - {S} {\joule\per\kelvin\per\mole} - \DeclareChemState \Gibbs {G} {\kilo\joule\per\mole} - } +\NewChemState \Enthalpy {H} {\kilo\joule\per\mole} +\NewChemState \Entropy [ delta=false, subscript-left=false ] + {S} {\joule\per\kelvin\per\mole} +\NewChemState \Gibbs {G} {\kilo\joule\per\mole} % -------------------------------------------------------------------------- % Newman projections @@ -2995,17 +3120,14 @@ } % \newman[<keyval>](<angle>){<1>,<2>,<3>,<4>,<5>,<6>} -\bool_if:NF \l__chemmacros_version_one_bool +\NewDocumentCommand \newman { o d() > { \SplitArgument { 5 } { , } } m } { - \NewDocumentCommand \newman { o d() > { \SplitArgument { 5 } { , } } m } - { - \group_begin: - \IfNoValueF { #1 } { \keys_set:nn { chemmacros / newman } { #1 } } - \IfNoValueTF { #2 } - { \chemmacros_newman_atoms:nnnnnnn { } #3 } - { \chemmacros_newman_atoms:nnnnnnn { #2 } #3 } - \group_end: - } + \group_begin: + \IfNoValueF { #1 } { \keys_set:nn { chemmacros / newman } { #1 } } + \IfNoValueTF { #2 } + { \chemmacros_newman_atoms:nnnnnnn { } #3 } + { \chemmacros_newman_atoms:nnnnnnn { #2 } #3 } + \group_end: } % place atoms: @@ -3783,21 +3905,13 @@ \IfNoValueTF { #1 } { \keys_set:nn { chemmacros } { #2 } } { - \bool_if:NTF \l__chemmacros_version_four_bool - { - \tl_if_eq:nnTF { #1 } { chemformula } - { \setchemformula { #2 } } - { \keys_set:nn { chemmacros / #1 } { #2 } } - } + \tl_if_eq:nnTF { #1 } { chemformula } + { \setchemformula { #2 } } { \keys_set:nn { chemmacros / #1 } { #2 } } } \ignorespaces } -% -------------------------------------------------------------------------- -% load old definitions: -\bool_if:NT \l__chemmacros_version_one_bool - { \file_input:n { chemmacros-version1 . cfg } } % -------------------------------------------------------------------------- % hyperref support @@ -4069,6 +4183,34 @@ Version history and `acid-base/K-water' - adapt \ox to updates in `l3fp' 2014/01/09 - version 4.2e - step bundle version due to changes in `ghsystem' +2014/01/24 - version 4.3 - \NewChemIUPAC, \LetChemIUPAC + - \NewChemParticle + - \NewChemNMR + - \NewChemPhase + - \NewChemReaction, \RenewChemReaction + - \NewChemState + - added macro names with more meaningfule names to + each of the one-letter name commands + - changed behaviour of \DeclareChem to match + \DeclareRobustCommand, i.e., no check if command + is defined; added a \NewChem variant to each that + /does/ check; use \NewChem instead of \DeclareChem + for definitions + - new iupac command \dento + - new option choice `nmr/pos=super' + - bug fix in appearance of coupling nuclei + - new possibilities for formatting the output of the + NMR coupling constants output with \J: + `coupling-pos=side/sub', `coupling-nuclei-pre', + coupling-nuclei-post', `coupling-bonds-pre', + coupling-bonds-post', `coupling-symbol' + - internal changes to the greek letter mapping + selection mechanism + - deprecate package option `strict' + - deprecate package option `cmversion': also all + backwards compatibility for version 1 has been + dropped + - drop command \mhName % --------------------------------------------------------------------------- % % TODO: |