%%; whizzy -ext .tex -mkslice "../bin/mkgpic -slice" -mkfile "../bin/mkgpic -file"
%%; whizzy -ext .tex -mkslice "make" -mkfile "make files"

\documentclass{article}

\title {WhizzyTeX with preprocessing}
\author {Didier R{\'e}my}
\let \lst \verb

\begin{document}

\maketitle

For illustration, we use a source file with inlined {\tt gpic} macros.
Such macros are surrounded by \lst".PS" and \lst".PE" markers on a single
line. The preprecessor is \lst"gpic -t" that transforms a file with such
macros into some latex code with \lst"\special" commands that more
DVI tools understand. 

WhizzyTeX must be told how to preprocess the slice and the file. 
A first solution would be to use the \lst"gpic -t" command for both.
However, one must first note that \lst"mkslice" command receives the target
file \lst"_whizzy_main.tex" as argument while the \lst"mkfile" command will
receive the target's name. So at least some analyses or source and target
must be done. Second, note gpic expansion does not preserve line numbers. 
This must then be correctly by inserting source line number information
before preprocessing the file. The macro \lst"\Setlineno" followed by a
number will tell WhizzyTeX to use that number for the current input line.
Since \lst"\inputlineno" is readable only, we instead compute the difference
and take that difference into account when printing line numbers. 

Since the preprocessor changes the name of the file, it should also insert a
command \lst"\SourceFile{main.ltx}" (or \lst"\SourceFile{subfile.ltx}") at
the beginning of the file.

The simplest way is to use a local configuration script file
\lst"whizzy.sh", as can be found in this directory. 

The script redefines \texttt{MKFILE} and \texttt{MKSLICE}. 
It also set the extension of processed files \texttt{.tex} 
and use the extension \texttt{.ltx} to source files. This should be used
rather than the converse, since the extension \texttt{.tex} has higher
priority than \texttt{.ltx} and indeed, the preprocessed file should always
be used when available.

We could also use the command \lst"make" to do the preprocessing: 

We can also the command make. For brievity, we assume that 
the commands \texttt{mkfile} and \texttt{mkslice} 
call \texttt{gpicmkfile} and \texttt{gpicmkslice} of file
\texttt{whizzy.sh}. 
\begin{quote}
\begin{verbatim}
SOURCES = main.ltx subfile.ltx
TEXFILES = $(patsubst %.ltx, %.tex, $(SOURCES))
GPIC=whizzygpic

main.dvi: $(TEXFILES)
	latex main.tex

files: $(TEXFILES)

# to force recompilation even if same date (second is not precise enough)
.force:
_whizzy_%.tex: _whizzy_%.new .force
	mkslice $@

%.tex: %.ltx
	mkfile $<

clean:
	rm -f *.{tex,log,aux,dvi}
\end{verbatim}
\end{quote}
Then
\begin{quote}\small
\begin{verbatim}
%; whizzy -ext .tex -mkslice "make" -mkfile "make"
\end{verbatim}
\end{quote}
In fact, all files, should have been at least processed once with 
\lst"make files". 



\subsection* {Other uses of preprocessing}

The use of {\tt gpic} macros with multiple files is already sophisticated. 
Preprocessing is simpler when either  line numbers are left unchanged, or 
when the document is composed of a single file. 

\subsection* {Examples of drawing}

Here is a drawing that need preprocessing:
.PS
scale=2
circlerad=0.3
define ell {
  ellipse height 0.8 width $4 
}
define ebox {
  box width $4 height 0.6 "$1" at ($2,$3)
}

B: box dashed width 2.7 height 3.
"{Generic structures}" at B.n above

M: ellipse height 0.6 width 1.6 "{Monoid}" at (1.3,0.8)
G: ellipse height 0.6 width 1.5 "{Group}" at M+(0,-1.3) 
arrow from M.s  to G.n
.PE
$$
\box\graph
$$
End of the drawing.

Note: Dashed and dotted lines are not implemented yet in gpic.

\input{subfile}

\end{document}
