summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tcolorbox/tcbtheorems.code.tex
blob: dc6b5651e7604927c7affd14f417c9d838ba0c52 (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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
%% The LaTeX package tcolorbox - version 5.1.1 (2022/06/24)
%% tcbtheorems.code.tex: Code for theorems in colorboxes
%%
%% -------------------------------------------------------------------------------------------
%% Copyright (c) 2006-2022 by Prof. Dr. Dr. Thomas F. Sturm <thomas dot sturm at unibw dot de>
%% -------------------------------------------------------------------------------------------
%%
%% 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 `author-maintained'.
%%
%% This work consists of all files listed in README
%%
%\makeatletter
\tcb@set@library@version{5.1.1}

\RequirePackage{amsmath}


\ExplSyntaxOn

\tl_new:N \l__tcobox_theo_description_color_tl
\tl_new:N \l__tcobox_theo_description_delimiter_left_tl
\tl_new:N \l__tcobox_theo_description_delimiter_right_tl
\tl_new:N \l__tcobox_theo_description_font_tl
\tl_new:N \l__tcobox_theo_hanging_indent_tl
\tl_new:N \l__tcobox_theo_label_separator_tl
\tl_new:N \l__tcobox_theo_separatorsign_tl
\tl_new:N \l__tcobox_theo_terminatorsign_tl
\bool_new:N \l__tcobox_theo_headempty_bool


\cs_new_nopar:Npn \__tcobox_theo_format_name_number:nn #1#2
  {
    \tl_if_empty:nTF { #1 }
      {
        \tl_if_empty:nF { #2 }
          {
            \bool_set_false:N \l__tcobox_theo_headempty_bool
            #2
          }
      }
      {
        \bool_set_false:N \l__tcobox_theo_headempty_bool
        #1
        \tl_if_empty:nF { #2 }
          {
            \nobreakspace
            #2
          }
      }
  }


\cs_new_nopar:Npn \__tcobox_theo_format_number_name:nn #1#2
  {
    \__tcobox_theo_format_name_number:nn { #2 } { #1 }
  }


\cs_new_nopar:Npn \__tcobox_theo_format_name:nn #1#2
  {
    \tl_if_empty:nF { #1 }
      {
        \bool_set_false:N \l__tcobox_theo_headempty_bool
        #1
      }
  }


\cs_new_nopar:Npn \__tcobox_theo_format_number:nn #1#2
  {
    \tl_if_empty:nF { #2 }
      {
        \bool_set_false:N \l__tcobox_theo_headempty_bool
        #2
      }
  }


\cs_new:Npn \__tcobox_theo_format_description_standard:n #1
  {
    \l__tcobox_theo_description_color_tl
    \l__tcobox_theo_description_font_tl
    \l__tcobox_theo_description_delimiter_left_tl
    #1
    \l__tcobox_theo_description_delimiter_right_tl
  }



\cs_new:Npn \__tcobox_theo_title:nnn #1#2#3
  {
    % format and save display name and number
    \bool_set_true:N \l__tcobox_theo_headempty_bool
    \tl_if_empty:nTF { #3 }
      {
        % no theorem title; insert name and number
        \__tcobox_theo_format:nn{#1}{#2}
        \l__tcobox_theo_terminatorsign_tl
      }
      {
        % box display name and number
        \hbox_set:Nn \l_tmpa_box
          {
            \__tcobox_theo_format:nn{#1}{#2}
            \bool_if:NF \l__tcobox_theo_headempty_bool
              {
                \l__tcobox_theo_separatorsign_tl
                \nobreakspace
              }
          }
        % set (hanging) indent for name and number
        \str_if_eq:VnTF \l__tcobox_theo_hanging_indent_tl { auto }
          {
            \hangindent \box_wd:N \l_tmpa_box
            \hangafter = 1
          }
          {
            \dim_set:Nn \l_tmpa_dim { \l__tcobox_theo_hanging_indent_tl }
            \if_dim:w \l_tmpa_dim = \c_zero_dim
            \else:
              \if_dim:w \l_tmpa_dim > \c_zero_dim
                \hangindent \l_tmpa_dim
                \hangafter = 1
              \else:
                \hangindent -\l_tmpa_dim
                \hangafter = -1
              \fi:
            \fi:
          }
        % insert box with name and number
        \mode_leave_vertical:
        \box_use_drop:N \l_tmpa_box
        % insert formated title
        \group_begin:
          \__tcobox_theo_format_description:n{#3}
        \group_end:
        \l__tcobox_theo_terminatorsign_tl
      }
  }


\NewDocumentCommand \__tcobox_new_tcbtheorem:w { m O{} m m +m m }
  {
    #1 [auto~counter,#2]{#3}[3][]
      {
        #5,
        title      = {\__tcobox_theo_title:nnn{#4}{\thetcbcounter}{##2}},
        list~entry = {\protect\numberline{\thetcbcounter}##2},
        nameref    = {##2},
        theo@label = {#6}{##3},
        ##1
      }
    #1 [#2,no~counter,list~inside=]{#3*}[2][]
      {
        #5,
        title = {\__tcobox_theo_title:nnn{#4}{}{##2}},
        ##1
      }
  }


\NewDocumentCommand \newtcbtheorem {}
  {
    \__tcobox_new_tcbtheorem:w \newtcolorbox
  }


\NewDocumentCommand \renewtcbtheorem {}
  {
    \__tcobox_new_tcbtheorem:w \renewtcolorbox
  }


\tcbset
  {
    theo@label/.code~n~args = {2}
      {
        \tl_if_empty:nF { #2 }
          {
            \tcbset
              {
                label                    = {#1\l__tcobox_theo_label_separator_tl#2},
                tcb@theo@full@label@supp = {#1\l__tcobox_theo_label_separator_tl#2},
                tcb@theo@label@supp      = {#2}
              }
          }
      },
    theorem/.style~n~args = {4}
      {
        step~and~label={#2}{#4},
        title={\__tcobox_theo_title:nnn{#1}{\cs:w the#2\cs_end:}{#3}}
      },
    theorem~name~and~number/.code =
      {
        \cs_set_eq:NN \__tcobox_theo_format:nn \__tcobox_theo_format_name_number:nn
      },
    theorem~number~and~name/.code =
      {
        \cs_set_eq:NN \__tcobox_theo_format:nn \__tcobox_theo_format_number_name:nn
      },
    theorem~name/.code =
      {
        \cs_set_eq:NN \__tcobox_theo_format:nn \__tcobox_theo_format_name:nn
      },
    theorem~number/.code =
      {
        \cs_set_eq:NN \__tcobox_theo_format:nn \__tcobox_theo_format_number:nn
      },
    separator~sign/         .tl_set:N = \l__tcobox_theo_separatorsign_tl,
    terminator~sign/        .tl_set:N = \l__tcobox_theo_terminatorsign_tl,
    label~separator/        .tl_set:N = \l__tcobox_theo_label_separator_tl,
    theorem~hanging~indent/ .tl_set:N = \l__tcobox_theo_hanging_indent_tl,
    theorem~hanging~indent/.default=auto,
    description~delimiters/.code~n~args = {2}
      {
        \tl_set:Nn \l__tcobox_theo_description_delimiter_left_tl  { #1 }
        \tl_set:Nn \l__tcobox_theo_description_delimiter_right_tl { #2 }
      },
    description~color/.code =
      {
        \tl_if_empty:nTF { #1 }
          {
            \tl_clear:N \l__tcobox_theo_description_color_tl
          }
          {
            \tl_set:Nn \l__tcobox_theo_description_color_tl { \color{#1} }
          }
      },
    description~color/.default=,
    description~font/.tl_set:N = \l__tcobox_theo_description_font_tl,
    description~font/.default  =,
    description~formatter/.code =
      {
        \cs_set_eq:NN \__tcobox_theo_format_description:n #1
      },
    description~formatter/.default = \__tcobox_theo_format_description_standard:n,
  }

\ExplSyntaxOff


\newtcbox{\tcboxmath}[1][]{nobeforeafter,math upper,tcbox raise base,#1}
\newtcbox{\tcbhighmath}[1][]{highlight math,nobeforeafter,math upper,tcbox raise base,#1}


\def\tcb@hack@amsmath{\tcb@hack@currenvir\vskip-\abovedisplayskip}

\if@fleqn%
\tcbset{%
  ams equation upper/.style={before upper*=\tcb@hack@amsmath\equation,after upper*=\endequation},%
  ams equation lower/.style={before lower*=\tcb@hack@amsmath\equation,after lower*=\endequation},%
  ams equation* upper/.style={before upper*=\tcb@hack@amsmath\csname equation*\endcsname,after upper*=\endequation},%
  ams equation* lower/.style={before lower*=\tcb@hack@amsmath\csname equation*\endcsname,after lower*=\endequation}%
}%
\else%
\tcbset{%
  ams equation upper/.style={before upper*=\tcb@hack@currenvir\equation,after upper*=\endequation},%
  ams equation lower/.style={before lower*=\tcb@hack@currenvir\equation,after lower*=\endequation},%
  ams equation* upper/.style={before upper*=\tcb@hack@currenvir\csname equation*\endcsname,after upper*=\endequation},%
  ams equation* lower/.style={before lower*=\tcb@hack@currenvir\csname equation*\endcsname,after lower*=\endequation},%
}%
\fi

\tcbset{
  math upper/.style={before upper*=$\displaystyle,after upper*=$},%
  math lower/.style={before lower*=$\displaystyle,after lower*=$},%
  math/.style={math upper,math lower},%
  ams equation/.style={ams equation upper,ams equation lower},%
  ams equation*/.style={ams equation* upper,ams equation* lower},%
  ams align upper/.style={before upper*=\tcb@hack@amsmath\align,after upper*=\endalign},%
  ams align lower/.style={before lower*=\tcb@hack@amsmath\align,after lower*=\endalign},%
  ams align/.style={ams align upper,ams align lower},%
  ams align* upper/.style={before upper*=\tcb@hack@amsmath\csname align*\endcsname,after upper*=\endalign},%
  ams align* lower/.style={before lower*=\tcb@hack@amsmath\csname align*\endcsname,after lower*=\endalign},%
  ams align*/.style={ams align* upper,ams align* lower},%
  ams gather upper/.style={before upper*=\tcb@hack@amsmath\gather,after upper*=\endgather},%
  ams gather lower/.style={before lower*=\tcb@hack@amsmath\gather,after lower*=\endgather},%
  ams gather/.style={ams gather upper,ams gather lower},%
  ams gather* upper/.style={before upper*=\tcb@hack@amsmath\csname gather*\endcsname,after upper*=\endgather},%
  ams gather* lower/.style={before lower*=\tcb@hack@amsmath\csname gather*\endcsname,after lower*=\endgather},%
  ams gather*/.style={ams gather* upper,ams gather* lower},%
  ams nodisplayskip upper/.style={before upper=\vskip-\abovedisplayskip},%
  ams nodisplayskip lower/.style={before lower=\vskip-\abovedisplayskip},%
  ams nodisplayskip/.style={ams nodisplayskip upper,ams nodisplayskip lower},%
  highlight math style/.style={highlight math/.style={notitle,nophantom,#1}},%
  separator sign colon/.style={separator sign={:}},%
  separator sign dash/.style={separator sign={\nobreakspace --}},%
  separator sign none/.style={separator sign=},%
  terminator sign colon/.style={terminator sign={:}},%
  terminator sign dash/.style={terminator sign={\nobreakspace --}},%
  terminator sign none/.style={terminator sign=},%
  description delimiters parenthesis/.style={description delimiters=()},
  description delimiters none/.style={description delimiters={}{}},
  theorem style/.is choice,
  theorem style/standard/.style={separator sign colon,description delimiters none,
    terminator sign none,theorem name and number,attach title},
  theorem style/change standard/.style={theorem style=standard,theorem number and name},
  theorem style/plain/.style={separator sign none,description delimiters parenthesis,
    terminator sign colon,theorem name and number,attach title to upper={\ }},
  theorem style/plain apart/.style={separator sign none,description delimiters parenthesis,
    terminator sign none,theorem name and number,attach title},
  theorem style/break/.style={theorem style=plain,attach title to upper={\par}},
  theorem style/change/.style={theorem style=plain,theorem number and name},
  theorem style/change apart/.style={theorem style=plain apart,theorem number and name},
  theorem style/change break/.style={theorem style=break,theorem number and name},
  theorem style/margin/.style={theorem style=plain,theorem name,before title=\makebox[0pt][r]{\thetcbcounter\ }},
  theorem style/margin apart/.style={theorem style=margin,attach title,terminator sign none},
  theorem style/margin break/.style={theorem style=margin,attach title to upper={\par}},
  theorem label supplement/.style={tcb@theo@label@supp/.style={#1}},
  theorem full label supplement/.style={tcb@theo@full@label@supp/.style={#1}},
}


\tcbset{%
  reset@theorems/.style={%
    description formatter,description color,description font,
    highlight math style={colframe=red,colback=yellow!25!white},%
    theorem style=standard,label separator=:,%
    theorem label supplement=,theorem full label supplement=,%
    theorem hanging indent%
  },
  initialize@reset=reset@theorems,
}