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"
7 <!-- ********************************************************************
8 $Id: math.xsl,v 1.1 2007/03/10 05:15:13 scott Exp $
9 ********************************************************************
11 This file is part of the XSL DocBook Stylesheet distribution.
12 See ../README or http://nwalsh.com/docbook/xsl/ for copyright
13 and other information.
15 ******************************************************************** -->
17 <xsl:template match=
"inlineequation">
18 <xsl:apply-templates/>
21 <xsl:template match=
"alt">
24 <xsl:template match=
"mathphrase">
26 <xsl:apply-templates select=
"." mode=
"class.attribute"/>
27 <xsl:apply-templates/>
31 <!-- "Support" for MathML -->
33 <xsl:template match=
"mml:*" xmlns:
mml=
"http://www.w3.org/1998/Math/MathML">
35 <xsl:copy-of select=
"@*"/>
36 <xsl:apply-templates/>
40 <!-- Support for TeX math in alt -->
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">
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"/>
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"/>
60 Unsupported TeX math notation:
61 <xsl:value-of select=
"$tex.math.in.alt"/>
66 <xsl:with-param name=
"encoding" select=
"$chunker.output.encoding"/>
72 <xsl:template name=
"tex.math.plain.head">
73 <xsl:text>\nopagenumbers

</xsl:text>
76 <xsl:template name=
"tex.math.plain.tail">
77 <xsl:text>\bye

</xsl:text>
80 <xsl:template match=
"inlineequation" mode=
"collect.tex.math.plain">
81 <xsl:variable name=
"filename">
83 <xsl:when test=
"graphic">
84 <xsl:call-template name=
"mediaobject.filename">
85 <xsl:with-param name=
"object" select=
"graphic"/>
89 <xsl:call-template name=
"select.mediaobject.filename">
90 <xsl:with-param name=
"olist" select=
"inlinemediaobject/*"/>
95 <xsl:variable name=
"output.delims">
96 <xsl:call-template name=
"tex.math.output.delims"/>
98 <xsl:variable name=
"tex" select=
"alt[@role='tex'] | inlinemediaobject/textobject[@role='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>
106 <xsl:value-of select=
"$tex"/>
107 <xsl:if test=
"$output.delims != 0">
108 <xsl:text>$

</xsl:text>
110 <xsl:text>\vfill\eject

</xsl:text>
114 <xsl:template match=
"equation|informalequation" mode=
"collect.tex.math.plain">
115 <xsl:variable name=
"filename">
117 <xsl:when test=
"graphic">
118 <xsl:call-template name=
"mediaobject.filename">
119 <xsl:with-param name=
"object" select=
"graphic"/>
123 <xsl:call-template name=
"select.mediaobject.filename">
124 <xsl:with-param name=
"olist" select=
"mediaobject/*"/>
129 <xsl:variable name=
"output.delims">
130 <xsl:call-template name=
"tex.math.output.delims"/>
132 <xsl:variable name=
"tex" select=
"alt[@role='tex'] | mediaobject/textobject[@role='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>
140 <xsl:value-of select=
"$tex"/>
141 <xsl:if test=
"$output.delims != 0">
142 <xsl:text>$$

</xsl:text>
144 <xsl:text>\vfill\eject

</xsl:text>
148 <xsl:template match=
"text()" mode=
"collect.tex.math.plain"/>
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>
158 <xsl:template name=
"tex.math.latex.tail">
159 <xsl:text>\end{document}

</xsl:text>
162 <xsl:template match=
"inlineequation" mode=
"collect.tex.math.latex">
163 <xsl:variable name=
"filename">
165 <xsl:when test=
"graphic">
166 <xsl:call-template name=
"mediaobject.filename">
167 <xsl:with-param name=
"object" select=
"graphic"/>
171 <xsl:call-template name=
"select.mediaobject.filename">
172 <xsl:with-param name=
"olist" select=
"inlinemediaobject/*"/>
177 <xsl:variable name=
"output.delims">
178 <xsl:call-template name=
"tex.math.output.delims"/>
180 <xsl:variable name=
"tex" select=
"alt[@role='tex'] | inlinemediaobject/textobject[@role='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>
188 <xsl:value-of select=
"$tex"/>
189 <xsl:if test=
"$output.delims != 0">
190 <xsl:text>$

</xsl:text>
192 <xsl:text>\newpage

</xsl:text>
196 <xsl:template match=
"equation|informalequation" mode=
"collect.tex.math.latex">
197 <xsl:variable name=
"filename">
199 <xsl:when test=
"graphic">
200 <xsl:call-template name=
"mediaobject.filename">
201 <xsl:with-param name=
"object" select=
"graphic"/>
205 <xsl:call-template name=
"select.mediaobject.filename">
206 <xsl:with-param name=
"olist" select=
"mediaobject/*"/>
211 <xsl:variable name=
"output.delims">
212 <xsl:call-template name=
"tex.math.output.delims"/>
214 <xsl:variable name=
"tex" select=
"alt[@role='tex'] | mediaobject/textobject[@role='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>
222 <xsl:value-of select=
"$tex"/>
223 <xsl:if test=
"$output.delims != 0">
224 <xsl:text>$$

</xsl:text>
226 <xsl:text>\newpage

</xsl:text>
230 <xsl:template match=
"text()" mode=
"collect.tex.math.latex"/>
232 <!-- Extracting image filename from mediaobject and graphic elements -->
234 <xsl:template name=
"select.mediaobject.filename">
235 <xsl:param name=
"olist"
236 select=
"imageobject|imageobjectco
237 |videoobject|audioobject|textobject"/>
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"/>
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]"/>
254 <xsl:template name=
"tex.math.output.delims">
255 <xsl:variable name=
"pi.delims">
256 <xsl:call-template name=
"pi-attribute">
257 <xsl:with-param name=
"pis" select=
".//processing-instruction('dbtex')"/>
258 <xsl:with-param name=
"attribute" select=
"'delims'"/>
261 <xsl:variable name=
"result">
263 <xsl:when test=
"$pi.delims = 'no'">0</xsl:when>
264 <xsl:when test=
"$pi.delims = '' and $tex.math.delims = 0">0</xsl:when>
265 <xsl:otherwise>1</xsl:otherwise>
268 <xsl:value-of select=
"$result"/>