Skip to main content

The PreTeXt Guide

Section 41.6 Environments and Blocks

Objects like <example> and <remark> are almost invariably children of a division, numbered, and work best with a <title>. tcolorbox is a massive package, that we have taken to as a solution to many under-the-bonnet technical problems, such as a hanging indent for numbers of <exercise> or laying out the panels of a <sidebyside>. But it also allows an incredible variety of styling options for these intermediate chunks of text. Think of variable placements of numbers and titles, borders and boxes, and colored backgrounds. With freedom comes responsibility! With a light touch, you can help your reader navigate the inherent structure of your PreTeXt source.
Whatever you call them: environments, blocks, or information objects, almost every one can be styled separately (2019-09-30: not captioned items yet, such as <figure>). For example,
<xsl:template match="example" mode="tcb-style">
    <xsl:text>colback=pink,</xsl:text>
</xsl:template>
would cause the background of every <example> to be light red in color. To make every PreTeXt element that is a variant of an <example> look identical, use one of the entities defined in xsl/entities.ent,
<xsl:template match="&EXAMPLE-LIKE;" mode="tcb-style">
    <xsl:text>colback=pink,</xsl:text>
</xsl:template>
. This would affect <example>, <question>, and <problem>, and future-proof your style when there is a demand for <illustration> as a new kind of “example-like.”
There is only one mode, but it can handle a variety of PreTeXt elements in the @match. The text produced by the template will be supplied in a named tcolorbox style via a \tcbset{} command. It is marginally more complicated than that. PreTeXt will manage certain aspects of creating a tcolorbox, such as forming the tcolorbox title to be a string like “Example 4.5 The Chain Rule.”, or just “Example 4.6” when an author does not include a PreTeXt <title>. As a style writer, you can change the font, color and placement of that string, but not the use of the type-name, the number, the title, or their order. The text of your template is additive, meaning it is in addition to what the stock PreTeXt conversion provides. Your options come last, so will be new and effective, or will replace what the base conversion to does. So in the example above, the base conversion to has colback=white (rather than the default gray!), and this will be overridden since pink will come later.
You have attempted of activities on this page.