summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2012-02-11 00:49:37 +0000
committerKarl Berry <karl@freefriends.org>2012-02-11 00:49:37 +0000
commit48ea98193ab70b9d4d1e5fb2acddd70a1ff3d5ae (patch)
tree292cdab18d35cc42df39f2d819c5b0751c97be39 /Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty
parent3562f80e5794c062e8d3b071c4305e06688cafcb (diff)
chemmacros (10feb12)
git-svn-id: svn://tug.org/texlive/trunk@25352 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.sty272
1 files changed, 182 insertions, 90 deletions
diff --git a/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty b/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty
index f53fbd5bbe8..fcba2944cd4 100644
--- a/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty
+++ b/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty
@@ -5,9 +5,9 @@
% - macros and commands for chemists - %
% --------------------------------------------------------------------------- %
% - Clemens Niederberger - %
-% - 2012/02/05 - %
+% - 2012/02/10 - %
% --------------------------------------------------------------------------- %
-% - http://www.mychemistry.eu/ - %
+% - https://bitbucket.org/cgnieder/chemmacros/ - %
% - contact@mychemistry.eu - %
% --------------------------------------------------------------------------- %
% - If you have any ideas, questions, suggestions or bugs to report, please - %
@@ -30,7 +30,7 @@
\RequirePackage{ expl3 , xparse , l3keys2e , xfrac , siunitx , tikz , mathtools , environ , scrlfile , etoolbox , bm }
\usetikzlibrary{calc,arrows}
-\ProvidesExplPackage {chemmacros} {2012/02/05} {3.0c} {macros and commands for chemists}
+\ProvidesExplPackage {chemmacros} {2012/02/10} {3.0d} {macros and commands for chemists}
\@ifpackageloaded { chemformula } {} { \RequirePackage { chemformula } }
@@ -167,6 +167,7 @@
\AtEndPreamble
{
+ \chemmacros_make_phases:
\bool_if:NT \l_chemmacros_ghsystem_bool
{ \RequirePackage { ghsystem } }
\bool_if:NT \l_chemmacros_bpchem_bool
@@ -202,16 +203,40 @@
See~the~documentation~for~more~information.
}
-\msg_set:nnnn { chemmacros } { particle }
+\msg_set:nnnn { chemmacros } { declare-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 \DeclareParticle ,~but
+ You've~tried~to~define~a~particle~with~\token_to_str:N \DeclareChemParticle ,~but
~the~command~sequence~ \token_to_str:N #1 \c_space_tl already~exists.~Choose~
another~name.
}
+\msg_set:nnnn { chemmacros } { renew-particle }
+ { The~particle~ \token_to_str:N #1 \c_space_tl is~not~defined. }
+ {
+ You've~tried~to~renew~the~particle~\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.
+ }
+ {
+ You've~tried~to~define~a~particle~with~\token_to_str:N \DeclareChemPhase ,~but
+ ~the~command~sequence~ \token_to_str:N #1 \c_space_tl already~exists.~Choose~
+ another~name.
+ }
+
+\msg_set:nnnn { chemmacros } { renew-phase }
+ { The~phase~ \token_to_str:N #1 \c_space_tl is~not~defined. }
+ {
+ You've~tried~to~renew~the~phase~\token_to_str:N #1 , but~it~doesn't~
+ exist.
+ }
+
\msg_set:nnn { chemmacros } { ox }
{
\token_to_str:N \ox \c_space_tl : ~ #1 ~ \msg_line_context: .
@@ -357,40 +382,22 @@
% --------------------------------------------------------------------------- %
% transition state symbol
-\AtBeginDocument
+\cs_new_nopar:Npn \transitionstatesymbol
+ { \ensuremath { \chemmacros_transitionstatesymbol: } }
+\cs_new_nopar:Npn \chemmacros_transitionstatesymbol:
+ { \mathpalette \chemmacros_transitionstatesymbol_aux: = }
+\cs_new_nopar:Npn \chemmacros_transitionstatesymbol_aux: #1#2
{
- \cs_new_nopar:Npn \chemmacros_transitionstatesymbol:
- {
- \mode_if_math:TF
- { \text { \chemmacros_transitionstatesymbol_aux: } }
- { \chemmacros_transitionstatesymbol_aux: }
- }
-
- \cs_new_nopar:Npn \chemmacros_transitionstatesymbol_aux:
- {
- \tikz[inner~sep=0,outer~sep=0,minimum~size=0,space-space,line~width=.3pt]
- {
- \draw (0,0) --
- node[pos=.36]
- (chemmacros_transitionstate_x) {}
- node[pos=.64]
- (chemmacros_transitionstate_y){}
- (0,.8em) ;
- \draw (chemmacros_transitionstate_x) ++(-.4em,0) -- ++(.8em,0) ;
- \draw (chemmacros_transitionstate_y) ++(-.4em,0) -- ++(.8em,0) ;
- }
- }
-
- \@ifpackageloaded{mychemistry}
- {
- \cs_set_eq:NN
- \transitionstatesymbol
- \chemmacros_transitionstatesymbol:
- }
+ \ooalign
{
- \cs_new_eq:NN
- \transitionstatesymbol
- \chemmacros_transitionstatesymbol:
+ \tex_hfil:D
+ $#1\mid$
+ \tex_hfil:D
+ \tex_cr:D
+ \tex_hfil:D
+ $#1#2$
+ \tex_hfil:D
+ \tex_cr:D
}
}
@@ -427,27 +434,66 @@
\bool_new:N \l_chemmacros_charge_append_bool
\bool_set_false:N \l_chemmacros_charge_append_bool
+% \DeclareChemParticle, \RenewChemParticle
\bool_if:NTF \l_chemmacros_use_mhchem_bool
{
- \NewDocumentCommand \DeclareParticle { mm }
+ \NewDocumentCommand \DeclareChemParticle { mm }
+ {
+ \cs_if_free:NTF #1
+ {
+ \cs_new_nopar:Npn #1
+ { \ce { #2 } \chemmacros_xspace: }
+ }
+ { \chemmacros_msg:nnxx { chemmacros } { declare-particle } { #1 } {} }
+ }
+ \NewDocumentCommand \RenewChemParticle { mm }
{
\cs_if_free:NTF #1
+ { \chemmacros_msg:nnxx { chemmacros } { renew-particle } { #1 } {} }
{
\cs_set_nopar:Npn #1
- { \chemmacros_atom:n { #2 } \chemmacros_xspace: }
+ { \ce { #2 } \chemmacros_xspace: }
}
- { \chemmacros_msg:nnxx { chemmacros } { particle } { #1 } {} }
}
}
{
- \NewDocumentCommand \DeclareParticle { mm }
+ \NewDocumentCommand \DeclareChemParticle { mm }
{
\cs_if_free:NTF #1
+ { \chemmacros_chem_particle:nn #1 { #2 } }
+ { \chemmacros_msg:nnxx { chemmacros } { declare-particle } { #1 } {} }
+ }
+ \NewDocumentCommand \RenewChemParticle { mm }
+ {
+ \cs_if_free:NTF #1
+ { \chemmacros_msg:nnxx { chemmacros } { renew-particle } { #1 } {} }
+ { \chemmacros_chem_particle:nn #1 { #2 } }
+ }
+ }
+
+\cs_new_nopar:Nn \chemmacros_chem_particle:nn
+ {
+ \cs_set_nopar:Npn #1
+ {
+ \bool_if:NTF \l_chemformula_inside_ch_bool
{
- \cs_set_nopar:Npn #1
- { \chemmacros_chemformula:n { #2 } \chemmacros_xspace: }
+ \chemformula_input_cmpd:nN { #2 } \l_chemmacros_chemformula_tl
+ \tl_set_rescan:Nno \l_chemmacros_chemformula_tl
+ { \ExplSyntaxOn }
+ { \l_chemmacros_chemformula_tl }
+ \tl_use:N \l_chemmacros_chemformula_tl
+ \tl_clear:N \l_chemmacros_chemformula_tl
+ }
+ {
+ \group_begin:
+ \chemformula_input:n { #2 }
+ \tl_set_rescan:Nno \l_tmpa_tl
+ { \ExplSyntaxOn }
+ { \l_chemformula_input_tl }
+ \chemformula_write:n { \l_tmpa_tl }
+ \group_end:
+ \chemmacros_xspace:
}
- { \chemmacros_msg:nnxx { chemmacros } { particle } { #1 } {} }
}
}
@@ -457,11 +503,11 @@
\cs_new_nopar:Npn \prt { \chemmacros_atom:n { p } \pch \chemmacros_xspace: }
}
{
- \DeclareParticle \el { e- }
- \DeclareParticle \prt { p+ }
+ \DeclareChemParticle \el { e- }
+ \DeclareChemParticle \prt { p+ }
}
-\DeclareParticle \ntr { n^0 }
+\DeclareChemParticle \ntr { n^0 }
\cs_new_nopar:Npn \chemmacros_bm:n #1
{
@@ -570,13 +616,13 @@
\cs_new_nopar:Npn \El { \chemmacros_atom:n { E } \pch \chemmacros_xspace: }
}
{
- \DeclareParticle \Hpl { H+ }
- \DeclareParticle \Hyd { OH- }
- \DeclareParticle \HtO { H3O+ }
- \DeclareParticle \El { E+ }
+ \DeclareChemParticle \Hpl { H+ }
+ \DeclareChemParticle \Hyd { OH- }
+ \DeclareChemParticle \HtO { H3O+ }
+ \DeclareChemParticle \El { E+ }
}
-\DeclareParticle \water { H2O }
+\DeclareChemParticle \water { H2O }
\NewDocumentCommand \chemmacros_Nu:w { o }
{
@@ -1532,47 +1578,94 @@
% --------------------------------------------------------------------------- %
% - phases
-\char_set_catcode_math_subscript:N \@
-\cs_new_nopar:Npn \sld
+\bool_new:N \l_chemmacros_phases_sub_bool
+\dim_new:N \l_chemmacros_phases_space_dim
+\dim_set:Nn \l_chemmacros_phases_space_dim { .1333 em }
+
+\keys_define:nn { chemmacros / phases }
{
- \peek_meaning:NTF [
- { \chemmacros_sld_aux_i:w }
- { \chemmacros_sld_aux_ii:w }
+ pos .choice: ,
+ pos / sub .code:n = \bool_set_true:N \l_chemmacros_phases_sub_bool ,
+ pos / side .code:n = \bool_set_false:N \l_chemmacros_phases_sub_bool ,
+ space .dim_set:N = \l_chemmacros_phases_space_dim
}
-\cs_new_nopar:Npn \chemmacros_sld_aux_i:w [#1]
- { \ensuremath { @ \mathrm { ( #1 ) } } }
+\char_set_catcode_math_subscript:N \@
+\prop_new:N \l_chemmacros_phases_prop
+\prop_new:N \l_chemmacros_phases_german_prop
-\cs_new_nopar:Npn \chemmacros_sld_aux_ii:w
+\NewDocumentCommand \DeclareChemPhase { mom }
{
- \ensuremath { @ \mathrm {
- (
- \bool_if:NTF \l_chemmacros_german_bool
- { f }
- { s }
- )
- } }
+ \tl_set_rescan:Nnn \l_tmpa_tl { \char_set_catcode_letter:N \\ } { #1 }
+ \tl_set:Nf \l_tmpa_tl { \tl_tail:V \l_tmpa_tl }
+ \cs_if_free:NTF #1
+ { \cs_new_nopar:Npn #1 {} }
+ { \chemmacros_msg:nnxx { chemmacros } { declare-phase } { #1 } {} }
+ \IfNoValueTF { #2 }
+ { \prop_put:Non \l_chemmacros_phases_german_prop { \l_tmpa_tl } { #3 } }
+ { \prop_put:Non \l_chemmacros_phases_german_prop { \l_tmpa_tl } { #2 } }
+ \prop_put:Non \l_chemmacros_phases_prop { \l_tmpa_tl } { #3 }
+ \chemmacros_make_phases:
}
-\cs_new_nopar:Npn \lqd
+\NewDocumentCommand \RenewChemPhase { mom }
{
- \peek_meaning:NTF [
- { \chemmacros_lqd_aux_i: }
- { \chemmacros_lqd_aux_ii: }
+ \tl_set_rescan:Nnn \l_tmpa_tl { \char_set_catcode_letter:N \\ } { #1 }
+ \tl_set:Nf \l_tmpa_tl { \tl_tail:V \l_tmpa_tl }
+ \cs_if_free:NT #1
+ { \chemmacros_msg:nnxx { chemmacros } { renew-phase } { #1 } {} }
+ \IfNoValueTF { #2 }
+ { \prop_put:Non \l_chemmacros_phases_german_prop { \l_tmpa_tl } { #3 } }
+ { \prop_put:Non \l_chemmacros_phases_german_prop { \l_tmpa_tl } { #2 } }
+ \prop_put:Non \l_chemmacros_phases_prop { \l_tmpa_tl } { #3 }
+ \chemmacros_make_phases:
}
-\cs_new_nopar:Npn \chemmacros_lqd_aux_i: [#1]
- { \ensuremath { @ \mathrm { ( #1 ) } } }
+\cs_new_nopar:Npn \chemmacros_make_phases:
+ {
+ \bool_if:NTF \l_chemmacros_german_bool
+ {
+ \prop_map_function:NN \l_chemmacros_phases_german_prop
+ \chemmacros_define_phases:nn
+ }
+ {
+ \prop_map_function:NN \l_chemmacros_phases_prop
+ \chemmacros_define_phases:nn
+ }
+ }
-\cs_new_nopar:Npn \chemmacros_lqd_aux_ii:
+\cs_new_nopar:Npn \chemmacros_define_phases:nn #1#2
{
- \ensuremath { @ \mathrm {
- (
- \bool_if:NTF \l_chemmacros_german_bool
- { f\/l }
- { l }
- )
- } }
+ \cs_set_nopar:cpn { #1 }
+ {
+ \bool_if:NTF \l_chemmacros_phases_sub_bool
+ { \ensuremath { @ { \text { (#2) } } } }
+ {
+ \ensuremath
+ {
+ \skip_horizontal:N \l_chemmacros_phases_space_dim
+ \text { (#2) }
+ }
+ }
+ }
+ }
+
+\DeclareChemPhase \sld [ f ] { s }
+\DeclareChemPhase \lqd [ f{}l ] { l }
+\DeclareChemPhase \gas { g }
+\DeclareChemPhase \aq { aq }
+
+\NewDocumentCommand \phase { m }
+ {
+ \bool_if:NTF \l_chemmacros_phases_sub_bool
+ { \ensuremath { @ { \text { (#1) } } } }
+ {
+ \ensuremath
+ {
+ \skip_horizontal:N \l_chemmacros_phases_space_dim
+ \text { (#1) }
+ }
+ }
}
\bool_if:NT \l_chemmacros_version_one_bool
@@ -1580,12 +1673,6 @@
\cs_new_eq:NN \solid \sld
\cs_new_eq:NN \liquid \lqd
}
-
-\cs_new_nopar:Npn \gas
- { \ensuremath { @ \mathrm { (g) } } }
-
-\cs_new_nopar:Npn \aq
- { \ensuremath { @ \mathrm { (aq) } } }
\char_set_catcode_letter:N \@
% --------------------------------------------------------------------------- %
@@ -2983,14 +3070,19 @@ Version history
- renamed formula => chemformula
and ghs => ghsystem to make the names unique
(following a request by Karl Berry for TeXlive)
-2012/02/03 - version 3.0b - new command \DeclareParticle, updated documentation
+2012/02/03 - version 3.0b - new command \DeclareChemParticle, updated documentation
2012/02/05 - version 3.0c - renamed pictogram files (following a request by
Karl Berry for TeXlive)
- new package option "Nu"
+2012/02/10 - version 3.0d - several bugfixes in chemformula
+ - bugfixes with \DeclareChemParticle
+ - new command \RenewChemParticle
+ - new option phases / pos
+ - new commands \DeclareChemPhase, \RenewChemPhase, \phase
+ - changed default behaviour of phases
+ - removed optional argument from \sld and \lqd
% --------------------------------------------------------------------------- %
% TODO:
- ox-option xfrac vs math?
-- Option „side“ for Phasen-Befehle?
-- \Nu konflikt mit `mathspec'
- resolve conflict with \listofreactions and \setcounter{reaction}{<int>} \ No newline at end of file