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