{Dednat6: An extensible (semi-)preprocessor for Lua\LaTeX\ that understands diagrams in \ASCII\ art} {Eduardo Ochs} {\def\code#1{\texttt{#1}}% \def\qcode#1{``\texttt{#1}''}% \def\bsl{\char92 }% \def\{{\char`\{ }% \def\}{\char`\} }% \noindent \AllTeX\ treats lines starting with \qcode{\%} as comments, and ignores them. This means that we can put anything we want in these \qcode{\%} lines, even code to be processed by other programs besides \TeX. In this talk we will describe a ``semi-preprocessor'', called \code{dednat6}, that makes blocks of lines starting with \qcode{\%L} be executed as Lua code, treats blocks of lines starting with \qcode{\%:} as 2D representations of derivation trees, and treats blocks of lines starting with \qcode{\%D} as diagrams in which a 2D representation specifies where the nodes are to be placed and a stack-based language inspired by Forth is used to connect these nodes with arrows. A predecessor of \code{dednat6}, called \code{dednat4}, was a preprocessor in the usual sense: running ``\code{dednat4.lua foo.tex}'' on a shell would convert the trees and diagrams in \qcode{\%:} and \qcode{\%D}-blocks in \code{foo.tex} to \qcode{\bsl def}s that \LaTeX\ can understand, and would put these \qcode{\bsl def}s in a file \code{foo.dnt}; we had to put in \code{foo.tex} an \qcode{\bsl input "foo.dnt"} that would load those definitions. \code{Dednat6} does something almost equivalent to that, but it uses Lua\LaTeX\ to avoid the need for an external preprocessor and for an auxiliary \qcode{.dnt} file. Here is how; the workflow is unusual, so let's see it in detail. Put a line\\ \code{\bsl directlua\{dofile("loaddednat6.lua")\}} \\in a file \code{bar.tex}. When we run \qcode{lualatex bar.tex} that line loads the \code{dednat6} library, initializes the global variable \code{tf} in the Lua interpreter with a \code{TexFile} object, and sets \code{tf.nline=1} to indicate that nothing in \code{bar.tex} has been processed with dednat6 yet. A (low-level) command like \code{\bsl directlua\{processlines(200, 300)\}} in \code{bar.tex} would ``process the lines 200 to 300 in \code{bar.tex} with dednat6'', which means to take all the blocks of \qcode{\%L}-lines, \qcode{\%:}-lines, and \qcode{\%D}-lines between the lines 200 to 300 in \code{bar.tex}, run them in the adequate interpreters, and then send the resulting \LaTeX\ code\Dash{}usually \qcode{\bsl def}s\Dash{}to the \code{latex} interpreter. The high-level macro \qcode{\bsl pu} runs \qcode{\bsl directlua(processuntil\{tex.inputlineno\})}, that runs \code{processlines} on the lines between \code{tf.nline=1} and the line where the current \qcode{\bsl pu} is, and advances \code{tf.nline}\Dash{}i.e., it processes with \code{dednat6} the lines in the current file between the previous \qcode{\bsl pu} and the current one. The strings \qcode{\%L}, \qcode{\%:}, and \qcode{\%D} are called ``heads'' in \code{dednat6}, and it's easy to add support for new heads; this can even be done in a \qcode{\%L} block. Note that with \code{dednat4} all the \qcode{\bsl def}s had to be loaded at once; in \code{dednat6} idioms like \qcode{\{\bsl pu ...\}}, \qcode{\$\bsl pu ...\$}, and \qcode{\$\$\bsl pu ...\$\$} can be used to make the \qcode{\bsl def}s between the last \qcode{\bsl pu} and the current one be local.}