Debian Codegraph @

texmf-dist/doc/latex/tikzpackets/tikzPackets.tex

raw
1 % Copyright (c) 2020 Robert Ryszard Paciorek <[email protected]>
2 %
3 % MIT License
4 %
5 % Permission is hereby granted, free of charge, to any person obtaining a copy
6 % of this software and associated documentation files (the "Software"), to deal
7 % in the Software without restriction, including without limitation the rights
8 % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 % copies of the Software, and to permit persons to whom the Software is
10 % furnished to do so, subject to the following conditions:
11 %
12 % The above copyright notice and this permission notice shall be included in all
13 % copies or substantial portions of the Software.
14 %
15 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 % SOFTWARE.
22
23 \documentclass[a4paper]{article}
24
25 \usepackage{tikzPackets}
26 \usepackage{adjustbox,hyperref,fancyvrb-ex,fvextra}
27
28 \oddsidemargin=0pt
29 \textwidth=430pt
30
31 \topmargin=-30pt
32 \textheight=662pt
33
34 \newcommand{\pkgLink}[1]{\texttt{\href{https://ctan.org/pkg/#1}{#1}}}
35
36 \fvset{
37 breaklines=true,
38 breakanywhere=true,
39 breakaftersymbolpre={},
40 breakaftersymbolpost={\tiny\ensuremath{\ \lhook\joinrel\rightarrow\ }},
41 breakanywheresymbolpre={},
42 breakanywheresymbolpost={\tiny\ensuremath{\ \lhook\joinrel\rightarrow\ }}
43 }
44
45 \begin{document}
46
47 \title{The \texttt{tikzPackets} package}
48 \author{Robert Ryszard Paciorek <[email protected]>}
49 \date{2020-07-13}
50 \maketitle
51
52 This package provide command for simple build network packets illustration with \pkgLink{tikz}.
53 Similar functionality (with tables instead of tikz) provide package \pkgLink{bytefield}.
54
55 \section{Basic Example}
56
57 \begin{CenterExample}
58 \begin{tikzpicture}
59 \packetsInit
60 \packetsBitWidth=4.5mm
61 \packetsPrintBitScale{31}
62
63 \packetsPutField{16}{Source Port}
64 \packetsPutField{16}{Destination Port}
65 \packetsEndLine{0}{}
66
67 \packetsPutField{16}{Length}
68 \packetsPutField{16}{Checksum}
69 \packetsEndLine{32}{}
70
71 \packetsPutField[protocolsField, minimum height=1.5cm]{32}{Data}
72 \packetsEndLine{64}{}
73 \end{tikzpicture}
74 \end{CenterExample}
75
76
77 \section{Macros description}
78
79 \subsection{packetsInit}
80
81 \Verb$\packetsInit$ is used to initialise \textit{tikzPackets} variables, counters and tikz styles.
82 Must be used in every \Verb$tikzpicture$ that use \textit{tikzPackets} package commands before any other \textit{tikzPackets} command.
83
84 \subsection{packetsPrintBitScale}
85
86 \Verb$\packetsPrintBitScale$ draw bits scale. It takes one argument: last bit value.
87
88 Formatting of bits scale can be adjust by redefine (after \Verb$\packetsInit$) tikz style \Verb$bitScaleInfo$, redefine \Verb$\packetsBitFont$ or \Verb$\packetsPrintBitNumber$ macro.
89
90 \subsection{packetsPutField}
91
92 \Verb$\packetsPutField$ draw packet field. It takes 4 arguments:
93 \begin{enumerate}
94 \item (optional) node style and formatting options
95 \item number of bits (width of field)
96 \item (optional) node name for new created node
97 \item name (text to display)
98 \end{enumerate}
99
100 \subsection{packetsPrintRangeOnLeft and packetsPrintRangeOnRight}
101
102 \Verb$\packetsPrintRangeOnLeft$ and \Verb$\packetsPrintRangeOnRight$ prints info (start bit number or bits range) on left or right side of current line.
103 Should be call after call all \Verb$\packetsPutField$ for this line. Both commands takes two arguments: first bit in line and last bit in line,
104 but \Verb$\packetsPrintRangeOnLeft$ ignore second argument.
105
106 Formatting of printing text can be adjust by redefine \Verb$\packetsBitFont$ macro or redefine \Verb$\packetsPrintRangeOnLeft$ / \Verb$\packetsPrintRangeOnRight$ macros.
107
108 \begin{CenterExample}
109 \begin{tikzpicture}
110 \packetsInit
111 \renewcommand{\packetsBitFont}{\scriptsize}
112 \packetsPutField{4}{A} \packetsPutField{4}{B} \packetsPutField{4}{C}
113 \packetsPrintRangeOnLeft{a}{b}
114 \packetsPrintRangeOnRight{d}{e}
115 \end{tikzpicture}
116 \end{CenterExample}
117
118 \subsection{packetsNextLine}
119
120 \Verb$\packetsNextLine$ end current line of field and prepare to start next line of field. It don't have arguments.
121
122 \subsection{packetsEndLine}
123
124 \Verb$\packetsEndLine$ call \Verb$\packetsPrintRangeOnLeft$ and \Verb$\packetsNextLine$.
125 Arguments are passed to \Verb$\packetsPrintRangeOnLeft$.
126
127 \subsection{packetsLastNode and packetsFirstNodeInLastLine}
128
129 \Verb$\packetsLastNode$ hold name of last added node by \Verb$\packetsPutField$ or \Verb$\packetsPrintBitScale$ (and is used for node positioning in \Verb$\packetsPutField$ and \Verb$\packetsPrintRangeOnRight$ macros).
130
131 \Verb$\packetsFirstNodeInLastLine$ hold name of first node (added by macro \Verb$\packetsPutField$ or \Verb$\packetsPrintBitScale$) in current line (and is used in \Verb$\packetsPutField$ and \Verb$\packetsPrintRangeOnLeft$ for positioning)
132
133 Both can be use for external to reference node adding by these macros (can be captured after add node by \Verb$\edef$) or can be used to start adding nodes by \Verb$\packetsPutField$ relative to some manually added node.
134
135 \begin{CenterExample}
136 \begin{tikzpicture}
137 \packetsInit
138 \packetsPutField{4}{A}
139 \packetsPutField{4}{B}
140
141 \node[
142 align=left, anchor=north west,
143 text width=7\packetsBitWidth, node font=\footnotesize
144 ] [] at (\packetsFirstNodeInLastLine.south west) {
145 Some extra info about this packet. And more more info \ldots
146 };
147 \end{tikzpicture}
148 \end{CenterExample}
149
150 \section{Styles and dimmensions}
151
152 Width of single bit is set by \Verb$\packetsBitWidth$ and default is 5mm. Default style for node created by \Verb$\packetsPutField$ is \Verb$protocolsField$ and it set line height to 1cm.
153 Package provide also \Verb$protocolsFieldBase$ style with minimal setting for node style.
154 Macro \Verb$\packetsBitFont$ define font settings for bits info.
155 All this change should be done after use \Verb$\packetsInit$.
156
157 \begin{CenterExample}
158 \begin{tikzpicture}
159 \packetsInit
160 \tikzstyle{protocolsField}=[protocolsFieldBase, draw, minimum height = 0.8cm]
161 \packetsBitWidth=10mm
162 \renewcommand{\packetsBitFont}{\scriptsize\it}
163
164 \packetsPrintBitScale{7}
165 \packetsPutField{4}{Long field names}
166 \packetsPutField{4}{and low rows}
167 \end{tikzpicture}
168 \end{CenterExample}
169
170 \end{document}