\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\definetuple}{mmmm}
{
\tl_new:c { g_tuple_#1_tl }
\tl_gset:cn { g_tuple_#1_tl } { {#2} {#3} {#4} }
}
\DeclareExpandableDocumentCommand{\extractfromtuple}{mm}
{
\tl_item:cn { g_tuple_#1_tl } { #2-1 }
}
\ExplSyntaxOff
\begin{document}
\definetuple{alice}{Alice}{Munich}{Germany}
\definetuple{bob}{Bob}{London}{United Kingdom}
\extractfromtuple{alice}{3}
\extractfromtuple{bob}{1}
\end{document}
In this simple case I've used a token list; for more complex tasks a sequence would be better, perhaps.
Another approach might be with property lists.
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\definetuple}{mmmm}
{
\prop_new:c { g_tuple_#1_prop }
\prop_gput:cnn { g_tuple_#1_prop } { name } {#2}
\prop_gput:cnn { g_tuple_#1_prop } { town } {#3}
\prop_gput:cnn { g_tuple_#1_prop } { country } {#4}
}
\DeclareExpandableDocumentCommand{\extractfromtuple}{mm}
{
\prop_get:cn { g_tuple_#1_prop } { #2 }
}
\ExplSyntaxOff
\begin{document}
\definetuple{alice}{Alice}{Munich}{Germany}
\definetuple{bob}{Bob}{London}{United Kingdom}
\extractfromtuple{alice}{country}
\extractfromtuple{bob}{name}
\end{document}
Here the available keys are name
, town
and country
. I'd prefer this approach for more complicated tasks, where, for example, data are added one piece of information at a time; for example one could define
\NewDocumentCommand{\addtotuple}{mmm}
{
\prop_gput:cnn { g_tuple_#1_prop } { #2 } { #3 }
}
and \addtotuple{alice}{town}{Berlin}
would move Alice to the north.
This should get you started....

\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[draw,fill=LightSteelBlue!60,minimum width=3cm,minimum height=1cm] (a) at (2,0) {capacity};
\node[draw,fill=LightSteelBlue!60,minimum width=3cm,minimum height=1cm] (b) at (2,1) {end};
\node[draw,rectangle, fill=LightSteelBlue!60,minimum width=3cm,minimum height=1cm] (c) at (2,2) {begin};
\foreach \x in {0,1,2,3}
\node[draw,rectangle, fill=LightSteelBlue!60,minimum width=2cm,minimum height=1cm] (d\x) at (10,\x-2){};
\foreach \x in {0,...,4}
\node[draw,rectangle, fill=White,minimum width=2cm,minimum height=1cm] (e\x) at (10,\x-7){};
\node[minimum width=2cm,minimum height=1cm] (f) at (10,-8){};
\draw[->,very thick] (c.east)--(d3.west);
\draw[->,very thick] (b.east)--(e4.west);
\draw[->,very thick] (a.east)--(f.west);
\end{tikzpicture}
\end{document}
Best Answer
You can use the
bytefield
package, developed exactly with the purpose of drawing protocol packet structures.An example taken from the manual:
The result: