summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/chemmacros/chemmacros.module.particles.code.tex
blob: 9d68712f81a27a8a8eb7e37cc38266209d76595e (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
% --------------------------------------------------------------------------
%
% 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-2019 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}{2016/04/02 particles}
  
\chemmacros_load_modules:n {charges,chemformula}

% --------------------------------------------------------------------------
% particles
\cs_new_protected:Nn \chemmacros_define_particle:Nn
  {
    \tl_set_rescan:Nnn \l__chemmacros_tmpa_tl { \ExplSyntaxOff } {#2}
    \use:x
      {
        \cs_set_protected:Npn \exp_not:N #1
          { \chemmacros_chemformula:n { \exp_not:V \l__chemmacros_tmpa_tl } }
      }
  }

\NewChemMacroset {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

\ChemCompatibilityFrom{5.3}
\dim_new:N  \l__chemmacros_nucleophile_dim
\dim_set:Nn \l__chemmacros_nucleophile_dim { .1em }

\chemmacros_define_keys:nn {particles}
  {
    space .dim_set:N = \l__chemmacros_nucleophile_dim
  }
\EndChemCompatibility

\chemmacros_define_keys:nn {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_if_compatibility:nnT {>=} {5.3}
              { \skip_horizontal:N \l__chemmacros_nucleophile_dim }
            \chemmacros_chemformula:n { {}^{-} }
          }
          { \chemmacros_chemformula:n { #2^{-} } }
      }
    \DeclareDocumentCommand #1 {o}
      {
        \group_begin:
          \IfNoValueF {##1}
            { \chemmacros_set_keys:nn {particles} {##1} }
          \use:c {__chemmacros_ \chemmacros_remove_backslash:N #1:}
        \group_end:
      }
  }

\NewChemMacroset {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   { H_3O^+ }
\NewChemParticle \water { H_2O }

% electrophile:
\NewChemParticle \El  { E^+ }

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

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

% --------------------------------------------------------------------------
\file_input_stop:
2016/01/13 - new option particles/space
2016/04/02 - adapt to formula methods `chemist' and `chemfig'