summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/projlib/projlib-math.sty
blob: f7fa7b81deb7a3af947266092eb4d5c0f9eb7176 (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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
%%
%% This is file `projlib-math.sty',
%% generated with the docstrip utility.

%% Copyright (C) 2021-2022 by Jinwen XU
%% 
%% This is part of the ProjLib Toolkit.
%% 
%% This work may be distributed and/or modified under the conditions of the
%% LaTeX Project Public License, either version 1.3c 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.3c or later is part of all distributions of LaTeX version
%% 2005/12/01 or later.
%% 
\NeedsTeXFormat{LaTeX2e}[2020-10-01]
\RequirePackage{l3keys2e}
\ProvidesExplPackage
  {projlib-math}
  {2022/03/19} {}
  {Efficient math setup}

\keys_define:nn { projlib-math }
  {
    , unknown     .code:n     = {}
  }
\ProcessKeysOptions { projlib-math }

\RequirePackage { mathtools }
\RequirePackage { mathrsfs }
\PassOptionsToPackage { warnings-off = { mathtools-colon, mathtools-overbracket } } { unicode-math }
\@ifpackageloaded { unicode-math } {} { \RequirePackage { amssymb } }

\msg_new:nnn { projlib-math }
  { operator-not-define }
  { The~math~operator~"\iow_char:N \\#1"~cannot~be~defined,~a~command~with~the~same~name~has~already~existed. }

\keys_define:nn { projlib-math-operator }
  {
    , style        .tl_set:N     = \l__projlib_math_operator_style_tl
    , unknown      .code:n       = {}
  }

\cs_new_protected:Nn \projlib_math_define_operator:nnn
  % #1 = bool for star or empty
  % #2 = list of operators
  % #3 = the option
  {
    \tl_clear:N \l__projlib_math_operator_style_tl
    \keys_set:nn { projlib-math-operator } { #3 }
    \clist_map_inline:nn { #2 }
      {
        \str_if_in:nnTF { ##1 } { = }
          {
            \seq_set_split:Nnn \l_tmpa_seq { = } { ##1 }
            \__projlib_math_define_operator:nee { #1 } { \seq_item:Nn \l_tmpa_seq { 1 } } { \seq_item:Nn \l_tmpa_seq { 2 } }
          }
          {
            \__projlib_math_define_operator:nee { #1 } { ##1 } { ##1 }
          }
      }
  }

\cs_new_protected:Nn \__projlib_math_define_operator:nnn
  % #1 = bool for star or empty
  % #2 = the operator
  % #3 = the content
  {
    \cs_if_exist:cTF { #2 }
      {
        \msg_warning:nnn  { projlib-math } { operator-not-define } { #2 }
      }
      {
        \bool_if:NTF #1
          {
            \exp_args:Nnf \use:n
              { \exp_args:Nnc \use:n { \DeclareMathOperator* } { #2 } }
          }
          {
            \exp_args:Nnf \use:n
              { \exp_args:Nc \DeclareMathOperator { #2 } }
          }
          % This is the f-argument of  \exp_args:Nnf :
          {
            \exp_args:NnV \use:nn
              { \exp_stop_f: }
              { \l__projlib_math_operator_style_tl } { #3 }
          }
      }
  }
\cs_generate_variant:Nn \__projlib_math_define_operator:nnn { nee }

\NewDocumentCommand \DefineOperator { s O{} m O{} }
  {
    \tl_if_blank:nTF { #2 }
      {
        \projlib_math_define_operator:nnn { #1 } { #3 } { #4 }
      }
      {
        \projlib_math_define_operator:nnn { #1 } { #3 } { #2 }
      }
  }

\msg_new:nnn { projlib-math }
  { shortcut-not-define }
  { The~shortcut~"\iow_char:N \\#1"~cannot~be~defined,~a~command~with~the~same~name~has~already~existed. }

\msg_new:nnn { projlib-math }
  { shortcut-type-not-define }
  { The~shortcut~type~"#1"~is~not~available,~a~command~with~the~same~name~has~already~existed. }

\keys_define:nn { projlib-math-shortcut }
  {
    , prefix       .clist_set:N  = \l__projlib_math_shortcut_prefix_clist
    , type         .tl_set:N     = \l__projlib_math_shortcut_type_tl
    , style        .tl_set:N     = \l__projlib_math_shortcut_style_tl
    , unknown      .code:n       = {}
  }

\cs_new_protected:Nn \projlib_math_define_shortcut:nnn
  % #1 = bool for star or empty
  % (currently the starred version is the same as normal version)
  % #2 = list of shortcuts
  % #3 = the option
  {
    \clist_clear:N \l__projlib_math_shortcut_prefix_clist
    \tl_clear:N \l__projlib_math_shortcut_type_tl
    \tl_clear:N \l__projlib_math_shortcut_style_tl
    \keys_set:nn { projlib-math-shortcut } { #3 }
    \tl_if_empty:NF \l__projlib_math_shortcut_type_tl
      {
        \cs_if_exist:cTF { \l__projlib_math_shortcut_type_tl }
          {
            \exp_args:Nne \use:n
              { \msg_warning:nnn  { projlib-math } { shortcut-type-not-define } }
              { \l__projlib_math_shortcut_type_tl }
          }
          {
            \exp_args:Nno \use:n
              {
                \exp_args:Nc \NewDocumentCommand { \l__projlib_math_shortcut_type_tl } { m }
              }
              {
                \l__projlib_math_shortcut_style_tl { ##1 }
              }
          }
      }
    \clist_map_inline:nn { #2 }
      {
        \str_if_in:nnTF { ##1 } { = }
          {
            \seq_set_split:Nnn \l_tmpa_seq { = } { ##1 }
            \clist_if_empty:NTF \l__projlib_math_shortcut_prefix_clist
              {
                \__projlib_math_define_shortcut:ee { \seq_item:Nn \l_tmpa_seq { 1 } } { \seq_item:Nn \l_tmpa_seq { 2 } }
              }
              {
                \clist_map_inline:Nn \l__projlib_math_shortcut_prefix_clist
                  {
                    \__projlib_math_define_shortcut:ee { ####1 \seq_item:Nn \l_tmpa_seq { 1 } } { \seq_item:Nn \l_tmpa_seq { 2 } }
                  }
              }
          }
          {
            \clist_if_empty:NTF \l__projlib_math_shortcut_prefix_clist
              {
                \__projlib_math_define_shortcut:ee { ##1 } { ##1 }
              }
              {
                \clist_map_inline:Nn \l__projlib_math_shortcut_prefix_clist
                  {
                    \__projlib_math_define_shortcut:ee { ####1 ##1 } { ##1 }
                  }
              }
          }
      }
  }

\cs_new_protected:Nn \__projlib_math_define_shortcut:nn
  % #1 = command name
  % #2 = the content
  {
    \cs_if_exist:cTF { #1 }
      {
        \msg_warning:nnn { projlib-math } { shortcut-type-not-define } { #1 }
      }
      {
        \exp_args:Nno \use:n
          { \exp_args:Nc \NewDocumentCommand { #1 } {} }
          { \l__projlib_math_shortcut_style_tl { #2 } }
      }
  }
\cs_generate_variant:Nn \__projlib_math_define_shortcut:nn { ee }

\NewDocumentCommand \DefineShortcut { s O{} m O{} }
  {
    \tl_if_blank:nTF { #2 }
      {
        \projlib_math_define_shortcut:nnn { #1 } { #3 } { #4 }
      }
      {
        \projlib_math_define_shortcut:nnn { #1 } { #3 } { #2 }
      }
  }

\endinput
%%
%% End of file `projlib-math.sty'.