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 using a command like the following.

pretext build pdf -x xsl/custom-latex.xsl

This assumes that you have an XSL file called custom-latex.xsl located in the folder xsl inside the root of your project. You can also specify this in your project.ptx manifest file using <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 pretext-href="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 @pretext-href attribute. Standard XSL would use @href here; the @pretext-href tells the CLI to substitute the correct stock XSL, so that you don't need to know the path to its location on your system. (See Section 44.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>\expandafter\let\expandafter\oldp\csname\string\proof\endcsname&#xa;</xsl:text>
    <xsl:text>\let\oldep\endproof&#xa;</xsl:text>
    <xsl:text>\renewenvironment{proof}[1][\proofname]{\oldp[\scshape #1]}{\oldep}&#xa;</xsl:text>
</xsl:param>

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.