Skip to main content

Section 5.7 Customizations, Thin XSL Stylesheets

Stringparams (Section 5.5) are an easy way to effect global changes in the presentation of your writing. But putting ten of them on every command-line gets old and cumbersome fast.

You may also wish to customize your output in some stylistic way. This might be especially true for /PDF/print output. For example, you might wish to have every chapter heading of your book in a nice shade of light blue, with the title flush right to the margin, countered by a thick solid rule extending all the way right, to the edge of the paper. Notice that this does not affect your content, it is strictly presentation.

We have done several things to encourage such customizations. We have tried to put as much stylistic information as possible in the preamble and keep as much as possible out of the body. (There is always room for improvement on this score, please be in touch if you have a need.) For small adjustments the latex.preamble.early and latex.preamble.late stringparam are possible vehicles, though all the code to make light blue, flush-right rules is going to be messy on the command-line.

Instead, you can make a small XSL file. You can then tell the PreTeXt-CLI to use that XSL file instead of the standard one provided by PreTeXt through the <xsl> element in a <target> of the project manifest.

Assume that you have an XSL file called custom-latex.xsl located in the folder xsl inside the root of your project. In your project.ptx manifest file, use <xsl>xsl/custom-latex.xsl</xsl> as an element in the corresponding <target>.

The custom XSL file should import the stock PreTeXt file for the type of output you want to create. This is done using the line <xsl:import href="./core/pretext-latex.xsl"/>, which should be placed near the top of the file; everything after it will redefine the various rules imported from the stock XSL. Note the @href attribute's value starts with ./core/. This works because the CLI copies all the standard XSL to a subfolder core of the temporary directory holding your custom XSL so that you don't need to know the path to its location on your system.

See Section 45.9 to see how to use such a stylesheet with the pretext/pretext script.

The easiest thing to put in this file is elements like

<xsl:param name="latex.font.size" select="'20pt'" />

which is functionally equivalent to our example in Section 5.5. Values given on the command-line supersede those given in an XSL file this way.

You can augment the preamble with as much code as you like in the following way.

<xsl:param name="latex.preamble.late">
    <xsl:text>% Proof environment with heading in small caps&#xa;</xsl:text>
    <xsl:text>\renewenvironment{proof}[1][\proofname]{\oldp[\scshape #1]}{\oldep}&#xa;</xsl:text>

There are a variety of things you can do generally, by overriding the imported XSL templates to change behavior, but such modifications are beyond the scope of this guide.