Debian Codegraph @

texmf-dist/doc/latex/tkzexample/tkzexample.tex

raw
1 % !TEX TS-program = lualatex
2 % encoding : utf8
3 % Documentation of tkzexample.sty
4 % Copyright 2022 Alain Matthes
5 % This work may be distributed and/or modified under the
6 % conditions of the LaTeX Project Public License, either version 1.3
7 % of this license or (at your option) any later version.
8 % The latest version of this license is in
9 % http://www.latex-project.org/lppl.txt
10 % and version 1.3 or later is part of all distributions of LaTeX
11 % version 2005/12/01 or later.
12 % This work has the LPPL maintenance status “maintained”.
13 % The Current Maintainer of this work is Alain Matthes.
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15 % %
16 % doc tkzexample.sty encodage : utf8 %
17 % %
18 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19 % %
20 % Créé par Alain Matthes le 21/03/2009 %
21 % Copyright (c) 2009, 2022 __AlterMundus__ All rights reserved.%
22 % version : 1.45c %
23 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24
25 \PassOptionsToPackage{unicode}{hyperref}
26
27 \documentclass[DIV = 14,
28 fontsize = 10,
29 index = totoc,
30 twoside,
31 cadre,
32 headings = small,
33 ]{tkz-doc}
34 %\usepackage{etoc}
35 \gdef\tkznameofpack{tkzexample.sty}
36 \gdef\tkzversionofpack{1.45c}
37 \gdef\tkzdateofpack{\today}
38 \gdef\tkznameofdoc{doc-tkzexample}
39 \gdef\tkzversionofdoc{1.45c}
40 \gdef\tkzdateofdoc{\today}
41 \gdef\tkzauthorofpack{Alain Matthes}
42 \gdef\tkzadressofauthor{}
43 \gdef\tkznamecollection{AlterMundus}
44 \gdef\tkzurlauthor{http://altermundus.fr}
45 \gdef\tkzengine{lualatex}
46 \gdef\tkzurlauthorcom{http://altermundus.fr}
47 \nameoffile{\tkznameofpack}
48 % -- Packages ---------------------------------------------------
49 \usepackage[dvipsnames,svgnames]{xcolor}
50 \usepackage{calc}
51 \usepackage{tkz-euclide,tkzexample,pgfornament}
52 \usetikzlibrary{backgrounds}
53 \usepackage[colorlinks,pdfencoding=auto, psdextra]{hyperref}
54 \hypersetup{
55 linkcolor=Gray,
56 citecolor=Green,
57 filecolor=Mulberry,
58 urlcolor=NavyBlue,
59 menucolor=Gray,
60 runcolor=Mulberry,
61 linkbordercolor=Gray,
62 citebordercolor=Green,
63 filebordercolor=Mulberry,
64 urlbordercolor=NavyBlue,
65 menubordercolor=Gray,
66 runbordercolor=Mulberry,
67 pdfsubject={Euclidean Geometry},
68 pdfauthor={\tkzauthorofpack},
69 pdftitle={\tkznameofpack},
70 pdfcreator={\tkzengine}
71 }
72
73 \usepackage{fontspec}
74 \setmainfont{texgyrepagella}[
75 Extension = .otf,
76 UprightFont = *-regular ,
77 ItalicFont = *-italic ,
78 BoldFont = *-bold ,
79 BoldItalicFont = *-bolditalic
80 ]
81 \setsansfont{texgyreheros}[
82 Extension = .otf,
83 UprightFont = *-regular ,
84 ItalicFont = *-italic ,
85 BoldFont = *-bold ,
86 BoldItalicFont = *-bolditalic ,
87 ]
88
89 \setmonofont{lmmono10-regular.otf}[
90 Numbers={Lining,SlashedZero},
91 ItalicFont=lmmonoslant10-regular.otf,
92 BoldFont=lmmonolt10-bold.otf,
93 BoldItalicFont=lmmonolt10-boldoblique.otf,
94 ]
95 \newfontfamily\ttcondensed{lmmonoltcond10-regular.otf}
96 %% (La)TeX font-related declarations:
97 \linespread{1.05} % Pagella needs more space between lines
98 %\usepackage{unicode-math}
99 \usepackage[math-style=literal,bold-style=literal]{unicode-math}
100 \usepackage{fourier-otf}
101 \let\rmfamily\ttfamily
102 \usepackage{multicol,lscape}
103 \usepackage[english]{babel}
104 \usepackage[normalem]{ulem}
105 \usepackage{multirow,multido,booktabs,cellspace}
106 \usepackage{shortvrb,fancyvrb,bookmark}
107
108 \usetikzlibrary{snakes}
109
110 %<--------------------------------------------------------------------------
111 % settings styles
112 \tkzSetUpColors[background=white,text=black]
113 \AtBeginDocument{\MakeShortVerb{\|}} % link to shortvrb
114 %<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––>
115
116 \begin{document}
117 \parindent=0pt
118 \tkzTitleFrame{tkzexample\\Presentation tool}
119 \clearpage
120
121
122 \nameoffile{\tkznameofpack}
123 \defoffile{\tkzname{\tkznameofpack} is a package to present examples and their sources. It is essential if you want to compile the documentation of my packages like \tkzname{tkz-euclide}. I needed for my first packages to work in UTF8 and to present my sources in French. These sources had accents so I had to adapt the code used by \tkzimp{T.Tantau} to present the examples of \tkzname{pgfmanual}. There are still some imperfections so I invite you to improve this code if necessary}.
124
125 \presentation
126
127 \vfill
128
129 Please report typos or any other comments to this documentation to: \href{mailto:[email protected]}{\textcolor{blue}{Alain Matthes}}.
130
131 This file can be redistributed and/or modified under the terms of the \LaTeX{}
132 Project Public License Distributed from \href{http://www.ctan.org/}{CTAN}\ archives.
133
134
135 \clearpage
136 \tableofcontents
137 \clearpage
138 %<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––>
139
140 \colorlet{graphicbackground}{blue!10!white}%
141 \colorlet{codebackground}{blue!20!lightgray!20}%
142 \colorlet{numbackground}{blue!50!black!50}%
143 \colorlet{numcolor}{white}%
144
145 \section{First example : no options}
146 \tkzname{\tkznameofpack} is based on the code of \tkzname{codeexample} of \tkzimp{T.Tantau} . I wanted to be able to use the accents of the French language in the sources.
147
148 How to use this environment? Without any options, the interpretation of a code and the source of this code are placed one above the other.
149
150 To do this, simply place the source code in a \tkzname{tkzexample}. The colors of the different boxes show their sizes.
151
152 The colors are obtained as follows:
153
154 |\colorlet{graphicbackground}{blue!10!white}| \\
155 |\colorlet{codebackground}{blue!20!lightgray!20}|\\
156
157 \begin{tkzexample}[]
158 \begin{minipage}{8cm}
159 \subsubsection{Minipage and accents without options}
160 This is a test for "minipage" and accents èçéà\&§.
161 The brackets |[]| even without options are mandatory.
162 \end{minipage}
163 \end{tkzexample}
164
165 \vspace{12pt}
166
167 |\begin{tkzexample}[]|\\
168 |\begin{minipage}{8cm}|\\
169 |\subsubsection{Minipage and accents without options}|\\
170 |This is a test for "minipage" and accents èçéà\&§. |\\
171 | The brackets |[]| even without options are mandatory.|\\
172 |\end{minipage}|\\
173 |\end{tkzexample}|\\
174
175 \vspace{12pt}
176 You may notice already a small default, |[]| square brackets are mandatory even without option.
177
178 \section{Inversion of the boxes: option \tkzname{overhang}}
179
180 \tkzname{overhang} allows to swap the source and the result.
181
182 |\begin{tkzexample}[overhang]|\\
183 |\begin{tikzpicture}|\\
184 | ...|\\
185 |\end{tkzexample}|\\
186
187
188 \begin{tkzexample}[overhang]
189 \begin{tikzpicture}
190 \tkzDefPoint(0,0){O}
191 \tkzDefPoint(1,0){a0}
192 \tkzDrawSegment(O,a0)
193 \foreach \i [count=\j] in {0,...,16}{%
194 \tkzDefPointWith[orthogonal normed](a\i,O)
195 \tkzGetPoint{a\j}
196 \pgfmathsetmacro{\c}{5*\i}
197 \tkzDrawPolySeg[fill=teal!\c](a\i,a\j,O)}
198 \end{tikzpicture}
199 \end{tkzexample}
200
201 \newpage
202 \section{Boxes with the same width: option \tkzname{vbox}}
203
204 In order to present the code under the interpretation, I set the vbox option so that the interpretation and the source are in a box of the same maximum width.
205
206 \vspace{12pt}
207 |\begin{tkzexample}[vbox]|\\
208 | ...|\\
209 |\end{tkzexample}|\\
210 \vspace{12pt}
211 which gives
212
213 \begin{tkzexample}[vbox]
214 \begin{tikzpicture}[scale=1]
215 \tikzset{new/.style={color=orange,line width=.2pt}}
216 \tkzDefPoint(0,0){A}\tkzDefPoint(6,0){D}
217 \tkzDefPoint(8,0){B}\tkzDefPoint(4,0){I}
218 \tkzDefLine[orthogonal=through D](A,D)
219 \tkzInterLC[R](D,tkzPointResult)(I,4) \tkzGetSecondPoint{C}
220 \tkzDefLine[orthogonal=through C](I,C) \tkzGetPoint{c}
221 \tkzDefLine[orthogonal=through B](A,B) \tkzGetPoint{b}
222 \tkzInterLL(C,c)(B,b) \tkzGetPoint{T}
223 \tkzInterLL(A,T)(C,D) \tkzGetPoint{P}
224 \tkzDrawArc(I,B)(A)
225 \tkzDrawSegments(A,B A,T C,D I,C) \tkzDrawSegment[new](I,C)
226 \tkzDrawLine[add = 1 and 0](C,T) \tkzDrawLine[add = 0 and 1](B,T)
227 \tkzMarkRightAngle(I,C,T)
228 \tkzDrawPoints(A,B,I,D,C,T)
229 \tkzLabelPoints(A,B,I,D) \tkzLabelPoints[above right](C,T)
230 \tkzMarkSegment[pos=.25,mark=s|](C,D) \tkzMarkSegment[pos=.75,mark=s|](C,D)
231 \end{tikzpicture}
232 \end{tkzexample}
233
234 \newpage
235
236 \section{Side by side: option \tkzname{latex}}
237
238 You must indicate the width of the box assigned to the interpretation, this is done with the option \tkzname{latex}:
239
240 \subsubsection{\tkzname{latex=7cm}}
241 \begin{tkzexample}[latex=7cm]
242 \begin{tikzpicture}[scale=.5]
243 \tkzInit[xmin=-6,ymin=-4,xmax=6,ymax=6]
244 \tkzClip
245 \tkzSetUpLine[thin,color=teal]
246 \tkzDefPoint(0,0){O}
247 \tkzDefPoint(132:5){A}
248 \tkzDefPoint(4,0){B}
249 \foreach \ang in {5,10,...,360}{%
250 \tkzDefPoint(\ang:4){M}
251 \tkzDefLine[mediator](A,M)
252 \tkzGetPoints{x}{y}
253 \tkzDrawLine[add= 3 and 3](x,y)}
254 \end{tikzpicture}
255 \end{tkzexample}
256
257 |\begin{tkzexample}[latex=7cm]|\\
258 |...| \\
259 |\end{tkzexample}| \\
260 \subsubsection{\tkzname{latex=8cm}}
261 \begin{tkzexample}[latex=8cm]
262 \begin{tikzpicture}[scale=.5]
263 \tkzInit[xmin=-6,ymin=-4,xmax=6,ymax=6]
264 \tkzClip
265 \tkzSetUpLine[thin,color=magenta]
266 \tkzDefPoint(0,0){O}
267 \tkzDefPoint(132:4){A}
268 \tkzDefPoint(5,0){B}
269 \foreach \ang in {5,10,...,360}{%
270 \tkzDefPoint(\ang:5){M}
271 \tkzDefLine[mediator](A,M)
272 \tkzGetPoints{x}{y}
273 \tkzDrawLine[add= 3 and 3](x,y)}
274 \end{tikzpicture}
275 \end{tkzexample}
276
277 |\begin{tkzexample}[latex=8cm]|\\
278 |...| \\
279 |\end{tkzexample}| \\
280 \newpage
281 \section{Side by side: option \tkzname{width}}
282 If the option \tkzname{latex= x cm} allows to reserve a box of width x cm for the code, the option \tkzname{width= x cm} allows to reserve a box of width x cm for the result.
283
284 We leave a box of 8cm for the result or drawing and the rest of the line will contain a minipage of 8cm. As you can see a new section has been created and the code is contained in a 8cm box
285
286
287 \begin{tkzexample}[overhang,width=6cm,code=red!10]
288 \begin{tikzpicture}[scale=.4]
289 \tkzDefPoints{0/0/P,5/0/Q,3/2/I}
290 \tkzDefCircle[orthogonal from=P](Q,I)
291 \tkzGetFirstPoint{E}
292 \tkzDrawCircles(P,E Q,E)
293 \tkzInterCC[common=E](P,E)(Q,E) \tkzGetFirstPoint{F}
294 \tkzDefPointOnCircle[through = center P angle 80 point E]
295 \tkzGetPoint{A}
296 \tkzInterLC[common=E](A,E)(Q,E) \tkzGetFirstPoint{C}
297 \tkzInterLL(A,F)(C,Q) \tkzGetPoint{D}
298 \tkzDrawLines[add=0 and .75](P,Q)
299 \tkzDrawLines[add=0 and 2](A,E)
300 \tkzDrawSegments(P,E E,F F,C A,F C,D)
301 \tkzDrawPoints(P,Q,E,F,A,C,D)
302 \tkzLabelPoints(P,Q,F,C,D)
303 \tkzLabelPoints[above](E,A)
304 \end{tikzpicture}
305 \end{tkzexample}
306
307 \vspace{24pt}
308 The options used to get this result are :
309 \vspace{12pt}
310
311 |\begin{tkzexample}[overhang,width=6cm,code=red!30]|\\
312 |...| \\
313 |\end{tkzexample}| \\
314
315
316 \newpage
317 \section{Option \tkzname{code} and option \tkzname{graphic}}
318
319 This option is used to color the background of the code.
320
321 \vspace{24pt}
322
323 |\begin{tkzexample}[overhang,width=9cm,code=gray!20,graphic=red!15]|\\
324 |...| \\
325 |\end{tkzexample}| \\
326
327 \begin{tkzexample}[overhang,width=9cm,code=gray!20,graphic=red!15]
328 \begin{tikzpicture}[scale=1]
329 \tkzDefPoint(2,3){A}
330 \tkzDefShiftPoint[A](30:3){B}
331 \tkzDefShiftPoint[A](-30:3){C}
332 \tkzDrawPolygon(A,B,C)
333 \tkzDrawPoints(A,B,C)
334 \tkzLabelPoints[right](B,C)
335 \tkzLabelPoints[above left](A)
336 \tkzMarkSegments[mark=|](A,B A,C B,C)
337 \end{tikzpicture}
338 \end{tkzexample}
339
340
341 \newpage
342 \section{Option \tkzname{num}}
343
344 You can number the lines of code. \tkzname{numcolor} and \tkzname{numbkgcolor} are used to define the style of the numbering.
345
346 \subsection{Example 1}
347 \begin{tkzexample}[width=6cm,num,numcolor=red,numbkgcolor=white,code style=\ttfamily]
348 \begin{tikzpicture}[scale=0.3]
349 \tkzDefPoint(-4,0){I}
350 \tkzDefPoint(4,0){J}
351 \tkzDefPoint(0,0){O}
352 \tkzInterCC(J,O)(O,J) \tkzGetPoints{L}{H}
353 \tkzInterCC(I,O)(O,I) \tkzGetPoints{K}{G}
354 \tkzInterLL(I,K)(J,H) \tkzGetPoint{M}
355 \tkzInterLL(I,G)(J,L) \tkzGetPoint{N}
356 \tkzDefPointsBy[symmetry=center J](L,H){D,E}
357 \tkzDefPointsBy[symmetry=center I](G,K){C,F}
358 \begin{scope}[line style/.style = {very thin,teal}]
359 \tkzDrawLines[add=1.5 and 1.5](I,K I,G J,H J,L)
360 \tkzDrawLines[add=.5 and .5](I,J)
361 \tkzDrawCircles(O,I I,O J,O)
362 \tkzDrawArc[delta=0,orange](N,D)(C)
363 \tkzDrawArc[delta=0,orange](M,F)(E)
364 \tkzDrawArc[delta=0,orange](J,E)(D)
365 \tkzDrawArc[delta=0,orange](I,C)(F)
366 \end{scope}
367 \end{tikzpicture}
368 \end{tkzexample}
369 this is obtained with:\\
370
371 |\begin{tkzexample}[width=6cm,num,numcolor=red,numbkgcolor=white,code style=\ttfamily]| \\
372 |...| \\
373 |\end{tkzexample}| \\
374
375
376
377 \subsection{Example 2}
378 \begin{tkzexample}[latex=5cm,code=red!20,num,small,hsep=24pt]
379 \begin{tikzpicture}[scale=.25]
380 \tkzDefPoints{0/0/A,12/0/B,6/12*sind(60)/C}
381 \foreach \density in {20,30,...,240}{%
382 \tkzDrawPolygon[fill=teal!\density](A,B,C)
383 \pgfnodealias{X}{A}
384 \tkzDefPointWith[linear,K=.15](A,B) \tkzGetPoint{A}
385 \tkzDefPointWith[linear,K=.15](B,C) \tkzGetPoint{B}
386 \tkzDefPointWith[linear,K=.15](C,X) \tkzGetPoint{C}}
387 \end{tikzpicture}
388 \end{tkzexample}
389
390 \vspace{12pt}
391 |\begin{tkzexample}[latex=5cm,code=red!20,num,small]|\\
392 |...|\\
393 |\end{tkzexample}|\\
394
395 \newpage
396 \vspace{12pt}
397 The global num option allows to have a global numbering of the lines with the next code:
398
399 \vspace{12pt}
400 |\begin{tkzexample}[latex=7cm,global num,small,hsep=1cm]|\\
401
402 |...|\\
403
404 |\end{tkzexample}|
405 \begin{tkzexample}[latex=7cm,global num,small,hsep=24pt]
406 \begin{tikzpicture}
407 \tkzSetUpCompass[color=purple,line width=1pt]
408 \tkzDefPoints{0/1/A,5/2/B,3/4/C}
409 \tkzDefEquiPoints[from=C,dist=1,show,
410 /tkzcompass/delta=20](A,B)
411 \tkzGetPoints{E}{H}
412 \tkzDrawLines[color=blue](C,E C,H A,B)
413 \tkzDrawPoints[color=blue](A,B,C)
414 \tkzDrawPoints[color=red](E,H)
415 \tkzLabelPoints(E,H)
416 \tkzLabelPoints[color=blue](A,B,C)
417 \end{tikzpicture}
418 \end{tkzexample}
419
420
421
422
423
424 % \pgfqkeys{/tkzexample}{%
425 % every tkzexample/.style={width=8cm+7pt}
426 % }
427 %
428 % | \pgfqkeys{/tkzexample}{%|
429 % | every tkzexample/.style={width=8cm+7pt}|
430 % | }|
431
432 \newpage
433 \section{Size option for code fonts}
434 The different size options for fonts are :
435
436 \begin{enumerate}
437
438 \item very small
439
440 \begin{tkzexample}[width=8cm,very small]
441 \begin{tikzpicture}[scale=.75]
442 \tkzDefPoints{0/0/A,6/0/B}
443 \tkzDefMidPoint(A,B)
444 \tkzGetPoint{I}
445 \tkzDefPointWith[orthogonal,K=-.75](B,A)
446 \tkzGetPoint{C}
447 \tkzInterLC(B,C)(B,I)
448 \tkzGetPoints{F}{D}
449 \tkzDuplicateSegment(B,F)(A,F)
450 \tkzGetPoint{E}
451 \tkzDrawArc[delta=10](F,E)(B)
452 \tkzInterLC(A,B)(A,E)
453 \tkzGetPoints{N}{M}
454 \tkzDrawArc[delta=10](A,M)(E)
455 \tkzDrawLines(A,B B,C A,F)
456 \tkzCompass(B,F)
457 \tkzDrawPoints(A,B,C,F,M,E)
458 \tkzLabelPoints(A,B,C,F,M)
459 \tkzLabelPoints[above](E)
460 \end{tikzpicture}
461 \end{tkzexample}
462
463 \item small
464
465 \begin{tkzexample}[width=6cm,small]
466 \begin{tikzpicture}[scale=1.2]
467 \tkzDefPoints{1/3/A,4/2/B}
468 \tkzDefPointWith[linear,K=0.5](A,B)
469 \tkzGetPoint{C}
470 \tkzDrawPoints[color=red](A,B,C)
471 \tkzDrawSegment(A,B)
472 \tkzLabelPoints[above right=3pt](A,B,C)
473 \end{tikzpicture}
474 \end{tkzexample}
475
476
477 \item normal
478
479 \begin{tkzexample}[width=6cm,normal]
480 \begin{tikzpicture}[scale=.75]
481 \tikzset{new/.style={color=orange,
482 line width=.2pt}}
483 \tkzDefPoints{0/0/O_1,0/1/O_2,0/3/A}
484 \tkzDefPoint(15:3){F}
485 \tkzInterLC(F,O_1)(O_1,A)
486 \tkzGetSecondPoint{E}
487 \tkzDefLine[parallel=through O_2](E,F)
488 \tkzGetPoint{x}
489 \tkzInterLC(x,O_2)(O_2,A) \tkzGetPoints{D}{C}
490 \tkzDrawCircles(O_1,A O_2,A)
491 \tkzDrawSegments[new](O_1,A E,F C,D)
492 \tkzDrawSegments[purple](A,E A,F)
493 \tkzDrawPoints(A,O_1,O_2,E,F,C,D)
494 \tkzLabelPoints(A,O_1,O_2,E,F,C,D)
495 \end{tikzpicture}
496 \end{tkzexample}\end{enumerate}
497
498
499
500 \newpage
501 \section{Option \tkzname{code only}}
502
503
504 |\begin{tkzexample}[small,code only]| \\
505 | \begin{minipage}{9cm}| \\
506 | \thispagestyle{empty}| \\
507 | \noindent| \\
508 | \begin{tikzpicture}| \\
509 | \draw (0,0) node[circle,| \\
510 | shade,| \\
511 | ball color=Peach,minimum size=2cm]{};| \\
512 | \draw[snake = expanding waves,| \\
513 | color = Peach,| \\
514 | line width = 3pt](1.2,0)--(4,0);| \\
515 | \end{tikzpicture}| \\
516 | \end{minipage}| \\
517 |\end{tkzexample}|
518
519 The result
520
521 \begin{tkzexample}[small,code only]
522 \begin{minipage}{9cm}
523 \begin{tikzpicture}
524 \draw (0,0) node[circle,
525 shade,
526 ball color=Peach,minimum size=2cm]{};
527 \draw[snake = expanding waves,
528 color = Peach,
529 line width = 3pt](1.2,0)--(4,0);
530 \end{tikzpicture}
531 \end{minipage}
532 \end{tkzexample}
533
534 \end{document}
535