Skip to main content

The PreTeXt Guide

Section 28.2 Extra Stylesheets

String parameters (Section 28.1) 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. This is our approach for styling output, much as CSS is used to style HTML output (Chapter 41)
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.)
You can start with a new small XSL file. You 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 do not need to know the path to its location on your system.
See Section 47.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'" />
. 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.