LaTeXport: revenge of the templates, and on to Tufte Book

I thought that I had the Template problem cracked, but when I started work on implementing a complex stylesheet in Tinderbox, for export as LaTeX, it quickly returned with a vengeance. It turns out to be a good example in debugging Tinderbox documents.

No more templates please

You will recall that, in my previous export setup for a basic LaTeX stylesheet, the prototypes for different components of the document were all based on the HTML Template prototype, in which I had recast all the markup conversions on export to generate LaTeX rather than HTML.

These all worked beautifully, so long as they were exported from regular notes, and not templates. The moment that a note had its $IsTemplate attribute set to true, export markup behaved very differently and not as intended. I attributed the problems that I experienced in getting notes to not be templates to inadvertently setting the default value of $IsTemplate to true, which may at some stage have happened. Despite fixing that issue, notes were still being turned into templates.

Then I noticed that when I created a new note at the top level, it was not set as a template; it was only when I dropped that note into a container (or created it in the container in the first place) that it was instantly changed into a template.

Whenever anything happens only when a note is in a container, you know that the container has an $OnAdd action which is responsible. Sure enough, HTML Template (as created using the Built-in Templates command in the File menu) has the following actions:
$Prototype="HTML Template";

which were being inherited by all my prototypes.


Removing those actions from all the prototypes which were based on HTML Template fixed this problem, at last.

Here is an updated version of my LaTeX paper document with that fixed: LaTeXpaper2

On to greater stylesheets

Edward R Tufte’s books are a joy to read in every respect, and I not only relish their content, but love their layout. If there’s one thing that LaTeX excels at, it’s making superb professional page design available to anyone who can be bothered to learn its conventions, and that includes tufte-latex, stylesheets which let you create documents as beautifully functional as his books.

If you have not come across these yet, their home page provides extensive details, and the LaTeX package is available from CTAN.

My starting point for a Tinderbox port of tufte-latex was my earlier simple LaTeX stylesheet, with its template bug finally nailed.


To support this more complex stylesheet, I have removed the subsubsection prototype, which is not supported, and added Introduction, Chapter, thought, continue and plain prototypes. The LaTeX page template contains the long and complex header taken from sample-book.tex, but remains built around
^children(/Templates/LaTeX page/LaTeX item)

as before.


My LaTeX Head prototype is much more complex, starting with the document metadata, then providing for a prefatory page of epigraphs. Because this content is very sensitive to paragraph placement, this prototype has the normal end paragraph markup (a ‘return’ character) removed, in $HTMLFirstParagraphEnd and $HTMLParagraphEnd, which are here both empty.


This is my example content using that prototype. Because the content of LaTeX Head and LaTeX Introduction is required for the rest of the stylesheet, I have flagged these are being essential.


When using such a sophisticated stylesheet, you are more likely to have to embed sections of LaTeX code and markup to build tables, display text, and other content which must not be marked up any further in export. The LaTeX plain prototype provides for this, in removing all markup for ‘HTML’ export. I had originally been tempted to use the Code prototype for this, but it was simpler to strip the markup out from my modified HTML Template.


That enables this sort of heavy code to be passed through without any meddling, which would probably break it.


By this stage, you may be wondering whether there is any point in using Tinderbox to construct this document. The example does not contain long continuous passages of regular text content, by its very nature, but in real world writing, most documents are unlikely to be so heavy in LaTeX code.


Even where the code does become quite dense, working in notes has many advantages in terms of document structure. Moving sections and tables around in the Outline view is very quick and simple, and Tinderbox as always helps you keep the complex in perfect order.


At the moment, my favourite LaTeX editor and renderer, the pre-release Compositor, is not ready to tackle such advanced stylesheets, but the output from my example document renders beautifully in TeXShop, as shown.

My Tinderbox document for developing tufte-book LaTeX documents is here: LaTeXtuftebk1
and in Downloads above.

There is scope for additional prototypes, according to your use of this stylesheet’s features: I would expect that someone writing a maths or physics book would want to separate out other document elements, which is easily done from my first cut. I have a part-written book using tufte-book on Cézanne’s paintings which I will be laying up in Tinderbox next.

The other important area which I have not yet touched upon is references and bibliography. I will come back to those in a week or two.