summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/substances
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2015-10-21 21:08:04 +0000
committerKarl Berry <karl@freefriends.org>2015-10-21 21:08:04 +0000
commitca8b37e0e9b1a89ad33804cfb8404f919c01b1f0 (patch)
tree918f841962543928f9839874400073051be3a82b /Master/texmf-dist/tex/latex/substances
parent906cc538429df04e26a1f8bbf54ff6930e1ffb1b (diff)
substances (21oct15)
git-svn-id: svn://tug.org/texlive/trunk@38684 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/substances')
-rw-r--r--Master/texmf-dist/tex/latex/substances/substances-default.def75
-rw-r--r--Master/texmf-dist/tex/latex/substances/substances.sty513
2 files changed, 366 insertions, 222 deletions
diff --git a/Master/texmf-dist/tex/latex/substances/substances-default.def b/Master/texmf-dist/tex/latex/substances/substances-default.def
index f802dbc00c5..c88c6a98fc3 100644
--- a/Master/texmf-dist/tex/latex/substances/substances-default.def
+++ b/Master/texmf-dist/tex/latex/substances/substances-default.def
@@ -8,7 +8,7 @@
% Web: https://bitbucket.org/cgnieder/substances/
% E-Mail: contact@mychemistry.eu
% --------------------------------------------------------------------------
-% Copyright 2012 Clemens Niederberger
+% Copyright 2012--2015 Clemens Niederberger
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
@@ -30,51 +30,50 @@
% feel free to contact me.
% --------------------------------------------------------------------------
% substances: default style
-\RequirePackage { chemfig , siunitx }
+\SubstancesStyle*{default}
+\RequirePackage {chemfig,siunitx}
% ----------------------------------------------------------------------------
% helper functions for the GHS properties:
-\cs_new:Npn \substances_get_pics:n #1
+\cs_new_protected:Npn \substances_get_pics:n #1
{
- \int_zero:N \l_tmpa_int
- \clist_map_inline:nn { #1 }
- {
- \int_incr:N \l_tmpa_int
- \int_compare:nF { \l_tmpa_int = 1 } { ~ }
- \ghspic{##1}
- }
+ \seq_set_split:Nnn \l_tmpa_seq {,} {#1}
+ \seq_set_map:NNn \l_tmpa_seq \l_tmpa_seq { \ghspic {##1} }
+ \seq_use:Nn \l_tmpa_seq {~}
}
-\cs_new:Npn \substances_get_ghs:nn #1#2
+\cs_new_protected:Npn \substances_get_ghs:nn #1#2
{
- \int_zero:N \l_tmpa_int
- \clist_map_inline:nn { #2 }
- {
- \int_incr:N \l_tmpa_int
- \int_compare:nF { \l_tmpa_int = 1 }
- { \bool_if:NT \l_ghsystem_hide_statement_bool { , } ~ }
- \ghs{#1}{##1}
- }
+ \seq_set_split:Nnn \l_tmpa_seq {,} {#2}
+ \seq_set_map:NNn \l_tmpa_seq \l_tmpa_seq { \ghs {#1} {##1} }
+ \seq_use:Nn \l_tmpa_seq
+ { \bool_if:NT \l__ghsystem_hide_statement_bool {,} ~ }
}
+\NewDocumentCommand \ghspictograms {m}
+ { \substances_get_pics:n {#1} }
+
+\NewDocumentCommand \ghsstatements {mm}
+ { \substances_get_ghs:nn {#1} {#2} }
+
% ----------------------------------------------------------------------------
-\DeclareSubstanceProperty { formula } [\ch]
-\DeclareSubstanceProperty { structure } [\chemfig]
-\DeclareSubstanceProperty { mass } [\SI][{\MolMass}]
-\DeclareSubstanceProperty { bp } [\SI][{\celsius}]
-\DeclareSubstanceProperty { mp } [\SI][{\celsius}]
-\DeclareSubstanceProperty { density } [\SI][{\gram\per\cmc}]
-\DeclareSubstanceProperty { phase }
-\DeclareSubstanceProperty {pKa} [\num]
-\DeclareSubstanceProperty {pKa1} [\num]
-\DeclareSubstanceProperty {pKa2} [\num]
-\DeclareSubstanceProperty {pKb} [\num]
-\DeclareSubstanceProperty {pKb1} [\num]
-\DeclareSubstanceProperty {pKb2} [\num]
-\DeclareSubstanceProperty { pictograms } [\substances_get_pics:n]
-\DeclareSubstanceProperty { H } [\substances_get_ghs:nn{H}]
-\DeclareSubstanceProperty { P } [\substances_get_ghs:nn{P}]
-\DeclareSubstanceProperty { EUH } [\substances_get_ghs:nn{EUH}]
-\DeclareSubstanceProperty {LD50} [\SI][{\milli\gram\per\kilo\gram}]
+\DeclareSubstanceProperty {formula} [\ch]
+\DeclareSubstanceProperty {structure} [\chemfig]
+\DeclareSubstanceProperty {mass} [\SI][{\MolMass}]
+\DeclareSubstanceProperty {bp} [\SI][{\celsius}]
+\DeclareSubstanceProperty {mp} [\SI][{\celsius}]
+\DeclareSubstanceProperty {density} [\SI][{{\gram\per\cubic\centi\metre}}]
+\DeclareSubstanceProperty {phase}
+\DeclareSubstanceProperty {pKa} [\num]
+\DeclareSubstanceProperty {pKa1} [\num]
+\DeclareSubstanceProperty {pKa2} [\num]
+\DeclareSubstanceProperty {pKb} [\num]
+\DeclareSubstanceProperty {pKb1} [\num]
+\DeclareSubstanceProperty {pKb2} [\num]
+\DeclareSubstanceProperty {pictograms} [\ghspictograms]
+\DeclareSubstanceProperty {H} [\ghsstatements{H}]
+\DeclareSubstanceProperty {P} [\ghsstatements{P}]
+\DeclareSubstanceProperty {EUH} [\ghsstatements{EUH}]
+\DeclareSubstanceProperty {LD50} [\SI][{{\milli\gram\per\kilo\gram}}]
-\tex_endinput:D \ No newline at end of file
+\tex_endinput:D
diff --git a/Master/texmf-dist/tex/latex/substances/substances.sty b/Master/texmf-dist/tex/latex/substances/substances.sty
index e9406055d2b..286c9463218 100644
--- a/Master/texmf-dist/tex/latex/substances/substances.sty
+++ b/Master/texmf-dist/tex/latex/substances/substances.sty
@@ -8,7 +8,7 @@
% Web: https://bitbucket.org/cgnieder/substances/
% E-Mail: contact@mychemistry.eu
% --------------------------------------------------------------------------
-% Copyright 2012 Clemens Niederberger
+% Copyright 2012--2015 Clemens Niederberger
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
@@ -29,80 +29,99 @@
% If you have any ideas, questions, suggestions or bugs to report, please
% feel free to contact me.
% --------------------------------------------------------------------------
-\RequirePackage{ expl3 , xparse , l3keys2e , xtemplate , chemmacros }
+\RequirePackage{ expl3 , xparse , l3keys2e , xtemplate }
\ProvidesExplPackage
{substances}
- {2012/07/22}
- {0.1}
+ {2015/10/21}
+ {0.2}
{A Chemical Database}
+\RequirePackage{chemmacros,chemfig,ghsystem}
+\usechemmodule{nomenclature,units}
+
% ----------------------------------------------------------------------------
% variables:
-\prop_new:N \l_substances_properties_pre_prop
-\prop_new:N \l_substances_properties_post_prop
+\tl_new:N \l__substances_tmpa_tl
+\tl_new:N \l__substances_tmpb_tl
+
+\prop_new:N \l__substances_properties_pre_prop
+\prop_new:N \l__substances_properties_post_prop
-\seq_new:N \l_substances_required_seq
+\seq_new:N \l__substances_required_seq
\seq_new:N \l_substances_chemicals_seq
\clist_new:N \l_substances_chemicals_clist
-\bool_new:N \l_substances_strict_bool
-\bool_new:N \l_substances_index_entry_bool
-\bool_new:N \l_substances_imakeidx_bool
-\bool_new:N \l_substances_multind_bool
-\bool_new:N \l_substances_splitidx_bool
+\bool_new:N \l__substances_strict_bool
+\bool_new:N \l__substances_index_entry_bool
+\bool_new:N \l__substances_imakeidx_bool
+\bool_new:N \l__substances_multind_bool
+\bool_new:N \l__substances_splitidx_bool
+\bool_new:N \l__substances_single_name_bool
+\bool_new:N \l__substances_single_alt_bool
+\bool_set_true:N \l__substances_single_alt_bool
-\tl_new:N \l_substances_style_tl
-\tl_set:Nn \l_substances_style_tl { default }
+\tl_new:N \l__substances_style_tl
+\tl_set:Nn \l__substances_style_tl {default}
\AtBeginDocument
{
- \@ifpackageloaded { imakeidx }
- { \bool_set_true:N \l_substances_imakeidx_bool } {}
- \@ifpackageloaded { splitidx }
- { \bool_set_true:N \l_substances_splitidx_bool } {}
- \@ifpackageloaded { multind }
- { \bool_set_true:N \l_substances_multind_bool } {}
+ \@ifpackageloaded {imakeidx}
+ { \bool_set_true:N \l__substances_imakeidx_bool } { }
+ \@ifpackageloaded {splitidx}
+ { \bool_set_true:N \l__substances_splitidx_bool } { }
+ \@ifpackageloaded {multind}
+ { \bool_set_true:N \l__substances_multind_bool } { }
}
% ----------------------------------------------------------------------------
% messages:
-\cs_new:Npn \substances_msg:nnn #1#2#3
+\cs_new_protected:Npn \substances_msg:nnn #1#2#3
+ {
+ \bool_if:NTF \l__substances_strict_bool
+ { \msg_error:nnnn {substances} {#1} {#2} {#3} }
+ { \msg_warning:nnnn {substances} {#1} {#2} {#3} }
+ }
+
+\cs_new_protected:Npn \substances_msg:nn #1#2
{
- \bool_if:NTF \l_substances_strict_bool
- { \msg_error:nnxx { substances } { #1 } { #2 } { #3 } }
- { \msg_warning:nnxx { substances } { #1 } { #2 } { #3 } }
+ \bool_if:NTF \l__substances_strict_bool
+ { \msg_error:nnn {substances} {#1} {#2} }
+ { \msg_warning:nnn {substances} {#1} {#2} }
}
-\msg_new:nnnn { substances } { property-missing }
+\msg_new:nnnn {substances} {property-missing}
{ Property~`#2'~not~defined~for~substance~`#1'~\msg_line_context:. }
{
You~called~property~`#2'~for~substance~`#1'.~It~seems~though~that~you~
haven't~defined~it,~yet.
}
-\msg_new:nnnn { substances } { field-missing }
+\msg_new:nnnn {substances} {field-missing}
{ Property~`#2'~is~not~defined~\msg_line_context:. }
{
You~called~property~`#2'~for~substance~`#1'.~This~property~has~not~been~
declared,~though.~Perhaps~you've~mispelled?
}
-\msg_new:nnnn { substances } { dadabase-missing }
- { I~can't~find~the~database~file~`#1'~\msg_line_context:. }
+\msg_new:nnnn {substances} {database-missing}
+ {
+ I~ can't~ find~ the~ database~ file~ `\__substances_database:n{#1}'~
+ \msg_line_context: .
+ }
{
- You~requested~the~database~file~`#1',~but~apparently~it~is~missing.~Maybe~
- you've~mispelled?
+ You~ requested~ the~ database~ file~ `\__substances_database:n{#1}',~ but~
+ apparently~ it~ is~ missing.~ Maybe~ you've~ mispelled?
}
-\msg_new:nnnn { substances } { required-field }
+\msg_new:nnnn {substances} {required-field}
{ The~field~`#1'~is~missing~for~substance~`#2'~\msg_line_context:. }
{
You~declared~the~the~substance~`#2'~but~forgot~to~add~the~required~
property~`#1'.
}
-\msg_new:nnnn { substances } { style-missing }
+\msg_new:nnnn {substances} {style-missing}
{ I~can't~find~the~file~`substances_#1.def'. }
{
You~specified~the~style~`#1'~which~means~you~want~me~to~load~the~file~
@@ -114,165 +133,171 @@
% options
\keys_define:nn { substances / options }
{
- strict .bool_set:N = \l_substances_strict_bool ,
- draft .code:n = \bool_set_true:N \l_substances_strict_bool ,
- final .code:n = \bool_set_false:N \l_substances_strict_bool ,
- index .bool_set:N = \l_substances_index_entry_bool ,
- style .tl_set:N = \l_substances_style_tl
+ strict .bool_set:N = \l__substances_strict_bool ,
+ draft .code:n = \bool_set_true:N \l__substances_strict_bool ,
+ final .code:n = \bool_set_false:N \l__substances_strict_bool ,
+ index .bool_set:N = \l__substances_index_entry_bool ,
+ style .tl_set:N = \l__substances_style_tl
}
\ProcessKeysOptions { substances / options }
% ----------------------------------------------------------------------------
% define new property fields:
-\cs_new:Npn \substances_define_property_field:nnnn #1#2#3#4
- {
- \IfBooleanT { #1 }
- { \seq_put_right:Nn \l_substances_required_seq { #2 } }
- \prop_if_exist:cF { l_substances_#2_prop }
- { \prop_new:c { l_substances_#2_prop } }
- \IfNoValueTF { #3 }
- { \prop_put:Nnn \l_substances_properties_pre_prop { #2 } { } }
- {
- \tl_if_blank:nTF { #3 }
- { \prop_put:Nnn \l_substances_properties_pre_prop { #2 } { } }
- { \prop_put:Nnn \l_substances_properties_pre_prop { #2 } { #3 } }
- }
- \IfNoValueTF { #4 }
- { \prop_put:Nnn \l_substances_properties_post_prop { #2 } { } }
- { \prop_put:Nnn \l_substances_properties_post_prop { #2 } { #4 } }
+\cs_new_protected:Npn \substances_define_property_field:nnnn #1#2#3#4
+ {
+ \bool_if:nT {#1}
+ { \seq_put_right:Nn \l__substances_required_seq {#2} }
+ \prop_if_exist:cF { l__substances_#2_prop }
+ { \prop_new:c { l__substances_#2_prop } }
+ \tl_if_blank:nTF {#3}
+ { \prop_put:Nnn \l__substances_properties_pre_prop {#2} { } }
+ { \prop_put:Nnn \l__substances_properties_pre_prop {#2} {#3} }
+ \tl_if_blank:nTF {#4}
+ { \prop_put:Nnn \l__substances_properties_post_prop {#2} { } }
+ { \prop_put:Nnn \l__substances_properties_post_prop {#2} {#4} }
}
-\NewDocumentCommand \DeclareSubstanceProperty { smoo }
- { \substances_define_property_field:nnnn { #1 } { #2 } { #3 } { #4 } }
+\NewDocumentCommand \DeclareSubstanceProperty { smO{}O{} }
+ { \substances_define_property_field:nnnn {#1} {#2} {#3} {#4} }
\@onlypreamble\DeclareSubstanceProperty
% ----------------------------------------------------------------------------
% declare new substance entry:
-\cs_new:Npn \substances_declare_substance:nn #1#2
+\cs_new_protected:Npn \substances_declare_substance:nn #1#2
{
- \seq_put_right:Nn \l_substances_chemicals_seq { #1 }
- \clist_put_right:Nn \l_substances_chemicals_clist { #1 }
- \prop_map_inline:Nn \l_substances_properties_pre_prop
+ \seq_put_right:Nn \l_substances_chemicals_seq {#1}
+ \clist_put_right:Nn \l_substances_chemicals_clist {#1}
+ \prop_map_inline:Nn \l__substances_properties_pre_prop
{
- \tl_set:Nn \l_tmpa_tl { ##2 }
- \prop_get:NnN \l_substances_properties_post_prop { ##1 } \l_tmpb_tl
- \substances_add_property:nnVV { #1 } { ##1 } \l_tmpa_tl \l_tmpb_tl
+ \tl_set:Nn \l__substances_tmpa_tl {##2}
+ \prop_get:NnN \l__substances_properties_post_prop
+ {##1}
+ \l__substances_tmpb_tl
+ \substances_add_property:nnVV {#1} {##1}
+ \l__substances_tmpa_tl
+ \l__substances_tmpb_tl
}
- \keys_set:nn { substances / #1 } { #2 }
- \seq_map_inline:Nn \l_substances_required_seq
+ \keys_set:nn { substances / #1 } {#2}
+ \seq_map_inline:Nn \l__substances_required_seq
{
\group_begin:
- \bool_set_true:N \l_substances_strict_bool
- \prop_if_in:cnF { l_substances_##1_prop } { #1 }
- { \substances_msg:nnn { required-field } { ##1 } { #1 } }
+ \bool_set_true:N \l__substances_strict_bool
+ \prop_if_in:cnF { l__substances_##1_prop } {#1}
+ { \substances_msg:nnn {required-field} {##1} {#1} }
\group_end:
}
- \prop_if_in:NnTF \l_substances_sort_prop { #1 }
+ \prop_if_in:NnTF \l__substances_sort_prop {#1}
{
- \substances_remove_braces:xN
- { \prop_get:Nn \l_substances_sort_prop { #1 } } \l_tmpa_tl
+ \substances_remove_braces_set:xN
+ { \prop_get:Nn \l__substances_sort_prop {#1} }
+ \l__substances_tmpa_tl
}
{
- \prop_get:NnN \l_substances_properties_pre_prop { name } \l_tmpa_tl
- \substances_remove_str_x:VnnN
- \l_tmpa_tl
- { #1 }
- { name }
- \l_tmpa_tl
+ \prop_get:NnN \l__substances_properties_pre_prop
+ {name}
+ \l__substances_tmpa_tl
+ \substances_remove_str_unbrace_set:VnnN
+ \l__substances_tmpa_tl
+ {#1}
+ {name}
+ \l__substances_tmpa_tl
}
- \prop_put:NnV \l_substances_sort_prop { #1 } \l_tmpa_tl
- \prop_if_in:NnT \l_substances_alt_prop { #1 }
+ \prop_put:NnV \l__substances_sort_prop {#1} \l__substances_tmpa_tl
+ \prop_if_in:NnT \l__substances_alt_prop {#1}
{
- \prop_if_in:NnTF \l_substances_altsort_prop { #1 }
+ \prop_if_in:NnTF \l__substances_altsort_prop {#1}
{
- \substances_remove_braces:xN
- { \prop_get:Nn \l_substances_altsort_prop { #1 } } \l_tmpa_tl
+ \substances_remove_braces_set:xN
+ { \prop_get:Nn \l__substances_altsort_prop {#1} }
+ \l__substances_tmpa_tl
}
{
- \prop_get:NnN \l_substances_properties_pre_prop { alt } \l_tmpa_tl
- \substances_remove_str_x:VnnN
- \l_tmpa_tl
- { #1 }
- { alt }
- \l_tmpa_tl
+ \prop_get:NnN \l__substances_properties_pre_prop {alt}
+ \l__substances_tmpa_tl
+ \substances_remove_str_unbrace_set:VnnN
+ \l__substances_tmpa_tl
+ {#1}
+ {alt}
+ \l__substances_tmpa_tl
}
- \prop_put:NnV \l_substances_altsort_prop { #1 } \l_tmpa_tl
+ \prop_put:NnV \l__substances_altsort_prop {#1} \l__substances_tmpa_tl
}
\bool_new:c { g_substances_#1_alt_index_entry_bool }
+ \bool_new:c { g_substances_#1_name_index_entry_bool }
}
-\cs_new:Npn \substances_add_property:nnnn #1#2#3#4
+\cs_new_protected:Npn \substances_add_property:nnnn #1#2#3#4
{
\keys_define:nn { substances / #1 }
{
#2 .code:n = \prop_put:cnn
- { l_substances_#2_prop } { #1 } { #3{##1}#4 }
+ { l__substances_#2_prop } {#1} { #3{##1}#4 }
}
}
\cs_generate_variant:Nn \substances_add_property:nnnn { nnVV }
\NewDocumentCommand \DeclareSubstance { mm }
- { \substances_declare_substance:nn { #1 } { #2 } }
+ { \substances_declare_substance:nn {#1} {#2} }
\@onlypreamble\DeclareSubstance
% ----------------------------------------------------------------------------
% recover values:
-\cs_new:Npn \substances_get_property:nn #1#2
+\cs_new_protected:Npn \substances_get_property:nn #1#2
{
- \IfSubstanceFieldTF { #2 }
+ \IfSubstanceFieldTF {#2}
{
- \IfSubstancePropertyTF { #1 } { #2 }
- { \prop_get:cn { l_substances_#2_prop } { #1 } }
- { {??} \substances_msg:nnn { property-missing } { #1 } { #2 } }
+ \IfSubstancePropertyTF {#1} {#2}
+ { \prop_get:cn { l__substances_#2_prop } {#1} }
+ { {??} \substances_msg:nnn {property-missing} {#1} {#2} }
}
- { {??} \substances_msg:nnn { field-missing } { #1 } { #2 } }
+ { {??} \substances_msg:nnn {field-missing} {#1} {#2} }
}
% ----------------------------------------------------------------------------
% some commands for creating user macros or whatever:
\NewDocumentCommand \GetSubstanceProperty { mm }
- { \substances_get_property:nn { #1 } { #2 } }
+ { \substances_get_property:nn {#1} {#2} }
\DeclareExpandableDocumentCommand \RetrieveSubstanceProperty { mm }
- { \substances_get_property:nn { #1 } { #2 } }
+ { \substances_get_property:nn {#1} {#2} }
\DeclareExpandableDocumentCommand \IfSubstanceFieldTF { mmm }
- { \cs_if_exist:cTF { l_substances_#1_prop } { #2 } { #3 } }
+ { \cs_if_exist:cTF { l__substances_#1_prop } {#2} {#3} }
\DeclareExpandableDocumentCommand \IfSubstanceFieldT { mm }
- { \cs_if_exist:cT { l_substances_#1_prop } { #2 } }
+ { \cs_if_exist:cT { l__substances_#1_prop } {#2} }
\DeclareExpandableDocumentCommand \IfSubstanceFieldF { mm }
- { \cs_if_exist:cF { l_substances_#1_prop } { #2 } }
+ { \cs_if_exist:cF { l__substances_#1_prop } {#2} }
\DeclareExpandableDocumentCommand \IfSubstanceExistTF { mmm }
- { \seq_if_in:NnTF \l_substances_chemicals_seq { #1 } { #2 } { #3 } }
+ { \seq_if_in:NnTF \l_substances_chemicals_seq {#1} {#2} {#3} }
\DeclareExpandableDocumentCommand \IfSubstanceExistT { mm }
- { \seq_if_in:NnT \l_substances_chemicals_seq { #1 } { #2 } }
+ { \seq_if_in:NnT \l_substances_chemicals_seq {#1} {#2} }
\DeclareExpandableDocumentCommand \IfSubstanceExistF { mm }
- { \seq_if_in:NnF \l_substances_chemicals_seq { #1 } { #2 } }
+ { \seq_if_in:NnF \l_substances_chemicals_seq {#1} {#2} }
\DeclareExpandableDocumentCommand \IfSubstancePropertyTF { mmmm }
{
- \cs_if_exist:cTF { l_substances_#2_prop }
- { \prop_if_in:cnTF { l_substances_#2_prop } { #1 } { #3 } { #4 } }
- { #4 }
+ \cs_if_exist:cTF { l__substances_#2_prop }
+ { \prop_if_in:cnTF { l__substances_#2_prop } {#1} {#3} {#4} }
+ {#4}
}
\DeclareExpandableDocumentCommand \IfSubstancePropertyT { mmm }
{
- \cs_if_exist:cT { l_substances_#2_prop }
- { \prop_if_in:cnT { l_substances_#2_prop } { #1 } { #3 } }
+ \cs_if_exist:cT { l__substances_#2_prop }
+ { \prop_if_in:cnT { l__substances_#2_prop } {#1} {#3} }
}
\DeclareExpandableDocumentCommand \IfSubstancePropertyF { mmm }
{
- \cs_if_exist:cTF { l_substances_#2_prop }
- { \prop_if_in:cnF { l_substances_#2_prop } { #1 } { #3 } }
- { #3 }
+ \cs_if_exist:cTF { l__substances_#2_prop }
+ { \prop_if_in:cnF { l__substances_#2_prop } {#1} {#3} }
+ {#3}
}
\DeclareExpandableDocumentCommand \ForAllSubstancesDo {}
@@ -290,101 +315,115 @@
% user command:
\NewDocumentCommand \chem { soomo }
{
- \IfNoValueF { #2 } { #2 }
- \IfNoValueTF { #5 }
+ \IfNoValueF {#2} {#2}
+ \IfNoValueTF {#5}
{
- \IfBooleanTF { #1 }
+ \IfBooleanTF {#1}
{
- \IfSubstancePropertyTF { #4 } { alt }
- { \RetrieveSubstanceProperty { #4 } { alt } }
- { \RetrieveSubstanceProperty { #4 } { name } }
+ \IfSubstancePropertyTF {#4} {alt}
+ { \RetrieveSubstanceProperty {#4} {alt} }
+ { \RetrieveSubstanceProperty {#4} {name} }
}
- { \RetrieveSubstanceProperty { #4 } { name } }
+ { \RetrieveSubstanceProperty {#4} {name} }
}
- { \substances_get_property:nn { #4 } { #5 } }
- \IfNoValueF { #3 } { #3 }
- \bool_if:NT \l_substances_index_entry_bool
- { \substances_index_entry:n { #4 } }
+ { \RetrieveSubstanceProperty {#4} {#5} }
+ \IfNoValueF {#3} {#3}
+ \SubstanceIndex {#4}
}
% ----------------------------------------------------------------------------
% index command to add an entry to the chemicals list if the option
% `index=true' is used:
-\cs_new:Npn \substances_index:nn #1#2
+\cs_new_protected:Npn \substances_index:nn #1#2
{
- \bool_if:NTF \l_substances_imakeidx_bool
- { \index [ #1 ] { #2 } }
+ \bool_if:NTF \l__substances_imakeidx_bool
+ { \index [ #1 ] {#2} }
{
- \bool_if:NTF \l_substances_splitidx_bool
- { \sindex [ #1 ] { #2 } }
+ \bool_if:NTF \l__substances_splitidx_bool
+ { \sindex [ #1 ] {#2} }
{
- \bool_if:NTF \l_substances_multind_bool
- { \index { #1 } { #2 } }
- { \index { #2 } }
+ \bool_if:NTF \l__substances_multind_bool
+ { \index {#1} {#2} }
+ { \index {#2} }
}
}
}
\cs_generate_variant:Nn \substances_index:nn { no,nx }
-\cs_new:Npn \substances_index_entry:n #1
- { \UseInstance { substances-index } { default } { #1 } }
+\cs_new_protected:Npn \substances_index_entry:nn #1#2
+ { \UseInstance {substances-index} {#1} {#2} }
-\cs_new:Npn \substances_remove_braces:xN #1#2
- { \exp_last_unbraced:NNx \tl_set:Nn #2 { #1 } }
-\cs_generate_variant:Nn \exp_last_unbraced:NNo { NNx }
+\NewDocumentCommand \SubstanceIndex {O{default}m}
+ {
+ \bool_if:NT \l__substances_index_entry_bool
+ { \substances_index_entry:nn {#1} {#2} }
+ }
-\cs_new:Npn \substances_remove_str_x:nnnN #1#2#3#4
+\cs_new_protected:Npn \substances_remove_braces_set:nN #1#2
+ { \tl_set:Nn #2 #1 }
+\cs_generate_variant:Nn \substances_remove_braces_set:nN {x}
+
+\cs_new_protected:Npn \substances_remove_str_unbrace_set:nnnN #1#2#3#4
{
- \tl_set:Nx #4
- { \prop_get:cn { l_substances_#3_prop } { #2 } }
- \tl_remove_all:Nn #4 { #1 }
- \substances_remove_braces:xN { #4 } #4
+ \tl_set:Nx #4 { \prop_get:cn { l__substances_#3_prop } {#2} }
+ \tl_remove_all:Nn #4 {#1}
+ \substances_remove_braces_set:xN {#4} #4
}
-\cs_generate_variant:Nn \substances_remove_str_x:nnnN { V }
+\cs_generate_variant:Nn \substances_remove_str_unbrace_set:nnnN { V }
% let's use xtemplate's features for possible customization later:
-\DeclareObjectType { substances-index } { 1 }
+\DeclareObjectType {substances-index} {1}
-\DeclareTemplateInterface { substances-index } { standard } { 1 }
+\DeclareTemplateInterface {substances-index} {standard} {1}
{
alternative-entry : boolean = true ,
alternative-name : boolean = true
}
-\DeclareTemplateCode { substances-index } { standard } { 1 }
+\DeclareTemplateCode {substances-index} {standard} {1}
{
- alternative-entry = \l_substances_index_alternative_entry_bool ,
- alternative-name = \l_substances_index_alternative_name_bool ,
+ alternative-entry = \l__substances_index_alternative_entry_bool ,
+ alternative-name = \l__substances_index_alternative_name_bool ,
}
{
\AssignTemplateKeys
\bool_if:nTF
{
- \l_substances_index_alternative_name_bool &&
- \prop_if_in_p:Nn \l_substances_alt_prop { #1 }
+ \l__substances_index_alternative_name_bool &&
+ \prop_if_in_p:Nn \l__substances_alt_prop {#1}
}
{
- \substances_index:nx { \c_job_name_tl -chem }
+ \bool_if:cF { g_substances_#1_name_index_entry_bool }
{
- \SubstanceIndexNameAltEntry
- { \prop_get:Nn \l_substances_sort_prop { #1 } }
- { \GetSubstanceProperty { #1 } { name } }
- { \GetSubstanceProperty { #1 } { alt } }
+ \substances_index:nx { \c_job_name_tl -chem }
+ {
+ \SubstanceIndexNameAltEntry
+ { \prop_get:Nn \l__substances_sort_prop {#1} }
+ { \GetSubstanceProperty {#1} {name} }
+ { \GetSubstanceProperty {#1} {alt} }
+ }
}
+ \bool_if:NT \l__substances_single_name_bool
+ { \bool_gset_true:c { g_substances_#1_name_index_entry_bool } }
}
{
- \substances_index:nx { \c_job_name_tl -chem }
+ \bool_if:cF { g_substances_#1_name_index_entry_bool }
{
- \SubstanceIndexNameEntry
- { \prop_get:Nn \l_substances_sort_prop { #1 } }
- { \GetSubstanceProperty { #1 } { name } }
+ \substances_index:nx { \c_job_name_tl -chem }
+ {
+ \SubstanceIndexNameEntry
+ { \prop_get:Nn \l__substances_sort_prop {#1} }
+ { \GetSubstanceProperty {#1} {name} }
+ }
}
+ \bool_if:NT \l__substances_single_name_bool
+ { \bool_gset_true:c { g_substances_#1_name_index_entry_bool } }
}
\bool_if:nT
{
- \l_substances_index_alternative_entry_bool &&
- \l_substances_index_alternative_name_bool &&
- \prop_if_in_p:Nn \l_substances_alt_prop { #1 }
+ \l__substances_index_alternative_entry_bool &&
+ \l__substances_index_alternative_name_bool &&
+ \prop_if_in_p:Nn \l__substances_alt_prop {#1}
}
{
\bool_if:cF { g_substances_#1_alt_index_entry_bool }
@@ -392,51 +431,157 @@
\substances_index:nx { \c_job_name_tl -chem }
{
\SubstanceIndexAltEntry
- { \prop_get:Nn \l_substances_altsort_prop { #1 } }
- { \GetSubstanceProperty { #1 } { name } }
- { \GetSubstanceProperty { #1 } { alt } }
+ { \prop_get:Nn \l__substances_altsort_prop {#1} }
+ { \GetSubstanceProperty {#1} {name} }
+ { \GetSubstanceProperty {#1} {alt} }
}
- \bool_gset_true:c { g_substances_#1_alt_index_entry_bool }
+ \substances_contains_see:NT \SubstanceIndexAltEntry
+ { \bool_gset_true:c { g_substances_#1_alt_index_entry_bool } }
}
}
}
-\DeclareInstance { substances-index } { default } { standard } { }
+\DeclareInstance {substances-index} {default} {standard} { }
\cs_new:Npn \SubstanceIndexNameEntry #1#2 { #1@#2 }
\cs_new:Npn \SubstanceIndexNameAltEntry #1#2#3 { #1@#2~(#3) }
\cs_new:Npn \SubstanceIndexAltEntry #1#2#3 { #1@#3|see{#2} }
+
+\cs_new_protected:Npn \substances_contains_see:NT #1#2
+ {
+ \tl_set_rescan:Nnx \l__substances_tmpa_tl {} {\cs_meaning:N #1 }
+ \tl_if_in:VnT \l__substances_tmpa_tl { |see } {#2}
+ }
+
% ----------------------------------------------------------------------------
% define some default fields:
-\cs_new_nopar:Npn \@CAS #1-#2-#3 { \iupac{#1\-#2\-#3} }
-\NewDocumentCommand \CAS { m } { \@CAS #1 }
+\cs_new_nopar:Npn \@CAS #1-#2-#3\relax { \iupac{#1-#2-#3} }
+\NewDocumentCommand \CAS { m } { \@CAS #1 \relax }
-\DeclareSubstanceProperty* { name } [\iupac]
-\DeclareSubstanceProperty { sort }
-\DeclareSubstanceProperty { alt } [\iupac]
-\DeclareSubstanceProperty { altsort }
-\DeclareSubstanceProperty { CAS } [\CAS]
-\DeclareSubstanceProperty { PubChem }
+\DeclareSubstanceProperty* {name} [\iupac]
+\DeclareSubstanceProperty {sort}
+\DeclareSubstanceProperty {alt} [\iupac]
+\DeclareSubstanceProperty {altsort}
+\DeclareSubstanceProperty {CAS} [\CAS]
+\DeclareSubstanceProperty {PubChem}
% ----------------------------------------------------------------------------
% load style file
-\file_if_exist:nTF { substances- \l_substances_style_tl .def }
- { \file_input:n { substances- \l_substances_style_tl .def } }
+\tl_const:Nn \c__substances_style_extension_tl {def}
+\tl_const:Nn \c__substances_style_prefix_tl {substances-}
+
+\cs_new:Npn \__substances_style:n #1
+ { \c__substances_style_prefix_tl#1.\c__substances_style_extension_tl }
+
+\cs_new_protected:Npn \substances_load_style:n #1
+ {
+ \tl_set:Nx \l__substances_tmpa_tl { \tl_trim_spaces:n {#1} }
+ \__substances_load_style:V \l__substances_tmpa_tl
+ }
+\cs_generate_variant:Nn \substances_load_style:n { V }
+
+\cs_new_protected:Npn \__substances_load_style:n #1
+ {
+ \substances_if_style_exist:nTF {#1}
+ {
+% \msg_log:nnn {substances} {loading-style} {#1}
+ \@onefilewithoptions
+ {\c__substances_style_prefix_tl#1}[][]
+ \c__substances_style_extension_tl
+ }
+ { \substances_msg:nn {style-missing} {#1} }
+ }
+\cs_generate_variant:Nn \__substances_load_style:n { V }
+
+\prg_new_conditional:Npnn \substances_if_style_exist:n #1 {T,F,TF}
+ {
+ \file_if_exist:nTF
+ { \__substances_style:n {#1} }
+ { \prg_return_true: }
+ { \prg_return_false: }
+ }
+
+\cs_new_protected:Npn \__substances_style:nn #1#2
+ {
+ \ProvidesFile { \__substances_style:n {#2} }
+ \bool_if:nT {#1} { \ExplSyntaxOn }
+ }
+
+\bool_new:N \l__substances_inside_style_file_bool
+
+\NewDocumentCommand \SubstancesStyle {sm}
+ {
+ \__substances_style:nn {#1} {#2}
+ \bool_set_true:N \l__substances_inside_style_file_bool
+ \AtEndOfPackage
+ { \bool_set_false:N \l__substances_inside_style_file_bool }
+ }
+
+\NewDocumentCommand \LoadSubstancesStyle {m}
+ {
+ \bool_if:NTF \l__substances_inside_style_file_bool
+ { \substances_load_style:n {#1} }
+ {}
+ }
+
+\substances_load_style:V \l__substances_style_tl
+
+% ----------------------------------------------------------------------------
+% load database file
+\tl_const:Nn \c__substances_database_extension_tl {sub}
+\tl_const:Nn \c__substances_database_prefix_tl {}
+
+\cs_new:Npn \__substances_database:n #1
+ { \c__substances_database_prefix_tl#1.\c__substances_database_extension_tl }
+
+\prg_new_conditional:Npnn \substances_if_database_exist:n #1 {T,F,TF}
{
- \substances_msg:nnn { style-missing } { \l_substances_style_tl } { }
- \file_input:n { substances-default.def }
+ \file_if_exist:nTF
+ { \__substances_database:n {#1} }
+ { \prg_return_true: }
+ { \prg_return_false: }
}
-\NewDocumentCommand \LoadSubstances { m }
+\cs_new_protected:Npn \__substances_load_database:n #1
{
- \file_if_exist:nTF { #1.sub }
- { \file_input:n { #1.sub } }
- { \substances_msg:nnn { database-missing } { #1.sub } { } }
+ \substances_if_database_exist:nTF {#1}
+ {
+ \@onefilewithoptions
+ {\c__substances_database_prefix_tl#1}[][]
+ \c__substances_database_extension_tl
+ }
+ { \substances_msg:nn {database-missing} {#1} }
}
+\cs_generate_variant:Nn \__substances_load_database:n { V }
+
+\cs_new_protected:Npn \substances_load_database:n #1
+ {
+ \tl_set:Nx \l__substances_tmpa_tl { \tl_trim_spaces:n {#1} }
+ \__substances_load_database:V \l__substances_tmpa_tl
+ }
+
+\NewDocumentCommand \LoadSubstances {m}
+ { \substances_load_database:n {#1} }
\@onlypreamble\LoadSubstances
+\cs_new_protected:Npn \__substances_database:nn #1#2
+ {
+ \ProvidesFile { \__substances_database:n {#2} }
+ \bool_if:nF {#1} { }
+ }
+
+\NewDocumentCommand \SubstancesDatabase {sm}
+ { \__substances_database:nn {#1} {#2} }
+
\tex_endinput:D
+% ----------------------------------------------------------------------------
% HISTORY:
-2012/07/22 v0.1 - first release to CTAN \ No newline at end of file
+2012/07/22 v0.1 - first release to CTAN
+2012/09/02 v0.1a - small fix due to updated l3kernel
+2015/10/21 v0.2 - maintenance: minor fixes, adapt to chemmacros v5
+ - change implementation of how style files are loaded
+ - change implementation of how database files are loaded
+
+% TODO: