Skip to content

Commit

Permalink
add nodetree visual debugger to Tart's chapter
Browse files Browse the repository at this point in the history
  • Loading branch information
robitex committed Apr 29, 2021
1 parent f7ee73f commit 5ba43ff
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ essere scaricato da questo

Per sostenere questa iniziativa la cosa migliore è associarsi al GuIT
consultando [la pagina web delle tipologie di
socio](https://guitex.org/home/it/diventa-socio/associarsi-a-guit).
adesione](https://guitex.org/home/it/diventa-socio/associarsi-a-guit).

Contenuti
---------
Expand Down
Binary file added image/nodetree-list-crop.pdf
Binary file not shown.
29 changes: 29 additions & 0 deletions image/nodetree.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<body style="font-family:'Fira Mono',monospace;font-size:12pt;color:#fcfcfc;background-color:#232627;"><span style="color:#fcfcfc;background-color:#232627;">$ luatex 04
</span><br>This is LuaTeX, Version 1.13.2 (TeX Live 2021) &#160;<br> restricted system commands enabled.
<br>(./04.tex
<br>├─<span style="font-weight:bold;color:#c0392b;background-color:#232627;">HLIST </span><span style="color:#f67400;background-color:#232627;">width:</span><span style="color:#fcfcfc;background-color:#232627;"> 5</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">, </span><span style="color:#f67400;background-color:#232627;">height:</span><span style="color:#fcfcfc;background-color:#232627;"> 6.44</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">
</span><br>│ ╚═<span style="color:#f67400;background-color:#232627;">head:</span><span style="color:#fcfcfc;background-color:#232627;">
</span><br>│ &#160;&#160;└─<span style="font-weight:bold;color:#16a085;background-color:#232627;">GLYPH </span><span style="color:#f67400;background-color:#232627;">char:</span><span style="color:#fcfcfc;background-color:#232627;"> 0, </span><span style="color:#f67400;background-color:#232627;">width:</span><span style="color:#fcfcfc;background-color:#232627;"> 5</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">, </span><span style="color:#f67400;background-color:#232627;">height:</span><span style="color:#fcfcfc;background-color:#232627;"> 6.44</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">
</span><br>├─<span style="font-weight:bold;color:#8e44ad;background-color:#232627;">GLUE </span><span style="color:#f67400;background-color:#232627;">width:</span><span style="color:#fcfcfc;background-color:#232627;"> 14</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">
</span><br>├─<span style="font-weight:bold;color:#c0392b;background-color:#232627;">HLIST </span><span style="color:#f67400;background-color:#232627;">width:</span><span style="color:#fcfcfc;background-color:#232627;"> 15</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">, </span><span style="color:#f67400;background-color:#232627;">height:</span><span style="color:#fcfcfc;background-color:#232627;"> 6.44</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">
</span><br>│ ╚═<span style="color:#f67400;background-color:#232627;">head:</span><span style="color:#fcfcfc;background-color:#232627;">
</span><br>│ &#160;&#160;├─<span style="font-weight:bold;color:#16a085;background-color:#232627;">GLYPH </span><span style="color:#f67400;background-color:#232627;">char:</span><span style="color:#fcfcfc;background-color:#232627;"> 8, </span><span style="color:#f67400;background-color:#232627;">width:</span><span style="color:#fcfcfc;background-color:#232627;"> 5</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">, </span><span style="color:#f67400;background-color:#232627;">height:</span><span style="color:#fcfcfc;background-color:#232627;"> 6.44</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">
</span><br>│ &#160;&#160;├─<span style="font-weight:bold;color:#16a085;background-color:#232627;">GLYPH </span><span style="color:#f67400;background-color:#232627;">char:</span><span style="color:#fcfcfc;background-color:#232627;"> 8, </span><span style="color:#f67400;background-color:#232627;">width:</span><span style="color:#fcfcfc;background-color:#232627;"> 5</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">, </span><span style="color:#f67400;background-color:#232627;">height:</span><span style="color:#fcfcfc;background-color:#232627;"> 6.44</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">
</span><br>│ &#160;&#160;└─<span style="font-weight:bold;color:#16a085;background-color:#232627;">GLYPH </span><span style="color:#f67400;background-color:#232627;">char:</span><span style="color:#fcfcfc;background-color:#232627;"> 8, </span><span style="color:#f67400;background-color:#232627;">width:</span><span style="color:#fcfcfc;background-color:#232627;"> 5</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">, </span><span style="color:#f67400;background-color:#232627;">height:</span><span style="color:#fcfcfc;background-color:#232627;"> 6.44</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">
</span><br>├─<span style="font-weight:bold;color:#8e44ad;background-color:#232627;">GLUE </span><span style="color:#f67400;background-color:#232627;">width:</span><span style="color:#fcfcfc;background-color:#232627;"> 11.5</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">
</span><br>├─<span style="font-weight:bold;color:#c0392b;background-color:#232627;">HLIST </span><span style="color:#f67400;background-color:#232627;">width:</span><span style="color:#fcfcfc;background-color:#232627;"> 10</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">, </span><span style="color:#f67400;background-color:#232627;">height:</span><span style="color:#fcfcfc;background-color:#232627;"> 6.44</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">
</span><br>│ ╚═<span style="color:#f67400;background-color:#232627;">head:</span><span style="color:#fcfcfc;background-color:#232627;">
</span><br>│ &#160;&#160;├─<span style="font-weight:bold;color:#16a085;background-color:#232627;">GLYPH </span><span style="color:#f67400;background-color:#232627;">char:</span><span style="color:#fcfcfc;background-color:#232627;"> 8, </span><span style="color:#f67400;background-color:#232627;">width:</span><span style="color:#fcfcfc;background-color:#232627;"> 5</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">, </span><span style="color:#f67400;background-color:#232627;">height:</span><span style="color:#fcfcfc;background-color:#232627;"> 6.44</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">
</span><br>│ &#160;&#160;└─<span style="font-weight:bold;color:#16a085;background-color:#232627;">GLYPH </span><span style="color:#f67400;background-color:#232627;">char:</span><span style="color:#fcfcfc;background-color:#232627;"> 8, </span><span style="color:#f67400;background-color:#232627;">width:</span><span style="color:#fcfcfc;background-color:#232627;"> 5</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">, </span><span style="color:#f67400;background-color:#232627;">height:</span><span style="color:#fcfcfc;background-color:#232627;"> 6.44</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">
</span><br>├─<span style="font-weight:bold;color:#8e44ad;background-color:#232627;">GLUE </span><span style="color:#f67400;background-color:#232627;">width:</span><span style="color:#fcfcfc;background-color:#232627;"> 11.5</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">
</span><br>├─<span style="font-weight:bold;color:#c0392b;background-color:#232627;">HLIST </span><span style="color:#f67400;background-color:#232627;">width:</span><span style="color:#fcfcfc;background-color:#232627;"> 15</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">, </span><span style="color:#f67400;background-color:#232627;">height:</span><span style="color:#fcfcfc;background-color:#232627;"> 6.44</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">
</span><br>│ ╚═<span style="color:#f67400;background-color:#232627;">head:</span><span style="color:#fcfcfc;background-color:#232627;">
</span><br>│ &#160;&#160;├─<span style="font-weight:bold;color:#16a085;background-color:#232627;">GLYPH </span><span style="color:#f67400;background-color:#232627;">char:</span><span style="color:#fcfcfc;background-color:#232627;"> 8, </span><span style="color:#f67400;background-color:#232627;">width:</span><span style="color:#fcfcfc;background-color:#232627;"> 5</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">, </span><span style="color:#f67400;background-color:#232627;">height:</span><span style="color:#fcfcfc;background-color:#232627;"> 6.44</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">
</span><br>│ &#160;&#160;├─<span style="font-weight:bold;color:#16a085;background-color:#232627;">GLYPH </span><span style="color:#f67400;background-color:#232627;">char:</span><span style="color:#fcfcfc;background-color:#232627;"> 8, </span><span style="color:#f67400;background-color:#232627;">width:</span><span style="color:#fcfcfc;background-color:#232627;"> 5</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">, </span><span style="color:#f67400;background-color:#232627;">height:</span><span style="color:#fcfcfc;background-color:#232627;"> 6.44</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">
</span><br>│ &#160;&#160;└─<span style="font-weight:bold;color:#16a085;background-color:#232627;">GLYPH </span><span style="color:#f67400;background-color:#232627;">char:</span><span style="color:#fcfcfc;background-color:#232627;"> 0, </span><span style="color:#f67400;background-color:#232627;">width:</span><span style="color:#fcfcfc;background-color:#232627;"> 5</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">, </span><span style="color:#f67400;background-color:#232627;">height:</span><span style="color:#fcfcfc;background-color:#232627;"> 6.44</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">
</span><br>├─<span style="font-weight:bold;color:#8e44ad;background-color:#232627;">GLUE </span><span style="color:#f67400;background-color:#232627;">width:</span><span style="color:#fcfcfc;background-color:#232627;"> 11.5</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">
</span><br>└─<span style="font-weight:bold;color:#c0392b;background-color:#232627;">HLIST </span><span style="color:#f67400;background-color:#232627;">width:</span><span style="color:#fcfcfc;background-color:#232627;"> 10</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">, </span><span style="color:#f67400;background-color:#232627;">height:</span><span style="color:#fcfcfc;background-color:#232627;"> 6.44</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">
</span><br> &#160;╚═<span style="color:#f67400;background-color:#232627;">head:</span><span style="color:#fcfcfc;background-color:#232627;">
</span><br> &#160;&#160;&#160;├─<span style="font-weight:bold;color:#16a085;background-color:#232627;">GLYPH </span><span style="color:#f67400;background-color:#232627;">char:</span><span style="color:#fcfcfc;background-color:#232627;"> 8, </span><span style="color:#f67400;background-color:#232627;">width:</span><span style="color:#fcfcfc;background-color:#232627;"> 5</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">, </span><span style="color:#f67400;background-color:#232627;">height:</span><span style="color:#fcfcfc;background-color:#232627;"> 6.44</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">
</span><br> &#160;&#160;&#160;└─<span style="font-weight:bold;color:#16a085;background-color:#232627;">GLYPH </span><span style="color:#f67400;background-color:#232627;">char:</span><span style="color:#fcfcfc;background-color:#232627;"> 8, </span><span style="color:#f67400;background-color:#232627;">width:</span><span style="color:#fcfcfc;background-color:#232627;"> 5</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">, </span><span style="color:#f67400;background-color:#232627;">height:</span><span style="color:#fcfcfc;background-color:#232627;"> 6.44</span><span style="color:#63686d;background-color:#232627;">pt</span><span style="color:#fcfcfc;background-color:#232627;">
</body>
54 changes: 49 additions & 5 deletions section/III-02-tartaglia-nodi.tex
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,60 @@ \subsection{Numeri e spazi}
Il sorgente compilabile diventa questo:
\sourcecode{file = [[app-tartaglia/04.tex]]}

\begin{figure}
\includegraphics[scale=0.62]{image/nodetree-list-crop.pdf}
\caption{Rappresentazione della lista dei nodi contenuta nella variabile
\code{list} del listato \key{04.tex} modificato per l'utilizzo del pacchetto
\code{nodetree}. Si può notare che i nodi glue tranne il primo hanno lunghezza
di 11,5pt perchè le cifre adiacenti sono sempre di due e tre cifre, il che porta
a calcolare sempre la stessa distanza per mantenere quella assiale di 24pt con
cifre larghe 5pt.}
\label{figNodetree}
\end{figure}

Se esageriamo con la grandezza dei numeri allora si sovrapporrano. Questo
succede se la lunghezza elastica è negativa poiché la distanza assiale di 24pt
(vedi la variabile locale \key{a}) è troppo piccola. A questo livello del
(vedi la variabile locale \key{'a'}) è troppo piccola. A questo livello del
codice, l'utente deve controllare che non ci siano sovrapposizioni specie
all'ultima riga del triangolo dove si trovano i numeri più grandi.


\subsection{Intermezzo: debug di una lista di nodi}

Per visualizzare i nodi di una lista per scopi di debug è possibile usare il
pacchetto \pack{nodetree} di Josef Friedrich. Uno dei modi è caricare la
libreria omonima e usare la funzione \fn{nodetree.print}\luastd{nodetree.print}
per stampare a terminale la rappresentazione dell'albero contenuta nel nodo
passato come argomento:
\begin{lines}
local list = ...
local nodetree = require "nodetree"
nodetree.print(list)
\end{lines}

La documentazione del pacchetto fornisce i dettagli delle opzioni, per esempio
per regolare la quantità d'informazioni tramite il parametro \opz{verbosity} o
per impostare stili di stampa. L'output può essere dirottato verso un file,
specie quando comprende numerose linee di testo.

Con questa tecnica la stampa della rappresentazione dell'albero dei nodi della
lista di numeri spaziati ottenuta alla sezione precedente con il codice del file
\code{04.tex}, e contenuta nella variabile \key{list}, è riportata nella
figura~\ref{figNodetree}.

Con \code{nodetree} si possono incontrare problemi se il terminale non è
compatibile con i codici di colori e con alcuni caratteri grafici usati per
collegare i nodi.


\begin{figure}[b]
\centering
\includegraphics{image/tart-left}
\caption{Triangolo di Tartaglia allineato a sinistra, ottenuto con il listato
\code{05.tex}.}
\label{figTriangoloTartagliaLeft}
\end{figure}

\subsection{Sovrapposizione scatole}

Il passo finale è quello di sovrapporre le scatole orizzontali a formare il
Expand Down Expand Up @@ -189,10 +236,7 @@ \subsection{Sovrapposizione scatole}
end
\end{lines}

Il risultato è questo:
\begin{center}
\includegraphics{image/tart-left}
\end{center}
Il risultato è quello della figura~\ref{figTriangoloTartagliaLeft}.


\subsection{Opzione allineamento}
Expand Down

0 comments on commit 5ba43ff

Please sign in to comment.