[Latte] Multi-file I/o

Bart Schaefer schaefer@zanshin.com
Fri, 18 Aug 2000 17:51:00 -0700 (PDT)

On Fri, 18 Aug 2000, Nick Moffitt wrote:

> begin  Bart Schaefer quotation:
> > The short answer is that it's the latte-html executable that generates
> > output, not the latte source file itself.  So to make multiple documents
> > you run latte-html multiple times.
> 	But this is not good, as every time I add a chapter to my
> document, I then have to update my makefiles to add another pass on
> the document.

Not if you write the Makefile to handle it in the first place.  First
you need a generic latte-html rule such as:

%.html: %.latte
	-rm -f $@
	latte-html --output=$@ $<

Then you have a rule that loops over all the stub files, maybe something

	for f in ch-*.latte; do \
	h=`echo $$f | sed 's/latte$/html/'`; $(MAKE) $$h; done

And then every time you want a new chapter, you just create a stub file
named ch-primate-toenails.latte or ch-72.latte whatever.

You can get fancier than that and have some kind of a dependency-building
pass, depending on just how complex you want your structure to be.

Or ...

> ... a content management system whereby people just write
> {\chapter The Growth of Toenails in the Upper Primates}

You could do that if you were willing to make it look like:

{\chapter \title={The Growth of Toenails in the Upper Primates} \number=72
  The entire contents of the chapter go here.  Note position of braces.

> 	And The Right Thing happens, just as it does with LaTeX.

Create a shell script called "latte-front":

while [ $# -gt 0 ]; do
 case "$1" in
 -*) break;;
 *=*) env="$env $1";;
 *) break;;
eval "$env" 'latte-html "$@"'

Then in your latte source, use something like:

{\def {\chapter \=title \=number \&rest}
   {\let {{\chnum {\getenv CHAPTER}}}
     {\if \chnum
          {\if {\equal \chnum \number} {{\h1 \title} \rest}}
       {\warn {\process-output
	 latte-front CHAPTER=\number --output=chapter\number.html \__FILE__}}

Warning, I haven't actually tried any of that, so there may be syntax
errors and other problems, but that should give you an idea.