| 1 |
<?xml version='1.0'?> |
| 2 |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
| 3 |
xmlns:mml="http://www.w3.org/1998/Math/MathML" |
| 4 |
exclude-result-prefixes="mml" |
| 5 |
version='1.0'> |
| 6 |
|
| 7 |
<!-- ******************************************************************** |
| 8 |
$Id: math.xsl 6961 2007-07-07 02:05:56Z xmldoc $ |
| 9 |
******************************************************************** |
| 10 |
|
| 11 |
This file is part of the XSL DocBook Stylesheet distribution. |
| 12 |
See ../README or http://docbook.sf.net/release/xsl/current/ for |
| 13 |
copyright and other information. |
| 14 |
|
| 15 |
******************************************************************** --> |
| 16 |
|
| 17 |
<xsl:template match="inlineequation"> |
| 18 |
<xsl:apply-templates/> |
| 19 |
</xsl:template> |
| 20 |
|
| 21 |
<xsl:template match="alt"> |
| 22 |
</xsl:template> |
| 23 |
|
| 24 |
<xsl:template match="mathphrase"> |
| 25 |
<span> |
| 26 |
<xsl:apply-templates select="." mode="class.attribute"/> |
| 27 |
<xsl:apply-templates/> |
| 28 |
</span> |
| 29 |
</xsl:template> |
| 30 |
|
| 31 |
<!-- "Support" for MathML --> |
| 32 |
|
| 33 |
<xsl:template match="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML"> |
| 34 |
<xsl:copy> |
| 35 |
<xsl:copy-of select="@*"/> |
| 36 |
<xsl:apply-templates/> |
| 37 |
</xsl:copy> |
| 38 |
</xsl:template> |
| 39 |
|
| 40 |
<!-- Support for TeX math in alt --> |
| 41 |
|
| 42 |
<xsl:template match="*" mode="collect.tex.math"> |
| 43 |
<xsl:call-template name="write.text.chunk"> |
| 44 |
<xsl:with-param name="filename" select="$tex.math.file"/> |
| 45 |
<xsl:with-param name="method" select="'text'"/> |
| 46 |
<xsl:with-param name="content"> |
| 47 |
<xsl:choose> |
| 48 |
<xsl:when test="$tex.math.in.alt = 'plain'"> |
| 49 |
<xsl:call-template name="tex.math.plain.head"/> |
| 50 |
<xsl:apply-templates select="." mode="collect.tex.math.plain"/> |
| 51 |
<xsl:call-template name="tex.math.plain.tail"/> |
| 52 |
</xsl:when> |
| 53 |
<xsl:when test="$tex.math.in.alt = 'latex'"> |
| 54 |
<xsl:call-template name="tex.math.latex.head"/> |
| 55 |
<xsl:apply-templates select="." mode="collect.tex.math.latex"/> |
| 56 |
<xsl:call-template name="tex.math.latex.tail"/> |
| 57 |
</xsl:when> |
| 58 |
<xsl:otherwise> |
| 59 |
<xsl:message> |
| 60 |
Unsupported TeX math notation: |
| 61 |
<xsl:value-of select="$tex.math.in.alt"/> |
| 62 |
</xsl:message> |
| 63 |
</xsl:otherwise> |
| 64 |
</xsl:choose> |
| 65 |
</xsl:with-param> |
| 66 |
<xsl:with-param name="encoding" select="$chunker.output.encoding"/> |
| 67 |
</xsl:call-template> |
| 68 |
</xsl:template> |
| 69 |
|
| 70 |
<!-- PlainTeX --> |
| 71 |
|
| 72 |
<xsl:template name="tex.math.plain.head"> |
| 73 |
<xsl:text>\nopagenumbers 
</xsl:text> |
| 74 |
</xsl:template> |
| 75 |
|
| 76 |
<xsl:template name="tex.math.plain.tail"> |
| 77 |
<xsl:text>\bye 
</xsl:text> |
| 78 |
</xsl:template> |
| 79 |
|
| 80 |
<xsl:template match="inlineequation" mode="collect.tex.math.plain"> |
| 81 |
<xsl:variable name="filename"> |
| 82 |
<xsl:choose> |
| 83 |
<xsl:when test="graphic"> |
| 84 |
<xsl:call-template name="mediaobject.filename"> |
| 85 |
<xsl:with-param name="object" select="graphic"/> |
| 86 |
</xsl:call-template> |
| 87 |
</xsl:when> |
| 88 |
<xsl:otherwise> |
| 89 |
<xsl:call-template name="select.mediaobject.filename"> |
| 90 |
<xsl:with-param name="olist" select="inlinemediaobject/*"/> |
| 91 |
</xsl:call-template> |
| 92 |
</xsl:otherwise> |
| 93 |
</xsl:choose> |
| 94 |
</xsl:variable> |
| 95 |
<xsl:variable name="output.delims"> |
| 96 |
<xsl:call-template name="tex.math.output.delims"/> |
| 97 |
</xsl:variable> |
| 98 |
<xsl:variable name="tex" select="alt[@role='tex'] | inlinemediaobject/textobject[@role='tex']"/> |
| 99 |
<xsl:if test="$tex"> |
| 100 |
<xsl:text>\special{dvi2bitmap outputfile </xsl:text> |
| 101 |
<xsl:value-of select="$filename"/> |
| 102 |
<xsl:text>} 
</xsl:text> |
| 103 |
<xsl:if test="$output.delims != 0"> |
| 104 |
<xsl:text>$</xsl:text> |
| 105 |
</xsl:if> |
| 106 |
<xsl:value-of select="$tex"/> |
| 107 |
<xsl:if test="$output.delims != 0"> |
| 108 |
<xsl:text>$ 
</xsl:text> |
| 109 |
</xsl:if> |
| 110 |
<xsl:text>\vfill\eject 
</xsl:text> |
| 111 |
</xsl:if> |
| 112 |
</xsl:template> |
| 113 |
|
| 114 |
<xsl:template match="equation|informalequation" mode="collect.tex.math.plain"> |
| 115 |
<xsl:variable name="filename"> |
| 116 |
<xsl:choose> |
| 117 |
<xsl:when test="graphic"> |
| 118 |
<xsl:call-template name="mediaobject.filename"> |
| 119 |
<xsl:with-param name="object" select="graphic"/> |
| 120 |
</xsl:call-template> |
| 121 |
</xsl:when> |
| 122 |
<xsl:otherwise> |
| 123 |
<xsl:call-template name="select.mediaobject.filename"> |
| 124 |
<xsl:with-param name="olist" select="mediaobject/*"/> |
| 125 |
</xsl:call-template> |
| 126 |
</xsl:otherwise> |
| 127 |
</xsl:choose> |
| 128 |
</xsl:variable> |
| 129 |
<xsl:variable name="output.delims"> |
| 130 |
<xsl:call-template name="tex.math.output.delims"/> |
| 131 |
</xsl:variable> |
| 132 |
<xsl:variable name="tex" select="alt[@role='tex'] | mediaobject/textobject[@role='tex']"/> |
| 133 |
<xsl:if test="$tex"> |
| 134 |
<xsl:text>\special{dvi2bitmap outputfile </xsl:text> |
| 135 |
<xsl:value-of select="$filename"/> |
| 136 |
<xsl:text>} 
</xsl:text> |
| 137 |
<xsl:if test="$output.delims != 0"> |
| 138 |
<xsl:text>$$</xsl:text> |
| 139 |
</xsl:if> |
| 140 |
<xsl:value-of select="$tex"/> |
| 141 |
<xsl:if test="$output.delims != 0"> |
| 142 |
<xsl:text>$$ 
</xsl:text> |
| 143 |
</xsl:if> |
| 144 |
<xsl:text>\vfill\eject 
</xsl:text> |
| 145 |
</xsl:if> |
| 146 |
</xsl:template> |
| 147 |
|
| 148 |
<xsl:template match="text()" mode="collect.tex.math.plain"/> |
| 149 |
|
| 150 |
<!-- LaTeX --> |
| 151 |
|
| 152 |
<xsl:template name="tex.math.latex.head"> |
| 153 |
<xsl:text>\documentclass{article} 
</xsl:text> |
| 154 |
<xsl:text>\pagestyle{empty} 
</xsl:text> |
| 155 |
<xsl:text>\begin{document} 
</xsl:text> |
| 156 |
</xsl:template> |
| 157 |
|
| 158 |
<xsl:template name="tex.math.latex.tail"> |
| 159 |
<xsl:text>\end{document} 
</xsl:text> |
| 160 |
</xsl:template> |
| 161 |
|
| 162 |
<xsl:template match="inlineequation" mode="collect.tex.math.latex"> |
| 163 |
<xsl:variable name="filename"> |
| 164 |
<xsl:choose> |
| 165 |
<xsl:when test="graphic"> |
| 166 |
<xsl:call-template name="mediaobject.filename"> |
| 167 |
<xsl:with-param name="object" select="graphic"/> |
| 168 |
</xsl:call-template> |
| 169 |
</xsl:when> |
| 170 |
<xsl:otherwise> |
| 171 |
<xsl:call-template name="select.mediaobject.filename"> |
| 172 |
<xsl:with-param name="olist" select="inlinemediaobject/*"/> |
| 173 |
</xsl:call-template> |
| 174 |
</xsl:otherwise> |
| 175 |
</xsl:choose> |
| 176 |
</xsl:variable> |
| 177 |
<xsl:variable name="output.delims"> |
| 178 |
<xsl:call-template name="tex.math.output.delims"/> |
| 179 |
</xsl:variable> |
| 180 |
<xsl:variable name="tex" select="alt[@role='tex'] | inlinemediaobject/textobject[@role='tex']"/> |
| 181 |
<xsl:if test="$tex"> |
| 182 |
<xsl:text>\special{dvi2bitmap outputfile </xsl:text> |
| 183 |
<xsl:value-of select="$filename"/> |
| 184 |
<xsl:text>} 
</xsl:text> |
| 185 |
<xsl:if test="$output.delims != 0"> |
| 186 |
<xsl:text>$</xsl:text> |
| 187 |
</xsl:if> |
| 188 |
<xsl:value-of select="$tex"/> |
| 189 |
<xsl:if test="$output.delims != 0"> |
| 190 |
<xsl:text>$ 
</xsl:text> |
| 191 |
</xsl:if> |
| 192 |
<xsl:text>\newpage 
</xsl:text> |
| 193 |
</xsl:if> |
| 194 |
</xsl:template> |
| 195 |
|
| 196 |
<xsl:template match="equation|informalequation" mode="collect.tex.math.latex"> |
| 197 |
<xsl:variable name="filename"> |
| 198 |
<xsl:choose> |
| 199 |
<xsl:when test="graphic"> |
| 200 |
<xsl:call-template name="mediaobject.filename"> |
| 201 |
<xsl:with-param name="object" select="graphic"/> |
| 202 |
</xsl:call-template> |
| 203 |
</xsl:when> |
| 204 |
<xsl:otherwise> |
| 205 |
<xsl:call-template name="select.mediaobject.filename"> |
| 206 |
<xsl:with-param name="olist" select="mediaobject/*"/> |
| 207 |
</xsl:call-template> |
| 208 |
</xsl:otherwise> |
| 209 |
</xsl:choose> |
| 210 |
</xsl:variable> |
| 211 |
<xsl:variable name="output.delims"> |
| 212 |
<xsl:call-template name="tex.math.output.delims"/> |
| 213 |
</xsl:variable> |
| 214 |
<xsl:variable name="tex" select="alt[@role='tex'] | mediaobject/textobject[@role='tex']"/> |
| 215 |
<xsl:if test="$tex"> |
| 216 |
<xsl:text>\special{dvi2bitmap outputfile </xsl:text> |
| 217 |
<xsl:value-of select="$filename"/> |
| 218 |
<xsl:text>} 
</xsl:text> |
| 219 |
<xsl:if test="$output.delims != 0"> |
| 220 |
<xsl:text>$$</xsl:text> |
| 221 |
</xsl:if> |
| 222 |
<xsl:value-of select="$tex"/> |
| 223 |
<xsl:if test="$output.delims != 0"> |
| 224 |
<xsl:text>$$ 
</xsl:text> |
| 225 |
</xsl:if> |
| 226 |
<xsl:text>\newpage 
</xsl:text> |
| 227 |
</xsl:if> |
| 228 |
</xsl:template> |
| 229 |
|
| 230 |
<xsl:template match="text()" mode="collect.tex.math.latex"/> |
| 231 |
|
| 232 |
<!-- Extracting image filename from mediaobject and graphic elements --> |
| 233 |
|
| 234 |
<xsl:template name="select.mediaobject.filename"> |
| 235 |
<xsl:param name="olist" |
| 236 |
select="imageobject|imageobjectco |
| 237 |
|videoobject|audioobject|textobject"/> |
| 238 |
|
| 239 |
<xsl:variable name="mediaobject.index"> |
| 240 |
<xsl:call-template name="select.mediaobject.index"> |
| 241 |
<xsl:with-param name="olist" select="$olist"/> |
| 242 |
<xsl:with-param name="count" select="1"/> |
| 243 |
</xsl:call-template> |
| 244 |
</xsl:variable> |
| 245 |
|
| 246 |
<xsl:if test="$mediaobject.index != ''"> |
| 247 |
<xsl:call-template name="mediaobject.filename"> |
| 248 |
<xsl:with-param name="object" |
| 249 |
select="$olist[position() = $mediaobject.index]"/> |
| 250 |
</xsl:call-template> |
| 251 |
</xsl:if> |
| 252 |
</xsl:template> |
| 253 |
|
| 254 |
<xsl:template name="tex.math.output.delims"> |
| 255 |
<xsl:variable name="pi.delims"> |
| 256 |
<xsl:call-template name="pi.dbtex_delims"> |
| 257 |
<xsl:with-param name="node" select="descendant-or-self::*"/> |
| 258 |
</xsl:call-template> |
| 259 |
</xsl:variable> |
| 260 |
<xsl:variable name="result"> |
| 261 |
<xsl:choose> |
| 262 |
<xsl:when test="$pi.delims = 'no'">0</xsl:when> |
| 263 |
<xsl:when test="$pi.delims = '' and $tex.math.delims = 0">0</xsl:when> |
| 264 |
<xsl:otherwise>1</xsl:otherwise> |
| 265 |
</xsl:choose> |
| 266 |
</xsl:variable> |
| 267 |
<xsl:value-of select="$result"/> |
| 268 |
</xsl:template> |
| 269 |
|
| 270 |
</xsl:stylesheet> |