Next update of VFS modules development guide
[samba.git] / docs / xslt / db2latex-xsl / xsl / mathml / mathml.presentation.mod.xsl
1 <?xml version='1.0'?>
2 <!DOCTYPE xsl:stylesheet
3 [
4  <!ENTITY % mmlalias PUBLIC "MathML alias" "ent/mmlalias.ent">  %mmlalias;
5  <!ENTITY % mmlextra PUBLIC "MathML extra" "ent/mmlextra.ent">  %mmlextra;
6 ]>
7 <!--############################################################################# 
8  |      $Id: mathml.presentation.mod.xsl,v 1.4 2004/01/18 10:39:50 j-devenish Exp $             
9  |- #############################################################################
10  |      $Author: j-devenish $                                                                                           
11  |                                                                                                              
12  |   PURPOSE: MathML presentation markup.
13  |      Note: these elements are not part of the DocBook DTD. I have extended
14  |    the docbook DTD in order to support this tags, so that's why I have these 
15  |      templates here.
16  |   
17  |      MathML namespace used -> mml
18  + ############################################################################## -->
19
20 <xsl:stylesheet version='1.0'
21         xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
22         xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns="http://www.w3.org/1998/Math/MathML">
23
24 <xsl:template match="mml:mrow">
25         <xsl:text>{</xsl:text> <xsl:apply-templates/> <xsl:text>}</xsl:text>
26 </xsl:template>
27
28 <xsl:variable name="latex.entities.xml" select="document('latex.entities.xml')"/>
29
30
31 <!-- TOKENS -->
32 <!-- Math Identifier -->
33 <xsl:template match="mml:mi">
34         <xsl:variable name="fontstyle" select="@fontstyle"/>
35         <xsl:variable name="identifier" select="normalize-space(.)"/>
36         <xsl:variable name="equivalent">
37                 <xsl:if test="string-length($identifier)=1">
38                         <xsl:value-of select="$latex.entities.xml/latex/character[@entity=$identifier]"/>
39                 </xsl:if>
40         </xsl:variable>
41         <xsl:choose>
42                 <xsl:when test="$identifier='&ExponentialE;'">
43                         <xsl:text>\textrm{e}</xsl:text>
44                 </xsl:when>
45                 <xsl:when test="$identifier='&ImaginaryI;'">
46                         <xsl:text>\textrm{i}</xsl:text>
47                 </xsl:when>
48                 <xsl:when test="$identifier='&#x0221E;'"><!--/infty infinity -->
49                         <xsl:text>\infty</xsl:text>
50                 </xsl:when>
51                 <!-- currently tries to map single-character identifiers only -->
52                 <xsl:when test="$equivalent!=''">
53                         <xsl:text>{</xsl:text>
54                         <xsl:copy-of select="$equivalent"/>
55                         <xsl:text>}</xsl:text>
56                 </xsl:when>
57                 <xsl:otherwise>
58                         <xsl:if test="$fontstyle='normal' or string-length($identifier)&gt;1">
59                                 <xsl:text>\textrm</xsl:text>
60                         </xsl:if>
61                         <xsl:text>{</xsl:text>
62                         <xsl:copy-of select="$identifier"/>
63                         <xsl:text>}</xsl:text>
64                 </xsl:otherwise>
65         </xsl:choose>
66 </xsl:template>
67
68 <!-- Math Number -->
69 <xsl:template match="mml:mn">
70         <xsl:copy-of select="normalize-space(.)"/>
71 </xsl:template>
72
73 <!-- Math Phantom -->
74 <xsl:template match="mml:mphantom">
75         <xsl:apply-templates/>
76 </xsl:template>
77
78 <!-- Empty unless $character is a single character -->
79 <xsl:template name="generate.equivalent">
80         <xsl:param name="arguments" select="0"/>
81         <xsl:param name="character"/>
82         <xsl:if test="string-length($character)=1">
83                 <xsl:choose>
84                         <xsl:when test="$arguments&gt;0">
85                                 <xsl:value-of select="$latex.entities.xml/latex/character[@entity=$character and @arguments=$arguments]"/>
86                         </xsl:when>
87                         <xsl:otherwise>
88                                 <xsl:value-of select="$latex.entities.xml/latex/character[@entity=$character and @arguments='']"/>
89                         </xsl:otherwise>
90                 </xsl:choose>
91         </xsl:if>
92 </xsl:template>
93
94 <!-- Math Operator -->
95 <xsl:template match="mml:mo">
96         <xsl:variable name="operator" select="normalize-space(.)"/>
97         <xsl:variable name="equivalent">
98                 <xsl:call-template name="generate.equivalent">
99                         <xsl:with-param name="character" select="$operator"/>
100                 </xsl:call-template>
101         </xsl:variable>
102         <xsl:choose>
103                 <xsl:when test="$operator='&ApplyFunction;'">
104                         <xsl:text></xsl:text>
105                 </xsl:when>
106                 <xsl:when test="$operator='&InvisibleComma;'">
107                         <xsl:text>\thinspace</xsl:text>
108                 </xsl:when>
109                 <xsl:when test="$operator='&InvisibleTimes;'">
110                         <xsl:text>\thinspace</xsl:text>
111                 </xsl:when>
112                 <xsl:when test="$operator='&Integral;'">
113                         <xsl:text>\int</xsl:text>
114                 </xsl:when>
115                 <xsl:when test="$operator='&Product;'">
116                         <xsl:text>\prod</xsl:text>
117                 </xsl:when>
118                 <xsl:when test="$operator='&Sum;'">
119                         <xsl:text>\sum</xsl:text>
120                 </xsl:when>
121                 <xsl:when test="$operator='&Hat;'">
122                         <xsl:text>\sphat</xsl:text>
123                 </xsl:when>
124                 <xsl:when test="$operator='&RightArrow;'">
125                         <xsl:text>\longrightarrow</xsl:text>
126                 </xsl:when>
127                 <xsl:when test="$operator='&Element;'">
128                         <xsl:text>\in</xsl:text>
129                 </xsl:when>
130                 <xsl:when test="$operator='&VerticalBar;'">
131                         <xsl:text>|</xsl:text>
132                 </xsl:when>
133                 <xsl:when test="$operator='&DifferentialD;'">
134                         <xsl:text>\textrm{d}</xsl:text>
135                 </xsl:when>
136                 <xsl:when test="$operator='('">
137                         <xsl:text> {\left( </xsl:text>
138                 </xsl:when>
139                 <xsl:when test="$operator=')'">
140                         <xsl:text> \right)} </xsl:text>
141                 </xsl:when>
142                 <xsl:when test="$operator='{'">
143                         <xsl:text> {\left\{ </xsl:text>
144                 </xsl:when>
145                 <xsl:when test="$operator='}'">
146                         <xsl:text> \right\}} </xsl:text>
147                 </xsl:when>
148                 <xsl:when test="$operator='['">
149                         <xsl:text> {\left[ </xsl:text>
150                 </xsl:when>
151                 <xsl:when test="$operator=']'">
152                         <xsl:text> \right]} </xsl:text>
153                 </xsl:when>
154                 <xsl:when test="$operator='max'">
155                         <xsl:text> \max </xsl:text>
156                 </xsl:when>
157                 <xsl:when test="$operator='min'">
158                         <xsl:text> \min </xsl:text>
159                 </xsl:when>
160                 <xsl:when test="$operator='+' or $operator='-' or $operator='/' or $operator='*'">
161                         <xsl:value-of select="$operator"/>
162                 </xsl:when>
163                 <xsl:when test="$equivalent">
164                         <xsl:value-of select="$equivalent"/>
165                 </xsl:when>
166                 <xsl:otherwise>
167                         <xsl:text>\operatorname{</xsl:text>
168                         <xsl:value-of select="$operator" />
169                         <xsl:text>}</xsl:text>
170                 </xsl:otherwise>
171         </xsl:choose>
172 </xsl:template>
173
174 <!-- Math String -->
175 <xsl:template match="mml:ms">
176         <xsl:text>\textrm{</xsl:text>
177         <xsl:copy-of select="normalize-space(.)" />
178         <xsl:text>}</xsl:text>
179 </xsl:template>
180
181 <!-- Math Text -->
182 <xsl:template match="mml:mtext">
183         <xsl:message>RCAS mtext, <xsl:copy-of select="."/> </xsl:message>
184         <xsl:text>\textrm{</xsl:text>
185         <xsl:copy-of select="." />
186         <xsl:text>}</xsl:text>
187 </xsl:template>
188
189 <!-- Math Space -->
190 <xsl:template match="mml:mspace">
191         <xsl:if test="@width!='' and not(contains(@width,'%'))">
192                 <xsl:text>\textrm{\hspace{</xsl:text><!-- kludge! -->
193                 <xsl:value-of select="@width"/>
194                 <xsl:text>}}</xsl:text>
195         </xsl:if>
196         <xsl:if test="@height!='' or @depth!=''">
197                 <xsl:message>Warning: mspace support does not include height or depth.</xsl:message>
198         </xsl:if>
199 </xsl:template>
200
201
202
203
204
205 <xsl:template match="mml:msup">
206         <xsl:apply-templates select="*[1]"/>
207         <xsl:text>^{</xsl:text><xsl:apply-templates select="*[2]"/><xsl:text>}</xsl:text>
208 </xsl:template>
209
210 <xsl:template match="mml:msub">
211         <xsl:apply-templates select="*[1]"/>
212         <xsl:text>_{</xsl:text><xsl:apply-templates select="*[2]"/><xsl:text>}</xsl:text>
213 </xsl:template>
214
215 <xsl:template match="mml:msubsup">
216 <xsl:choose>
217         <xsl:when test="name(*[1])='mo'">
218                 <xsl:apply-templates select="*[1]"/>
219                 <!-- sub -->
220                 <xsl:text>_{</xsl:text><xsl:apply-templates select="*[2]"/><xsl:text>}</xsl:text>
221                 <!-- super -->
222                 <xsl:text>^{</xsl:text><xsl:apply-templates select="*[3]"/><xsl:text>}</xsl:text>
223      </xsl:when>
224      <xsl:otherwise>
225                 <!-- base -->
226                 <xsl:text>{</xsl:text><xsl:apply-templates select="*[1]"/><xsl:text>}</xsl:text>
227                 <!-- sub -->
228                 <xsl:text>_{</xsl:text><xsl:apply-templates select="*[2]"/><xsl:text>}</xsl:text>
229                 <!-- super -->
230                 <xsl:text>^{</xsl:text><xsl:apply-templates select="*[3]"/><xsl:text>}</xsl:text>
231         </xsl:otherwise>
232 </xsl:choose>
233 </xsl:template>
234
235 <xsl:template match="mml:mmultiscripts">
236 </xsl:template>
237
238 <xsl:template match="mml:munder">
239 <!--
240 <xsl:choose>
241         <xsl:when test="*[2] = &#818;">
242                 <xsl:text>\underline{</xsl:text><xsl:apply-templates select="*[1]"/><xsl:text>}</xsl:text>
243         </xsl:when>
244         <xsl:when test="normalize-space(*[2]) = &#65080;">
245                 <xsl:text>\underbrace{</xsl:text><xsl:apply-templates select="*[1]"/><xsl:text>}</xsl:text>
246         </xsl:when>
247         <xsl:when test="normalize-space(*[2]) = &#9141;">
248                 <xsl:text>\underbrace{</xsl:text><xsl:apply-templates select="*[1]"/><xsl:text>}</xsl:text>
249         </xsl:when>
250         <xsl:otherwise>
251         <xsl:text>\underset{</xsl:text>
252                 <xsl:apply-templates select="*[2]"/>
253         <xsl:text>}{</xsl:text>
254                 <xsl:apply-templates select="*[1]"/>
255         <xsl:text>}</xsl:text>
256 -->
257         <xsl:text>{</xsl:text>
258         <xsl:apply-templates select="*[1]"/>
259         <xsl:text>_{</xsl:text>
260         <xsl:apply-templates select="*[2]"/>
261         <xsl:text>}}</xsl:text>
262 <!--
263         </xsl:otherwise>
264 </xsl:choose>
265 -->
266 </xsl:template>
267 <xsl:template match="mml:mover">
268 <!--<xsl:choose>
269         <xsl:when test="normalize-space(*[2]) = &#175;">
270                 <xsl:text>\overline{</xsl:text><xsl:apply-templates select="*[1]"/><xsl:text>}</xsl:text>
271         </xsl:when>
272         <xsl:when test="normalize-space(*[2]) = &#65079;"> 
273                 <xsl:text>\overbrace{</xsl:text><xsl:apply-templates select="*[1]"/><xsl:text>}</xsl:text>
274         </xsl:when>
275         <xsl:when test="normalize-space(*[2]) = &#65077;"> 
276                 <xsl:text>\widehat{</xsl:text><xsl:apply-templates select="*[1]"/><xsl:text>}</xsl:text>
277         </xsl:when>
278         <xsl:when test="normalize-space(*[2]) = &#9140;">
279                 <xsl:text>\widehat{</xsl:text><xsl:apply-templates select="*[1]"/><xsl:text>}</xsl:text>
280         </xsl:when>
281         <xsl:otherwise>
282         </xsl:otherwise>
283 </xsl:choose>-->
284         <xsl:choose>
285                 <xsl:when test="@accent='true' or ( local-name(*[2])='mo' and not(@accent='false'))">
286                         <xsl:variable name="equivalent">
287                                 <xsl:call-template name="generate.equivalent">
288                                         <xsl:with-param name="arguments" select="1"/>
289                                         <xsl:with-param name="character" select="normalize-space(*[2])"/>
290                                 </xsl:call-template>
291                         </xsl:variable>
292                         <xsl:choose>
293                                 <xsl:when test="$equivalent!=''">
294                                         <xsl:text>{</xsl:text>
295                                         <xsl:value-of select="$equivalent"/>
296                                         <xsl:text>{</xsl:text>
297                                         <xsl:apply-templates select="*[1]"/>
298                                         <xsl:text>}}</xsl:text>
299                                 </xsl:when>
300                                 <xsl:otherwise>
301                                         <xsl:text>{</xsl:text>
302                                         <xsl:apply-templates select="*[1]"/>
303                                         <xsl:text>^{</xsl:text>
304                                         <xsl:apply-templates select="*[2]"/>
305                                         <xsl:text>}}</xsl:text>
306                                 </xsl:otherwise>
307                         </xsl:choose>
308                 </xsl:when>
309                 <xsl:otherwise>
310                         <xsl:text>{</xsl:text>
311                         <xsl:apply-templates select="*[1]"/>
312                         <xsl:text>^{</xsl:text>
313                         <xsl:apply-templates select="*[2]"/>
314                         <xsl:text>}}</xsl:text>
315                 </xsl:otherwise>
316         </xsl:choose>
317 </xsl:template>
318
319
320
321 <!-- Math UnderOver -->
322 <xsl:template match="mml:munderover">
323         <xsl:text>{</xsl:text>
324         <xsl:apply-templates select="*[1]"/>
325         <xsl:text>_{</xsl:text>
326         <xsl:apply-templates select="*[2]"/>
327         <xsl:text>}</xsl:text>
328         <xsl:text>^{</xsl:text>
329         <xsl:apply-templates select="*[3]"/>
330         <xsl:text>}}</xsl:text>
331         <!--
332         <xsl:text>\overset{</xsl:text>
333                         <xsl:apply-templates select="*[3]"/>
334                 <xsl:text>}{\underset{</xsl:text>
335                                 <xsl:apply-templates select="*[2]"/>
336                                         <xsl:text>}{</xsl:text>
337                                 <xsl:apply-templates select="*[1]"/>
338         <xsl:text>}}</xsl:text>
339         -->
340 </xsl:template>
341
342
343
344 <!-- Math Fenced -->
345 <xsl:template match="mml:mfenced">
346 <!-- get open,close, separators att -->
347         <xsl:choose>
348                 <xsl:when test="@open='('">
349                         <xsl:text> {\left( </xsl:text>
350                 </xsl:when>
351                 <xsl:when test="@open='{'">
352                         <xsl:text> {\left\{ </xsl:text>
353                 </xsl:when>
354                 <xsl:when test="@open='['">
355                         <xsl:text> {\left[\, </xsl:text>
356                 </xsl:when>
357                 <xsl:otherwise>
358                         <xsl:text> {\left( </xsl:text>
359                 </xsl:otherwise>
360         </xsl:choose>
361         <xsl:apply-templates select="*[1]"/>
362         <xsl:choose>
363                 <xsl:when test="@close=')'">
364                         <xsl:text> \right)} </xsl:text>
365                 </xsl:when>
366                 <xsl:when test="@close='}'">
367                         <xsl:text> \right\}} </xsl:text>
368                 </xsl:when>
369                 <xsl:when test="@close=']'">
370                         <xsl:text> \,\right]} </xsl:text>
371                 </xsl:when>
372                 <xsl:otherwise>
373                         <xsl:text> \right)} </xsl:text>
374                 </xsl:otherwise>
375         </xsl:choose>
376 </xsl:template>
377
378
379
380 <!-- Math frac -->
381 <xsl:template match="mml:mfrac">
382 <xsl:choose>
383 <xsl:when test="@linethickness">
384         <xsl:choose>
385         <xsl:when test="@linethickness='thin'">
386                 <xsl:text> \frac[1pt]{ </xsl:text>
387         </xsl:when>
388         <xsl:when test="@linethickness='medium'">
389                 <xsl:text> \frac[1.1pt]{ </xsl:text>
390         </xsl:when>
391         <xsl:when test="@linethickness='thick'">
392                 <xsl:text> \frac[1.2pt]{ </xsl:text>
393         </xsl:when>
394         <xsl:otherwise>
395                 <xsl:text> \frac[</xsl:text><xsl:value-of select="@linethickness"/><xsl:text>]{ </xsl:text>
396         </xsl:otherwise>
397         </xsl:choose>
398 </xsl:when>
399 <xsl:otherwise>
400         <xsl:text> \frac{ </xsl:text>
401 </xsl:otherwise>
402 </xsl:choose>
403 <!--    <xsl:value-of select="*[1]"/> -->
404 <xsl:apply-templates select="*[1]"/>
405 <xsl:text> }{ </xsl:text>
406 <!--    <xsl:value-of select="*[2]"/> -->
407 <xsl:apply-templates select="*[2]"/>
408 <xsl:text> }</xsl:text>
409 </xsl:template>
410
411
412 <!-- Math msqrt -->
413 <xsl:template match="mml:msqrt">
414         <xsl:text> \sqrt{ </xsl:text>
415         <xsl:apply-templates/>
416         <xsl:text> }</xsl:text>
417 </xsl:template>
418
419
420 <!-- Math mroot -->
421 <xsl:template match="mml:mroot">
422         <xsl:text> \sqrt[</xsl:text><xsl:apply-templates select="*[1]"/><xsl:text>]{</xsl:text>
423                 <xsl:apply-templates select="*[2]"/><xsl:text> }</xsl:text>
424 </xsl:template>
425
426
427
428 <xsl:template name="mtable.format.tabular">
429         <xsl:param name="cols" select="1"/>
430         <xsl:param name="i" select="1"/>
431         <xsl:choose>
432                 <!-- Out of the recursive iteration -->
433                 <xsl:when test="$i > $cols"></xsl:when>
434                 <!-- There are still columns to count -->
435                 <xsl:otherwise>
436                         <xsl:text>c</xsl:text>
437                                 <!-- Recursive for next column -->
438                         <xsl:call-template name="mtable.format.tabular">
439                                         <xsl:with-param name="i" select="$i+1"/>
440                                         <xsl:with-param name="cols" select="$cols"/>
441                         </xsl:call-template>
442                 </xsl:otherwise>
443         </xsl:choose>
444 </xsl:template>
445
446
447 <xsl:template match="mml:mtable">
448 <xsl:variable name="rows" select="mml:mtr"/>
449 <xsl:text>\begin{array}{</xsl:text>
450 <xsl:call-template name="mtable.format.tabular"><xsl:with-param name="cols" select="count($rows)"/></xsl:call-template>
451 <xsl:text>}&#10;</xsl:text>
452         <xsl:apply-templates/>
453 <xsl:text>\end{array} </xsl:text>
454 </xsl:template>
455
456 <xsl:template match="mml:mtr">
457 <!-- Row starts here -->
458 <xsl:apply-templates/>
459 <!-- End Row here -->
460 </xsl:template>
461
462 <xsl:template match="mml:mtd">
463     <xsl:apply-templates/><xsl:text> &amp; </xsl:text> 
464 </xsl:template>
465
466 <xsl:template match="mml:mtd[position()=last()]">
467     <xsl:apply-templates/><xsl:text>\\&#10;</xsl:text>
468 </xsl:template>
469
470 <xsl:template match="mml:mtd[position()=last()]">
471     <xsl:apply-templates/><xsl:text>\\&#10;</xsl:text>
472 </xsl:template>
473
474 <xsl:template match="mml:mphantom">
475     <xsl:apply-templates mode="phantom"/>
476 </xsl:template>
477
478 <xsl:template match="mml:mi" mode="phantom">
479         <xsl:variable name="fontstyle" select="@fontstyle"/>
480         <xsl:variable name="identifier" select="normalize-space(.)"/>
481         <xsl:choose>
482                 <xsl:when test="$identifier='&ExponentialE;'">
483                         <xsl:text>\textrm{e}</xsl:text>
484                 </xsl:when>
485                 <xsl:when test="$identifier='&ImaginaryI;'">
486                         <xsl:text>\textrm{i}</xsl:text>
487                 </xsl:when>
488                 <xsl:otherwise>
489                         <xsl:text>\textrm{</xsl:text> <xsl:copy-of select="$identifier"/> <xsl:text>}</xsl:text>
490                 </xsl:otherwise>
491         </xsl:choose>
492 </xsl:template>
493 </xsl:stylesheet>