Test latex

From 清冽之泉
Jump to navigation Jump to search

<diagram> %% LaTeX2e file `tmp-gen-anatomy-of-a-for-loop.tex' %% generated by the `filecontents' environment %% from source `codeanatomy.lstlisting' on 2025/10/19. %% \lstset{escapeinside={!}{!}} \begin{lrbox}{\mycodebox} \begin{lstlisting} !\iPart{init}{\bgcode{int power = 1;}}! for ( !\cPart{i}{int i = 0}!; !\cPart{c}{i <= n}!; !\cPart{u}{i++}! ) {

   !\mtPoint{left}!System.out.println(i + " " + power);!\mtPoint{right}!
   power *= 2;!\mbPoint{bottom}!

} \end{lstlisting} \end{lrbox}

\begin{tikzpicture}[

 remember picture
 ,code annotation/.append style={%
   font=\sffamily\itshape\scriptsize
 }

] % {[on background layer]\draw[code grid debug] (-2.5,-0.5) grid (5.5,3.5);} \node(code) [anatomy] at (0,0){\usebox\mycodebox}; \fitExtrem{b}{(left) (right) (bottom)} % Annotations \codeAnnotation{initText} (-1.5,2.7) {initialize another\\

                                       variable in a \extremPoint{initPoint}[0.75ex]\\
                                       separate\\ statement}

\codeAnnotation{iText} (1.2,3.5) {declare and initialize\\ a loop control variable} \codeAnnotation{cText} (3.5,3) {loop-\\continuation\\condition} \codeAnnotation{uText} (6,3) {increment} \codeAnnotation{bText} (3.5,-0.25) {body} % arrows on the background {[on background layer]

 \draw[->,annotation] (initPoint) -- (init.north west);
 \draw[->,annotation] (iText) -- (i);
 \draw[->,annotation] (cText) -- (c);
 \draw[->,annotation] (uText) -- (u);
 \draw[->,annotation] (bText) -- (b);

} \end{tikzpicture} </diagram>