-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathxeboiboites.sty
366 lines (329 loc) · 13 KB
/
xeboiboites.sty
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{xeboiboites}[2015/06/18 version 0.9e]
\RequirePackage{xkeyval}
\RequirePackage{tikz}
\RequirePackage{pgf}
\RequirePackage{amsthm}
\RequirePackage{framed}
\usetikzlibrary{decorations.pathmorphing,calc}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\pgfmathsetseed{1} % To have predictable results
\define@key{boxedtheorem}{thcounter}{\def\thcounter{#1}}
\define@key{boxedtheorem}{size}{\def\size{#1}}
\define@key{boxedtheorem}{small box style}{\def\smallboxstyle{#1}}
\define@key{boxedtheorem}{big box style}{\def\bigboxstyle{#1}}
\define@key{boxedtheorem}{spanning style}{\def\spanningstyle{#1}}
\define@key{boxedtheorem}{headfont}{\def\headfont{#1}}
\define@key{boxedtheorem}{image}{\def\image{#1}}
\define@key{boxedtheorem}{upshift}{\def\upshift{#1}}
\define@key{boxedtheorem}{rightshift}{\def\rightshift{#1}}
\define@key{boxedtheorem}{broken edges}{\def\tornstyle{#1}}
\define@key{boxedtheorem}{other edges}{\def\otheredges{#1}}
\presetkeys{boxedtheorem}{headfont=, image=logo-tex, thcounter=, small box style=,%
big box style=, spanning style=, size = .9\textwidth,%
broken edges=, other edges=,rightshift=-1.95cm,upshift=-.3cm}{}
%To expand properly \smallboxstyle, \bigboxstyle and \spanningstyle in \tikset.
\tikzset{
execute style/.style={#1},
execute macro/.style={execute style/.expand once=#1},
}
\newcommand{\couleurs}[1][]{%
\setkeys{boxedtheorem}{#1}
\tikzset{fancytitle/.style={draw=black, rectangle,right=10pt}}
\tikzset{fancytitle/.append style={execute macro=\smallboxstyle}}
\tikzset{mybox/.style={draw=black, rectangle, inner sep=10pt, inner ysep=20pt}}
\tikzset{mybox/.append style={execute macro=\bigboxstyle}}
\tikzset{formulabox/.style={draw=black, rectangle}}
\tikzset{formulabox/.append style={execute macro=\bigboxstyle}}
\tikzset{span/.style={black}}
\tikzset{span/.append style={execute macro=\spanningstyle}}
\tikzset{torn/.style={execute macro=\tornstyle}}
\tikzset{other edges/.style={execute macro=\otheredges}}
}
%Hand drawn style : http://tex.stackexchange.com/questions/39296/simulating-hand-drawn-lines
\pgfdeclaredecoration{penciline}{initial}{%
\state{initial}[width=+\pgfdecoratedinputsegmentremainingdistance,auto corner on length=1mm,]{%
\pgfpathcurveto%
{% From
\pgfqpoint{\pgfdecoratedinputsegmentremainingdistance}%
{\pgfdecorationsegmentamplitude}%
}%
{% Control 1
\pgfmathrand
\pgfpointadd{\pgfqpoint{\pgfdecoratedinputsegmentremainingdistance}{0pt}}%
{\pgfqpoint{-\pgfdecorationsegmentaspect\pgfdecoratedinputsegmentremainingdistance}%
{\pgfmathresult\pgfdecorationsegmentamplitude}%
}%
}%
{% To
\pgfpointadd{\pgfpointdecoratedinputsegmentlast}{\pgfpoint{1pt}{1pt}}%
}%
}%
\state{final}{}%
}
% To create a nice looking box
% http://www.texample.net/tikz/examples/boxes-with-text-and-math/
\newsavebox{\boiboite}
\newcommand{\titre}{Titre}
\newenvironment{boite}[2][]%
{%
\renewcommand{\titre}{#2}
\couleurs[#1]
\begin{lrbox}{\boiboite}%
\begin{minipage}[!h]{\size}
}%
{%
\end{minipage}
\end{lrbox}
\begin{center}
\begin{tikzpicture}
\node[mybox] (box) {\usebox{\boiboite}};
\node[fancytitle] at (box.north west) {\titre};
\end{tikzpicture}
\end{center}
}
\newcommand{\newboxedtheorem}[4][]{%
\couleurs[#1]
\@ifnotempty{#4}{%
\@ifundefined{the#4}{\@ifundefined{\thcounter}{\newcounter{#4}}{%
\newcounter{#4}[\thcounter ]}}{}%
}
\newenvironment{#2}[1][]{%
\@ifnotempty{#4}{\refstepcounter{#4}}
\begin{boite}[#1]{{\headfont#3\@ifnotempty{#4}{ \csname the#4\endcsname}}\@ifnotempty{##1}{ \headfont(##1)}}
}%
{%
\end{boite}
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Boxes with no title
\newsavebox{\boiboitedeux}
\newenvironment{notitlebox}[1][]%
{%
\couleurs[#1]
\begin{lrbox}{\boiboitedeux}%
\begin{minipage}[!h]{\size}
}%
{%
\end{minipage}
\end{lrbox}
\begin{center}
\begin{tikzpicture}
\node [formulabox] (box){\usebox{\boiboitedeux}};
\end{tikzpicture}
\end{center}
}
\newcommand{\newboxedequation}[2][]{%
\couleurs[#1]
\newenvironment{#2}[1][]{%
\begin{notitlebox}[#1]
}%
{%
\end{notitlebox}
}
}
%%%%%%%%%%%%%%%%%%%%%% Spanning environment (line in the margin + image)
% Macro to draw the shape behind the text, when it fits completly in the page
\def\spanframe#1{%
\tikz{%
\node[inner xsep=1.1em] (A) {#1};% Draw the text of the node
\begin{pgfonlayer}{background}% Draw the shape behind
\draw[span] (A.north west) -- (A.south west);%
\end{pgfonlayer}}}%
% Macro to draw the shape, when the text will continue in next page
\def\spanframetop#1{%
\tikz{%
\node[inner xsep=1.1em] (A) {#1};% % Draw the text of the node
\begin{pgfonlayer}{background}%
\draw[span] (A.north west) -- (A.south west);%
\end{pgfonlayer}}}%
% Macro to draw the shape, when the text continues from previous page
\def\spanframebottom#1{%
\tikz{%
\node[inner xsep=1.1em] (A) {#1};% % Draw the text of the node
\begin{pgfonlayer}{background}%
\draw[span] (A.north west) -- (A.south west);%
\end{pgfonlayer}}%
}%
% Macro to draw the shape, when both the text continues from previous page
% and it will continue in next page
\def\spanframemiddle#1{%
\tikz{%
\node[inner xsep=1.1em] (A) {#1};% % Draw the text of the node
\begin{pgfonlayer}{background}%
\draw[span] (A.north west) -- (A.south west);%
\end{pgfonlayer}}}%
% Define the environment which puts the frame
% In this case, the environment also accepts an argument with an optional
% title (which defaults to ``Example'', which is typeset in a box overlaid
% on the top border
\newcommand{\newspanning}[4][]{%
\couleurs[#1]%
\@ifnotempty{#4}{%
\@ifundefined{the#4}{\@ifundefined{\thcounter}{\newcounter{#4}}{%
\newcounter{#4}[\thcounter ] }}{}%
}
\newenvironment{#2}[1][]{%
\couleurs[#1]
\@ifnotempty{#4}{\refstepcounter{#4}}
\def\FrameCommand{\spanframe}%
\def\FirstFrameCommand{\spanframetop}%
\def\LastFrameCommand{\spanframebottom}%
\def\MidFrameCommand{\spanframemiddle}%
\vskip 1.3\baselineskip%
\MakeFramed {\FrameRestore}%
\noindent\tikz\node[inner sep=1ex,,fill=white, %
anchor=west, overlay] at (-2em, 2em) {\headfont#3%
\@ifnotempty{#4}{ \csname the#4\endcsname}\@ifnotempty{##1}{ \headfont(##1)}};%
\tikz\node[anchor=west, overlay] at (\rightshift,\upshift)%
{\includegraphics[width=1cm]{\image}};%
\ignorespaces%
}%
{%
\endMakeFramed%
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%% Breakable boxes
%%%%%%%%%%%%% http://www.texample.net/tikz/examples/framed-tikz/
% Macro to draw the shape behind the text, when it fits completly in the page
\def\someframe#1{
\tikz{
\node[inner sep=8pt] (A) {#1}; % Draw the text of the node
\noindent
\begin{pgfonlayer}{background} % Draw the shape behind
\draw[mybox, other edges]
(A.south east) -- (A.south west) -- (A.north west) -- (A.north east) -- cycle;
\end{pgfonlayer}}}
% Macro to draw the shape, when the text will continue in next page
\def\someframetop#1{
\tikz{
\node[inner sep=5pt] (A) {#1}; % Draw the text of the node
\begin{pgfonlayer}{background}
\draw[mybox] % Draw the ``complete shape'' behind
(A.south east) decorate[torn] {-- (A.south west)}
decorate[other edges] {-- (A.north west) -- (A.north east) -- cycle};
\end{pgfonlayer}}}
% Macro to draw the shape, when the text continues from previous page
\def\someframebottom#1{
\tikz{
\node[inner sep=5pt] (A) {#1}; % Draw the text of the node
\begin{pgfonlayer}{background}
\draw[mybox] % Draw the ``complete shape'' behind
decorate[other edges] {(A.south east) -- (A.south west) -- (A.north west)}
decorate[torn] {-- (A.north east)} decorate[other edges] {-- cycle};
\end{pgfonlayer}}}
% Macro to draw the shape, when both the text continues from previous page
% and it will continue in next page
\def\someframemiddle#1{
\tikz{
\node[inner sep=5pt] (A) {#1}; % Draw the text of the node
\begin{pgfonlayer}{background}
\draw[mybox] % Draw the ``complete shape'' behind
(A.south east) decorate[torn] {-- (A.south west)}
decorate[other edges]{-- (A.north west)}
decorate[torn] {-- (A.north east)}
decorate[other edges]{-- cycle};
\end{pgfonlayer}}}
% Command to define a new environment that can span over multiple pages
\newcommand{\newbreakabletheorem}[4][]{%
\couleurs[#1]%
\@ifnotempty{#4}{%
\@ifundefined{the#4}{\@ifundefined{\thcounter}{\newcounter{#4}}{%
\newcounter{#4}[\thcounter ] }}{}%
}
\newenvironment{#2}[1][]{%
\couleurs[#1]%
\@ifnotempty{#4}{\refstepcounter{#4}}
\def\FrameCommand{\someframe}%
\def\FirstFrameCommand{\someframetop}%
\def\LastFrameCommand{\someframebottom}%
\def\MidFrameCommand{\someframemiddle}%
\vskip 1.2\baselineskip
\MakeFramed{\hsize\size\FrameRestore}
\noindent \tikz \node[inner sep=1ex,anchor=west, overlay, fancytitle] at (0pt,6pt) %
{\headfont#3 \@ifnotempty{#4}{\csname the#4\endcsname}\@ifnotempty{##1}{ \headfont(##1)}}; \par \noindent
\ignorespaces%
}%
{%
\endMakeFramed%
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%% Parchment boxes
%%%%%%%%%%%%% http://www.texample.net/tikz/examples/framed-tikz/
% Macro to draw the shape behind the text, when it fits completly in the
% page
\def\parchmentframe#1{
\tikz{
\node[inner sep=8pt] (A) {#1}; % Draw the text of the node
\noindent
\begin{pgfonlayer}{background} % Draw the shape behind
\draw[mybox,other edges]
(A.south east) -- (A.south west) -- (A.north west) -- (A.north east) -- cycle;
\end{pgfonlayer}}}
% Macro to draw the shape, when the text will continue in next page
\def\parchmentframetop#1{
\tikz{
\node[inner sep=8pt] (A) {#1}; % Draw the text of the node
\begin{pgfonlayer}{background}
\draw[torn,overlay] % Add the torn lower border
($(A.south east)-(0,.3)$) -- ($(A.south west)-(0,.3)$) --
($(A.south west)+(0,.4)$) -- ($(A.south east)+(0,.4)$);
\draw[mybox,overlay] % Draw the ``complete shape'' behind
($(A.south east)+(0,.1)$) decorate[torn] {-- ($(A.south west)+(0,.1)$)}
decorate[other edges] {-- (A.north west) -- (A.north east) -- cycle};
\end{pgfonlayer}}}
% Macro to draw the shape, when the text continues from previous page
\def\parchmentframebottom#1{
\tikz{
\node[inner sep=8pt] (A) {#1}; % Draw the text of the node
\begin{pgfonlayer}{background}
\draw[torn,overlay] % Add the torn upper border
($(A.north east)-(0,.4)$) -- ($(A.north west)-(0,.4)$) --
($(A.north west)+(0,.3)$) -- ($(A.north east)+(0,.3)$) -- cycle;
\draw[mybox,overlay] % Draw the ``complete shape'' behind
(A.south east) decorate[other edges] {-- (A.south west) -- (A.north west) }
decorate[torn] {-- (A.north east)} decorate[other edges] {-- cycle};
\end{pgfonlayer}}}
% Macro to draw the shape, when both the text continues from previous page
% and it will continue in next page
\def\parchmentframemiddle#1{
\tikz{
\node[inner sep=8pt] (A) {#1}; % Draw the text of the node
\begin{pgfonlayer}{background}
\draw[torn,overlay] % Add the torn upper border
($(A.north east)-(0,.4)$) -- ($(A.north west)-(0,.4)$) --
($(A.north west)+(0,.3)$) -- ($(A.north east)+(0,.3)$) -- cycle;
\draw[torn,overlay] % Add the torn lower border
($(A.south east)-(0,.3)$) -- ($(A.south west)-(0,.3)$) --
($(A.south west)+(0,.4)$) -- ($(A.south east)+(0,.4)$);
\draw[mybox,overlay] % Draw the ``complete shape'' behind
(A.south east) decorate[torn] { -- (A.south west)}
decorate[other edges]{-- (A.north west)}
decorate[torn] {-- (A.north east)}
decorate[other edges]{-- cycle};
\end{pgfonlayer}}}
% Command to define a new environment that can span over multiple pages
\newcommand{\newparchment}[4][]{%
\couleurs[#1]%
\@ifnotempty{#4}{%
\@ifundefined{the#4}{\@ifundefined{\thcounter}{\newcounter{#4}}{%
\newcounter{#4}[\thcounter ] }}{}%
}
\newenvironment{#2}[1][]{%
\couleurs[#1]%
\@ifnotempty{#4}{\refstepcounter{#4}}
\def\FrameCommand{\parchmentframe}%
\def\FirstFrameCommand{\parchmentframetop}%
\def\LastFrameCommand{\parchmentframebottom}%
\def\MidFrameCommand{\parchmentframemiddle}%
\vskip 1.2\baselineskip
\MakeFramed{\hsize\size\FrameRestore}
\noindent \tikz \node[inner sep=1ex,anchor=west, overlay, fancytitle] at (0pt,10pt) %
{\headfont#3 \@ifnotempty{#4}{\csname the#4\endcsname}\@ifnotempty{##1}{ \headfont(##1)}}; \par \noindent
\ignorespaces%
}%
{%
\endMakeFramed%
}
}