Debian Codegraph @

texmf-dist/doc/latex/codeanatomy/demo-using-a-primitive-data-type.tex

raw
1 %% LaTeX2e file `tmp-gen-using-a-primitive-data-type.tex'
2 %% generated by the `filecontents' environment
3 %% from source `codeanatomy.lstlisting' on 2025/10/19.
4 %%
5 \lstset{escapeinside={!}{!}}
6 \begin{lrbox}{\mycodebox}
7 \begin{lstlisting}
8 !\cPart{d}{int a, b;}!
9 !\iPart{v}{a}! = !\cPart{l}{1234}!;
10 !\iPart{a}{b = 99}!;
11 !\cPart{i}{int c = a + b}!;
12 \end{lstlisting}
13 \end{lrbox}
14 \begin{tikzpicture}[
15 remember picture %
16 ,code annotation/.append style = { % customize style of annotation text
17 font=\sffamily\footnotesize
18 }
19 ]
20 {[on background layer]\draw[code grid debug] (-2.5,-0.5) grid (2.5,2.5);}
21 \node(code) [anatomy] at (0,0){\usebox\mycodebox};
22 % Annotations
23 \codeAnnotation{declareText} ( 1,2.75 ) {declaration statement}
24 \codeAnnotation{literalText} ( 2.5,1.45) {literal}
25 \codeAnnotation{varText} (-1.5,1.75 ) {variable name}
26 \codeAnnotation{assignText} (-1.5,0.75 ) {assignment\\statement}
27 \codeAnnotation{initText} (-1.5,-0.75) {inline initialization\\statement}
28 % Arrows
29 \draw[->,annotation] (declareText) -- (d);
30 \draw[->,annotation] (literalText) -- (l);
31 \draw[->,annotation] (varText.south east) -- (v);
32 \draw[->,annotation] (assignText) -- (a);
33 \draw[->,annotation] (initText) -- (i.south west);
34 \end{tikzpicture}