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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
|
% \iffalse meta-comment
%
% File: codeanatomy.dtx Copyright (C) 2019 Hong-Phuc Bui
%
% It may be distributed and/or modified under the conditions of the
% LaTeX Project Public License (LPPL), either version 1.3c of this
% license or (at your option) any later version. The latest version
% of this license is in the file
%
% https://www.latex-project.org/lppl.txt
%
%
% -----------------------------------------------------------------------
%
% The development version of the bundle can be found at
%
% https://github.com/hpb-htw/codeanatomy
%
% for those people who are interested.
%
% -----------------------------------------------------------------------
% \fi
%
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}[2018/12/01]
%<package>\ProvidesPackage{codeanatomy}[2019/07/10 v0.1-Alpha draw Code Anatomy]
% \fi
%
% \iffalse
%<*driver>
\documentclass[full]{l3doc}
\usepackage{fontspec}
\usepackage{luaotfload}
\usepackage{biblatex}
\addbibresource{literatur.bib}
\newcommand{\slsh}{\textbackslash{}}
\newcommand{\TikZ}{Ti\textit{k}Z}
\def\thinmargin{\list{}{\rightmargin-50pt\leftmargin-90pt}\item[]}
\let\endthinmargin=\endlist
\usepackage{listings}
\lstset {
basicstyle=\small\ttfamily
,escapeinside={+}{+}
}
\usepackage{codeanatomy}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \GetFileInfo{\jobname.sty}
% \DoNotIndex{}
%
% \title{^^A
% \pkg{codeanatomy} -- Draw Code Anatomy^^A
% \thanks{This file describes \fileversion,^^A
% last revised \filedate.}\\[1ex]^^A
% \normalsize{Reference}^^A
% }^^A
%
% \author{^^A
% Hồng-Phúc Bùi^^A
% \thanks{^^A
% E-mail:
% \href{mailto:Hồng-Phúc Bùi}
% {hong-phuc.bui (at) htwsaar dot de}^^A
% }^^A
% }
%
% \date{Released \filedate}
%
%
%
% \maketitle
% \tableofcontents
%
% \section{Hints}
% Usage of this Package can be found in \texttt{codeanatomy.usage.pdf} and \texttt{codeanatomy.lstlisting.pdf}.
% This document show only generated reference of commands in this Package.
%
% \begin{implementation}
% ^^A %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Implementation}
%
%
%
% \subsection{Package Dependenies}
% \begin{macrocode}
\RequirePackage{expl3}
\RequirePackage{xparse}
\RequirePackage[rgb]{xcolor}
\RequirePackage{tikz}
% \end{macrocode}
%
% Load necsessary \TikZ{} libraries.
% \begin{macrocode}
\usetikzlibrary{
tikzmark
,fit
,arrows.meta
,bending
,shapes
,chains
,backgrounds
,scopes
,decorations
,decorations.pathmorphing
}
% \end{macrocode}
%
% \subsection{Setup styles}
% ^^A+++++++++++++++++++++
% \subsubsection{Colors}
% ^^A-------------------
% Define colors which are used in \pkg{codeanatomy}
% \DescribeMacro{annotationcolor}
% \tikz{\draw[fill=annotationcolor] circle(1ex); }
% \begin{macrocode}
\definecolor{annotationcolor}{rgb}{0,0.50002,1} % Blue
% \end{macrocode}
%
%
% \DescribeMacro{bgcmdcolor}
% \tikz{\draw[fill=bgcmdcolor] circle(1ex); }
% \begin{macrocode}
\colorlet{bgcmdcolor}{gray} % Grey
% \end{macrocode}
%
% \subsubsection{\TikZ{} styles for code in a Code Anatomy}
% ^^A------------------------------------------------------
%
% \DescribeMacro{anatomy}
% \TikZ{} style for annotation labels: \\
% |\tikz{\node(code) [anatomy] at (0,0) {code line 1\\code line 2}; }|\\
% yields \tikz{\node(code) [anatomy] at (0,0) {code line 1\\code line 2}; }
% \begin{macrocode}
\tikzset{anatomy/.style={%
anchor=south west,%
inner sep=0,%
align=left,%
font=\ttfamily
}
}
% \end{macrocode}
%
%
%
% \DescribeMacro{code part}
% \TikZ{} style to marce a piece of code in an anatomy: \\
% |\tikz{\node(code) [code part] at (0,0) {let a = 12;};}|\\
% yields \tikz{\node(code) [code part] at (0,0) {let a = 12;};}
% \begin{macrocode}
\tikzset{code part/.style={%
rectangle,%
draw=annotationcolor,%
align=left,%
minimum height=1.175em,%
inner sep=1.75pt,%
outer sep=0.1pt,%
font=\ttfamily
}
}
% \end{macrocode}
%
%
%
% \DescribeMacro{fit extrem}
% \TikZ{} style to mark a piece of multiple line code in an anatomy:\\
% |\tikz{ \node(c)[fit extrem, fit={(0,0) (0.5,0.975) (1,0)}] {}; }|\\
% yields \tikz{ \node(c)[fit extrem, fit={(0,0) (0.5,0.975) (1,0)}] {}; }
% \begin{macrocode}
\tikzset{fit extrem/.style={%
rectangle,%
draw=annotationcolor,%
align=left,%
minimum height=1.175em,%
inner sep=1.75pt,%
outer sep=0.1pt,%
font=\ttfamily
}
}
% \end{macrocode}
%
%
%
%
% \DescribeMacro{annotation}
% setup style of arrows from annotation labels to code parts:\\
% |\tikz{\draw[] (1,0) circle(3ex); \draw[->,annotation] (0,0) -- (1,0);}|\\
% yields \tikz{\draw[] (1,0) circle(3ex); \draw[->,annotation] (0,0) -- (1,0);}
% \begin{macrocode}
\tikzset{annotation/.style={%
preaction={
draw=white,%
line width=3.5pt,%
arrows={-Triangle Cap[]},%
},%
draw=annotationcolor,%
arrows={-Latex[%
round,%
color=annotationcolor]
}
}
}
% \end{macrocode}
%
%
% \DescribeMacro{code annotation}
% setup style for a annotation label \tikz{\node(a)[code annotation] at (0,0) {function name};}
% \begin{macrocode}
\tikzset{code annotation/.style={%
inner sep=2pt,%
text=annotationcolor,%
align=center,%
font=\sffamily\small
}
}
% \end{macrocode}
%
%
%
% \DescribeMacro{code grid debug}
% \TikZ{} styles to draw debug grid on the background of anatomy
% \begin{macrocode}
\tikzset{code grid debug/.style={%
step=1.0,%
draw=gray!20,%
very thin,%
on background layer
}
}
% \end{macrocode}
%
%
%
%
% \subsection{Command used to set code and code anatomy}
% \DescribeMacro{\codeBlock}
% Complete code listing of a Code Anatomy figure is typeset by this command.
% Syntax |\codeBlock| \marg{code}, whereas \marg{code} is the \emph{formatted} code listing.
% This command can be used if there are no other packages to typeset code listing in use.
% \begin{macrocode}
\NewDocumentCommand{\codeBlock}{m}%
{\node(code) [anatomy] at (0,0) {#1};}
% \end{macrocode}
%
%
% \DescribeMacro{\cPart}
% Assign a piece of typeset code --typical in one line-- to a \TikZ{} Node, so that it can
% be annotated. Syntax: |\cPart| \marg{node name} \marg{piece of code} whereas \marg{node name}
% is a unique \TikZ{} node name in the |tikzpicture| and \marg{piece of code} is a single code part
% to be marked.
% \begin{macrocode}
\NewDocumentCommand{\cPart}{mm} %
{\tikzmarknode[code part]{#1}{#2}}
% \end{macrocode}
%
%
% \DescribeMacro{\iPart}
% Assign a piece of typeset code --typical in one line-- to a \TikZ{} Node, so that it can
% be annotated. Syntax: |\cPart| \marg{node name} \marg{piece of code} whereas \marg{node name}
% is a unique \TikZ{} node name in the |tikzpicture| and \marg{piece of code} is a single code part
% to be marked.
% \begin{macrocode}
\NewDocumentCommand{\iPart}{mm} %
{\tikzmarknode[code part,draw=none,inner sep=0.75pt]{#1}{#2}}
% \end{macrocode}
%
%
%
%
% \DescribeMacro{\mtPoint}
% Marks a point as a \textbf{m}ost \textbf{t}op in a Code Block.
% \begin{macrocode}
\NewDocumentCommand{\mtPoint}{m}
{\tikzmarknode{#1}{\phantom{\rule[1.8ex]{0.1ex}{0.1ex}}}}
% \end{macrocode}
%
%
%
%
% \DescribeMacro{\hmtPoint}
% Marks a point as a \textbf{h}eigher \textbf{m}ost \textbf{t}op point in a Code Block.
% \begin{macrocode}
\NewDocumentCommand{\hmtPoint}{m}
{\tikzmarknode{#1}{\phantom{\rule[2.5ex]{0.1ex}{0.1ex}}}}
% \end{macrocode}
%
%
% \DescribeMacro{\mbPoint}
% Marks a point as a \textbf{d}eeper \textbf{m}ost \textbf{b}ottom point in a Code Block.
% \begin{macrocode}
\NewDocumentCommand{\mbPoint}{m}
{\tikzmarknode{#1}{\phantom{\rule[-0.55ex]{0.1ex}{0.1ex}}}}
% \end{macrocode}
%
%
% \DescribeMacro{\dmbPoint}
% Marks a point as a \textbf{d}eeper \textbf{m}ost \textbf{b}ottom point in a Code Block.
% \begin{macrocode}
\NewDocumentCommand{\dmbPoint}{m}
{\tikzmarknode{#1}{\phantom{\rule[-2ex]{0.1ex}{0.1ex}}}}
% \end{macrocode}
%
%
% \DescribeMacro{\extremPoint}
% Create a \TikZ{} Node as reference point for later use in |\fitExtrem|.
% Syntax:\\
% |\extremPoint| \marg{node name} \oarg{yshift} \oarg{xshift} \oarg{style}
% whereas
% \begin{itemize}
% \item \marg{node name} is the \TikZ{} node name which is used in |\fitExtrem| to reference to this point
% \item \oarg{yshift} A length, default 0ex which places this markpoint on the base line,
% shift this mark point vertical, for positive value over base line, negative value under
% base line.
% \item \oarg{xshift} Same as \oarg{yshift} but for horizontal direction.
% \item \oarg{style} is a \TikZ{} style (may be defined by user).
% \end{itemize}
%
% For example:\\\noindent
% |\begin{tikzpicture}[remember picture]|\\
% |\node(code) [anatomy] at (0,0) {|\\
% | \extremPoint{tl}[2ex]Line with some text\extremPoint{br}[-1ex]\\|\\
% | \extremPoint{tl2}other Line with some text\\|\\
% | some more line\extremPoint{br2}\\|\\
% |};|\\
% |\fitExtrem{box1}{(tl) (br)}|\\
% |\fitExtrem{box2}{(tl2) (br2)}|\\
% |\end{tikzpicture}|\\
%
% yields
%
% \begin{tikzpicture}[remember picture]
% \node(code) [anatomy] at (0,0) {
% \extremPoint{tl}[2ex]Line with some text\extremPoint{br}[-1ex]\\
% \extremPoint{tl2}other Line with some text\\
% some more line\extremPoint{br2}\\
% };
% \fitExtrem{box1}{(tl) (br)}
% \fitExtrem{box2}{(tl2) (br2)}
% \end{tikzpicture}
% \begin{macrocode}
\NewDocumentCommand{\extremPoint}{m O{0ex} O{0.1ex} O{} }
{\tikzmarknode[#4]{#1}{\phantom{\rule[#2]{#3}{0.1ex}}}}
% \end{macrocode}
%
%
%
% \DescribeMacro{\fitExtrem}
% Create a rectangle box over given extrem points defined by |\*Point{}|. Syntax:\\
% |\fitExtrem| \marg{node name} \marg{extrem points}\\
% whereas\\
% \begin{itemize}
% \item \marg{node name} is a unique \TikZ{} node name in the current anatomy
% \item \marg{extrem points} is a list of \TikZ{} node name created by |\*Point|,
% each name is surrounded by |()|.
% \end{itemize}
%
% example:\\ \noindent^^A%%
% |\begin{tikzpicture}[remember picture]|\\
% |\node(code) [anatomy] at (0,0) {|\\
% |\mtPoint{left}Line 1\\|\\
% |Long Line 2\extremPoint{right}\\|\\
% |Line 3\mbPoint{bottom}|\\
% |};|\\
% |\fitExtrem{box} { (left) (bottom) (right) }|\\
% |\end{tikzpicture}|\\
%
% yields
%
% \begin{tikzpicture}[remember picture]
% \node(code) [anatomy] at (0,0) {
% \mtPoint{left}Line 1\\
% Long Line 2\extremPoint{right}\\
% Line 3\mbPoint{bottom}
% };
% \fitExtrem{box} { (left) (bottom) (right) }
% \end{tikzpicture}
%
% \begin{macrocode}
\NewDocumentCommand{\fitExtrem}{mm}
{\node(#1)[fit extrem,fit={#2}]{};}
% \end{macrocode}
%
%
% \DescribeMacro{\bgcode}
% Typeset a piece of code in color |bgcmdcolor|. Syntax:\\
% |\bgcode| \marg{piece of code} \\
% for example: |\tikz{\codeBlock{let a := 12\bgcode{;}}}|\\
% yields \tikz{\codeBlock{let a := 12\bgcode{;}}}
% \begin{macrocode}
\NewDocumentCommand{\bgcode}{m}{\textcolor{bgcmdcolor}{#1}}
% \end{macrocode}
%
%
% \DescribeMacro{\ptab}
% \DescribeMacro{\phspace}
% Produce a horizontal space of 4 small characters |h| respective 1 small character |h|\\
% for example: |\tikz{\codeBlock{a\ptab{}b}}| yields \tikz{\codeBlock{a\ptab{}b}}
% \begin{macrocode}
\NewDocumentCommand{\ptab}{}{\phantom{hhhh}}
\NewDocumentCommand{\phspace}{}{\phantom{h}}
% \end{macrocode}
%
%
%
% \DescribeMacro{\codeAnnotation}
% Typeset Annotation labels for a code Part. Syntax:\\
% |\codeAnnotation| \marg{node name} \parg{coordinate} \marg{label text}\\
% whereas
% \begin{itemize}
% \item \marg{node name} is a unique \TikZ{} node name in the |tikzpicture|,
% \item \parg{coordinate} is the coordinate of the annotation label, surrounded by a |()|,
% \item \marg{label text} text content to be typeset.
% \end{itemize}
%
% \noindent^^A%
% |\begin{tikzpicture}[remember picture]|\\
% |\codeBlock{a \cPart{a}{:=} 12 + 13}|\\
% |\codeAnnotation{codeLabel} (1,-0.5) {assignment}|\\
% |\draw[->,annotation] (codeLabel) -- (a);|\\
% |\end{tikzpicture}| \\ \medskip
%
% yields \\ \medskip
%
% \begin{tikzpicture}[remember picture]
% \codeBlock{a \cPart{a}{:=} 12 + 13}
% \codeAnnotation{codeLabel} (1,-0.5) {assignment}
% \draw[->,annotation] (codeLabel) -- (a);
% \end{tikzpicture}
%
% \begin{macrocode}
\NewDocumentCommand{\codeAnnotation}{m r() m } %
{
\node(#1)[code annotation] at (#2) {#3} ;
}
% \end{macrocode}
%
% \end{implementation}
%
% \PrintIndex
%
%
\endinput
|