summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tcolorbox/tcbmagazine.code.tex
blob: e85f6143da198c563e038b91bda1d0e3fd655ee8 (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
%% The LaTeX package tcolorbox - version 4.41 (2020/09/29)
%% tcbmagazine.code.tex: Code for box sets and magazine styles
%%
%% -------------------------------------------------------------------------------------------
%% Copyright (c) 2006-2020 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
%%
\tcb@set@library@version{4.41}

\tcbuselibrary{breakable}

\def\newboxarray#1{%
  \ifcsdef{tcb@boxarray@#1@allocated}{%
    \tcb@warning{box array '#1' is allocated again by \string\newboxarray. Memory and registers are wasted}%
  }{}%
  \global\csdef{tcb@boxarray@#1@size}{0}%
  \global\csdef{tcb@boxarray@#1@allocated}{0}%
}

\newboxarray{default}

\newrobustcmd*{\boxarraygetsize}[2][default]{%
  \letcs#2{tcb@boxarray@#1@size}%
  \ifdef{#2}{}{%
    \tcb@error{undefined box array '#1'}%
    {You have to say \string\newboxarray{#1}, before '#1' can be used as box array.}%
  }%
}

\newrobustcmd*{\boxarrayreset}[1][default]{%
  \boxarraygetsize[#1]\tcb@box@array@size%
  \global\csdef{tcb@boxarray@#1@size}{0}%
}

\newrobustcmd*{\boxarrayclear}[1][default]{%
  \boxarraygetsize[#1]\tcb@box@array@size%
  \global\csdef{tcb@boxarray@#1@size}{0}%
  \letcs\tcb@box@array@allocated{tcb@boxarray@#1@allocated}%
  \begingroup%
    \count@=0%
    \loop%
    \ifnum\count@<\tcb@box@array@allocated\relax%
      \advance\count@ 1\relax%
      \letcs\tcb@box@array@box{tcb@boxarray@#1@\number\count@ @box}%
      \setbox0=\box\tcb@box@array@box%
    \repeat%
  \endgroup%
}

\newrobustcmd*{\boxarraygetbox}[3][default]{%
  \boxarraygetsize[#1]\tcb@box@array@size%
  \let#2\@undefined%
  \ifnum\numexpr#3>0\relax%
    \ifnum\numexpr#3>\tcb@box@array@size\relax%
    \else%
      \letcs#2{tcb@boxarray@#1@#3@box}%
    \fi%
  \fi%
}

\newrobustcmd*{\boxarraygetwidth}[3][default]{%
  \boxarraygetbox[#1]{\tcb@box@array@box}{#3}%
  \ifdefined\tcb@box@array@box%
    \tcbdimto#2{\wd\tcb@box@array@box}%
  \else%
    \let#2\tcb@zpt%
  \fi%
}

\newrobustcmd*{\boxarraygetheight}[3][default]{%
  \boxarraygetbox[#1]{\tcb@box@array@box}{#3}%
  \ifdefined\tcb@box@array@box%
    \tcbdimto#2{\ht\tcb@box@array@box}%
  \else%
    \let#2\tcb@zpt%
  \fi%
}

\newrobustcmd*{\boxarraygetdepth}[3][default]{%
  \boxarraygetbox[#1]{\tcb@box@array@box}{#3}%
  \ifdefined\tcb@box@array@box%
    \tcbdimto#2{\dp\tcb@box@array@box}%
  \else%
    \let#2\tcb@zpt%
  \fi%
}

\newrobustcmd*{\boxarraygettotalheight}[3][default]{%
  \boxarraygetbox[#1]{\tcb@box@array@box}{#3}%
  \ifdefined\tcb@box@array@box%
    \tcbdimto#2{\ht\tcb@box@array@box+\dp\tcb@box@array@box}%
  \else%
    \let#2\tcb@zpt%
  \fi%
}

\newrobustcmd*{\useboxarray}[2][default]{%
  \boxarraygetbox[#1]{\tcb@box@array@box}{#2}%
  \ifdefined\tcb@box@array@box%
    \usebox{\tcb@box@array@box}%
  \fi%
}

\newrobustcmd{\usetcboxarray}[3][default]{%
  \boxarraygetbox[#1]{\tcb@box@array@box}{#2}%
  \ifdefined\tcb@box@array@box%
    \tcbox[#3]{\usebox{\tcb@box@array@box}}%
  \fi%
}

\newrobustcmd*{\consumeboxarray}[2][default]{%
  \boxarraygetbox[#1]{\tcb@box@array@box}{#2}%
  \ifdefined\tcb@box@array@box%
    \leavevmode\box\tcb@box@array@box\relax%
  \fi%
}

\newrobustcmd{\consumetcboxarray}[3][default]{%
  \boxarraygetbox[#1]{\tcb@box@array@box}{#2}%
  \ifdefined\tcb@box@array@box%
    \tcbox[#3]{\leavevmode\box\tcb@box@array@box\relax}%
  \fi%
}

\newrobustcmd{\ifboxarrayempty}[2][default]{%
  \begingroup%
    \boxarraygetbox[#1]{\tcb@box@array@box}{#2}%
    \ifdefined\tcb@box@array@box\relax%
      \aftergroup\@secondoftwo%
    \else%
      \aftergroup\@firstoftwo%
    \fi%
  \endgroup%
}

\def\boxarraystore#1{%
  \boxarraygetsize[#1]\tcb@box@array@size%
  \numdef\tcb@box@array@size{\tcb@box@array@size+1}%
  \global\cslet{tcb@boxarray@#1@size}{\tcb@box@array@size}%
  \letcs\tcb@box@array@allocated{tcb@boxarray@#1@allocated}%
  \ifnum\tcb@box@array@allocated<\tcb@box@array@size\relax%
    \newbox\tcb@box@array@box\csxdef{tcb@boxarray@#1@\tcb@box@array@size @box}{\the\tcb@box@array@box}%
    \global\cslet{tcb@boxarray@#1@allocated}{\tcb@box@array@size}%
  \else%
    \letcs\tcb@box@array@box{tcb@boxarray@#1@\tcb@box@array@size @box}%
  \fi%
  \edef\reserved@a{%
    \endgroup
    \global\setbox\tcb@box@array@box\hbox{%
      \begingroup\aftergroup}%
        \def\noexpand\@currenvir{\@currenvir}%
        \def\noexpand\@currenvline{\on@line}}%
  \reserved@a
    \@endpefalse
    \color@setgroup
      \ignorespaces}

\def\endboxarraystore{\unskip\color@endgroup}

\def\tcb@storetoboxarray@begin#1#2[#3]{\begin{boxarraystore}{#1}}
\def\tcb@storetoboxarray@end{\end{boxarraystore}}

\tcbset{
  store to box array/.code={%
    \def\kvtcb@float{S}\def\tcb@float@env@begin{\tcb@storetoboxarray@begin{#1}}\def\tcb@float@env@end{\tcb@storetoboxarray@end}},
  store to box array/.default=default,
  reset box array/.code={\boxarrayreset[#1]},
  reset box array/.default=default,
  reset and store to box array/.style={reset box array={#1},store to box array={#1}},%
  reset and store to box array/.default=default,
  do not store to box array/.style={nofloat},
}