~ubuntu-branches/ubuntu/vivid/installation-guide/vivid-proposed

« back to all changes in this revision

Viewing changes to build/stylesheets/db2latex/mathml/mathml.content.functions.mod.xsl

  • Committer: Bazaar Package Importer
  • Author(s): Frans Pop
  • Date: 2005-10-25 17:37:25 UTC
  • Revision ID: james.westby@ubuntu.com-20051025173725-aq0bm11be7bfd7rw
Tags: 20051025
* Mention in copyright that full GPL is included in the manual.
  Closes: #334925
* Register installed documents with doc-base.
* Minor updates in English text and translations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.content.functions.mod.xsl,v 1.2 2004/01/18 10:45:35 j-devenish Exp $                
 
9
 |- #############################################################################
 
10
 |      $Author: j-devenish $                                                                                           
 
11
 |                                                                                                              
 
12
 |   PURPOSE: MathML content 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:fn">
 
25
</xsl:template>
 
26
 
 
27
<!--
 
28
<xsl:template match="mml:apply/lowlimit">
 
29
<xsl:variable name="first" select="../child::*[1]"/>
 
30
</xsl:template>
 
31
 
 
32
<xsl:template match="mml:apply/uplimit">
 
33
<xsl:variable name="first" select="../child::*[1]"/>
 
34
</xsl:template>
 
35
 
 
36
<xsl:template match="mml:apply/degree">
 
37
<xsl:variable name="first" select="../child::*[1]"/>
 
38
</xsl:template>
 
39
-->
 
40
 
 
41
 
 
42
<!-- conditions -->
 
43
<!-- no support for deprecated reln-->
 
44
<xsl:template match="mml:condition">
 
45
        <xsl:text>{</xsl:text><xsl:apply-templates/><xsl:text>}</xsl:text>
 
46
</xsl:template>
 
47
 
 
48
 
 
49
 
 
50
 
 
51
 
 
52
 
 
53
<!--UNARY 
 
54
          unary arithmetic                      exp, factorial, minus, abs, conjugate, arg, real, imaginary
 
55
        unary logical                           not
 
56
        unary functional                        inverse, ident
 
57
        unary elementary classical
 
58
        functions                                       sin, cos, tan, sec, csc, cot, sinh, cosh, tanh, sech, csch, coth, arcsin,
 
59
                                          arccos, arctan, arccosh, arccot, arccoth, arccsc, arccsch, arcsec, arcsech, arcsinh,
 
60
                                          arctanh, exp, ln, log
 
61
        unary linear algebra                    determinant, transpose
 
62
        unary calculus and vector calculus
 
63
                                          divergence, grad, curl, laplacian
 
64
        unary set-theoretic                     card
 
65
-->
 
66
 
 
67
<!-- BINARY
 
68
          binary arithmetic                     quotient, divide, minus, power, rem
 
69
        binary logical                          implies, equivalent, approx
 
70
        binary set operators                    setdiff
 
71
        binary linear algebra                   vectorproduct, scalarproduct, outerproduct
 
72
-->
 
73
 
 
74
<!-- N-ARY and OTHER
 
75
         n-ary statistical mean, sdev, variance, median, mode
 
76
        n-ary logical and, or, xor
 
77
        n-ary linear algebra selector
 
78
        n-ary set operator union, intersect
 
79
        n-ary functional fn, compose
 
80
        integral, sum, product operators int, sum, product
 
81
        differential operator diff, partialdiff
 
82
        quantifier forall, exists
 
83
-->
 
84
<!-- Get the first child (operator), and check if its name is a fn , or operator-->
 
85
<!-- Is the operator taking qualifiers? -->
 
86
<!-- Operators  : int, sum, product, root, diff, partialdiff, limit, log, moment, min, max, forall, exists -->
 
87
<!-- Qualifiers : lowlimit, uplimit, bvar, degree, logbase, interval, condition  -->
 
88
 
 
89
 
 
90
<!-- apply/apply -->
 
91
<xsl:template match="mml:apply[mml:apply]">  <!-- when the function itself is defined by other functions: (F+G)(x) -->
 
92
        <xsl:choose>
 
93
                <xsl:when test="count(child::*)>=2">
 
94
                        <xsl:text>{</xsl:text><xsl:apply-templates select="child::*[position()=1]"/><xsl:text>}</xsl:text>      
 
95
                        <xsl:text>{</xsl:text><xsl:apply-templates select="child::*[position()!=1]"/><xsl:text>}</xsl:text>     
 
96
                </xsl:when>
 
97
        <xsl:otherwise> <!-- apply only contains apply, no operand-->
 
98
                        <xsl:text>{</xsl:text><xsl:apply-templates select="child::*"/><xsl:text>}</xsl:text>    
 
99
        </xsl:otherwise>
 
100
        </xsl:choose>
 
101
</xsl:template>
 
102
 
 
103
 
 
104
<!-- force function or operator MathML 1.0 deprecated-->
 
105
<!-- partial support for func/operators defined using presentation markup-->
 
106
<xsl:template match="mml:apply[mml:fn]">
 
107
<mrow>
 
108
<xsl:choose>
 
109
<xsl:when test="*[position()=1 and self::mml:fn]/mml:mo/mml:mchar/@name='PlusMinus'">
 
110
  <!--if operator is infix (we assume this to be the default when we have mchars(for instance PlusMinus); perhaps we should test further the name attribute)-->
 
111
  <xsl:choose>
 
112
  <xsl:when test="count(child::*)>=3">
 
113
    <mrow>
 
114
      <xsl:for-each select="child::*[position()!=last() and  position()!=1]">
 
115
        <xsl:apply-templates select="."/><xsl:copy-of select="preceding-sibling::mml:fn/*"/>
 
116
      </xsl:for-each>
 
117
      <xsl:apply-templates select="child::*[position()!=1 and position()=last()]"/>
 
118
    </mrow>
 
119
  </xsl:when>
 
120
  <xsl:when test="count(child::*)=2">
 
121
    <mrow><xsl:copy-of select="child::mml:fn[position()=1]/*"/><xsl:apply-templates select="child::*[position()=2]"/></mrow>
 
122
  </xsl:when>
 
123
  <xsl:otherwise> <!-- apply only contains fn, no operand-->
 
124
    <mrow><xsl:apply-templates select="child::mml:fn/*"/></mrow>
 
125
  </xsl:otherwise>
 
126
  </xsl:choose>
 
127
</xsl:when>  
 
128
<xsl:otherwise>  <!-- if operator is prefix (common case)-->
 
129
  <xsl:choose>
 
130
    <xsl:when test="name(mml:fn/*[position()=1])='apply'"> <!-- fn definition is complex, surround with brackets, but only one child-->
 
131
      <mfenced separators=""><mrow><xsl:apply-templates select="mml:fn/*"/></mrow></mfenced>
 
132
    </xsl:when>
 
133
    <xsl:otherwise>
 
134
      <mi><xsl:apply-templates select="mml:fn/*"/></mi>
 
135
    </xsl:otherwise>
 
136
  </xsl:choose>
 
137
  <xsl:if test="count(*)>1">  <!-- if no operands, don't put empty parentheses-->
 
138
    <mo><mchar name="ApplyFunction"/></mo>
 
139
    <mfenced>
 
140
      <xsl:apply-templates select="*[position()!=1]"/>
 
141
    </mfenced>
 
142
  </xsl:if>
 
143
</xsl:otherwise>
 
144
</xsl:choose>
 
145
</mrow>
 
146
</xsl:template>
 
147
 
 
148
 
 
149
 
 
150
 
 
151
<!-- quotient -->
 
152
<xsl:template match="mml:apply[mml:quotient]">
 
153
  <mrow>  <!-- the third notation uses UNICODE chars x0230A and x0230B -->
 
154
    <mo>integer part of</mo>
 
155
    <mrow>
 
156
      <xsl:choose> <!-- surround with brackets if operands are composed-->
 
157
      <xsl:when test="child::*[position()=2] and name()='mml:apply'">
 
158
        <mfenced separators=""><xsl:apply-templates select="*[position()=2]"/></mfenced>
 
159
      </xsl:when>
 
160
      <xsl:otherwise>
 
161
        <xsl:apply-templates select="*[position()=2]"/>
 
162
      </xsl:otherwise>
 
163
      </xsl:choose>
 
164
      <mo>/</mo>
 
165
      <xsl:choose>
 
166
      <xsl:when test="child::*[position()=3] and name()='mml:apply'">
 
167
        <mfenced separators=""><xsl:apply-templates select="*[position()=3]"/></mfenced>
 
168
      </xsl:when>
 
169
      <xsl:otherwise>
 
170
        <xsl:apply-templates select="*[position()=3]"/>
 
171
      </xsl:otherwise>
 
172
      </xsl:choose>
 
173
    </mrow>
 
174
  </mrow>
 
175
</xsl:template>
 
176
 
 
177
 
 
178
<!-- factorial -->
 
179
<xsl:template match="mml:apply[mml:factorial]">
 
180
        <xsl:text>{</xsl:text>
 
181
        <xsl:choose> 
 
182
                <xsl:when test="name(*[position()=2])='mml:apply'">
 
183
                        <xsl:text>{</xsl:text><xsl:apply-templates select="*[position()=2]"/><xsl:text>}</xsl:text>
 
184
                </xsl:when>
 
185
                <xsl:otherwise>
 
186
                        <xsl:apply-templates select="*[position()=2]"/>
 
187
                </xsl:otherwise>
 
188
        </xsl:choose>
 
189
        <xsl:text>!(fact)</xsl:text>
 
190
        <xsl:text>}</xsl:text>
 
191
</xsl:template>
 
192
 
 
193
 
 
194
<!-- divide -->
 
195
<xsl:template match="mml:apply[mml:divide]">
 
196
        <xsl:text>{ \frac</xsl:text>
 
197
        <xsl:text>{ </xsl:text>
 
198
        <xsl:apply-templates select="child::*[position()=2]"/>
 
199
        <xsl:text>}</xsl:text>
 
200
        <xsl:text>{ </xsl:text>
 
201
        <xsl:apply-templates select="child::*[position()=3]"/>
 
202
        <xsl:text>}</xsl:text>
 
203
        <xsl:text>}</xsl:text>
 
204
</xsl:template>
 
205
 
 
206
 
 
207
<!-- APPLY CONTAINING MAX       -->
 
208
<xsl:template match="mml:apply/mml:max"/>
 
209
<xsl:template match="mml:apply[mml:max]">
 
210
        <xsl:text>{</xsl:text>
 
211
        <xsl:choose>
 
212
                <xsl:when test="mml:bvar"> <!-- if there are bvars-->
 
213
                        <xsl:text>\max_{</xsl:text>
 
214
                <!-- Select every bvar except the last one (position() only counts bvars, not the other siblings)-->
 
215
                        <xsl:for-each select="mml:bvar[position()!=last()]">  
 
216
                        <xsl:apply-templates select="."/><xsl:text>,</xsl:text>
 
217
                        </xsl:for-each>
 
218
                        <xsl:apply-templates select="mml:bvar[position()=last()]"/>
 
219
                        <xsl:text>}</xsl:text>
 
220
                </xsl:when>
 
221
                <xsl:otherwise> <!-- No bvars, no underscore... -->
 
222
                        <xsl:text>\max</xsl:text>
 
223
                </xsl:otherwise>
 
224
        </xsl:choose>
 
225
        <xsl:text>\left\{</xsl:text>
 
226
        <xsl:for-each select="child::*[name()!='mml:condition' and      name()!='mml:bvar' and  name()!='mml:max' and   position()!=last()]">
 
227
                <xsl:apply-templates select="."/><xsl:text>,</xsl:text>
 
228
                <xsl:message>RCAS: MathML mml:apply[mml:min] Applying templates to <xsl:copy-of select="name(.)"/></xsl:message>
 
229
        </xsl:for-each>
 
230
        <xsl:apply-templates select="child::*[name()!='mml:condition' and       name()!='mml:bvar' and  name()!='mml:max' and   position()=last()]"/>
 
231
        <!-- If there is a condition, do not close... -->       
 
232
        <xsl:if test="mml:condition">
 
233
                <xsl:text>|</xsl:text><xsl:apply-templates select="mml:condition"/>
 
234
        </xsl:if>
 
235
        <xsl:text>\right\}</xsl:text>
 
236
        <xsl:text>}</xsl:text>
 
237
</xsl:template>
 
238
 
 
239
 
 
240
<!-- APPLY CONTAINING MIN       -->
 
241
<xsl:template match="mml:apply/mml:min"/>
 
242
<xsl:template match="mml:apply[mml:min]">
 
243
        <xsl:text>{</xsl:text>
 
244
        <xsl:choose>
 
245
                <xsl:when test="mml:bvar"> <!-- if there are bvars-->
 
246
                        <xsl:text>\min_{</xsl:text>
 
247
                        <!-- Select every bvar except the last one (position() only counts bvars, not the other siblings)-->
 
248
                        <xsl:for-each select="mml:bvar[position()!=last()]">  
 
249
                        <xsl:apply-templates select="."/><xsl:text>,</xsl:text>
 
250
                        </xsl:for-each>
 
251
                        <xsl:apply-templates select="mml:bvar[position()=last()]"/>
 
252
                        <xsl:text>}</xsl:text>
 
253
                </xsl:when>
 
254
                <xsl:otherwise> <!-- No bvars, no underscore... -->
 
255
                        <xsl:text>\min</xsl:text>
 
256
                </xsl:otherwise>
 
257
        </xsl:choose>
 
258
        <xsl:text>\left\{</xsl:text>
 
259
        <xsl:for-each select="child::*[name()!='mml:condition' and      name()!='mml:bvar' and  name()!='mml:min' and   position()!=last()]">
 
260
                <xsl:message>RCAS: MathML mml:apply[mml:min] Applying templates to <xsl:copy-of select="name(.)"/></xsl:message>
 
261
                <xsl:apply-templates select="."/>
 
262
                <xsl:text>,</xsl:text>
 
263
        </xsl:for-each>
 
264
        <xsl:apply-templates select="child::*[name()!='mml:condition' and       name()!='mml:bvar' and  name()!='mml:min' and   position()=last()]"/>
 
265
        <!-- If there is a condition, do not close... -->       
 
266
        <xsl:if test="mml:condition">
 
267
                <xsl:text>|</xsl:text><xsl:apply-templates select="mml:condition"/>
 
268
        </xsl:if>
 
269
        <xsl:text>\right\}</xsl:text>
 
270
        <xsl:text>}</xsl:text>
 
271
</xsl:template>
 
272
 
 
273
 
 
274
 
 
275
 
 
276
 
 
277
 
 
278
 
 
279
 
 
280
<!-- APPLY CONTAINING substraction(minus)       -->
 
281
<!-- unary or binary operator                   -->
 
282
<xsl:template match="mml:apply[mml:minus]">
 
283
<xsl:text>{</xsl:text>
 
284
<xsl:choose> <!-- binary -->
 
285
        <xsl:when test="count(child::*)=3">
 
286
                <xsl:apply-templates select="child::*[position()=2]"/>
 
287
                <xsl:text>-</xsl:text>
 
288
                <xsl:choose>
 
289
                <xsl:when test="((name(*[position()=3])='mml:ci' or name(*[position()=3])='mml:cn') and contains(*[position()=3]/text(),'-')) or (name(*[position()=3])='mml:apply')">
 
290
                        <xsl:text>\left(</xsl:text> <xsl:apply-templates select="*[position()=3]"/><xsl:text>\right)</xsl:text>
 
291
                        <!-- surround negative or complex things with brackets -->
 
292
                        </xsl:when>
 
293
                <xsl:otherwise>
 
294
                        <xsl:apply-templates select="*[position()=3]"/>
 
295
                      </xsl:otherwise>
 
296
                </xsl:choose>
 
297
        </xsl:when>
 
298
        <xsl:otherwise> <!-- unary -->
 
299
                <xsl:text>-</xsl:text>
 
300
                <xsl:choose>
 
301
                <xsl:when test=
 
302
                        "((name(*[position()=2])='mml:ci' or name(*[position()=2])='mml:cn') and contains(*[position()=2]/text(),'-')) or (name(*[position()=2])='mml:apply')">
 
303
                        <xsl:text>\left(</xsl:text>
 
304
                                <xsl:apply-templates select="child::*[position()=last()]"/>
 
305
                        <xsl:text>\right)</xsl:text>
 
306
                </xsl:when>
 
307
                <xsl:otherwise>
 
308
                        <xsl:apply-templates select="child::*[position()=last()]"/>
 
309
                </xsl:otherwise>
 
310
                </xsl:choose>
 
311
        </xsl:otherwise>
 
312
</xsl:choose>
 
313
<xsl:text>}</xsl:text>
 
314
</xsl:template>
 
315
 
 
316
 
 
317
<!-- addition -->
 
318
<xsl:template match="mml:apply[mml:plus]">
 
319
  <xsl:choose>
 
320
  <xsl:when test="count(child::*)>=3">
 
321
    <mrow>
 
322
      <xsl:choose>
 
323
        <xsl:when test="((name(*[position()=2])='mml:ci' or name(*[position()=2])='mml:cn') and contains(*[position()=2]/text(),'-')) or (*[position()=2 and self::mml:apply and child::mml:minus])">
 
324
          <mfenced separators=""><xsl:apply-templates select="*[position()=2]"/></mfenced> <!-- surround negative things with brackets -->
 
325
        </xsl:when>
 
326
        <xsl:otherwise>
 
327
          <xsl:apply-templates select="*[position()=2]"/>
 
328
        </xsl:otherwise>
 
329
      </xsl:choose>
 
330
      <xsl:for-each select="child::*[position()!=1 and position()!=2]">
 
331
        <xsl:choose>
 
332
        <xsl:when test="((name(.)='mml:ci' or name(.)='mml:cn') and contains(./text(),'-')) or (self::mml:apply and child::mml:minus)"> <!-- surround negative things with brackets -->
 
333
          <mo>+</mo><mfenced separators=""><xsl:apply-templates select="."/></mfenced>
 
334
        </xsl:when>
 
335
        <xsl:otherwise>
 
336
          <mo>+</mo><xsl:apply-templates select="."/>
 
337
        </xsl:otherwise>
 
338
        </xsl:choose>
 
339
      </xsl:for-each>
 
340
    </mrow>
 
341
  </xsl:when>
 
342
  <xsl:when test="count(child::*)=2">
 
343
    <mrow>
 
344
      <mo>+</mo><xsl:apply-templates select="child::*[position()=2]"/>
 
345
    </mrow>
 
346
  </xsl:when>
 
347
  <xsl:otherwise>
 
348
    <mo>+</mo>
 
349
  </xsl:otherwise>
 
350
  </xsl:choose>
 
351
</xsl:template>
 
352
 
 
353
<!-- power -->
 
354
<xsl:template match="mml:apply[mml:power]">
 
355
        <xsl:text> {</xsl:text>
 
356
        <xsl:choose>
 
357
                <xsl:when test="name(*[position()=2])='mml:apply'">
 
358
                        <xsl:text>\left(</xsl:text>
 
359
                        <xsl:apply-templates select="child::*[position()=2]"/>
 
360
                        <xsl:text>\rigth)</xsl:text>
 
361
                </xsl:when>
 
362
                <xsl:otherwise>
 
363
                        <xsl:apply-templates select="child::*[position()=2]"/>
 
364
                </xsl:otherwise>
 
365
        </xsl:choose>
 
366
        <xsl:text>}^{</xsl:text>
 
367
                <xsl:apply-templates select="child::*[position()=3]"/>
 
368
        <xsl:text>} </xsl:text>
 
369
</xsl:template>
 
370
 
 
371
<!-- remainder -->
 
372
<xsl:template match="mml:apply[mml:rem]">
 
373
  <mrow>
 
374
    <xsl:choose> <!-- surround with brackets if operands are composed-->
 
375
    <xsl:when test="name(*[position()=2])='mml:apply'">
 
376
      <mfenced separators=""><xsl:apply-templates select="*[position()=2]"/></mfenced>
 
377
    </xsl:when>
 
378
    <xsl:otherwise>
 
379
      <xsl:apply-templates select="*[position()=2]"/>
 
380
    </xsl:otherwise>
 
381
    </xsl:choose>
 
382
    <mo>mod</mo>
 
383
    <xsl:choose>
 
384
    <xsl:when test="name(*[position()=3])='mml:apply'">
 
385
      <mfenced separators=""><xsl:apply-templates select="*[position()=3]"/></mfenced>
 
386
    </xsl:when>
 
387
    <xsl:otherwise>
 
388
      <xsl:apply-templates select="*[position()=3]"/>
 
389
    </xsl:otherwise>
 
390
    </xsl:choose>
 
391
  </mrow>
 
392
</xsl:template>
 
393
 
 
394
<!-- multiplication -->
 
395
<xsl:template match="mml:apply[mml:times]">
 
396
<xsl:choose>
 
397
<xsl:when test="count(child::*)>=3">
 
398
  <mrow>
 
399
    <xsl:for-each select="child::*[position()!=last() and  position()!=1]">
 
400
      <xsl:choose>
 
401
      <xsl:when test="mml:plus"> <!--add brackets around + children for priority purpose-->
 
402
        <mfenced separators=""><xsl:apply-templates select="."/></mfenced><mo><mchar name="InvisibleTimes"/></mo>
 
403
      </xsl:when>
 
404
      <xsl:when test="mml:minus"> <!--add brackets around - children for priority purpose-->
 
405
        <mfenced separators=""><xsl:apply-templates select="."/></mfenced><mo><mchar name="InvisibleTimes"/></mo>
 
406
      </xsl:when>
 
407
      <xsl:when test="(name(.)='mml:ci' or name(.)='mml:cn') and contains(text(),'-')"> <!-- have to do it using contains because starts-with doesn't seem to work well in XT-->
 
408
        <mfenced separators=""><xsl:apply-templates select="."/></mfenced><mo><mchar name="InvisibleTimes"/></mo>
 
409
      </xsl:when>
 
410
      <xsl:otherwise>
 
411
        <xsl:apply-templates select="."/><mo><mchar name="InvisibleTimes"/></mo>
 
412
      </xsl:otherwise>
 
413
      </xsl:choose>
 
414
    </xsl:for-each>
 
415
    <xsl:for-each select="child::*[position()=last()]">
 
416
      <xsl:choose>
 
417
      <xsl:when test="mml:plus">
 
418
        <mfenced separators=""><xsl:apply-templates select="."/></mfenced>
 
419
      </xsl:when>
 
420
      <xsl:when test="mml:minus">
 
421
        <mfenced separators=""><xsl:apply-templates select="."/></mfenced>
 
422
      </xsl:when>
 
423
      <xsl:when test="(name(.)='mml:ci' or name(.)='mml:cn') and contains(text(),'-')"> <!-- have to do it using contains because starts-with doesn't seem to work well in  XT-->
 
424
        <mfenced separators=""><xsl:apply-templates select="."/></mfenced>
 
425
      </xsl:when>
 
426
      <xsl:otherwise>
 
427
        <xsl:apply-templates select="."/>
 
428
      </xsl:otherwise>
 
429
      </xsl:choose>
 
430
    </xsl:for-each>
 
431
  </mrow>
 
432
</xsl:when>
 
433
<xsl:when test="count(child::*)=2">  <!-- unary -->
 
434
  <mrow>
 
435
    <mo><mchar name="InvisibleTimes"/></mo>
 
436
    <xsl:choose>
 
437
      <xsl:when test="mml:plus">
 
438
        <mfenced separators=""><xsl:apply-templates select="*[position()=2]"/></mfenced>
 
439
      </xsl:when>
 
440
      <xsl:when test="mml:minus">
 
441
        <mfenced separators=""><xsl:apply-templates select="*[position()=2]"/></mfenced>
 
442
      </xsl:when>
 
443
      <xsl:when test="(*[position()=2 and self::mml:ci] or *[position()=2 and self::mml:cn]) and contains(*[position()=2]/text(),'-')">
 
444
        <mfenced separators=""><xsl:apply-templates select="*[position()=2]"/></mfenced>
 
445
      </xsl:when>
 
446
      <xsl:otherwise>
 
447
        <xsl:apply-templates select="*[position()=2]"/>
 
448
      </xsl:otherwise>
 
449
    </xsl:choose>
 
450
  </mrow>
 
451
</xsl:when>
 
452
<xsl:otherwise>  <!-- no operand -->
 
453
  <mo><mchar name="InvisibleTimes"/></mo>
 
454
</xsl:otherwise>
 
455
</xsl:choose>
 
456
</xsl:template>
 
457
 
 
458
<!-- root -->
 
459
<xsl:template match="mml:apply[mml:root]">
 
460
  <xsl:choose>
 
461
  <xsl:when test="mml:degree">
 
462
    <xsl:choose>
 
463
    <xsl:when test="mml:degree/mml:cn/text()='2'"> <!--if degree=2 display a standard square root-->
 
464
      <msqrt>
 
465
        <xsl:apply-templates select="child::*[position()=3]"/>
 
466
      </msqrt>
 
467
    </xsl:when>
 
468
    <xsl:otherwise>
 
469
      <mroot>
 
470
        <xsl:apply-templates select="child::*[position()=3]"/>
 
471
        <mrow><xsl:apply-templates select="mml:degree/*"/></mrow>
 
472
      </mroot>
 
473
    </xsl:otherwise>
 
474
    </xsl:choose>
 
475
  </xsl:when>
 
476
  <xsl:otherwise> <!-- no degree specified-->
 
477
    <msqrt>
 
478
      <xsl:apply-templates select="child::*[position()=2]"/>
 
479
    </msqrt>
 
480
  </xsl:otherwise>
 
481
  </xsl:choose>
 
482
</xsl:template>
 
483
 
 
484
<!-- greatest common divisor -->
 
485
<xsl:template match="mml:apply[mml:gcd]">
 
486
  <mrow>
 
487
    <mi>gcd</mi><mo><mchar name="ApplyFunction"/></mo>
 
488
    <mfenced>
 
489
      <xsl:apply-templates select="child::*[position()!=1]"/>
 
490
    </mfenced>
 
491
  </mrow>
 
492
</xsl:template>
 
493
 
 
494
<!-- AND -->
 
495
<xsl:template match="mml:apply[mml:and]">
 
496
<mrow>
 
497
  <xsl:choose>
 
498
  <xsl:when test="count(*)>=3"> <!-- at least two operands (common case)-->
 
499
    <xsl:for-each select="child::*[position()!=last() and  position()!=1]">
 
500
      <xsl:choose>
 
501
      <xsl:when test="mml:or"> <!--add brackets around OR children for priority purpose-->
 
502
        <mfenced separators=""><xsl:apply-templates select="."/></mfenced><mo><mchar name="And"/></mo>
 
503
      </xsl:when>
 
504
      <xsl:when test="mml:xor"> <!--add brackets around XOR children for priority purpose-->
 
505
       <mfenced separators=""><xsl:apply-templates select="."/></mfenced><mo><mchar name="And"/></mo> 
 
506
      </xsl:when>
 
507
      <xsl:otherwise>
 
508
        <xsl:apply-templates select="."/><mo><mchar name="And"/></mo>
 
509
      </xsl:otherwise>
 
510
      </xsl:choose>
 
511
    </xsl:for-each>
 
512
    <xsl:for-each select="child::*[position()=last()]">
 
513
      <xsl:choose>
 
514
      <xsl:when test="mml:or">
 
515
        <mfenced separators=""><xsl:apply-templates select="."/></mfenced>
 
516
      </xsl:when>
 
517
      <xsl:when test="mml:xor">
 
518
        <mfenced separators=""><xsl:apply-templates select="."/></mfenced>
 
519
      </xsl:when>
 
520
      <xsl:otherwise>
 
521
        <xsl:apply-templates select="."/>
 
522
      </xsl:otherwise>
 
523
      </xsl:choose>
 
524
    </xsl:for-each>
 
525
  </xsl:when>
 
526
  <xsl:when test="count(*)=2">
 
527
    <mo><mchar name="And"/></mo><xsl:apply-templates select="*[position()=last()]"/>
 
528
  </xsl:when>
 
529
  <xsl:otherwise>
 
530
    <mo><mchar name="And"/></mo>
 
531
  </xsl:otherwise>
 
532
  </xsl:choose>
 
533
</mrow>
 
534
</xsl:template>
 
535
 
 
536
<!-- OR -->
 
537
<xsl:template match="mml:apply[mml:or]">
 
538
<mrow>
 
539
  <xsl:choose>
 
540
  <xsl:when test="count(*)>=3">
 
541
    <xsl:for-each select="child::*[position()!=last() and  position()!=1]">
 
542
      <xsl:apply-templates select="."/><mo><mchar name="Or"/></mo>
 
543
    </xsl:for-each>
 
544
    <xsl:apply-templates select="child::*[position()=last()]"/>
 
545
    </xsl:when>
 
546
    <xsl:when test="count(*)=2">
 
547
      <mo><mchar name="Or"/></mo><xsl:apply-templates select="*[position()=last()]"/>
 
548
  </xsl:when>
 
549
  <xsl:otherwise>
 
550
    <mo><mchar name="Or"/></mo>
 
551
  </xsl:otherwise>
 
552
  </xsl:choose>
 
553
</mrow>
 
554
</xsl:template>
 
555
 
 
556
<!-- XOR -->
 
557
<xsl:template match="mml:apply[mml:xor]">
 
558
<mrow>
 
559
  <xsl:choose>
 
560
  <xsl:when test="count(*)>=3">
 
561
    <xsl:for-each select="child::*[position()!=last() and  position()!=1]">
 
562
      <xsl:apply-templates select="."/><mo>xor</mo>
 
563
    </xsl:for-each>
 
564
    <xsl:apply-templates select="child::*[position()=last()]"/>
 
565
    </xsl:when>
 
566
    <xsl:when test="count(*)=2">
 
567
      <mo>xor</mo><xsl:apply-templates select="*[position()=last()]"/>
 
568
  </xsl:when>
 
569
  <xsl:otherwise>
 
570
    <mo>xor</mo>
 
571
  </xsl:otherwise>
 
572
  </xsl:choose>
 
573
</mrow>
 
574
</xsl:template>
 
575
 
 
576
<!-- NOT -->
 
577
<xsl:template match="mml:apply[mml:not]">
 
578
  <mrow>
 
579
    <mo><mchar name="Not"/></mo>
 
580
    <xsl:choose>
 
581
    <xsl:when test="child::mml:apply"><!--add brackets around OR,AND,XOR children for priority purpose-->
 
582
      <mfenced separators="">
 
583
        <xsl:apply-templates select="child::*[position()=2]"/>
 
584
      </mfenced>
 
585
    </xsl:when>
 
586
    <xsl:otherwise>
 
587
      <xsl:apply-templates select="child::*[position()=2]"/>
 
588
    </xsl:otherwise>
 
589
    </xsl:choose>
 
590
  </mrow>
 
591
</xsl:template>
 
592
 
 
593
<!-- implies -->
 
594
<xsl:template match="mml:apply[mml:implies]">
 
595
  <mrow>
 
596
    <xsl:apply-templates select="child::*[position()=2]"/>
 
597
    <mo><mchar name="DoubleRightArrow"/></mo>
 
598
    <xsl:apply-templates select="child::*[position()=3]"/>
 
599
  </mrow>
 
600
</xsl:template>
 
601
 
 
602
<xsl:template match="mml:reln[mml:implies]">
 
603
  <mrow>
 
604
    <xsl:apply-templates select="child::*[position()=2]"/>
 
605
    <mo><mchar name="DoubleRightArrow"/></mo>
 
606
    <xsl:apply-templates select="child::*[position()=3]"/>
 
607
  </mrow>
 
608
</xsl:template>
 
609
 
 
610
<!-- for all-->
 
611
<xsl:template match="mml:apply[mml:forall]">
 
612
  <mrow>
 
613
    <mo><mchar name="ForAll"/></mo>
 
614
    <mrow>
 
615
      <xsl:for-each select="mml:bvar[position()!=last()]">
 
616
        <xsl:apply-templates select="."/><mo>,</mo>
 
617
      </xsl:for-each>
 
618
      <xsl:apply-templates select="mml:bvar[position()=last()]"/>
 
619
    </mrow>
 
620
    <xsl:if test="mml:condition">
 
621
      <mrow><mo>,</mo><xsl:apply-templates select="mml:condition"/></mrow>
 
622
    </xsl:if>
 
623
    <xsl:choose>
 
624
      <xsl:when test="mml:apply">
 
625
        <mo>:</mo><xsl:apply-templates select="mml:apply"/>
 
626
      </xsl:when>
 
627
      <xsl:when test="mml:reln">
 
628
        <mo>:</mo><xsl:apply-templates select="mml:reln"/>
 
629
      </xsl:when>
 
630
    </xsl:choose>
 
631
  </mrow>
 
632
</xsl:template>
 
633
 
 
634
<!-- in -->
 
635
<xsl:template match="mml:apply[mml:in]">
 
636
        <xsl:text>{</xsl:text>
 
637
        <xsl:apply-templates select="child::*[position()=2]"/>
 
638
        <xsl:text>\in</xsl:text>
 
639
        <xsl:apply-templates select="child::*[position()=3]"/>
 
640
        <xsl:text>}</xsl:text>
 
641
</xsl:template>
 
642
 
 
643
<!-- leq -->
 
644
<xsl:template match="mml:apply[mml:leq]">
 
645
        <xsl:text>{</xsl:text>
 
646
        <xsl:apply-templates select="child::*[position()=2]"/>
 
647
        <xsl:text>\leq</xsl:text>
 
648
        <xsl:apply-templates select="child::*[position()=3]"/>
 
649
        <xsl:text>}</xsl:text>
 
650
</xsl:template>
 
651
 
 
652
<!-- geq -->
 
653
<xsl:template match="mml:apply[mml:geq]">
 
654
        <xsl:text>{</xsl:text>
 
655
        <xsl:apply-templates select="child::*[position()=2]"/>
 
656
        <xsl:text>\geq</xsl:text>
 
657
        <xsl:apply-templates select="child::*[position()=3]"/>
 
658
        <xsl:text>}</xsl:text>
 
659
</xsl:template>
 
660
 
 
661
<!-- domain -->
 
662
<xsl:template match="mml:apply[mml:domain]">
 
663
        <xsl:text>\mbox{dom}(</xsl:text>
 
664
        <xsl:apply-templates select="child::*[position()=2]"/>
 
665
        <xsl:text>)</xsl:text>
 
666
</xsl:template>
 
667
 
 
668
<!-- notin -->
 
669
<xsl:template match="mml:apply[mml:notin]">
 
670
        <xsl:text>{</xsl:text>
 
671
        <xsl:apply-templates select="child::*[position()=2]"/>
 
672
        <xsl:text>\notin</xsl:text>
 
673
        <xsl:apply-templates select="child::*[position()=3]"/>
 
674
        <xsl:text>}</xsl:text>
 
675
</xsl:template>
 
676
 
 
677
<!-- exist-->
 
678
<xsl:template match="mml:apply[mml:exists]">
 
679
  <mrow>
 
680
    <mo><mchar name="Exists"/></mo>
 
681
    <mrow>
 
682
      <xsl:for-each select="mml:bvar[position()!=last()]">
 
683
        <xsl:apply-templates select="."/><mo>,</mo>
 
684
      </xsl:for-each>
 
685
      <xsl:apply-templates select="mml:bvar[position()=last()]"/>
 
686
    </mrow>
 
687
    <xsl:if test="mml:condition">
 
688
      <mrow><mo>,</mo><xsl:apply-templates select="mml:condition"/></mrow>
 
689
    </xsl:if>
 
690
    <xsl:choose>
 
691
      <xsl:when test="mml:apply">
 
692
        <mo>:</mo><xsl:apply-templates select="mml:apply"/>
 
693
      </xsl:when>
 
694
      <xsl:when test="mml:reln">
 
695
        <mo>:</mo><xsl:apply-templates select="mml:reln"/>
 
696
      </xsl:when>
 
697
    </xsl:choose>
 
698
  </mrow>
 
699
</xsl:template>
 
700
 
 
701
<!-- absolute value -->
 
702
<xsl:template match="mml:apply[mml:abs]">
 
703
  <mrow><mo>|</mo><xsl:apply-templates select="child::*[position()=last()]"/><mo>|</mo></mrow>
 
704
</xsl:template>
 
705
 
 
706
<!-- conjugate -->
 
707
<xsl:template match="mml:apply[mml:conjugate]">
 
708
  <mover>
 
709
    <xsl:apply-templates select="child::*[position()=2]"/>
 
710
    <mo><mchar name="ovbar"/></mo>  <!-- does not work, UNICODE x0233D  or perhaps OverBar-->
 
711
  </mover>
 
712
</xsl:template>
 
713
 
 
714
<!-- argument of complex number -->
 
715
<xsl:template match="mml:apply[mml:arg]">
 
716
  <mrow>
 
717
    <mi>arg</mi><mo><mchar name="ApplyFunction"/></mo><mfenced separators=""><xsl:apply-templates select="child::*[position()=2]"/></mfenced>
 
718
  </mrow>
 
719
</xsl:template>
 
720
 
 
721
<!-- real part of complex number -->
 
722
<xsl:template match="mml:apply[mml:real]">
 
723
  <mrow>
 
724
    <mi><xsl:text disable-output-escaping='yes'>&amp;#x0211C;</xsl:text><!-- mchar Re or realpart should work--></mi>
 
725
    <mo><mchar name="ApplyFunction"/></mo>
 
726
    <mfenced separators=""><xsl:apply-templates select="child::*[position()=2]"/></mfenced>
 
727
  </mrow>
 
728
</xsl:template>
 
729
 
 
730
<!-- imaginary part of complex number -->
 
731
<xsl:template match="mml:apply[mml:imaginary]">
 
732
  <mrow>
 
733
    <mi><xsl:text disable-output-escaping='yes'>&amp;#x02111;</xsl:text><!-- mchar Im or impart should work--></mi>
 
734
    <mo><mchar name="ApplyFunction"/></mo>
 
735
    <mfenced separators=""><xsl:apply-templates select="child::*[position()=2]"/></mfenced>
 
736
  </mrow>
 
737
</xsl:template>
 
738
 
 
739
<!-- lowest common multiple -->
 
740
<xsl:template match="mml:apply[mml:lcm]">
 
741
  <mrow>
 
742
    <mi>lcm</mi><mo><mchar name="ApplyFunction"/></mo>
 
743
    <mfenced>
 
744
      <xsl:apply-templates select="child::*[position()!=1]"/>
 
745
    </mfenced>
 
746
  </mrow>
 
747
</xsl:template>
 
748
 
 
749
 
 
750
</xsl:stylesheet>