Section19.4LaTeX-generated images

PreTeXt makes it straightforward to embed code that produces images (such as TikZ) into your source files. xsltproc basically just dumps your code out to your file so that it compiles nicely. However, for HTML display, you will need SVG graphic files. This is where the pretext/pretext script comes in. Running the pretext/pretext script frequently requires patience, particularly on Windows, so settle in with an experienced user before attempting the steps in this section. See Chapter 44 for complete details.

Our example here just illustrates using TikZ to make a simple figure (the Hasse diagram of a poset), but lots of other graphics packages can be used. One step required is to put the following three lines in the <docinfo> tag of your main file. <latex-image-preamble> is used to set up the preamble that should be used for making SVG images from your PreTeXt source. Macros that you wish to use more broadly should be put inside <macros> inside <docinfo>.

<latex-image-preamble>
\usepackage{tikz}
</latex-image-preamble>


The code in Listing 19.4.1 produces the following output:

Well, that's not 100% true for HTML. If you just run xsltproc, your browser will display an error message about not being able to find the graphic file, since it doesn't exist. To generate the image, we have to run the pretext/pretex script. To do this, on the command line we run the following command (on a single line).

/path/to/pretext/pretext -c latex-image -f
svg -d /path/to/html/output/directory/images /path/to/yoursource.ptx