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