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