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