Using Saxon 12.8, I can compile an XML source to a TEX file. I am using the XSL file for Latex from TEIC/Stylesheets to do this.
My XML source however has some math that will need the amsmath package. For example, I might have
<formula notation="latex" type="inline">\tfrac{3}{4}</formula>
I cannot figure out the proper way to get Saxon to include "\usepackage{amsmath}" in the generated tex source so that it will compile. Sure, I could manually edit the generated TEX file but that seems like an error-prone and tedious hack.
I've tried overriding the XSL file
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="3.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tei="http://www.tei-c.org/ns/1.0"
exclude-result-prefixes="tei">
<!-- Import the main TEI→LaTeX stylesheet -->
<xsl:import href="/home/myusername/saxon-he/Stylesheets/profiles/tei/latex/to.xsl"/>
<!-- Inject amsmath into the LaTeX preamble -->
<xsl:template name="latex-preamble">
<xsl:call-template name="latex-preamble"/>
<xsl:text>\usepackage{amsmath}</xsl:text>
</xsl:template>
<!-- Handle formula elements -->
<xsl:template match="tei:formula[@notation='latex']">
<xsl:choose>
<!-- If explicitly marked as block/display -->
<xsl:when test="@rend='display'">
<xsl:text> \[</xsl:text>
<xsl:value-of select="."/>
<xsl:text>\] </xsl:text>
</xsl:when>
<!-- Default: inline -->
<xsl:otherwise>
<xsl:text>$</xsl:text>
<xsl:value-of select="."/>
<xsl:text>$</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
But it doesn't work (that is, the relavent override section above doesn't include the amsmath package so the genderated TEX file doesn't compile, complaining about undefined control sequences). This seems like it should be really easy to do. I just want to tell saxon I'll need to include the line "\usepackage{amsmath}" in my generated TEX source. How do I do this?
latexPackagesandlatextSetupandlatexBeginthat you can override, although there are warnings like "The basic LaTeX setup which you should not really tinker with unless you really understand why and how. ". Let's hope someone with TEI and TEI to LaTeX skills comes along to help you out.