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