% (find-angg "LATEX/2018tug-dednat6-abs.tex")
% (defun c () (interactive) (find-LATEXsh "lualatex -record 2018tug-dednat6-abs.tex"))
% (defun d () (interactive) (find-xpdfpage "~/LATEX/2018tug-dednat6-abs.pdf"))
% (defun e () (interactive) (find-LATEX "2018tug-dednat6-abs.tex"))
% (defun u () (interactive) (find-latex-upload-links "2018tug-dednat6-abs"))
% (find-xpdfpage "~/LATEX/2018tug-dednat6-abs.pdf")
% (find-sh0 "cp -v  ~/LATEX/2018tug-dednat6-abs.tex /tmp/")
% (find-sh0 "cp -v  ~/LATEX/2018tug-dednat6-abs.pdf /tmp/")
% (find-sh0 "cp -v  ~/LATEX/2018tug-dednat6-abs.pdf /tmp/pen/")
%   file:///home/edrx/LATEX/2018tug-dednat6-abs.pdf
%               file:///tmp/2018tug-dednat6-abs.pdf
%           file:///tmp/pen/2018tug-dednat6-abs.pdf
% http://angg.twu.net/LATEX/2018tug-dednat6-abs.pdf

% tug2018@tug.org
% https://www.tug.org/tug2018/cfp.html
% https://www.tug.org/TUGboat/sampleart.ltx
% https://www.tug.org/tug2018/register.html

\documentclass[oneside]{book}
\begin{document}

\def\code#1{\texttt{#1}}
\def\qcode#1{``\texttt{#1}''}
\def\bsl{\char92}

{\bf Dednat6: an extensible (semi-)preprocessor for LuaLaTeX that
  understands diagrams in ASCII art}

Eduardo Ochs

UFF, Brazil

eduardoochs@gmail.com

http://angg.twu.net/dednat6.html


\medskip

(La)TeX 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
LuaLaTeX to avoid the need for an external preprocessor and for an
auxiliar \qcode{.dnt} file. Here is how; the workflow is unusual,
so let's see it in detail.

Put a line \qcode{\bsl directlua\{dofile("loaddednat6.lua")\}} in a
file \code{bar.tex}. When we run \qcode{lualatex bar.tex} that line
loads the 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 --- usually \qcode{\bsl def}s --- to the 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} --- i.e., it processes with 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 dednat6, and it's easy to add support for new heads; this
can even be done in a \qcode{\%L} block.

Note that with dednat4 all the \qcode{\bsl def}s had to be loaded at
once; in 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.

\end{document}

% Local Variables:
% coding: utf-8-unix
% End:
