From a1cc0e0ea92d774194ebc156455ec9f3771998f2 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Wed, 21 Mar 2012 23:09:51 +0000 Subject: chemmacros (21mar12) git-svn-id: svn://tug.org/texlive/trunk@25721 c570f23f-e606-0410-a88d-b1316a301751 --- .../tex/latex/chemmacros/chemformula.sty | 78 ++++++++++++---- .../texmf-dist/tex/latex/chemmacros/chemmacros.sty | 100 ++++++++++++++++----- .../texmf-dist/tex/latex/chemmacros/ghsystem.sty | 7 +- 3 files changed, 143 insertions(+), 42 deletions(-) (limited to 'Master/texmf-dist/tex/latex/chemmacros') diff --git a/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty b/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty index 11b5e014f7f..a509e2772a1 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/03/14 - % +% - 2012/03/20 - % % --------------------------------------------------------------------------- % % - https://bitbucket.org/cgnieder/chemmacros/ - % % - contact@mychemistry.eu - % @@ -30,8 +30,8 @@ \RequirePackage{ expl3 } \ProvidesExplPackage {chemformula} - {2012/03/14} - {3.1c} + {2012/03/20} + {3.2} {typeset chemical compounds and reactions} %-----------------------------------------------------------------------------% @@ -81,7 +81,7 @@ % pass options to the `chemmacros' package \DeclareOption* { \PassOptionsToPackage { \CurrentOption } { chemmacros } } -\ProcessOptions\relax +\ProcessOptions \scan_stop: \RequirePackage { chemmacros , nicefrac } @@ -228,6 +228,13 @@ \pgfusepathqfillstroke } +% a possibility to overwrite the arrow tips: +\providecommand*\pgfarrowsrenewalias[4]{% + \let\savedef\pgf@arrows@check@already + \def\pgf@arrows@check@already##1##2##3{##3}% + \pgfarrowsdeclarealias{#1}{#2}{#3}{#4}% + \let\pgf@arrows@check@already\savedef} + %-----------------------------------------------------------------------------% % dimension variables \dim_new:N \l_chemformula_arrow_length_dim @@ -494,12 +501,12 @@ { \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 + \chemformula_generate_arrows:V \l_chemformula_input_tl + \chemformula_generate_name:V \l_chemformula_output_tl \tl_set_rescan:Nno \l_chemformula_output_tl { \ExplSyntaxOn } { \l_chemformula_output_tl } - \chemformula_write:n { \l_chemformula_output_tl } + \chemformula_write:V \l_chemformula_output_tl \group_end: } @@ -541,7 +548,7 @@ \NewDocumentCommand \ch { om } { \chemformula_ch:nn { #1 } { #2 } } -\cs_new:Npn \chemformula_write:n #1 +\cs_new:Nn \chemformula_write:V { \mode_if_math:TF { @@ -556,7 +563,7 @@ %-----------------------------------------------------------------------------% % arrow generation & detection -\cs_set:Npn \chemformula_generate_arrows:n #1 +\cs_set:Nn \chemformula_generate_arrows:V { \tl_set:No \l_tmpa_tl { #1 } \seq_map_inline:Nn \l_chemformula_arrows_type_seq @@ -566,7 +573,6 @@ } \tl_set_eq:NN \l_chemformula_output_tl \l_tmpa_tl } -\cs_generate_variant:Nn \chemformula_generate_arrows:n { N } \cs_new:Npn \chemformula_detect_arrows:n #1 { @@ -612,14 +618,13 @@ } \cs_generate_variant:Nn \width_to_dim:nn { Nn } -\cs_new:Npn \chemformula_generate_name:n #1 +\cs_new:Nn \chemformula_generate_name:V { \tl_set:No \l_tmpa_tl { #1 } \tl_if_in:onT { \l_tmpa_tl } { ! } { \tl_replace_all:Nnn \l_tmpa_tl { ! } { \chemformula_name_cmpd:w } } \tl_set_eq:NN \l_chemformula_output_tl \l_tmpa_tl } -\cs_generate_variant:Nn \chemformula_generate_name:n { N } \cs_new:Npn \chemformula_detect_name:n #1 { @@ -633,6 +638,8 @@ % parsing input % booleans: \bool_new:N \l_chemformula_inside_ch_bool +\bool_new:N \l_chemformula_options_bool +\bool_new:N \l_chemformula_is_option_bool \bool_new:N \l_chemformula_stoich_bool \bool_new:N \l_chemformula_is_plus_bool \bool_new:N \l_chemformula_is_up_bool @@ -1128,8 +1135,8 @@ \chemformula_input_escape_math:n { #1 } \chemformula_input_stoich:n { #1 } \chemformula_clean_chem_macros:o { \l_chemformula_tmpa_tl } - \chemformula_input_cmpd:oN - { \l_chemformula_tmpa_tl } \l_chemformula_input_tl + \chemformula_input_cmpd:VN + \l_chemformula_tmpa_tl \l_chemformula_input_tl \chemformula_input_arrow:n { #1 } \chemformula_input_name:n { #1 } \chemformula_input_plus:n { #1 } @@ -1137,6 +1144,25 @@ \chemformula_input_down:n { #1 } } +%-----------------------------------------------------------------------------% +% set options for next compound: +% TODO: this is not working: +% - applies to first instead of the next cmpd +\cs_new:Npn \chemformula_input_options:n #1 + { + \makeatother + \tl_set_rescan:Nnn \l_tmpa_tl { \makeatletter } { #1 } + \tl_if_in:VnTF \l_tmpa_tl { @ } + { + \bool_set_true:N \l_chemformula_options_bool + \bool_set_true:N \l_chemformula_is_option_bool + \tl_remove_all:Nn \l_tmpa_tl { @ } + \exp_last_unbraced:Nno \tl_set:Nn \l_chemformula_internal_options_tl + { \l_tmpa_tl } + } + { \bool_set_false:N \l_chemformula_is_option_bool } + } + %-----------------------------------------------------------------------------% % input stoichiometric factors \cs_new:Npn \chemformula_input_stoich:n #1 @@ -1236,8 +1262,19 @@ { \bool_set_true:N \l_chemformula_is_up_bool } \chemformula_detect_arrows:n { #1 } \chemformula_detect_name:n { #1 } + \chemformula_input_options:n { #1 } + \bool_if:NT \l_chemformula_is_option_bool + { + \tl_put_right:Nn #2 + { + \group_begin: + \keys_set:nV { chemmacros / chemformula } + \l_chemformula_internal_options_tl + } + } \bool_if:nT { + !\l_chemformula_is_option_bool && !\l_chemformula_is_plus_bool && !\l_chemformula_is_down_bool && !\l_chemformula_is_up_bool && @@ -1250,6 +1287,15 @@ \tl_put_right:Nn #2 { \chemformula_font_inner: } \chemformula_handle_sub_and_superscripts:nN { #1 } #2 + \bool_if:NT \l_chemformula_options_bool + { + \tl_put_right:Nn #2 + { + \group_end: + \tl_clear:N \l_chemformula_internal_options_tl + } + \bool_set_false:N \l_chemformula_options_bool + } } } { @@ -1258,7 +1304,7 @@ \tl_clear:N \l_chemformula_stoich_tl } } -\cs_generate_variant:Nn \chemformula_input_cmpd:nN { oN , fN , xN } +\cs_generate_variant:Nn \chemformula_input_cmpd:nN { VN } \cs_new:Nn \chemformula_font_inner: { @@ -1694,6 +1740,8 @@ VERSION HISTORY - new option charge-vshift 2012/03/14 - version 3.1c - a few changes in chemmacros.sty - improved arrow labels +2012/03/20 - version 3.2 - new: option input via @{} + - a few changes in chemmacros.sty %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % TODO diff --git a/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty b/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty index 77dab7f9d0c..b06c416bc68 100644 --- a/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty +++ b/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty @@ -5,7 +5,7 @@ % - macros and commands for chemists - % % --------------------------------------------------------------------------- % % - Clemens Niederberger - % -% - 2012/03/14 - % +% - 2012/03/20 - % % --------------------------------------------------------------------------- % % - https://bitbucket.org/cgnieder/chemmacros/ - % % - contact@mychemistry.eu - % @@ -33,8 +33,8 @@ \ProvidesExplPackage {chemmacros} - {2012/03/14} - {3.1c} + {2012/03/20} + {3.2} {macros and commands for chemists} \@ifpackageloaded { chemformula } {} { \RequirePackage { chemformula } } @@ -305,6 +305,23 @@ exist. } +\msg_set:nnnn { chemmacros } { declare-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 \c_space_tl + already~exists.~Choose~another~name. + } + +\msg_set:nnnn { chemmacros } { f } + { The~latin~phrase \token_to_str:N #1 \c_space_tl is~not~defined. } + { + You've~tried~to~renew~the~latin~phrase~\token_to_str:N #1 ,~but~it~doesn't~ + exist. + } + \msg_set:nnnn { chemmacros } { declare-phase } { The~command~sequence~ \token_to_str:N #1 \c_space_tl is~already~defined. @@ -600,7 +617,7 @@ \tl_set_rescan:Nno \l_tmpa_tl { \ExplSyntaxOn } { \l_chemformula_input_tl } - \chemformula_write:n { \l_tmpa_tl } + \chemformula_write:V \l_tmpa_tl \group_end: \chemmacros_xspace: } @@ -996,17 +1013,49 @@ \cs_set_eq:NN \iupac \chemmacros_iupac:n % latin phrases +\tl_new:N \l_chemmacros_latin_format_tl +\tl_set:Nn \l_chemmacros_latin_format_tl { \itshape } + +\keys_define:nn { chemmacros / latin } + { format . tl_set:N = \l_chemmacros_latin_format_tl } + +\cs_new:Npn \chemmacros_latin:n #1 + { { \l_chemmacros_latin_format_tl #1 } } + +\prop_new:N \l_chemmacros_latin_prop +\NewDocumentCommand \DeclareChemLatin { mm } + { + \cs_if_free:NTF #1 + { + \cs_new:Npn #1 { \chemmacros_latin:n { #2 } \chemmacros_xspace: } + \prop_put:Nnn \l_chemmacros_latin_prop { #1 } { #2 } + } + { \chemmacros_msg:nnxx { chemmacros } { declare-latin } { #1 } { } } + } + +\NewDocumentCommand \RenewChemLatin { mm } + { + \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 } { } } + } + \AtBeginDocument { \bool_if:NTF \l_chemmacros_chemstyle_bool { - \cs_new_nopar:Npn \insitu { \latin{in~situ} \chemmacros_xspace: } - \cs_new_nopar:Npn \abinitio { \latin{ab~initio} \chemmacros_xspace: } + \AfterPackage* { chemstyle } + { + \cs_undefine:N \invacuo + \cs_set_eq:NN \chemmacros_latin:n \cst@latin + } } { - \cs_new_nopar:Npn \insitu { \textit{in~situ} \chemmacros_xspace: } - \cs_new_nopar:Npn \abinitio { \textit{ab~initio} \chemmacros_xspace: } + \cs_new_eq:NN \latin \chemmacros_latin:n } + \DeclareChemLatin \insitu { in~situ } + \DeclareChemLatin \abinitio { ab~initio } + \DeclareChemLatin \invacuo { in~vacuo } } % --------------------------------------------------------------------------- % @@ -1447,7 +1496,7 @@ \tl_set:Nn \l_chemmacros_redox_end_tl { #2 } } -\NewDocumentCommand \redox { > { \SplitArgument { 1 } { , } } d() o o m } +\NewDocumentCommand \redox { > { \SplitArgument { 1 } { , } } r() o o G{} } { \IfNoValueT { #1 } { @@ -1820,7 +1869,7 @@ \char_set_catcode_letter:N \@ % --------------------------------------------------------------------------- % -% reaction environments for mhchem +% reaction environments % redefine mathtools' command \MT_define_tagform:nwnn to ensure we add an % entry to the list of reactions even if the user redefines the reaction tag @@ -1838,13 +1887,21 @@ \addcontentsline { lor } { reaction } { \l_chemmacros_reaction_lorname_tl #3 #2 ##1 #4 - \tl_use:c { l_chemmacros_reaction_ \thereaction _tl } + \tl_use:N \g_chemmacros_reaction_description_tl } + \tl_gclear:N \g_chemmacros_reaction_description_tl } } } } +\tl_new:N \g_chemmacros_reaction_description_tl +\NewDocumentCommand \AddRxnDesc { m } + { + \tl_if_blank:nF { #1 } + { \tl_gset:Nn \g_chemmacros_reaction_description_tl { : ~ #1 } } + } + % define \listofreactions \tl_new:N \l_chemmacros_reaction_lorname_tl \tl_new:N \reactionlistname @@ -1886,7 +1943,7 @@ { \usetagform { CMreaction } } { \usetagform { reaction } } % => this is problematic because it disallows resetting the counter: - \tl_new:c { l_chemmacros_reaction_ \thereaction _tl } +% \tl_new:c { l_chemmacros_reaction_ \thereaction _tl } } % switch back to equation tags @@ -1930,12 +1987,7 @@ \NewEnviron { #2 } [ 2 ] [] { \chemmacros_begin_reaction: - \tl_if_blank:nF { ##1 } - { - \tl_set:cn - { l_chemmacros_reaction_ \thereaction _tl } - { : ~ ##1 } - } + \AddRxnDesc { ##1 } \begin { #3 } { ##2 } \chemmacros_equation_chemformula:o { \BODY } \end{ #3 } @@ -1955,12 +2007,7 @@ \NewEnviron { #2 } [ 1 ] [] { \chemmacros_begin_reaction: - \tl_if_blank:nF { ##1 } - { - \tl_set:cn - { l_chemmacros_reaction_ \thereaction _tl } - { : ~ ##1 } - } + \AddRxnDesc { ##1 } \begin { #3 } \chemmacros_equation_chemformula:o { \BODY } \end { #3 } @@ -3265,6 +3312,11 @@ Version history 2012/03/14 - version 3.1c - compatibility with KOMA's global option "version = " - bugfix in the list of reactions +2012/03/20 - version 3.2 - new feature in chemformula + - improved list of reactions: resetting the "reaction" + counter now doesn't cause errors any more + - \AddRxnDesc added which allows to add descriptions + to each reaction in the "reactions" environment % --------------------------------------------------------------------------- % % TODO: diff --git a/Master/texmf-dist/tex/latex/chemmacros/ghsystem.sty b/Master/texmf-dist/tex/latex/chemmacros/ghsystem.sty index 72e2ab854e7..4c91a0b8796 100644 --- a/Master/texmf-dist/tex/latex/chemmacros/ghsystem.sty +++ b/Master/texmf-dist/tex/latex/chemmacros/ghsystem.sty @@ -5,7 +5,7 @@ % - macros and commands for chemists - % % --------------------------------------------------------------------------- % % - Clemens Niederberger - % -% - 2012/03/14 - % +% - 2012/03/20 - % % --------------------------------------------------------------------------- % % - https://bitbucket.org/cgnieder/chemmacros/ - % % - contact@mychemistry.eu - % @@ -30,8 +30,8 @@ \RequirePackage{ expl3 } \ProvidesExplPackage {ghsystem} - {2012/03/14} - {3.1c} + {2012/03/20} + {3.2} {globally harmonised system} % --------------------------------------------------------------------------- % @@ -455,6 +455,7 @@ VERSION HISTORY 2012/02/26 - version 3.1a - changes in the chemmacros package 2012/03/03 - version 3.1b - changes in packages chemformula and chemmacros 2012/03/14 - version 3.1c - changes in packages chemformula and chemmacros +2012/03/20 - version 3.2 - changes in packages chemformula and chemmacros %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % TODO: -- cgit v1.2.3