]> matita.cs.unibo.it Git - helm.git/blob - helm/style/mml2mmlv1_0_original.xsl
Initial revision
[helm.git] / helm / style / mml2mmlv1_0_original.xsl
1 <?xml version="1.0"?>
2
3 <!-- ====================================================== -->
4 <!-- XSL Transform of MathML content to MathML presentation -->
5 <!--    By Igor Rodionov, Computer Science Department of    -->
6 <!--   the University of Western Ontario, London, Canada    -->
7 <!--  Complies with the W3C Working Draft from Dec.3, 1999  -->
8 <!--             Version x.xx from Feb. 18, 2000            -->
9 <!--              Comments to:  igor@csd.uwo.ca             -->
10 <!--                                                        -->
11 <!-- (C) Copyright 1999, 2000 Symbolic Computation          -->
12 <!--     Laboratory, University of Western Ontario.         -->
13 <!-- ====================================================== -->
14
15 <!-- ====================================================== -->
16 <!--  May 11, 2000 - HELM group:                            -->
17 <!--  Added the namespace prefix to all the output elements -->
18 <!--  Changed the mml prefix into m                         -->
19 <!--  Swapped math element out of the semantic element      -->
20 <!--  Added the declaration of the xlink namespace          --> 
21 <!-- ====================================================== -->
22
23 <xsl:stylesheet id="mml2mml"
24                 version="1.0"
25                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
26                 xmlns:m="http://www.w3.org/1998/Math/MathML"
27                 xmlns:xlink="http://www.w3.org/1999/xlink">
28
29 <xsl:output method="xml" indent="yes" encoding="iso-8859-1"/>
30
31 <!-- ***************************************************** -->
32 <!--  Parameters affectin' stylesheet's run-time behavior  -->
33 <!-- ***************************************************** -->
34
35 <!-- SEM_SW: -1 - strip off all semantics
36              0  - pass semantics "as is" (default)
37              1  - add semantics at top level only
38              2  - add semantics at all levels
39              3  - semantics at top level with cross-references
40 -->
41 <!-- HELM: SEM_SW was 0 -->
42 <xsl:param name="SEM_SW" select="1"/>
43
44 <!-- Miscellaneous Variable Definitions -->
45
46 <xsl:variable name="NO" select="0"/>
47 <xsl:variable name="YES" select="1"/>
48 <xsl:variable name="PAR_NO" select="-7"/>
49 <xsl:variable name="PAR_YES" select="-5"/>
50 <xsl:variable name="PAR_SAME" select="-3"/>
51 <xsl:variable name="NO_PARAM" select="-1"/>
52
53 <!-- Operator Precedence Definitions -->
54
55 <xsl:variable name="NO_PREC" select="0"/>
56 <xsl:variable name="UNION_PREC" select="1"/>
57 <xsl:variable name="SETDIFF_PREC" select="1"/>
58 <xsl:variable name="INTERSECT_PREC" select="3"/>
59 <xsl:variable name="OR_PREC" select="5"/>
60 <xsl:variable name="XOR_PREC" select="5"/>
61 <xsl:variable name="AND_PREC" select="7"/>
62 <xsl:variable name="PLUS_PREC" select="9"/>
63 <xsl:variable name="MINUS_PREC" select="9"/>
64 <xsl:variable name="MUL_PREC" select="11"/>
65 <xsl:variable name="DIV_PREC" select="11"/>
66 <xsl:variable name="NEG_PREC" select="13"/>
67 <xsl:variable name="FUNCTION_PREC" select="99"/>
68
69
70 <!-- THE TOPMOST ELEMENT: MATH -->
71
72 <xsl:template match = "m:math">
73   <xsl:choose>
74     <xsl:when test="$SEM_SW>0">
75 <!-- HELM: deleted math (we have already inserted at object level) -->
76      <!--<m:math>-->
77       <m:semantics>
78           <xsl:apply-templates mode = "semantics"/>
79        <m:annotation-xml encoding="MathML">
80           <xsl:copy-of select = "*"/>
81        </m:annotation-xml>
82       </m:semantics>
83      <!--</m:math>-->
84     </xsl:when>
85     <xsl:otherwise>
86       <!--<m:math>-->
87         <xsl:apply-templates mode = "semantics"/>
88       <!--</m:math>-->  
89     </xsl:otherwise>
90   </xsl:choose>
91 </xsl:template>
92
93 <!-- SEMANTICS -->
94
95 <xsl:template match = "m:*" mode = "semantics">
96   <xsl:param name="IN_PREC" select="$NO_PREC"/>
97   <xsl:param name="PARAM" select="$NO_PARAM"/>
98   <xsl:param name="PAREN" select="$PAR_NO"/>
99   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
100   <xsl:choose>
101     <xsl:when test="$SEM_SW=-1 and self::m:semantics">
102       <xsl:apply-templates select="*[1]">
103         <xsl:with-param name="IN_PREC" select="$IN_PREC"/>
104         <xsl:with-param name="PARAM" select="$PARAM"/>
105         <xsl:with-param name="PAREN" select="$PAREN"/>
106         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
107       </xsl:apply-templates>
108     </xsl:when>
109     <xsl:when test="$SEM_SW=0 and self::m:semantics">
110       <m:semantics>
111         <xsl:apply-templates select="*[1]">
112           <xsl:with-param name="IN_PREC" select="$IN_PREC"/>
113           <xsl:with-param name="PARAM" select="$PARAM"/>
114           <xsl:with-param name="PAREN" select="$PAREN"/>
115           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
116         </xsl:apply-templates>
117         <xsl:copy-of select="m:annotation-xml"/>
118       </m:semantics>
119     </xsl:when>
120     <xsl:when test="$SEM_SW=2">
121       <m:semantics>
122         <xsl:choose>
123           <xsl:when test="self::m:semantics">
124             <xsl:apply-templates select="*[1]">
125               <xsl:with-param name="IN_PREC" select="$IN_PREC"/>
126               <xsl:with-param name="PARAM" select="$PARAM"/>
127               <xsl:with-param name="PAREN" select="$PAREN"/>
128               <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
129             </xsl:apply-templates>
130             <xsl:copy-of select="m:annotation-xml"/>
131           </xsl:when>
132           <xsl:otherwise>
133             <xsl:apply-templates select=".">
134               <xsl:with-param name="IN_PREC" select="$IN_PREC"/>
135               <xsl:with-param name="PARAM" select="$PARAM"/>
136               <xsl:with-param name="PAREN" select="$PAREN"/>
137               <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
138             </xsl:apply-templates>
139             <m:annotation-xml encoding="MathML">
140               <xsl:copy-of select="."/>
141             </m:annotation-xml>
142           </xsl:otherwise>
143         </xsl:choose>
144       </m:semantics>
145     </xsl:when>
146     <xsl:when test="$SEM_SW=3 and @id">
147       <m:mrow idref="{@id}">
148         <xsl:apply-templates select=".">
149           <xsl:with-param name="IN_PREC" select="$IN_PREC"/>
150           <xsl:with-param name="PARAM" select="$PARAM"/>
151           <xsl:with-param name="PAREN" select="$PAREN"/>
152           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
153         </xsl:apply-templates>
154       </m:mrow>
155     </xsl:when>
156     <xsl:otherwise>
157       <xsl:apply-templates select=".">
158         <xsl:with-param name="IN_PREC" select="$IN_PREC"/>
159         <xsl:with-param name="PARAM" select="$PARAM"/>
160         <xsl:with-param name="PAREN" select="$PAREN"/>
161         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
162       </xsl:apply-templates>
163     </xsl:otherwise>
164   </xsl:choose>
165 </xsl:template>
166
167 <xsl:template match = "m:semantics">
168   <xsl:apply-templates select="*[1]" mode = "semantics"/>
169 </xsl:template>
170
171
172 <!-- BASIC ELEMENTS -->
173
174 <xsl:template match = "m:cn">
175   <xsl:param name="IN_PREC" select="$NO_PREC"/>
176   <xsl:param name="PAREN" select="$PAR_NO"/>
177   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
178   <xsl:choose>
179     <xsl:when test=". &lt; 0 and $IN_PREC &gt; 0 and $PAREN=$PAR_NO and $PAR_NO_IGNORE=$NO">
180       <m:mfenced separators="">
181         <xsl:apply-templates select="." mode="cn"/>
182       </m:mfenced>
183     </xsl:when>
184     <xsl:otherwise>
185       <xsl:apply-templates select="." mode="cn"/>
186     </xsl:otherwise>
187   </xsl:choose>
188 </xsl:template>
189
190 <xsl:template match = "m:cn" mode="cn">
191   <xsl:choose>
192     <xsl:when test="@base and (not(@type) or @type='integer' or @type='real')">
193       <m:msub>
194         <m:mn> <xsl:apply-templates mode = "semantics"/> </m:mn>
195         <m:mn> <xsl:value-of select="@base"/> </m:mn>
196       </m:msub>
197     </xsl:when>
198     <xsl:when test="@type='complex' and not(@base) and child::m:sep[1]">
199       <m:mfenced separators="">
200         <m:mn> <xsl:apply-templates select="text()[1]" mode = "semantics"/> </m:mn>
201         <xsl:if test="text()[2] &lt; 0">
202           <m:mo>-</m:mo>
203           <m:mn> <xsl:value-of select="-text()[2]"/> </m:mn>
204         </xsl:if>
205         <xsl:if test="not(text()[2] &lt; 0)">
206           <m:mo>+</m:mo>
207           <xsl:apply-templates select="text()[2]" mode = "semantics"/>
208         </xsl:if>
209         <m:mo> <mchar name="InvisibleTimes"/> </m:mo>
210         <m:mo>i</m:mo>
211       </m:mfenced>
212     </xsl:when>
213     <xsl:when test="@type='complex' and @base and child::m:sep[1]">
214       <m:msub>
215         <m:mfenced separators="">
216           <m:mn> <xsl:apply-templates select="text()[1]" mode = "semantics"/> </m:mn>
217           <xsl:if test="text()[2] &lt; 0">
218             <m:mo>-</m:mo>
219             <m:mn> <xsl:value-of select="-text()[2]"/> </m:mn>
220           </xsl:if>
221           <xsl:if test="not(text()[2] &lt; 0)">
222             <m:mo>+</m:mo>
223             <m:mn> <xsl:apply-templates select="text()[2]" mode = "semantics"/> </m:mn>
224           </xsl:if>
225           <m:mo> <mchar name="InvisibleTimes"/> </m:mo>
226           <m:mo>i</m:mo>
227         </m:mfenced>
228         <m:mn> <xsl:value-of select="@base"/> </m:mn>
229       </m:msub>
230     </xsl:when>
231     <xsl:when test="@type='rational' and not(@base) and child::m:sep[1]">
232       <m:mrow>
233         <m:mn> <xsl:apply-templates select="text()[1]" mode = "semantics"/> </m:mn>
234         <m:mo>/</m:mo>
235         <m:mn> <xsl:apply-templates select="text()[2]" mode = "semantics"/> </m:mn>
236       </m:mrow>
237     </xsl:when>
238     <xsl:when test="@type='rational' and @base and child::m:sep[1]">
239       <m:msub>
240         <m:mfenced separators="">
241           <m:mn> <xsl:apply-templates select="text()[1]" mode = "semantics"/> </m:mn>
242           <m:mo>/</m:mo>
243           <m:mn> <xsl:apply-templates select="text()[2]" mode = "semantics"/> </m:mn>
244         </m:mfenced>
245         <m:mn> <xsl:value-of select="@base"/> </m:mn>
246       </m:msub>
247     </xsl:when>
248     <xsl:when test="@type='polar' and not(@base) and child::m:sep[1]">
249       <m:mrow>
250         <m:mo>Polar</m:mo>
251         <m:mfenced separators=",">
252           <m:mn> <xsl:apply-templates select="text()[1]" mode = "semantics"/> </m:mn>
253           <m:mn> <xsl:apply-templates select="text()[2]" mode = "semantics"/> </m:mn>
254         </m:mfenced>
255       </m:mrow>
256     </xsl:when>
257     <xsl:when test="@type='polar' and @base and child::m:sep[1]">
258       <m:msub>
259         <m:mrow>
260           <m:mo>Polar</m:mo>
261           <m:mfenced separators=",">
262             <m:mn> <xsl:apply-templates select="text()[1]" mode = "semantics"/> </m:mn>
263             <m:mn> <xsl:apply-templates select="text()[2]" mode = "semantics"/> </m:mn>
264           </m:mfenced>
265         </m:mrow>
266         <m:mn> <xsl:value-of select="@base"/> </m:mn>
267       </m:msub>
268    </xsl:when>
269     <xsl:otherwise>
270       <m:mn> <xsl:apply-templates mode = "semantics"/> </m:mn>
271     </xsl:otherwise>
272   </xsl:choose>
273 </xsl:template>
274
275 <xsl:template match = "m:ci">
276   <xsl:choose>
277     <xsl:when test="@type='vector' or @type=matrix or @type=set">
278       <m:mi fontweight="bold"> <xsl:apply-templates mode = "semantics"/> </m:mi>
279     </xsl:when>
280     <xsl:otherwise>
281 <!-- HELM: aggiunta choose temporanea per HREF invece di:
282 <m:mi> <xsl:apply-templates mode = "semantics"/> </m:mi>-->
283      <xsl:choose>
284      <xsl:when test="string(@definitionURL) = &quot;&quot;">
285       <m:mi> <xsl:apply-templates mode = "semantics"/> </m:mi>
286      </xsl:when>
287      <xsl:otherwise>
288       <m:mi xlink:href="{@definitionURL}"> <xsl:apply-templates mode = "semantics"/> </m:mi>
289      </xsl:otherwise>
290      </xsl:choose>
291     </xsl:otherwise>
292   </xsl:choose>
293 </xsl:template>
294
295 <xsl:template match = "m:csymbol">
296   <xsl:choose>
297     <xsl:when test="*[1]">
298       <xsl:copy-of select = "*"/>
299     </xsl:when>
300     <xsl:otherwise>
301       <m:mo> <xsl:apply-templates mode = "semantics"/> </m:mo>
302     </xsl:otherwise>
303   </xsl:choose>
304 </xsl:template>
305
306
307 <!-- BASIC CONTENT ELEMENTS -->
308
309 <xsl:template match = "m:apply[m:fn[1]]">
310   <m:mrow>
311     <xsl:apply-templates select = "m:fn[1]" mode = "semantics"/>
312     <m:mfenced separators=",">
313       <xsl:apply-templates select = "*[position()>1]" mode = "semantics"/>
314     </m:mfenced>
315   </m:mrow>
316 </xsl:template>
317
318 <xsl:template match = "m:fn">
319   <xsl:apply-templates select = "*[1]" mode = "semantics">
320     <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
321   </xsl:apply-templates>
322 </xsl:template>
323
324 <xsl:template match = "m:interval">
325   <xsl:choose>
326     <xsl:when test="@closure='closed'">
327       <m:mfenced open="[" close="]" separators=",">
328         <xsl:apply-templates mode = "semantics"/>
329       </m:mfenced>
330     </xsl:when>
331     <xsl:when test="@closure='open'">
332       <m:mfenced separators=",">
333         <xsl:apply-templates mode = "semantics"/>
334       </m:mfenced>
335     </xsl:when>
336     <xsl:when test="@closure='open-closed'">
337       <m:mfenced open="(" close="]" separators=",">
338         <xsl:apply-templates mode = "semantics"/>
339       </m:mfenced>
340     </xsl:when>
341     <xsl:when test="@closure='closed-open'">
342       <m:mfenced open="[" close=")" separators=",">
343         <xsl:apply-templates mode = "semantics"/>
344       </m:mfenced>
345     </xsl:when>
346     <xsl:otherwise>
347       <m:mfenced open="[" close="]" separators=",">
348         <xsl:apply-templates mode = "semantics"/>
349       </m:mfenced>
350     </xsl:otherwise>
351   </xsl:choose>
352 </xsl:template>
353
354 <xsl:template match = "m:apply[m:*[1][self::m:apply[m:inverse[1]]]]">
355   <m:mrow>
356     <xsl:apply-templates select = "*[1]" mode = "semantics"/>
357     <m:mfenced separators=",">
358       <xsl:apply-templates select = "*[position()>1]" mode = "semantics"/>
359     </m:mfenced>
360  </m:mrow>
361 </xsl:template>
362
363 <xsl:template match = "m:apply[*[1][self::m:inverse]]">
364   <xsl:choose>
365     <xsl:when test="*[2]=m:exp">
366       <m:mo>ln</m:mo>
367     </xsl:when>
368     <xsl:when test="*[2]=m:ln | m:log">
369       <m:mo>exp</m:mo>
370     </xsl:when>
371     <xsl:when test="*[2]=m:sin">
372       <m:mo>arcsin</m:mo>
373     </xsl:when>
374     <xsl:when test="*[2]=m:cos">
375       <m:mo>arccos</m:mo>
376     </xsl:when>
377     <xsl:when test="*[2]=m:tan">
378       <m:mo>arctan</m:mo>
379     </xsl:when>
380     <xsl:when test="*[2]=m:sec">
381       <m:mo>arcsec</m:mo>
382     </xsl:when>
383     <xsl:when test="*[2]=m:csc">
384       <m:mo>arccsc</m:mo>
385     </xsl:when>
386     <xsl:when test="*[2]=m:cot">
387       <m:mo>arccot</m:mo>
388     </xsl:when>
389     <xsl:when test="*[2]=m:sinh">
390       <m:mo>arcsinh</m:mo>
391     </xsl:when>
392     <xsl:when test="*[2]=m:cosh">
393       <m:mo>arccosh</m:mo>
394     </xsl:when>
395     <xsl:when test="*[2]=m:tanh">
396       <m:mo>arctanh</m:mo>
397     </xsl:when>
398     <xsl:when test="*[2]=m:sech">
399       <m:mo>arcsech</m:mo>
400     </xsl:when>
401     <xsl:when test="*[2]=m:csch">
402       <m:mo>arccsch</m:mo>
403     </xsl:when>
404     <xsl:when test="*[2]=m:coth">
405       <m:mo>arccoth</m:mo>
406     </xsl:when>
407     <xsl:when test="*[2]=m:arcsin">
408       <m:mo>sin</m:mo>
409     </xsl:when>
410     <xsl:when test="*[2]=m:arccos">
411       <m:mo>cos</m:mo>
412     </xsl:when>
413     <xsl:when test="*[2]=m:arctan">
414       <m:mo>tan</m:mo>
415     </xsl:when>
416     <xsl:otherwise>
417       <m:msup>
418         <xsl:apply-templates select = "*[2]" mode = "semantics"/>
419         <m:mfenced>
420           <m:mn>-1</m:mn>
421         </m:mfenced>
422       </m:msup>
423     </xsl:otherwise>
424   </xsl:choose>
425 </xsl:template>
426
427 <xsl:template match = "m:sep"/>
428
429 <xsl:template match = "m:condition">
430   <xsl:choose>
431     <xsl:when test="parent::m:apply[m:forall[1]]"/>
432     <xsl:otherwise>
433       <xsl:if test="not(*[2])">
434         <xsl:apply-templates mode = "semantics"/>
435       </xsl:if>
436       <xsl:if test="*[2]">
437         <m:mrow>
438           <xsl:apply-templates mode = "semantics"/>
439         </m:mrow>
440       </xsl:if>
441     </xsl:otherwise>
442   </xsl:choose>
443 </xsl:template>
444
445 <xsl:template match = "m:declare"/>
446
447 <xsl:template match = "m:lambda">
448   <m:mrow>
449     <m:mo> &#x039b; </m:mo>
450     <m:mfenced separators=",">
451       <xsl:for-each select = "*">
452         <xsl:choose>
453           <xsl:when test="self::m:ci or self::m:cn">
454             <xsl:apply-templates select = "." mode="semantics"/>
455           </xsl:when>
456           <xsl:otherwise>
457             <m:mrow>
458               <xsl:apply-templates select = "." mode="semantics"/>
459             </m:mrow>
460           </xsl:otherwise>
461         </xsl:choose>
462       </xsl:for-each>
463     </m:mfenced>
464   </m:mrow>
465 </xsl:template>
466
467 <xsl:template match = "m:apply[m:*[1][self::m:apply[m:compose[1]]]]">
468   <m:mrow>
469     <xsl:apply-templates select = "*[1]" mode = "semantics"/>
470     <m:mfenced separators=",">
471       <xsl:apply-templates select = "*[position()>1]" mode = "semantics"/>
472     </m:mfenced>
473  </m:mrow>
474 </xsl:template>
475
476 <xsl:template match = "m:apply[*[1][self::m:compose]]">
477   <m:mfenced separators="">
478     <xsl:apply-templates select = "m:*[2][self::m:ci[@type='fn'] | self::m:fn]" mode="semantics"/>
479     <xsl:for-each select = "m:*[position()>2][self::m:ci[@type='fn'] | self::m:fn]">
480       <m:mo> <mchar name="SmallCircle"/> </m:mo>
481       <xsl:apply-templates select = "." mode="semantics"/>
482     </xsl:for-each>
483   </m:mfenced>
484 </xsl:template>
485
486 <xsl:template match = "m:ident">
487   <m:mo>id</m:mo>
488 </xsl:template>
489
490
491 <!-- ARITHMETIC, ALGEBRA & LOGIC -->
492
493 <xsl:template match = "m:apply[m:quotient[1]]">
494   <m:mfenced open="&#x230a;" close="&#x230b;" separators="">
495     <xsl:apply-templates select="*[2]" mode = "semantics">
496       <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
497     </xsl:apply-templates>
498     <m:mo>/</m:mo>
499     <xsl:apply-templates select="*[3]" mode = "semantics">
500       <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
501       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
502     </xsl:apply-templates>
503   </m:mfenced>
504 </xsl:template>
505
506 <xsl:template match = "m:apply[*[1][self::m:exp]]">
507   <m:msup>
508     <m:mo>e</m:mo>
509     <xsl:apply-templates select = "*[2]" mode = "semantics"/>
510   </m:msup>
511 </xsl:template>
512
513 <xsl:template match = "m:apply[m:factorial[1]]">
514   <m:mrow>
515     <xsl:apply-templates select = "*[2]" mode = "semantics">
516       <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
517       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
518     </xsl:apply-templates>
519     <m:mo>!</m:mo>
520   </m:mrow>
521 </xsl:template>
522
523 <xsl:template match = "m:apply[m:max[1] | m:min[1]]">
524   <m:mrow>
525     <xsl:if test="*[2]=m:bvar">
526       <m:munder>
527         <xsl:if test="*[1]=m:max">
528           <m:mo>max</m:mo>
529         </xsl:if>
530         <xsl:if test="*[1]=m:min">
531           <m:mo>min</m:mo>
532         </xsl:if>
533         <xsl:apply-templates select="*[2]" mode = "semantics"/>
534       </m:munder>
535       <xsl:if test="*[3]=m:condition">
536         <m:mfenced open="{{" close="}}" separators="">
537           <m:mfenced open="" close="" separators=",">
538             <xsl:for-each select = "*[position()>3]">
539               <xsl:apply-templates select = "." mode="semantics"/>
540             </xsl:for-each>
541           </m:mfenced>
542           <m:mo>|</m:mo>
543           <xsl:apply-templates select="*[3]" mode = "semantics"/>
544         </m:mfenced>
545       </xsl:if>
546       <xsl:if test="not(*[3]=m:condition)">
547         <m:mfenced open="{{" close="}}" separators=",">
548           <xsl:for-each select = "*[position()>2]">
549             <xsl:apply-templates select = "." mode="semantics"/>
550           </xsl:for-each>
551         </m:mfenced>
552       </xsl:if>
553     </xsl:if>
554     <xsl:if test="*[2]=m:condition">
555       <xsl:if test="*[1]=m:max">
556         <m:mo>max</m:mo>
557       </xsl:if>
558       <xsl:if test="*[1]=m:min">
559         <m:mo>min</m:mo>
560       </xsl:if>
561       <m:mfenced open="{{" close="}}" separators="">
562         <xsl:if test="*[3]">
563           <m:mfenced open="" close="" separators=",">
564             <xsl:for-each select = "*[position()>2]">
565               <xsl:apply-templates select = "." mode="semantics"/>
566             </xsl:for-each>
567           </m:mfenced>
568           <m:mo>|</m:mo>
569         </xsl:if>
570         <xsl:apply-templates select="*[2]" mode = "semantics"/>
571       </m:mfenced>
572     </xsl:if>
573     <xsl:if test="not(*[2]=m:condition) and not(*[2]=m:bvar)">
574       <xsl:if test="*[1]=m:max">
575         <m:mo>max</m:mo>
576       </xsl:if>
577       <xsl:if test="*[1]=m:min">
578         <m:mo>min</m:mo>
579       </xsl:if>
580       <m:mfenced open="{{" close="}}" separators=",">
581         <xsl:for-each select = "*[position()>1]">
582           <xsl:apply-templates select = "." mode="semantics"/>
583         </xsl:for-each>
584       </m:mfenced>
585     </xsl:if>
586   </m:mrow>
587 </xsl:template>
588
589 <xsl:template match = "m:apply[m:minus[1]]">
590   <xsl:param name="IN_PREC" select="$NO_PREC"/>
591   <xsl:param name="PARAM" select="$NO_PARAM"/>
592   <xsl:param name="PAREN" select="$PAR_NO"/>
593   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
594   <xsl:choose>
595     <xsl:when test="$IN_PREC &gt; $MINUS_PREC or $IN_PREC=$MINUS_PREC and $PARAM=$PAR_SAME">
596       <m:mfenced separators="">
597         <xsl:apply-templates select="." mode="minus">
598           <xsl:with-param name="PARAM" select="$PARAM"/>
599           <xsl:with-param name="PAREN" select="$PAR_YES"/>
600           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
601         </xsl:apply-templates>
602       </m:mfenced>
603     </xsl:when>
604     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC and not($SEM_SW=2)">
605       <xsl:apply-templates select="." mode="minus">
606         <xsl:with-param name="PARAM" select="$PARAM"/>
607         <xsl:with-param name="PAREN" select="$PAREN"/>
608         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
609       </xsl:apply-templates>
610     </xsl:when>
611     <xsl:otherwise>
612       <m:mrow>
613         <xsl:apply-templates select="." mode="minus">
614           <xsl:with-param name="PARAM" select="$PARAM"/>
615           <xsl:with-param name="PAREN" select="$PAREN"/>
616           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
617         </xsl:apply-templates>
618       </m:mrow>
619     </xsl:otherwise>
620   </xsl:choose>
621 </xsl:template>
622
623 <xsl:template match = "m:apply[m:minus[1]]" mode="minus">
624   <xsl:param name="PARAM" select="$NO_PARAM"/>
625   <xsl:param name="PAREN" select="$PAR_NO"/>
626   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
627   <xsl:if test="not(*[3])">
628     <m:mo>-</m:mo>
629     <xsl:apply-templates select="*[2]" mode = "semantics">
630       <xsl:with-param name="IN_PREC" select="$NEG_PREC"/>
631       <xsl:with-param name="PAREN" select="$PAREN"/>
632       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
633     </xsl:apply-templates>
634   </xsl:if>
635   <xsl:if test="*[3]">
636     <xsl:apply-templates select="*[2]" mode = "semantics">
637       <xsl:with-param name="IN_PREC" select="$MINUS_PREC"/>
638       <xsl:with-param name="PARAM" select="$PARAM"/>
639       <xsl:with-param name="PAREN" select="$PAREN"/>
640       <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
641     </xsl:apply-templates>
642     <m:mo>-</m:mo>
643     <xsl:apply-templates select="*[3]" mode = "semantics">
644       <xsl:with-param name="IN_PREC" select="$MINUS_PREC"/>
645       <xsl:with-param name="PARAM" select="$PAR_SAME"/>
646       <xsl:with-param name="PAREN" select="$PAREN"/>
647       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
648     </xsl:apply-templates>
649   </xsl:if>
650 </xsl:template>
651
652 <xsl:template match = "m:apply[m:plus[1]]">
653   <xsl:param name="IN_PREC" select="$NO_PREC"/>
654   <xsl:param name="PARAM" select="$NO_PARAM"/>
655   <xsl:param name="PAREN" select="$PAR_NO"/>
656   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
657   <xsl:choose>
658     <xsl:when test="$IN_PREC &gt; $PLUS_PREC or $IN_PREC=$PLUS_PREC and $PARAM=$PAR_SAME">
659       <m:mfenced separators="">
660         <xsl:apply-templates select="." mode="plus">
661           <xsl:with-param name="PARAM" select="$IN_PREC"/>
662           <xsl:with-param name="PAREN" select="$PAR_YES"/>
663           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
664         </xsl:apply-templates>
665       </m:mfenced>
666     </xsl:when>
667     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC and not($SEM_SW=2)">
668       <xsl:apply-templates select="." mode="plus">
669         <xsl:with-param name="PARAM" select="$PARAM"/>
670         <xsl:with-param name="PAREN" select="$PAREN"/>
671         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
672       </xsl:apply-templates>
673     </xsl:when>
674     <xsl:otherwise>
675       <m:mrow>
676         <xsl:apply-templates select="." mode="plus">
677           <xsl:with-param name="PARAM" select="$IN_PREC"/>
678           <xsl:with-param name="PAREN" select="$PAREN"/>
679           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
680         </xsl:apply-templates>
681       </m:mrow>
682     </xsl:otherwise>
683   </xsl:choose>
684 </xsl:template>
685
686 <xsl:template match = "m:apply[m:plus[1]]" mode="plus">
687   <xsl:param name="PARAM" select="$NO_PARAM"/>
688   <xsl:param name="PAREN" select="$PAR_NO"/>
689   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
690   <xsl:if test="*[2]">
691     <xsl:apply-templates select="*[2]" mode = "semantics">
692       <xsl:with-param name="IN_PREC" select="$PLUS_PREC"/>
693       <xsl:with-param name="PARAM" select="$PARAM"/>
694       <xsl:with-param name="PAREN" select="$PAREN"/>
695       <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
696     </xsl:apply-templates>
697     <xsl:for-each select = "*[position()>2]">
698       <xsl:choose>
699         <xsl:when test=". &lt; 0">
700           <m:mo>-</m:mo>
701           <m:mn> <xsl:value-of select="-."/> </m:mn>
702         </xsl:when>
703         <xsl:when test="self::m:apply[m:minus[1]] and not(*[3])">
704           <xsl:apply-templates select="." mode = "semantics">
705             <xsl:with-param name="IN_PREC" select="$PLUS_PREC"/>
706             <xsl:with-param name="PAREN" select="$PAREN"/>
707             <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
708           </xsl:apply-templates>
709         </xsl:when>
710         <xsl:otherwise>
711           <m:mo>+</m:mo>
712           <xsl:apply-templates select="." mode = "semantics">
713             <xsl:with-param name="IN_PREC" select="$PLUS_PREC"/>
714             <xsl:with-param name="PAREN" select="$PAREN"/>
715             <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
716           </xsl:apply-templates>
717         </xsl:otherwise>
718       </xsl:choose>
719     </xsl:for-each>
720   </xsl:if>
721 </xsl:template>
722
723 <xsl:template match = "m:apply[m:power[1]]">
724   <xsl:choose>
725     <xsl:when test="*[2]=m:apply[m:ln[1] | m:log[1] | m:abs[1] | m:gcd[1] | m:sin[1] | m:cos[1] | m:tan[1] | m:sec[1] | m:csc[1] | m:cot[1] | m:sinh[1] | m:cosh[1] | m:tanh[1] | m:sech[1] | m:csch[1] | m:coth[1] | m:arcsin[1] | m:arccos[1] | m:arctan[1]]">
726       <xsl:apply-templates select="*[2]" mode = "semantics"/>
727     </xsl:when>
728     <xsl:otherwise>
729       <m:msup>
730         <xsl:apply-templates select = "*[2]" mode = "semantics">
731           <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
732           <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
733         </xsl:apply-templates>
734         <xsl:apply-templates select = "*[3]" mode = "semantics"/>
735       </m:msup>
736     </xsl:otherwise>
737   </xsl:choose>
738 </xsl:template>
739
740 <xsl:template match = "m:apply[m:rem[1] | m:divide[1]]">
741   <xsl:param name="IN_PREC" select="$NO_PREC"/>
742   <xsl:param name="PARAM" select="$NO_PARAM"/>
743   <xsl:param name="PAREN" select="$PAR_NO"/>
744   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
745   <xsl:choose>
746     <xsl:when test="$IN_PREC &gt; $DIV_PREC or $IN_PREC=$DIV_PREC and $PARAM=$PAR_SAME">
747       <m:mfenced separators="">
748         <xsl:apply-templates select="." mode="remdiv">
749           <xsl:with-param name="PARAM" select="$IN_PREC"/>
750           <xsl:with-param name="PAREN" select="$PAR_YES"/>
751           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
752         </xsl:apply-templates>
753       </m:mfenced>
754     </xsl:when>
755     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC and not($SEM_SW=2)">
756       <xsl:apply-templates select="." mode="remdiv">
757         <xsl:with-param name="PARAM" select="$PARAM"/>
758         <xsl:with-param name="PAREN" select="$PAREN"/>
759         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
760       </xsl:apply-templates>
761     </xsl:when>
762     <xsl:otherwise>
763       <m:mrow>
764         <xsl:apply-templates select="." mode="remdiv">
765           <xsl:with-param name="PARAM" select="$IN_PREC"/>
766           <xsl:with-param name="PAREN" select="$PAREN"/>
767           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
768         </xsl:apply-templates>
769       </m:mrow>
770     </xsl:otherwise>
771   </xsl:choose>
772 </xsl:template>
773
774 <xsl:template match = "m:apply[m:rem[1] | m:divide[1]]" mode="remdiv">
775   <xsl:param name="PARAM" select="$NO_PARAM"/>
776   <xsl:param name="PAREN" select="$PAR_NO"/>
777   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
778   <xsl:apply-templates select = "*[2]" mode = "semantics">
779     <xsl:with-param name="IN_PREC" select="$DIV_PREC"/>
780       <xsl:with-param name="PARAM" select="$PARAM"/>
781       <xsl:with-param name="PAREN" select="$PAREN"/>
782       <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
783   </xsl:apply-templates>
784   <xsl:if test="m:rem">
785     <m:mo>%</m:mo>
786   </xsl:if>
787   <xsl:if test="m:divide">
788     <m:mo>/</m:mo>
789   </xsl:if>
790   <xsl:apply-templates select = "*[3]" mode = "semantics">
791     <xsl:with-param name="IN_PREC" select="$DIV_PREC"/>
792     <xsl:with-param name="PARAM" select="$PAR_SAME"/>
793     <xsl:with-param name="PAREN" select="$PAREN"/>
794     <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
795   </xsl:apply-templates>
796 </xsl:template>
797
798 <xsl:template match = "m:apply[m:times[1]]">
799   <xsl:param name="IN_PREC" select="$NO_PREC"/>
800   <xsl:param name="PARAM" select="$NO_PARAM"/>
801   <xsl:param name="PAREN" select="$PAR_NO"/>
802   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
803   <xsl:choose>
804     <xsl:when test="$IN_PREC &gt; $MUL_PREC or $IN_PREC=$MUL_PREC and $PARAM=$PAR_SAME">
805       <m:mfenced separators="">
806         <xsl:apply-templates select="." mode="times">
807           <xsl:with-param name="PARAM" select="$IN_PREC"/>
808           <xsl:with-param name="PAREN" select="$PAR_YES"/>
809           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
810         </xsl:apply-templates>
811       </m:mfenced>
812     </xsl:when>
813     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC and not($SEM_SW=2)">
814       <xsl:apply-templates select="." mode="times">
815         <xsl:with-param name="PARAM" select="$PARAM"/>
816         <xsl:with-param name="PAREN" select="$PAREN"/>
817         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
818       </xsl:apply-templates>
819     </xsl:when>
820     <xsl:otherwise>
821       <m:mrow>
822         <xsl:apply-templates select="." mode="times">
823           <xsl:with-param name="PARAM" select="$IN_PREC"/>
824           <xsl:with-param name="PAREN" select="$PAREN"/>
825           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
826         </xsl:apply-templates>
827       </m:mrow>
828     </xsl:otherwise>
829   </xsl:choose>
830 </xsl:template>
831
832 <xsl:template match = "m:apply[m:times[1]]" mode="times">
833   <xsl:param name="PARAM" select="$NO_PARAM"/>
834   <xsl:param name="PAREN" select="$PAR_NO"/>
835   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
836   <xsl:apply-templates select="*[2]" mode = "semantics">
837     <xsl:with-param name="IN_PREC" select="$MUL_PREC"/>
838     <xsl:with-param name="PARAM" select="$PARAM"/>
839     <xsl:with-param name="PAREN" select="$PAREN"/>
840     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
841   </xsl:apply-templates>
842   <xsl:if test="*[3]">
843     <xsl:for-each select = "*[position()>2]">
844       <m:mo> <mchar name="InvisibleTimes"/> </m:mo>
845       <xsl:apply-templates select="." mode = "semantics">
846         <xsl:with-param name="IN_PREC" select="$MUL_PREC"/>
847         <xsl:with-param name="PAREN" select="$PAREN"/>
848         <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
849       </xsl:apply-templates>
850     </xsl:for-each>
851   </xsl:if>
852 </xsl:template>
853
854 <xsl:template match = "m:apply[m:root[1]]">
855   <m:msqrt>
856     <xsl:if test="*[2]=m:degree">
857       <xsl:apply-templates select="*[3]" mode = "semantics"/>
858       <xsl:apply-templates select="*[2]" mode = "semantics"/>
859     </xsl:if>
860     <xsl:if test="not(*[2]=m:degree)">
861       <xsl:apply-templates select="*[2]" mode = "semantics"/>
862       <m:mn>2</m:mn>
863     </xsl:if>
864   </m:msqrt>
865 </xsl:template>
866
867 <xsl:template match = "m:apply[m:gcd[1]]">
868   <m:mrow>
869     <xsl:if test="not(parent::m:apply[m:power[1]])">
870       <m:mo>gcd</m:mo>
871     </xsl:if>
872     <xsl:if test="parent::m:apply[m:power[1]]">
873       <m:msup>
874         <m:mo>gcd</m:mo>
875         <xsl:apply-templates select = "../*[3]" mode = "semantics"/>
876       </m:msup>
877     </xsl:if>
878     <m:mfenced separators=",">
879       <xsl:for-each select = "*[position()>1]">
880         <xsl:apply-templates select = "." mode="semantics"/>
881       </xsl:for-each>
882     </m:mfenced>
883   </m:mrow>
884 </xsl:template>
885
886 <xsl:template match = "m:apply[m:and[1]]">
887   <xsl:param name="IN_PREC" select="$NO_PREC"/>
888   <xsl:param name="PAREN" select="$PAR_NO"/>
889   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
890   <xsl:choose>
891     <xsl:when test="$IN_PREC &gt; $AND_PREC">
892       <m:mfenced separators="">
893         <xsl:apply-templates select="." mode="and">
894           <xsl:with-param name="PARAM" select="$IN_PREC"/>
895           <xsl:with-param name="PAREN" select="$PAR_YES"/>
896         </xsl:apply-templates>
897       </m:mfenced>
898     </xsl:when>
899     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC and not($SEM_SW=2)">
900       <xsl:apply-templates select="." mode="and">
901         <xsl:with-param name="PARAM" select="$IN_PREC"/>
902         <xsl:with-param name="PAREN" select="$PAREN"/>
903         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
904       </xsl:apply-templates>
905     </xsl:when>
906     <xsl:otherwise>
907       <m:mrow>
908         <xsl:apply-templates select="." mode="and">
909           <xsl:with-param name="PARAM" select="$IN_PREC"/>
910           <xsl:with-param name="PAREN" select="$PAREN"/>
911           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
912         </xsl:apply-templates>
913       </m:mrow>
914     </xsl:otherwise>
915   </xsl:choose>
916 </xsl:template>
917
918 <xsl:template match = "m:apply[m:and[1]]" mode="and">
919   <xsl:param name="PARAM" select="$NO_PARAM"/>
920   <xsl:param name="PAREN" select="$PAR_NO"/>
921   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
922   <xsl:apply-templates select="*[2]" mode = "semantics">
923     <xsl:with-param name="IN_PREC" select="$AND_PREC"/>
924     <xsl:with-param name="PARAM" select="$PARAM"/>
925     <xsl:with-param name="PAREN" select="$PAREN"/>
926     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
927   </xsl:apply-templates>
928   <xsl:for-each select = "*[position()>2]">
929     <m:mo> <mchar name="wedge"/> </m:mo>
930     <xsl:apply-templates select="." mode = "semantics">
931       <xsl:with-param name="IN_PREC" select="$AND_PREC"/>
932       <xsl:with-param name="PAREN" select="$PAREN"/>
933       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
934     </xsl:apply-templates>
935   </xsl:for-each>
936 </xsl:template>
937
938 <xsl:template match = "m:apply[m:or[1]]">
939   <xsl:param name="IN_PREC" select="$NO_PREC"/>
940   <xsl:param name="PAREN" select="$PAR_NO"/>
941   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
942   <xsl:choose>
943     <xsl:when test="$IN_PREC &gt; $OR_PREC">
944       <m:mfenced separators="">
945         <xsl:apply-templates select="." mode="or">
946           <xsl:with-param name="PARAM" select="$IN_PREC"/>
947           <xsl:with-param name="PAREN" select="$PAR_YES"/>
948         </xsl:apply-templates>
949       </m:mfenced>
950     </xsl:when>
951     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC and not($SEM_SW=2)">
952       <xsl:apply-templates select="." mode="or">
953         <xsl:with-param name="PARAM" select="$IN_PREC"/>
954         <xsl:with-param name="PAREN" select="$PAREN"/>
955         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
956       </xsl:apply-templates>
957     </xsl:when>
958     <xsl:otherwise>
959       <m:mrow>
960         <xsl:apply-templates select="." mode="or">
961           <xsl:with-param name="PARAM" select="$IN_PREC"/>
962           <xsl:with-param name="PAREN" select="$PAREN"/>
963           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
964         </xsl:apply-templates>
965       </m:mrow>
966     </xsl:otherwise>
967   </xsl:choose>
968 </xsl:template>
969
970 <xsl:template match = "m:apply[m:or[1]]" mode="or">
971   <xsl:param name="PARAM" select="$NO_PARAM"/>
972   <xsl:param name="PAREN" select="$PAR_NO"/>
973   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
974   <xsl:apply-templates select="*[2]" mode = "semantics">
975     <xsl:with-param name="IN_PREC" select="$OR_PREC"/>
976     <xsl:with-param name="PARAM" select="$PARAM"/>
977     <xsl:with-param name="PAREN" select="$PAREN"/>
978     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
979   </xsl:apply-templates>
980   <xsl:for-each select = "*[position()>2]">
981     <m:mo> <mchar name="vee"/> </m:mo>
982     <xsl:apply-templates select="." mode = "semantics">
983       <xsl:with-param name="IN_PREC" select="$OR_PREC"/>
984       <xsl:with-param name="PAREN" select="$PAREN"/>
985       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
986     </xsl:apply-templates>
987   </xsl:for-each>
988 </xsl:template>
989
990 <xsl:template match = "m:apply[m:xor[1]]">
991   <xsl:param name="IN_PREC" select="$NO_PREC"/>
992   <xsl:param name="PAREN" select="$PAR_NO"/>
993   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
994   <xsl:choose>
995     <xsl:when test="$IN_PREC &gt; $XOR_PREC">
996       <m:mfenced separators="">
997         <xsl:apply-templates select="." mode="xor">
998           <xsl:with-param name="PARAM" select="$IN_PREC"/>
999           <xsl:with-param name="PAREN" select="$PAR_YES"/>
1000           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1001         </xsl:apply-templates>
1002       </m:mfenced>
1003     </xsl:when>
1004     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC and not($SEM_SW=2)">
1005       <xsl:apply-templates select="." mode="xor">
1006         <xsl:with-param name="PARAM" select="$IN_PREC"/>
1007         <xsl:with-param name="PAREN" select="$PAREN"/>
1008       </xsl:apply-templates>
1009     </xsl:when>
1010     <xsl:otherwise>
1011       <m:mrow>
1012         <xsl:apply-templates select="." mode="xor">
1013           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1014           <xsl:with-param name="PAREN" select="$PAREN"/>
1015           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1016         </xsl:apply-templates>
1017       </m:mrow>
1018     </xsl:otherwise>
1019   </xsl:choose>
1020 </xsl:template>
1021
1022 <xsl:template match = "m:apply[m:xor[1]]" mode="xor">
1023   <xsl:param name="PARAM" select="$NO_PARAM"/>
1024   <xsl:param name="PAREN" select="$PAR_NO"/>
1025   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1026   <xsl:apply-templates select="*[2]" mode = "semantics">
1027     <xsl:with-param name="IN_PREC" select="$XOR_PREC"/>
1028     <xsl:with-param name="PARAM" select="$PARAM"/>
1029     <xsl:with-param name="PAREN" select="$PAREN"/>
1030     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1031   </xsl:apply-templates>
1032   <xsl:for-each select = "*[position()>2]">
1033     <m:mo> <mchar name="xor"/> </m:mo>
1034     <xsl:apply-templates select="." mode = "semantics">
1035       <xsl:with-param name="IN_PREC" select="$XOR_PREC"/>
1036       <xsl:with-param name="PAREN" select="$PAREN"/>
1037       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1038     </xsl:apply-templates>
1039   </xsl:for-each>
1040 </xsl:template>
1041
1042 <xsl:template match = "m:apply[m:not[1]]">
1043   <m:mrow>
1044     <m:mo>not</m:mo>
1045     <xsl:apply-templates select = "*[2]" mode = "semantics">
1046       <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
1047     </xsl:apply-templates>
1048   </m:mrow>
1049 </xsl:template>
1050
1051 <xsl:template match = "m:apply[m:forall[1]]">
1052   <m:mrow>
1053     <m:mo>for all</m:mo>
1054     <m:mfenced separators=",">
1055       <xsl:for-each select = "m:bvar">
1056         <xsl:apply-templates select = "." mode="semantics"/>
1057       </xsl:for-each>
1058     </m:mfenced>
1059     <xsl:if test="m:condition">
1060       <m:mo>:</m:mo>
1061       <xsl:apply-templates select = "m:condition/*" mode = "semantics"/>
1062       <m:mo>,</m:mo>
1063     </xsl:if>
1064     <xsl:apply-templates select = "*[position()>1 and not(self::m:bvar) and not(self::m:condition)]" mode = "semantics"/>
1065   </m:mrow>
1066 </xsl:template>
1067
1068 <xsl:template match = "m:apply[m:exists[1]]">
1069   <m:mrow>
1070     <m:mo> <mchar name="Exists"/> </m:mo>
1071     <m:mfenced separators=",">
1072       <xsl:for-each select = "m:bvar">
1073         <xsl:apply-templates select = "." mode="semantics"/>
1074       </xsl:for-each>
1075     </m:mfenced>
1076     <xsl:if test="m:condition">
1077       <m:mo>,</m:mo>
1078       <xsl:apply-templates select = "m:condition/*" mode = "semantics"/>
1079     </xsl:if>
1080     <m:mo>:</m:mo>
1081     <xsl:apply-templates select = "*[position()>1 and not(self::m:bvar) and not(self::m:condition)]" mode = "semantics"/>
1082   </m:mrow>
1083 </xsl:template>
1084
1085 <xsl:template match = "m:apply[m:abs[1]]">
1086   <xsl:if test="not(parent::m:apply[m:power[1]])">
1087     <m:mfenced open="|" close="|" separators="">
1088       <xsl:apply-templates select = "*[position()>1]" mode = "semantics"/>
1089     </m:mfenced>
1090   </xsl:if>
1091   <xsl:if test="parent::m:apply[m:power[1]]">
1092     <m:msup>
1093       <m:mfenced open="|" close="|" separators="">
1094         <xsl:apply-templates select = "*[position()>1]" mode = "semantics"/>
1095       </m:mfenced>
1096       <xsl:apply-templates select = "../*[3]" mode = "semantics"/>
1097     </m:msup>
1098   </xsl:if>
1099 </xsl:template>
1100
1101 <xsl:template match = "m:apply[m:conjugate[1]]">
1102   <m:mover>
1103     <m:mrow>
1104       <xsl:apply-templates select = "*[position()>1]" mode = "semantics"/>
1105     </m:mrow>
1106     <m:mo> <mchar name="UnderBar"/> </m:mo>
1107   </m:mover>
1108 </xsl:template>
1109
1110 <xsl:template match = "m:apply[m:arg[1] | m:real[1] | m:imaginary[1]]">
1111   <m:mrow>
1112     <xsl:choose>
1113       <xsl:when test="m:arg">
1114         <m:mo>arg</m:mo>
1115       </xsl:when>
1116       <xsl:when test="m:real">
1117         <m:mo>Real</m:mo>
1118       </xsl:when>
1119       <xsl:when test="m:imaginary">
1120         <m:mo>Imaginary</m:mo>
1121       </xsl:when>
1122     </xsl:choose>
1123     <m:mfenced separators="">
1124       <xsl:apply-templates select = "*[2]" mode = "semantics"/>
1125     </m:mfenced>
1126   </m:mrow>
1127 </xsl:template>
1128
1129
1130 <!-- RELATIONS -->
1131
1132 <xsl:template match = "m:apply[m:neq | m:approx | m:tendsto | m:implies | m:in | m:notin | m:notsubset | m:notprsubset | m:subset | m:prsubset | m:eq | m:gt | m:lt | m:geq | m:leq | m:equivalent]">
1133   <m:mrow>
1134     <xsl:if test="*[1]=m:neq or *[1]=m:approx or *[1]=m:tendsto or *[1]=m:implies or *[1]=m:in or *[1]=m:notin or *[1]=m:notsubset or *[1]=m:notprsubset">
1135       <xsl:apply-templates select = "*[2]" mode = "semantics"/>
1136       <xsl:if test="*[1]=m:neq">
1137         <m:mo> <mchar name="NotEqual"/> </m:mo>
1138       </xsl:if>
1139       <xsl:if test="*[1]=m:approx">
1140         <m:mo> <mchar name="approxeq"/> </m:mo>
1141       </xsl:if>
1142       <xsl:if test="*[1]=m:tendsto">
1143         <m:mo> <mchar name="RightArrow"/> </m:mo>
1144       </xsl:if>
1145       <xsl:if test="*[1]=m:implies">
1146         <m:mo> <mchar name="DoubleRightArrow"/> </m:mo>
1147       </xsl:if>
1148       <xsl:if test="*[1]=m:in">
1149         <m:mo> <mchar name="Element"/> </m:mo>
1150       </xsl:if>
1151       <xsl:if test="*[1]=m:notin">
1152         <m:mo> <mchar name="NotElement"/> </m:mo>
1153       </xsl:if>
1154       <xsl:if test="*[1]=m:notsubset">
1155         <m:mo> <mchar name="NotSubset"/> </m:mo>
1156       </xsl:if>
1157       <xsl:if test="*[1]=m:notprsubset">
1158         <m:mo> <mchar name="NotSubsetEqual"/> </m:mo>
1159       </xsl:if>
1160       <xsl:apply-templates select = "*[3]" mode = "semantics"/>
1161       <xsl:if test="*[1]=m:tendsto and m:tendsto[1][@type='below']">
1162         <m:mo>-</m:mo>
1163       </xsl:if>
1164       <xsl:if test="*[1]=m:tendsto and m:tendsto[1][@type='above']">
1165         <m:mo>+</m:mo>
1166       </xsl:if>
1167     </xsl:if>
1168     <xsl:if test="*[1]=m:subset or *[1]=m:prsubset or *[1]=m:eq or *[1]=m:gt or *[1]=m:lt or *[1]=m:geq or *[1]=m:leq or *[1]=m:equivalent">
1169       <xsl:apply-templates select = "*[2]" mode="semantics"/>
1170       <xsl:for-each select = "*[position()>2]">
1171         <xsl:if test="../*[self::m:subset][1]">
1172           <m:mo>  <mchar name="SubsetEqual"/> </m:mo>
1173         </xsl:if>
1174         <xsl:if test="../*[self::m:prsubset][1]">
1175           <m:mo> <mchar name="subset"/> </m:mo>
1176         </xsl:if>
1177         <xsl:if test="../*[self::m:eq][1]">
1178           <m:mo>=</m:mo>
1179         </xsl:if>
1180         <xsl:if test="../*[self::m:gt][1]">
1181           <m:mo>&gt;</m:mo>
1182         </xsl:if>
1183         <xsl:if test="../*[self::m:lt][1]">
1184           <m:mo>&lt;</m:mo>
1185         </xsl:if>
1186         <xsl:if test="../*[self::m:geq][1]">
1187           <m:mo> <mchar name="geq"/> </m:mo>
1188         </xsl:if>
1189         <xsl:if test="../*[self::m:leq][1]">
1190           <m:mo> <mchar name="leq"/> </m:mo>
1191         </xsl:if>
1192         <xsl:if test="../*[self::m:equivalent][1]">
1193           <m:mo> <mchar name="Congruent"/> </m:mo>
1194         </xsl:if>
1195         <xsl:apply-templates select = "." mode="semantics"/>
1196       </xsl:for-each>
1197     </xsl:if>
1198   </m:mrow>
1199 </xsl:template>
1200
1201
1202 <!-- CALCULUS -->
1203
1204 <xsl:template match = "m:apply[*[1][self::m:ln]]">
1205   <m:mrow>
1206     <xsl:choose>
1207       <xsl:when test="parent::m:apply[m:power[1]]">
1208         <m:msup>
1209           <m:mo>ln</m:mo>
1210           <xsl:apply-templates select = "../*[3]" mode = "semantics"/>
1211         </m:msup>
1212       </xsl:when>
1213       <xsl:otherwise>
1214         <m:mo>ln</m:mo>
1215       </xsl:otherwise>
1216     </xsl:choose>
1217     <xsl:apply-templates select = "*[2]" mode = "semantics">
1218       <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
1219     </xsl:apply-templates>
1220   </m:mrow>
1221 </xsl:template>
1222
1223 <xsl:template match = "m:apply[m:log[1]]">
1224   <m:mrow>
1225     <xsl:choose>
1226       <xsl:when test="parent::m:apply[m:power[1]]">
1227         <xsl:if test="not(*[2]=m:logbase)">
1228           <m:msup>
1229             <m:mo>log</m:mo>
1230             <xsl:apply-templates select = "../*[3]" mode = "semantics"/>
1231           </m:msup>
1232         </xsl:if>
1233         <xsl:if test="*[2]=m:logbase">
1234           <m:msubsup>
1235             <m:mo>log</m:mo>
1236             <xsl:apply-templates select = "../*[3]" mode = "semantics"/>
1237             <xsl:apply-templates select = "m:logbase" mode = "semantics"/>
1238           </m:msubsup>
1239         </xsl:if>
1240       </xsl:when>
1241       <xsl:otherwise>
1242         <xsl:if test="not(*[2]=m:logbase)">
1243           <m:mo>log</m:mo>
1244         </xsl:if>
1245         <xsl:if test="*[2]=m:logbase">
1246           <m:msub>
1247             <m:mo>log</m:mo>
1248             <xsl:apply-templates select = "m:logbase" mode = "semantics"/>
1249           </m:msub>
1250         </xsl:if>
1251       </xsl:otherwise>
1252     </xsl:choose>
1253     <xsl:if test="*[2]=m:logbase">
1254       <xsl:apply-templates select = "*[3]" mode = "semantics">
1255         <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
1256       </xsl:apply-templates>
1257     </xsl:if>
1258     <xsl:if test="not(*[2]=m:logbase)">
1259       <xsl:apply-templates select = "*[2]" mode = "semantics">
1260         <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
1261       </xsl:apply-templates>
1262     </xsl:if>
1263   </m:mrow>
1264 </xsl:template>
1265
1266 <xsl:template match = "m:apply[m:diff[1]]">
1267   <m:mrow>
1268     <xsl:if test="*[2]=m:bvar and m:bvar[*[2]=m:degree]">
1269       <m:mfrac>
1270         <m:msup>
1271           <m:mo>d</m:mo>
1272           <xsl:apply-templates select = "m:bvar/m:degree" mode = "semantics"/>
1273         </m:msup>
1274         <m:mrow>
1275           <m:mo>d</m:mo>
1276           <m:msup>
1277             <xsl:apply-templates select = "m:bvar/*[1]" mode = "semantics"/>
1278             <xsl:apply-templates select = "m:bvar/m:degree" mode = "semantics"/>
1279           </m:msup>
1280         </m:mrow>
1281       </m:mfrac>
1282     </xsl:if>
1283     <xsl:if test="*[2]=m:bvar and not(m:bvar[*[2]=m:degree])">
1284       <m:mfrac>
1285         <m:mo>d</m:mo>
1286         <m:mrow>
1287           <m:mo>d</m:mo>
1288           <xsl:apply-templates select = "m:bvar/*[1]" mode = "semantics"/>
1289         </m:mrow>
1290       </m:mfrac>
1291     </xsl:if>
1292     <xsl:apply-templates select = "*[3]" mode = "semantics"/>
1293   </m:mrow>
1294 </xsl:template>
1295
1296 <xsl:template match = "m:apply[m:partialdiff[1]]">
1297   <m:mrow>
1298     <xsl:for-each select = "m:bvar">
1299       <xsl:if test="*[last()]=m:degree">
1300         <m:mfrac>
1301           <m:msup>
1302              <m:mo>d</m:mo>
1303              <xsl:apply-templates select = "m:degree" mode = "semantics"/>
1304           </m:msup>
1305           <m:mrow>
1306             <m:mo>d</m:mo>
1307             <m:msup>
1308               <xsl:apply-templates select = "*[1]" mode = "semantics"/>
1309               <xsl:apply-templates select = "m:degree" mode = "semantics"/>
1310             </m:msup>
1311           </m:mrow>
1312         </m:mfrac>
1313       </xsl:if>
1314       <xsl:if test="not(*[last()]=m:degree)">
1315         <m:mfrac>
1316           <m:mo>d</m:mo>
1317           <m:mrow>
1318             <m:mo>d</m:mo>
1319             <xsl:apply-templates select = "*[1]" mode = "semantics"/>
1320           </m:mrow>
1321         </m:mfrac>
1322       </xsl:if>
1323     </xsl:for-each>
1324     <xsl:apply-templates select = "*[last()]" mode = "semantics"/>
1325   </m:mrow>
1326 </xsl:template>
1327
1328 <xsl:template match = "m:lowlimit | m:uplimit | m:bvar | m:degree | m:logbase">
1329   <xsl:apply-templates mode = "semantics"/>
1330 </xsl:template>
1331
1332 <xsl:template match = "m:apply[m:divergence[1] | m:grad[1] | m:curl[1]]">
1333   <m:mrow>
1334     <xsl:if test="*[1]=m:divergence">
1335       <m:mo>div</m:mo>
1336     </xsl:if>
1337     <xsl:if test="*[1]=m:grad">
1338     <m:mo>grad</m:mo>
1339     </xsl:if>
1340     <xsl:if test="*[1]=m:curl">
1341     <m:mo>curl</m:mo>
1342     </xsl:if>
1343     <xsl:choose>
1344       <xsl:when test="*[2]=m:ci">
1345         <xsl:apply-templates select = "*[2]" mode = "semantics"/>
1346       </xsl:when>
1347       <xsl:otherwise>
1348         <m:mfenced separators="">
1349           <xsl:apply-templates select = "*[2]" mode = "semantics"/>
1350         </m:mfenced>
1351       </xsl:otherwise>
1352     </xsl:choose>
1353   </m:mrow>
1354 </xsl:template>
1355
1356 <xsl:template match = "m:apply[m:laplacian[1]]">
1357   <m:mrow>
1358     <m:msup>
1359       <m:mo> &#x0394; </m:mo>
1360       <m:mn>2</m:mn>
1361     </m:msup>
1362     <xsl:apply-templates select = "*[2]" mode = "semantics"/>
1363   </m:mrow>
1364 </xsl:template>
1365
1366
1367 <!-- SET THEORY -->
1368
1369 <xsl:template match = "m:set | m:list">
1370   <m:mfenced open="{{" close="}}" separators="">
1371     <xsl:if test="*[1]=m:bvar and *[2]=m:condition">
1372       <xsl:apply-templates select="m:bvar" mode = "semantics"/>
1373       <m:mo>|</m:mo>
1374       <xsl:apply-templates select="m:condition" mode = "semantics"/>
1375     </xsl:if>
1376     <xsl:if test="*[1]=m:condition and not(child::m:bvar)">
1377       <m:mfenced open="" close="" separators=",">
1378         <xsl:for-each select = "*[not(self::m:condition) and not(self::m:bvar)]">
1379           <xsl:apply-templates select = "." mode="semantics"/>
1380         </xsl:for-each>
1381       </m:mfenced>
1382       <m:mo>|</m:mo>
1383       <xsl:apply-templates select="m:condition" mode = "semantics"/>
1384     </xsl:if>
1385     <xsl:if test="not(child::m:bvar) and not(child::m:condition)">
1386       <m:mfenced open="" close="" separators=",">
1387         <xsl:for-each select = "*">
1388           <xsl:apply-templates select = "." mode="semantics"/>
1389         </xsl:for-each>
1390       </m:mfenced>
1391     </xsl:if>
1392   </m:mfenced>
1393 </xsl:template>
1394
1395 <xsl:template match = "m:apply[m:union[1]]">
1396   <xsl:param name="IN_PREC" select="$NO_PREC"/>
1397   <xsl:param name="PARAM" select="$NO_PARAM"/>
1398   <xsl:param name="PAREN" select="$PAR_NO"/>
1399   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1400   <xsl:choose>
1401     <xsl:when test="$IN_PREC &gt; $UNION_PREC or $IN_PREC=$UNION_PREC and $PARAM=$PAR_SAME">
1402       <m:mfenced separators="">
1403         <xsl:apply-templates select="." mode="union">
1404           <xsl:with-param name="PARAM" select="$PARAM"/>
1405           <xsl:with-param name="PAREN" select="$PAREN"/>
1406           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1407         </xsl:apply-templates>
1408       </m:mfenced>
1409     </xsl:when>
1410     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC and not($SEM_SW=2)">
1411       <xsl:apply-templates select="." mode="union">
1412         <xsl:with-param name="PARAM" select="$PARAM"/>
1413         <xsl:with-param name="PAREN" select="$PAREN"/>
1414         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1415       </xsl:apply-templates>
1416     </xsl:when>
1417     <xsl:otherwise>
1418       <m:mrow>
1419         <xsl:apply-templates select="." mode="union">
1420           <xsl:with-param name="PARAM" select="$PARAM"/>
1421           <xsl:with-param name="PAREN" select="$PAREN"/>
1422           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1423         </xsl:apply-templates>
1424       </m:mrow>
1425     </xsl:otherwise>
1426   </xsl:choose>
1427 </xsl:template>
1428
1429 <xsl:template match = "m:apply[m:union[1]]" mode="union">
1430   <xsl:param name="PARAM" select="$NO_PARAM"/>
1431   <xsl:param name="PAREN" select="$PAR_NO"/>
1432   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1433   <xsl:apply-templates select = "*[2]" mode="semantics">
1434     <xsl:with-param name="IN_PREC" select="$UNION_PREC"/>
1435     <xsl:with-param name="PARAM" select="$PARAM"/>
1436     <xsl:with-param name="PAREN" select="$PAREN"/>
1437     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1438   </xsl:apply-templates>
1439   <xsl:for-each select = "*[position()>2]">
1440     <m:mo> <mchar name="Union"/> </m:mo>
1441     <xsl:apply-templates select = "." mode="semantics">
1442       <xsl:with-param name="IN_PREC" select="$UNION_PREC"/>
1443       <xsl:with-param name="PAREN" select="$PAREN"/>
1444       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1445     </xsl:apply-templates>
1446   </xsl:for-each>
1447 </xsl:template>
1448
1449 <xsl:template match = "m:apply[m:intersect[1]]">
1450   <xsl:param name="IN_PREC" select="$NO_PREC"/>
1451   <xsl:param name="PARAM" select="$NO_PARAM"/>
1452   <xsl:param name="PAREN" select="$PAR_NO"/>
1453   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1454   <xsl:choose>
1455     <xsl:when test="$IN_PREC &gt; $INTERSECT_PREC">
1456       <m:mfenced separators="">
1457         <xsl:apply-templates select="." mode="intersect">
1458           <xsl:with-param name="PARAM" select="$PARAM"/>
1459           <xsl:with-param name="PAREN" select="$PAREN"/>
1460           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1461         </xsl:apply-templates>
1462       </m:mfenced>
1463     </xsl:when>
1464     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC and not($SEM_SW=2)">
1465       <xsl:apply-templates select="." mode="intersect">
1466         <xsl:with-param name="PARAM" select="$PARAM"/>
1467         <xsl:with-param name="PAREN" select="$PAREN"/>
1468         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1469       </xsl:apply-templates>
1470     </xsl:when>
1471     <xsl:otherwise>
1472       <m:mrow>
1473         <xsl:apply-templates select="." mode="intersect">
1474           <xsl:with-param name="PARAM" select="$PARAM"/>
1475           <xsl:with-param name="PAREN" select="$PAREN"/>
1476           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1477         </xsl:apply-templates>
1478       </m:mrow>
1479     </xsl:otherwise>
1480   </xsl:choose>
1481 </xsl:template>
1482
1483 <xsl:template match = "m:apply[m:intersect[1]]" mode="intersect">
1484   <xsl:param name="PARAM" select="$NO_PARAM"/>
1485   <xsl:param name="PAREN" select="$PAR_NO"/>
1486   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1487   <xsl:apply-templates select = "*[2]" mode="semantics">
1488     <xsl:with-param name="IN_PREC" select="$INTERSECT_PREC"/>
1489     <xsl:with-param name="PARAM" select="$PARAM"/>
1490     <xsl:with-param name="PAREN" select="$PAREN"/>
1491     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1492   </xsl:apply-templates>
1493   <xsl:for-each select = "*[position()>2]">
1494     <m:mo> <mchar name="Intersection"/> </m:mo>
1495     <xsl:apply-templates select = "." mode="semantics">
1496       <xsl:with-param name="IN_PREC" select="$INTERSECT_PREC"/>
1497       <xsl:with-param name="PAREN" select="$PAREN"/>
1498       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1499     </xsl:apply-templates>
1500   </xsl:for-each>
1501 </xsl:template>
1502
1503 <xsl:template match = "m:apply[m:setdiff[1]]">
1504   <xsl:param name="IN_PREC" select="$NO_PREC"/>
1505   <xsl:param name="PARAM" select="$NO_PARAM"/>
1506   <xsl:param name="PAREN" select="$PAR_NO"/>
1507   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1508   <xsl:choose>
1509     <xsl:when test="$IN_PREC &gt; $SETDIFF_PREC or $IN_PREC=$SETDIFF_PREC and $PARAM=$PAR_SAME">
1510       <m:mfenced separators="">
1511         <xsl:apply-templates select="." mode="setdiff">
1512           <xsl:with-param name="PARAM" select="$PARAM"/>
1513           <xsl:with-param name="PAREN" select="$PAREN"/>
1514           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1515         </xsl:apply-templates>
1516       </m:mfenced>
1517     </xsl:when>
1518     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC and not($SEM_SW=2)">
1519       <xsl:apply-templates select="." mode="setdiff">
1520         <xsl:with-param name="PARAM" select="$PARAM"/>
1521         <xsl:with-param name="PAREN" select="$PAREN"/>
1522         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1523       </xsl:apply-templates>
1524     </xsl:when>
1525     <xsl:otherwise>
1526       <m:mrow>
1527         <xsl:apply-templates select="." mode="setdiff">
1528           <xsl:with-param name="PARAM" select="$PARAM"/>
1529           <xsl:with-param name="PAREN" select="$PAREN"/>
1530           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1531         </xsl:apply-templates>
1532       </m:mrow>
1533     </xsl:otherwise>
1534   </xsl:choose>
1535 </xsl:template>
1536
1537 <xsl:template match = "m:apply[m:setdiff[1]]" mode="setdiff">
1538   <xsl:param name="PARAM" select="$NO_PARAM"/>
1539   <xsl:param name="PAREN" select="$PAR_NO"/>
1540   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1541   <xsl:apply-templates select = "*[2]" mode = "semantics">
1542     <xsl:with-param name="IN_PREC" select="$SETDIFF_PREC"/>
1543     <xsl:with-param name="PARAM" select="$PARAM"/>
1544     <xsl:with-param name="PAREN" select="$PAREN"/>
1545     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1546   </xsl:apply-templates>
1547   <m:mo>\</m:mo>
1548   <xsl:apply-templates select = "*[3]" mode = "semantics">
1549     <xsl:with-param name="IN_PREC" select="$SETDIFF_PREC"/>
1550     <xsl:with-param name="PARAM" select="$PAR_SAME"/>
1551     <xsl:with-param name="PAREN" select="$PAREN"/>
1552     <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1553   </xsl:apply-templates>
1554 </xsl:template>
1555
1556 <xsl:template match = "m:apply[m:card[1]]">
1557   <m:mfenced open="|" close="|" separators=",">
1558     <xsl:for-each select = "*[position()>1]">
1559       <xsl:apply-templates select = "." mode="semantics"/>
1560     </xsl:for-each>
1561   </m:mfenced>
1562 </xsl:template>
1563
1564
1565 <!-- SEQUENCES AND SERIES -->
1566
1567 <xsl:template match = "m:apply[m:sum[1] | m:product[1]]">
1568   <m:mrow>
1569     <xsl:choose>
1570       <xsl:when test="*[2]=m:bvar and m:lowlimit and m:uplimit">
1571         <m:munderover>
1572           <xsl:if test="*[1]=m:sum">
1573             <m:mo> <mchar name="Sum"/> </m:mo>
1574           </xsl:if>
1575           <xsl:if test="*[1]=m:product">
1576             <m:mo> <mchar name="Product"/> </m:mo>
1577           </xsl:if>
1578           <m:mrow>
1579             <xsl:apply-templates select = "*[2]" mode = "semantics"/>
1580             <m:mo>=</m:mo>
1581             <xsl:apply-templates select = "m:lowlimit" mode = "semantics"/>
1582           </m:mrow>
1583           <xsl:apply-templates select = "m:uplimit" mode = "semantics"/>
1584         </m:munderover>
1585         <xsl:apply-templates select = "*[5]" mode = "semantics"/>
1586       </xsl:when>
1587       <xsl:when test="*[2]=m:bvar and *[3]=m:condition">
1588         <m:munder>
1589           <xsl:if test="*[1]=m:sum">
1590             <m:mo> <mchar name="Sum"/> </m:mo>
1591           </xsl:if>
1592           <xsl:if test="*[1]=m:product">
1593             <m:mo> <mchar name="Product"/> </m:mo>
1594           </xsl:if>
1595           <xsl:apply-templates select = "*[3]" mode = "semantics"/>
1596         </m:munder>
1597         <xsl:apply-templates select = "*[4]" mode = "semantics"/>
1598       </xsl:when>
1599     </xsl:choose>
1600   </m:mrow>
1601 </xsl:template>
1602
1603 <xsl:template match = "m:apply[m:limit[1]]">
1604   <m:mrow>
1605     <m:munder>
1606       <m:mo>lim</m:mo>
1607       <m:mrow>
1608         <xsl:if test="*[2]=m:bvar and *[3]=m:lowlimit">
1609             <xsl:apply-templates select = "*[2]" mode = "semantics"/>
1610             <m:mo> <mchar name="RightArrow"/> </m:mo>
1611             <xsl:apply-templates select = "*[3]" mode = "semantics"/>
1612         </xsl:if>
1613         <xsl:if test="*[2]=m:bvar and *[3]=m:condition">
1614           <xsl:apply-templates select = "*[3]" mode = "semantics"/>
1615         </xsl:if>
1616       </m:mrow>
1617     </m:munder>
1618     <xsl:apply-templates select = "*[4]" mode = "semantics"/>
1619   </m:mrow>
1620 </xsl:template>
1621
1622
1623 <!-- TRIGONOMETRY -->
1624
1625 <xsl:template match = "m:apply[*[1][self::m:sin | self::m:cos | self::m:tan | self::m:sec | self::m:csc | self::m:cot | self::m:sinh | self::m:cosh | self::m:tanh | self::m:sech | self::m:csch | self::m:coth | self::m:arcsin | self::m:arccos | self::m:arctan]]">
1626   <m:mrow>
1627     <xsl:if test="not(parent::m:apply[m:power[1]])">
1628       <xsl:apply-templates select = "*[1]" mode = "trigonometry"/>
1629     </xsl:if>
1630     <xsl:if test="parent::m:apply[m:power[1]]">
1631       <m:msup>
1632         <xsl:apply-templates select = "*[1]" mode = "trigonometry"/>
1633         <xsl:apply-templates select = "../*[3]" mode = "semantics"/>
1634       </m:msup>
1635     </xsl:if>
1636     <xsl:apply-templates select = "*[2]" mode = "semantics">
1637       <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
1638       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1639     </xsl:apply-templates>
1640   </m:mrow>
1641 </xsl:template>
1642
1643 <xsl:template match = "m:*" mode = "trigonometry">
1644     <xsl:choose>
1645       <xsl:when test="self::m:sin">
1646         <m:mo>sin</m:mo>
1647       </xsl:when>
1648       <xsl:when test="self::m:cos">
1649         <m:mo>cos</m:mo>
1650       </xsl:when>
1651       <xsl:when test="self::m:tan">
1652         <m:mo>tan</m:mo>
1653       </xsl:when>
1654       <xsl:when test="self::m:sec">
1655         <m:mo>sec</m:mo>
1656       </xsl:when>
1657       <xsl:when test="self::m:csc">
1658         <m:mo>csc</m:mo>
1659       </xsl:when>
1660       <xsl:when test="self::m:cot">
1661         <m:mo>cot</m:mo>
1662       </xsl:when>
1663       <xsl:when test="self::m:sinh">
1664         <m:mo>sinh</m:mo>
1665       </xsl:when>
1666       <xsl:when test="self::m:cosh">
1667         <m:mo>cosh</m:mo>
1668       </xsl:when>
1669       <xsl:when test="self::m:tanh">
1670         <m:mo>tanh</m:mo>
1671       </xsl:when>
1672       <xsl:when test="self::m:sech">
1673         <m:mo>sech</m:mo>
1674       </xsl:when>
1675       <xsl:when test="self::m:csch">
1676         <m:mo>csch</m:mo>
1677       </xsl:when>
1678       <xsl:when test="self::m:coth">
1679         <m:mo>coth</m:mo>
1680       </xsl:when>
1681       <xsl:when test="self::m:arcsin">
1682         <m:mo>arcsin</m:mo>
1683       </xsl:when>
1684       <xsl:when test="self::m:arccos">
1685         <m:mo>arccos</m:mo>
1686       </xsl:when>
1687       <xsl:when test="self::m:arctan">
1688         <m:mo>arctan</m:mo>
1689       </xsl:when>
1690     </xsl:choose>
1691 </xsl:template>
1692
1693
1694 <!-- STATISTICS -->
1695
1696 <xsl:template match = "m:apply[m:mean[1]]">
1697   <m:mfenced open="&lt;" close="&gt;" separators=",">
1698     <xsl:for-each select = "*[position()>1]">
1699       <xsl:apply-templates select = "." mode="semantics"/>
1700     </xsl:for-each>
1701   </m:mfenced>
1702 </xsl:template>
1703
1704 <xsl:template match = "m:apply[m:sdev[1]]">
1705   <m:mrow>
1706     <m:mo> &#x03c3; </m:mo>
1707     <m:mfenced separators=",">
1708       <xsl:for-each select = "*[position()>1]">
1709         <xsl:apply-templates select = "." mode="semantics"/>
1710       </xsl:for-each>
1711     </m:mfenced>
1712   </m:mrow>
1713 </xsl:template>
1714
1715 <xsl:template match = "m:apply[m:variance[1]]">
1716   <m:mrow>
1717     <m:mo> &#x03c3; </m:mo>
1718     <m:msup>
1719       <m:mfenced separators=",">
1720         <xsl:for-each select = "*[position()>1]">
1721           <xsl:apply-templates select = "." mode="semantics"/>
1722         </xsl:for-each>
1723       </m:mfenced>
1724       <m:mn>2</m:mn>
1725     </m:msup>
1726   </m:mrow>
1727 </xsl:template>
1728
1729 <xsl:template match = "m:apply[m:median[1]]">
1730   <m:mrow>
1731     <m:mo>median</m:mo>
1732     <m:mfenced separators=",">
1733       <xsl:for-each select = "*[position()>1]">
1734         <xsl:apply-templates select = "." mode="semantics"/>
1735       </xsl:for-each>
1736     </m:mfenced>
1737   </m:mrow>
1738 </xsl:template>
1739
1740 <xsl:template match = "m:apply[m:mode[1]]">
1741   <m:mrow>
1742     <m:mo>mode</m:mo>
1743     <m:mfenced separators=",">
1744       <xsl:for-each select = "*[position()>1]">
1745         <xsl:apply-templates select = "." mode="semantics"/>
1746       </xsl:for-each>
1747     </m:mfenced>
1748   </m:mrow>
1749 </xsl:template>
1750
1751 <xsl:template match = "m:apply[m:moment[1]]">
1752   <m:mfenced open="&lt;" close="&gt;" separators="">
1753     <xsl:if test="*[2]=m:degree">
1754       <m:msup>
1755         <xsl:apply-templates select="*[3]" mode = "semantics"/>
1756         <xsl:apply-templates select="*[2]" mode = "semantics"/>
1757       </m:msup>
1758     </xsl:if>
1759     <xsl:if test="not(*[2]=m:degree)">
1760       <xsl:for-each select = "*[position()>1]">
1761         <xsl:apply-templates select = "." mode="semantics"/>
1762       </xsl:for-each>
1763     </xsl:if>
1764   </m:mfenced>
1765 </xsl:template>
1766
1767
1768 <!-- LINEAR ALGEBRA -->
1769
1770 <xsl:template match="m:vector">
1771   <m:mfenced separators="">
1772     <m:mtable>
1773       <xsl:for-each select="*">
1774         <m:mtd>
1775           <xsl:apply-templates select="." mode = "semantics"/>
1776         </m:mtd>
1777       </xsl:for-each>
1778     </m:mtable>
1779   </m:mfenced>
1780 </xsl:template>
1781
1782 <xsl:template match = "m:matrix">
1783   <m:mfenced separators="">
1784     <m:mtable>
1785       <xsl:apply-templates mode = "semantics"/>
1786     </m:mtable>
1787   </m:mfenced>
1788 </xsl:template>
1789
1790 <xsl:template match = "m:matrixrow">
1791   <m:mtr>
1792     <xsl:for-each select="*">
1793       <m:mtd>
1794         <xsl:apply-templates select="." mode = "semantics"/>
1795       </m:mtd>
1796     </xsl:for-each>
1797   </m:mtr>
1798 </xsl:template>
1799
1800 <xsl:template match = "m:apply[m:determinant[1]]">
1801   <m:mrow>
1802     <m:mo>det</m:mo>
1803     <xsl:apply-templates select = "*[2]" mode = "semantics"/>
1804   </m:mrow>
1805 </xsl:template>
1806
1807 <xsl:template match = "m:apply[m:transpose[1]]">
1808   <m:msup>
1809     <xsl:apply-templates select = "*[2]" mode = "semantics"/>
1810     <m:mo>T</m:mo>
1811   </m:msup>
1812 </xsl:template>
1813
1814 <xsl:template match = "m:apply[m:selector[1]]">
1815   <xsl:if test="*[2]=m:matrix and *[3]=m:cn">
1816       <xsl:variable name="m" select = "*[3]"/>
1817       <xsl:choose>
1818         <xsl:when test="*[4]=m:cn">
1819           <xsl:variable name="n" select = "*[4]"/>
1820           <xsl:copy-of select = "m:matrix/*[position()=$m]/*[position()=$n]"/>
1821         </xsl:when>
1822         <xsl:otherwise>
1823           <xsl:copy-of select = "m:matrix/*[position()=$m]"/>
1824         </xsl:otherwise>
1825       </xsl:choose>
1826   </xsl:if>
1827   <xsl:if test="(*[2]=m:vector or *[2]=m:list) and *[3]=m:cn">
1828     <xsl:variable name="m" select = "*[3]"/>
1829     <xsl:copy-of select = "*[2]/*[position()=$m]"/>
1830   </xsl:if>
1831 </xsl:template>
1832
1833 <xsl:template match = "m:apply[m:vectorproduct[1] | m:scalarproduct[1] | m:outerproduct[1]]">
1834   <m:mrow>
1835     <xsl:apply-templates select="*[2]" mode = "semantics"/>
1836     <xsl:choose>
1837       <xsl:when test="m:vectorproduct[1]">
1838         <m:mo> <mchar name="Cross"/> </m:mo>
1839       </xsl:when>
1840       <xsl:when test="m:scalarproduct[1] | m:outerproduct[1]">
1841         <m:mo>.</m:mo>
1842       </xsl:when>
1843     </xsl:choose>
1844     <xsl:apply-templates select="*[3]" mode = "semantics"/>
1845   </m:mrow>
1846 </xsl:template>
1847
1848 </xsl:stylesheet>