summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/chemmacros/chemmacros.module.particles.code.tex
blob: 110dd05c8ea506d277ab2fcd6a20dc5c92836e54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
% --------------------------------------------------------------------------
%
% the CHEMMACROS package -- module: `particles'
%
% --------------------------------------------------------------------------
% Clemens Niederberger
% --------------------------------------------------------------------------
% https://github.org/cgnieder/chemmacros/
% contact@mychemistry.eu
% --------------------------------------------------------------------------
% If you have any ideas, questions, suggestions or bugs to report, please
% feel free to contact me.
% --------------------------------------------------------------------------
% Copyright 2011-2015 Clemens Niederberger
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Clemens Niederberger.
% --------------------------------------------------------------------------
\ChemModule{particles}{2015/07/15 particles}
  
\chemmacros_load_modules:n {charges,chemformula}

% --------------------------------------------------------------------------
% particles
\cs_new_protected:Nn \chemmacros_define_particle:Nn
  { \cs_set_protected:Npn #1 { \chemformula_chcpd:nn {} {#2} } }

\chemmacros_new_macroset:nnn {Particle} {mm}
  { \chemmacros_define_particle:Nn #1 {#2} }

% --------------------------------------------------------------------------
% nucleophiles
\cs_new_protected:Npn \chemmacros_elpair:n #1
  {
    \bool_if:NTF \l__chemmacros_elpair_dots_bool
      { \chlewis { 0: } {#1} }
      { \chlewis { 0| } {#1} }
  }

\bool_new:N \l__chemmacros_nucleophile_elpair_bool
\bool_new:N \l__chemmacros_elpair_dots_bool

\keys_define:nn {chemmacros/particles}
  {
    elpair         .choice: ,
    elpair / false .code:n    =
      { \bool_set_false:N \l__chemmacros_nucleophile_elpair_bool } ,
    elpair / dots  .code:n    =
      {
        \bool_set_true:N \l__chemmacros_nucleophile_elpair_bool
        \bool_set_true:N \l__chemmacros_elpair_dots_bool
      } ,
    elpair / dash  .code:n    =
      {
        \bool_set_true:N \l__chemmacros_nucleophile_elpair_bool
        \bool_set_false:N \l__chemmacros_elpair_dots_bool
      } ,
    elpair         .default:n = dots
  }

\cs_new_protected:Npn \chemmacros_declare_nucleophile:Nn #1#2
  {
    \cs_set_protected:cpn {__chemmacros_ \chemmacros_remove_backslash:N #1:}
      {
        \bool_if:NTF \l__chemmacros_nucleophile_elpair_bool
          { \chemmacros_elpair:n { #2 } \chemmacros_chemformula:n { {}- } }
          { \chemmacros_chemformula:n { #2- } }
      }
    \DeclareDocumentCommand #1 {o}
      {
        \group_begin:
          \IfNoValueF {##1}
            { \keys_set:nn {chemmacros/particles} {##1} }
          \use:c {__chemmacros_ \chemmacros_remove_backslash:N #1:}
        \group_end:
      }
  }

\chemmacros_new_macroset:nnn {Nucleophile} {mm}
  { \chemmacros_declare_nucleophile:Nn #1 {#2} }



% --------------------------------------------------------------------------
% particles:
\NewChemParticle \el  { e- }
\NewChemParticle \prt { p+ }
\NewChemParticle \ntr { n^0 }

% ions, molecules
% proton, hydroxide, hydronium/oxonium, water:
\NewChemParticle \Hpl { H+ }
\NewChemParticle \Hyd { OH- }
\NewChemParticle \Oxo { H3O+ }
\NewChemParticle \water { H2O }

% electrophile:
\NewChemParticle \El  { E+ }

% nucleophiles:
\NewChemNucleophile \Nuc {Nu}
\NewChemNucleophile \ba  {ba}

\ChemCompatibilityTo{5.2}
  \DeclareChemDeprecated \Hto \Oxo
  \DeclareChemDeprecated \Nu \Nuc
\EndChemCompatibility

% --------------------------------------------------------------------------