summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/chemmacros/chemmacros.module.acid-base.code.tex
blob: 2bb4a557d6e7b56b9b1387a4210b30f02809d94c (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: `acid-base'
%
% --------------------------------------------------------------------------
% 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-2016 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{acid-base}{2016/02/04 acid/base}

\chemmacros_load_modules:n {charges}

% --------------------------------------------------------------------------
% equilibrium constants:

\tl_new:N  \l__chemmacros_equilibrium_constant_tl
\tl_set:Nn \l__chemmacros_equilibrium_constant_tl {K}
\prop_new:N \l__chemmacros_eq_constants_prop

\prg_new_conditional:Npnn \chemmacros_if_eq_constant:Nn #1#2 {T,F,TF}
  {
    \cs_if_exist:NTF #1
      {
        \tl_if_eq:xnTF
          { \prop_item:Nn \l__chemmacros_eq_constants_prop {#1} }
          {#2}
          { \prg_return_true: }
          { \prg_return_false: }
      }
      { \prg_return_false: }
  }
\cs_generate_variant:Nn \tl_if_eq:nnTF {x}

% #1: cs
% #2: translation id and option name
% #3: default translation
\cs_new_protected:Npn \chemmacros_define_eq_constant:Nnn #1#2#3
  {
    \chemmacros_if_eq_constant:NnF {#1} {#2}
      {
        \cs_new_protected:Npn #1 {}
        \prop_put:Nnn \l__chemmacros_eq_constants_prop {#1} {#2}
        \tl_new:c {l__chemmacros_#2_tl}
        \chemmacros_define_keys:nn {acid-base}
          { #2 .tl_set:c = l__chemmacros_#2_tl }
      }
    \tl_set:cn
      {l__chemmacros_#2_tl}
      { \chemmacros_translate:n {#2} }
    \DeclareTranslationFallback {#2} {#3}
    \cs_set_protected:Npn #1
      {
        \ensuremath
          {
            \chemmacros_bold:n
              {
                \l__chemmacros_equilibrium_constant_tl
                \c_math_subscript_token
                  { \tl_use:c {l__chemmacros_#2_tl} }
              }
          }
      }
  }

\NewChemMacroset {EqConstant} {mmm}
  { \chemmacros_define_eq_constant:Nnn #1 {#2} {#3} }

\NewChemEqConstant \Ka {K-acid}  { \mathrm{a} }
\NewChemEqConstant \Kb {K-base}  { \mathrm{b} }
\NewChemEqConstant \Kw {K-water} { \mathrm{w} }

\chemmacros_if_compatiblity:nnT {>=} {5.4}
  {
    \chemmacros_define_keys:nn {acid-base}
      { eq-constant .tl_set:N = \l__chemmacros_equilibrium_constant_tl }
  }

\chemmacros_define_keys:nn {acid-base}
  {
    p-style           .choice: ,
    p-style / slanted .code:n   = \cs_set_eq:NN \chemmacros_p_style:n \textsl ,
    p-style / italics .code:n   = \cs_set_eq:NN \chemmacros_p_style:n \textit ,
    p-style / upright .code:n   = \cs_set_eq:NN \chemmacros_p_style:n \textup ,
    p-style           .initial:n = upright
  }

\cs_new_protected:Npn \chemmacros_p:n #1
  {
    \group_begin:
      \mbox
        {
          \chemmacros_p_style:n {p}
          \ensuremath {#1}
        }
    \group_end:
  }

\NewDocumentCommand \p  {m} { \chemmacros_p:n {#1} }
\NewDocumentCommand \pH  {} { \chemmacros_p:n { \chemmacros_chemformula:n {H} } }
\NewDocumentCommand \pOH {} { \chemmacros_p:n { \chemmacros_chemformula:n {OH} } }

\NewDocumentCommand \pKa {o}
  {
    \chemmacros_p:n
      {
        \Ka \IfNoValueF {#1}
          { {} \c_math_subscript_token { \chemmacros_bold:n {#1} } }
      }
  }

\NewDocumentCommand \pKb {o}
  {
    \chemmacros_p:n
      {
        \Kb \IfNoValueF {#1}
          { {} \c_math_subscript_token { \chemmacros_bold:n {#1} } }
      }
  }

% --------------------------------------------------------------------------
\tex_endinput:D
2016/02/04 - \NewChemEqConstant and family, new option `eq-constant'