]> matita.cs.unibo.it Git - helm.git/blob - helm/style/mml2mmlv1_0.xsl
Some bug fixed
[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 <!-- <CSC> Originale:
347      <m:mi> 
348       <xsl:call-template name="insert"/>
349       <xsl:apply-templates mode = "semantics"/> 
350      </m:mi>
351 </CSC> -->
352 <!-- <CSC> Modificato: -->
353  <xsl:choose>
354   <xsl:when test="child::text()">
355    <m:mi> 
356     <xsl:call-template name="insert"/>
357     <xsl:apply-templates mode = "semantics"/> 
358    </m:mi>
359   </xsl:when>
360   <xsl:otherwise>
361    <xsl:copy-of select="*"/> 
362   </xsl:otherwise>
363  </xsl:choose>
364 <!-- </CSC> -->
365     </xsl:otherwise>
366   </xsl:choose>
367 </xsl:template>
368
369 <xsl:template match = "m:csymbol">
370   <xsl:choose>
371     <xsl:when test="*[1]">
372       <xsl:copy-of select = "*"/>
373     </xsl:when>
374     <xsl:otherwise>
375       <m:mo> <xsl:apply-templates mode = "semantics"/> </m:mo>
376     </xsl:otherwise>
377   </xsl:choose>
378 </xsl:template>
379
380
381 <!-- BASIC CONTENT ELEMENTS -->
382
383 <xsl:template match = "m:apply[m:fn[1]]">
384   <m:mrow>
385     <xsl:apply-templates select = "m:fn[1]" mode = "semantics"/>
386     <m:mfenced separators=",">
387       <xsl:apply-templates select = "*[position()>1]" mode = "semantics"/>
388     </m:mfenced>
389   </m:mrow>
390 </xsl:template>
391
392 <xsl:template match = "m:fn">
393   <xsl:apply-templates select = "*[1]" mode = "semantics">
394     <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
395   </xsl:apply-templates>
396 </xsl:template>
397
398 <xsl:template match = "m:interval">
399   <xsl:choose>
400     <xsl:when test="@closure='closed'">
401       <m:mfenced open="[" close="]" separators=",">
402         <xsl:apply-templates mode = "semantics"/>
403       </m:mfenced>
404     </xsl:when>
405     <xsl:when test="@closure='open'">
406       <m:mfenced separators=",">
407         <xsl:apply-templates mode = "semantics"/>
408       </m:mfenced>
409     </xsl:when>
410     <xsl:when test="@closure='open-closed'">
411       <m:mfenced open="(" close="]" separators=",">
412         <xsl:apply-templates mode = "semantics"/>
413       </m:mfenced>
414     </xsl:when>
415     <xsl:when test="@closure='closed-open'">
416       <m:mfenced open="[" close=")" separators=",">
417         <xsl:apply-templates mode = "semantics"/>
418       </m:mfenced>
419     </xsl:when>
420     <xsl:otherwise>
421       <m:mfenced open="[" close="]" separators=",">
422         <xsl:apply-templates mode = "semantics"/>
423       </m:mfenced>
424     </xsl:otherwise>
425   </xsl:choose>
426 </xsl:template>
427
428 <xsl:template match = "m:apply[m:*[1][self::m:apply[m:inverse[1]]]]">
429   <m:mrow>
430     <xsl:apply-templates select = "*[1]" mode = "semantics"/>
431     <m:mfenced separators=",">
432       <xsl:apply-templates select = "*[position()>1]" mode = "semantics"/>
433     </m:mfenced>
434  </m:mrow>
435 </xsl:template>
436
437 <!-- HELM: these "semantical" Transformations are REALLY questionable.
438      Andrea -->
439
440 <xsl:template match = "m:apply[*[1][self::m:inverse]]">
441   <xsl:choose>
442     <xsl:when test="*[2]=m:exp">
443       <m:mo>ln</m:mo>
444     </xsl:when>
445     <xsl:when test="*[2]=m:ln | m:log">
446       <m:mo>exp</m:mo>
447     </xsl:when>
448     <xsl:when test="*[2]=m:sin">
449       <m:mo>arcsin</m:mo>
450     </xsl:when>
451     <xsl:when test="*[2]=m:cos">
452       <m:mo>arccos</m:mo>
453     </xsl:when>
454     <xsl:when test="*[2]=m:tan">
455       <m:mo>arctan</m:mo>
456     </xsl:when>
457     <xsl:when test="*[2]=m:sec">
458       <m:mo>arcsec</m:mo>
459     </xsl:when>
460     <xsl:when test="*[2]=m:csc">
461       <m:mo>arccsc</m:mo>
462     </xsl:when>
463     <xsl:when test="*[2]=m:cot">
464       <m:mo>arccot</m:mo>
465     </xsl:when>
466     <xsl:when test="*[2]=m:sinh">
467       <m:mo>arcsinh</m:mo>
468     </xsl:when>
469     <xsl:when test="*[2]=m:cosh">
470       <m:mo>arccosh</m:mo>
471     </xsl:when>
472     <xsl:when test="*[2]=m:tanh">
473       <m:mo>arctanh</m:mo>
474     </xsl:when>
475     <xsl:when test="*[2]=m:sech">
476       <m:mo>arcsech</m:mo>
477     </xsl:when>
478     <xsl:when test="*[2]=m:csch">
479       <m:mo>arccsch</m:mo>
480     </xsl:when>
481     <xsl:when test="*[2]=m:coth">
482       <m:mo>arccoth</m:mo>
483     </xsl:when>
484     <xsl:when test="*[2]=m:arcsin">
485       <m:mo>sin</m:mo>
486     </xsl:when>
487     <xsl:when test="*[2]=m:arccos">
488       <m:mo>cos</m:mo>
489     </xsl:when>
490     <xsl:when test="*[2]=m:arctan">
491       <m:mo>tan</m:mo>
492     </xsl:when>
493     <xsl:otherwise>
494       <m:msup>
495         <xsl:apply-templates select = "*[2]" mode = "semantics"/>
496         <m:mfenced>
497           <m:mn>-1</m:mn>
498         </m:mfenced>
499       </m:msup>
500     </xsl:otherwise>
501   </xsl:choose>
502 </xsl:template>
503
504 <xsl:template match = "m:sep"/>
505
506 <xsl:template match = "m:condition">
507   <xsl:choose>
508     <xsl:when test="parent::m:apply[m:forall[1]]"/>
509     <xsl:otherwise>
510       <xsl:if test="not(*[2])">
511         <xsl:apply-templates mode = "semantics"/>
512       </xsl:if>
513       <xsl:if test="*[2]">
514         <m:mrow>
515           <xsl:apply-templates mode = "semantics"/>
516         </m:mrow>
517       </xsl:if>
518     </xsl:otherwise>
519   </xsl:choose>
520 </xsl:template>
521
522 <xsl:template match = "m:declare"/>
523
524 <xsl:template match = "m:lambda">
525   <m:mrow>
526     <m:mo> &#x039b; </m:mo>
527     <m:mfenced separators=",">
528       <xsl:for-each select = "*">
529         <xsl:choose>
530           <xsl:when test="self::m:ci or self::m:cn">
531             <xsl:apply-templates select = "." mode="semantics"/>
532           </xsl:when>
533           <xsl:otherwise>
534             <m:mrow>
535               <xsl:apply-templates select = "." mode="semantics"/>
536             </m:mrow>
537           </xsl:otherwise>
538         </xsl:choose>
539       </xsl:for-each>
540     </m:mfenced>
541   </m:mrow>
542 </xsl:template>
543
544 <xsl:template match = "m:apply[m:*[1][self::m:apply[m:compose[1]]]]">
545   <m:mrow>
546     <xsl:apply-templates select = "*[1]" mode = "semantics"/>
547     <m:mfenced separators=",">
548       <xsl:apply-templates select = "*[position()>1]" mode = "semantics"/>
549     </m:mfenced>
550  </m:mrow>
551 </xsl:template>
552
553 <xsl:template match = "m:apply[*[1][self::m:compose]]">
554   <m:mfenced separators="">
555     <xsl:apply-templates select = "m:*[2][self::m:ci[@type='fn'] | self::m:fn]" mode="semantics"/>
556     <xsl:for-each select = "m:*[position()>2][self::m:ci[@type='fn'] | self::m:fn]">
557       <m:mo> <xsl:call-template name="insert2"/> <mchar name="SmallCircle"/> </m:mo>
558       <xsl:apply-templates select = "." mode="semantics"/>
559     </xsl:for-each>
560   </m:mfenced>
561 </xsl:template>
562
563 <xsl:template match = "m:ident">
564   <m:mo>id</m:mo>
565 </xsl:template>
566
567
568 <!-- ARITHMETIC, ALGEBRA & LOGIC -->
569
570 <xsl:template match = "m:apply[m:quotient[1]]">
571   <m:mfenced open="&#x230a;" close="&#x230b;" separators="">
572     <xsl:call-template name="insert_xref"/>
573     <xsl:apply-templates select="*[2]" mode = "semantics">
574       <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
575     </xsl:apply-templates>
576     <m:mo><xsl:call-template name="insert1"/>/</m:mo>
577     <xsl:apply-templates select="*[3]" mode = "semantics">
578       <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
579       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
580     </xsl:apply-templates>
581   </m:mfenced>
582 </xsl:template>
583
584 <xsl:template match = "m:apply[*[1][self::m:exp]]">
585   <m:msup>
586     <m:mo>e</m:mo>
587     <xsl:apply-templates select = "*[2]" mode = "semantics"/>
588   </m:msup>
589 </xsl:template>
590
591 <xsl:template match = "m:apply[m:factorial[1]]">
592   <m:mrow>
593     <xsl:call-template name="insert_xref"/>
594     <xsl:apply-templates select = "*[2]" mode = "semantics">
595       <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
596       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
597     </xsl:apply-templates>
598     <m:mo><xsl:call-template name="insert1"/>!</m:mo>
599   </m:mrow>
600 </xsl:template>
601
602 <xsl:template match = "m:apply[m:max[1] | m:min[1]]">
603   <m:mrow>
604     <xsl:call-template name="insert_xref"/>
605     <xsl:if test="*[2]=m:bvar">
606       <m:munder>
607         <xsl:if test="*[1]=m:max">
608           <m:mo><xsl:call-template name="insert1"/>max</m:mo>
609         </xsl:if>
610         <xsl:if test="*[1]=m:min">
611           <m:mo>min</m:mo>
612         </xsl:if>
613         <xsl:apply-templates select="*[2]" mode = "semantics"/>
614       </m:munder>
615       <xsl:if test="*[3]=m:condition">
616         <m:mfenced open="{{" close="}}" separators="">
617           <m:mfenced open="" close="" separators=",">
618             <xsl:for-each select = "*[position()>3]">
619               <xsl:apply-templates select = "." mode="semantics"/>
620             </xsl:for-each>
621           </m:mfenced>
622           <m:mo>|</m:mo>
623           <xsl:apply-templates select="*[3]" mode = "semantics"/>
624         </m:mfenced>
625       </xsl:if>
626       <xsl:if test="not(*[3]=m:condition)">
627         <m:mfenced open="{{" close="}}" separators=",">
628           <xsl:for-each select = "*[position()>2]">
629             <xsl:apply-templates select = "." mode="semantics"/>
630           </xsl:for-each>
631         </m:mfenced>
632       </xsl:if>
633     </xsl:if>
634     <xsl:if test="*[2]=m:condition">
635       <xsl:if test="*[1]=m:max">
636         <m:mo>max</m:mo>
637       </xsl:if>
638       <xsl:if test="*[1]=m:min">
639         <m:mo>min</m:mo>
640       </xsl:if>
641       <m:mfenced open="{{" close="}}" separators="">
642         <xsl:if test="*[3]">
643           <m:mfenced open="" close="" separators=",">
644             <xsl:for-each select = "*[position()>2]">
645               <xsl:apply-templates select = "." mode="semantics"/>
646             </xsl:for-each>
647           </m:mfenced>
648           <m:mo>|</m:mo>
649         </xsl:if>
650         <xsl:apply-templates select="*[2]" mode = "semantics"/>
651       </m:mfenced>
652     </xsl:if>
653     <xsl:if test="not(*[2]=m:condition) and not(*[2]=m:bvar)">
654       <xsl:if test="*[1]=m:max">
655         <m:mo>max</m:mo>
656       </xsl:if>
657       <xsl:if test="*[1]=m:min">
658         <m:mo><xsl:call-template name="insert1"/>min</m:mo>
659       </xsl:if>
660       <m:mfenced open="{{" close="}}" separators=",">
661         <xsl:for-each select = "*[position()>1]">
662           <xsl:apply-templates select = "." mode="semantics"/>
663         </xsl:for-each>
664       </m:mfenced>
665     </xsl:if>
666   </m:mrow>
667 </xsl:template>
668
669 <xsl:template match = "m:apply[m:minus[1]]">
670   <xsl:param name="IN_PREC" select="$NO_PREC"/>
671   <xsl:param name="PARAM" select="$NO_PARAM"/>
672   <xsl:param name="PAREN" select="$PAR_NO"/>
673   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
674   <xsl:choose>
675     <xsl:when test="$IN_PREC &gt; $MINUS_PREC or $IN_PREC=$MINUS_PREC and $PARAM=$PAR_SAME">
676       <m:mfenced separators="">
677         <xsl:call-template name="insert_xref"/>
678         <xsl:apply-templates select="." mode="minus">
679           <xsl:with-param name="PARAM" select="$PARAM"/>
680           <xsl:with-param name="PAREN" select="$PAR_YES"/>
681           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
682         </xsl:apply-templates>
683       </m:mfenced>
684     </xsl:when>
685     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC and not($SEM_SW=2)">
686       <xsl:apply-templates select="." mode="minus">
687         <xsl:with-param name="PARAM" select="$PARAM"/>
688         <xsl:with-param name="PAREN" select="$PAREN"/>
689         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
690       </xsl:apply-templates>
691     </xsl:when>
692     <xsl:otherwise>
693       <m:mrow>
694         <xsl:call-template name="insert_xref"/>
695         <xsl:apply-templates select="." mode="minus">
696           <xsl:with-param name="PARAM" select="$PARAM"/>
697           <xsl:with-param name="PAREN" select="$PAREN"/>
698           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
699         </xsl:apply-templates>
700       </m:mrow>
701     </xsl:otherwise>
702   </xsl:choose>
703 </xsl:template>
704
705 <xsl:template match = "m:apply[m:minus[1]]" mode="minus">
706   <xsl:param name="PARAM" select="$NO_PARAM"/>
707   <xsl:param name="PAREN" select="$PAR_NO"/>
708   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
709   <xsl:if test="not(*[3])">
710     <m:mo><xsl:call-template name="insert1"/>-</m:mo>
711     <xsl:apply-templates select="*[2]" mode = "semantics">
712       <xsl:with-param name="IN_PREC" select="$NEG_PREC"/>
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:if test="*[3]">
718     <xsl:apply-templates select="*[2]" mode = "semantics">
719       <xsl:with-param name="IN_PREC" select="$MINUS_PREC"/>
720       <xsl:with-param name="PARAM" select="$PARAM"/>
721       <xsl:with-param name="PAREN" select="$PAREN"/>
722       <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
723     </xsl:apply-templates>
724     <m:mo><xsl:call-template name="insert1"/>-</m:mo>
725     <xsl:apply-templates select="*[3]" mode = "semantics">
726       <xsl:with-param name="IN_PREC" select="$MINUS_PREC"/>
727       <xsl:with-param name="PARAM" select="$PAR_SAME"/>
728       <xsl:with-param name="PAREN" select="$PAREN"/>
729       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
730     </xsl:apply-templates>
731   </xsl:if>
732 </xsl:template>
733
734 <xsl:template match = "m:apply[m:plus[1]]">
735   <xsl:param name="IN_PREC" select="$NO_PREC"/>
736   <xsl:param name="PARAM" select="$NO_PARAM"/>
737   <xsl:param name="PAREN" select="$PAR_NO"/>
738   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
739   <xsl:choose>
740     <xsl:when test="$IN_PREC &gt; $PLUS_PREC or $IN_PREC=$PLUS_PREC and $PARAM=$PAR_SAME">
741       <m:mfenced separators="">
742         <xsl:call-template name="insert_xref"/>
743         <xsl:apply-templates select="." mode="plus">
744           <xsl:with-param name="PARAM" select="$IN_PREC"/>
745           <xsl:with-param name="PAREN" select="$PAR_YES"/>
746           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
747         </xsl:apply-templates>
748       </m:mfenced>
749     </xsl:when>
750     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC and not($SEM_SW=2)">
751       <xsl:apply-templates select="." mode="plus">
752         <xsl:with-param name="PARAM" select="$PARAM"/>
753         <xsl:with-param name="PAREN" select="$PAREN"/>
754         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
755       </xsl:apply-templates>
756     </xsl:when>
757     <xsl:otherwise>
758       <m:mrow>
759         <xsl:call-template name="insert_xref"/>
760         <xsl:apply-templates select="." mode="plus">
761           <xsl:with-param name="PARAM" select="$IN_PREC"/>
762           <xsl:with-param name="PAREN" select="$PAREN"/>
763           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
764         </xsl:apply-templates>
765       </m:mrow>
766     </xsl:otherwise>
767   </xsl:choose>
768 </xsl:template>
769
770 <xsl:template match = "m:apply[m:plus[1]]" mode="plus">
771   <xsl:param name="PARAM" select="$NO_PARAM"/>
772   <xsl:param name="PAREN" select="$PAR_NO"/>
773   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
774   <xsl:if test="*[2]">
775     <xsl:apply-templates select="*[2]" mode = "semantics">
776       <xsl:with-param name="IN_PREC" select="$PLUS_PREC"/>
777       <xsl:with-param name="PARAM" select="$PARAM"/>
778       <xsl:with-param name="PAREN" select="$PAREN"/>
779       <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
780     </xsl:apply-templates>
781     <xsl:for-each select = "*[position()>2]">
782       <xsl:choose>
783         <xsl:when test=". &lt; 0">
784           <m:mo>-</m:mo>
785           <m:mn> <xsl:value-of select="-."/> </m:mn>
786         </xsl:when>
787         <xsl:when test="self::m:apply[m:minus[1]] and not(*[3])">
788           <xsl:apply-templates select="." mode = "semantics">
789             <xsl:with-param name="IN_PREC" select="$PLUS_PREC"/>
790             <xsl:with-param name="PAREN" select="$PAREN"/>
791             <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
792           </xsl:apply-templates>
793         </xsl:when>
794         <xsl:otherwise>
795           <m:mo><xsl:call-template name="insert2"/>+</m:mo>
796           <xsl:apply-templates select="." mode = "semantics">
797             <xsl:with-param name="IN_PREC" select="$PLUS_PREC"/>
798             <xsl:with-param name="PAREN" select="$PAREN"/>
799             <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
800           </xsl:apply-templates>
801         </xsl:otherwise>
802       </xsl:choose>
803     </xsl:for-each>
804   </xsl:if>
805 </xsl:template>
806
807 <xsl:template match = "m:apply[m:power[1]]">
808   <xsl:choose>
809     <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]]">
810       <xsl:apply-templates select="*[2]" mode = "semantics"/>
811     </xsl:when>
812     <xsl:otherwise>
813       <m:msup>
814         <xsl:apply-templates select = "*[2]" mode = "semantics">
815           <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
816           <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
817         </xsl:apply-templates>
818         <xsl:apply-templates select = "*[3]" mode = "semantics"/>
819       </m:msup>
820     </xsl:otherwise>
821   </xsl:choose>
822 </xsl:template>
823
824 <xsl:template match = "m:apply[m:rem[1] | m:divide[1]]">
825   <xsl:param name="IN_PREC" select="$NO_PREC"/>
826   <xsl:param name="PARAM" select="$NO_PARAM"/>
827   <xsl:param name="PAREN" select="$PAR_NO"/>
828   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
829   <xsl:choose>
830     <xsl:when test="$IN_PREC &gt; $DIV_PREC or $IN_PREC=$DIV_PREC and $PARAM=$PAR_SAME">
831       <m:mfenced separators="">
832         <xsl:call-template name="insert_xref"/>
833         <xsl:apply-templates select="." mode="remdiv">
834           <xsl:with-param name="PARAM" select="$IN_PREC"/>
835           <xsl:with-param name="PAREN" select="$PAR_YES"/>
836           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
837         </xsl:apply-templates>
838       </m:mfenced>
839     </xsl:when>
840     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC and not($SEM_SW=2)">
841       <xsl:apply-templates select="." mode="remdiv">
842         <xsl:with-param name="PARAM" select="$PARAM"/>
843         <xsl:with-param name="PAREN" select="$PAREN"/>
844         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
845       </xsl:apply-templates>
846     </xsl:when>
847     <xsl:otherwise>
848       <m:mrow>
849         <xsl:call-template name="insert_xref"/>
850         <xsl:apply-templates select="." mode="remdiv">
851           <xsl:with-param name="PARAM" select="$IN_PREC"/>
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       </m:mrow>
856     </xsl:otherwise>
857   </xsl:choose>
858 </xsl:template>
859
860 <xsl:template match = "m:apply[m:rem[1] | m:divide[1]]" mode="remdiv">
861   <xsl:param name="PARAM" select="$NO_PARAM"/>
862   <xsl:param name="PAREN" select="$PAR_NO"/>
863   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
864   <xsl:apply-templates select = "*[2]" mode = "semantics">
865     <xsl:with-param name="IN_PREC" select="$DIV_PREC"/>
866       <xsl:with-param name="PARAM" select="$PARAM"/>
867       <xsl:with-param name="PAREN" select="$PAREN"/>
868       <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
869   </xsl:apply-templates>
870   <xsl:if test="m:rem">
871     <m:mo><xsl:call-template name="insert1"/>%</m:mo>
872   </xsl:if>
873   <xsl:if test="m:divide">
874     <m:mo><xsl:call-template name="insert1"/>/</m:mo>
875   </xsl:if>
876   <xsl:apply-templates select = "*[3]" mode = "semantics">
877     <xsl:with-param name="IN_PREC" select="$DIV_PREC"/>
878     <xsl:with-param name="PARAM" select="$PAR_SAME"/>
879     <xsl:with-param name="PAREN" select="$PAREN"/>
880     <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
881   </xsl:apply-templates>
882 </xsl:template>
883
884 <xsl:template match = "m:apply[m:times[1]]">
885   <xsl:param name="IN_PREC" select="$NO_PREC"/>
886   <xsl:param name="PARAM" select="$NO_PARAM"/>
887   <xsl:param name="PAREN" select="$PAR_NO"/>
888   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
889   <xsl:choose>
890     <xsl:when test="$IN_PREC &gt; $MUL_PREC or $IN_PREC=$MUL_PREC and $PARAM=$PAR_SAME">
891       <m:mfenced separators="">
892         <xsl:call-template name="insert_xref"/>
893         <xsl:apply-templates select="." mode="times">
894           <xsl:with-param name="PARAM" select="$IN_PREC"/>
895           <xsl:with-param name="PAREN" select="$PAR_YES"/>
896           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
897         </xsl:apply-templates>
898       </m:mfenced>
899     </xsl:when>
900     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC and not($SEM_SW=2)">
901       <xsl:apply-templates select="." mode="times">
902         <xsl:with-param name="PARAM" select="$PARAM"/>
903         <xsl:with-param name="PAREN" select="$PAREN"/>
904         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
905       </xsl:apply-templates>
906     </xsl:when>
907     <xsl:otherwise>
908       <m:mrow>
909          <xsl:call-template name="insert_xref"/>
910         <xsl:apply-templates select="." mode="times">
911           <xsl:with-param name="PARAM" select="$IN_PREC"/>
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       </m:mrow>
916     </xsl:otherwise>
917   </xsl:choose>
918 </xsl:template>
919
920 <xsl:template match = "m:apply[m:times[1]]" mode="times">
921   <xsl:param name="PARAM" select="$NO_PARAM"/>
922   <xsl:param name="PAREN" select="$PAR_NO"/>
923   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
924   <xsl:apply-templates select="*[2]" mode = "semantics">
925     <xsl:with-param name="IN_PREC" select="$MUL_PREC"/>
926     <xsl:with-param name="PARAM" select="$PARAM"/>
927     <xsl:with-param name="PAREN" select="$PAREN"/>
928     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
929   </xsl:apply-templates>
930   <xsl:if test="*[3]">
931     <xsl:for-each select = "*[position()>2]">
932 <!-- HELM: MODIFICA PROVVISORIA -->
933 <!--      <m:mo><xsl:call-template name="insert2"/>
934                 <mchar name="InvisibleTimes"/> </m:mo> -->
935       <m:mo><xsl:call-template name="insert2"/>*</m:mo>
936       <xsl:apply-templates select="." mode = "semantics">
937         <xsl:with-param name="IN_PREC" select="$MUL_PREC"/>
938         <xsl:with-param name="PAREN" select="$PAREN"/>
939         <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
940       </xsl:apply-templates>
941     </xsl:for-each>
942   </xsl:if>
943 </xsl:template>
944
945 <!-- HELM: COMMENTO : dove metto la uri della definizione di radice ???? -->
946
947 <xsl:template match = "m:apply[m:root[1]]">
948   <m:msqrt>
949     <xsl:call-template name="insert_xref"/>
950     <xsl:if test="*[2]=m:degree">
951       <xsl:apply-templates select="*[3]" mode = "semantics"/>
952       <xsl:apply-templates select="*[2]" mode = "semantics"/>
953     </xsl:if>
954     <xsl:if test="not(*[2]=m:degree)">
955       <xsl:apply-templates select="*[2]" mode = "semantics"/>
956       <m:mn>2</m:mn>
957     </xsl:if>
958   </m:msqrt>
959 </xsl:template>
960
961 <xsl:template match = "m:apply[m:gcd[1]]">
962   <m:mrow>
963     <xsl:call-template name="insert_xref"/>
964     <xsl:if test="not(parent::m:apply[m:power[1]])">
965       <m:mo><xsl:call-template name="insert1"/>gcd</m:mo>
966     </xsl:if>
967     <xsl:if test="parent::m:apply[m:power[1]]">
968       <m:msup>
969         <m:mo><xsl:call-template name="insert1"/>gcd</m:mo>
970         <xsl:apply-templates select = "../*[3]" mode = "semantics"/>
971       </m:msup>
972     </xsl:if>
973     <m:mfenced separators=",">
974       <xsl:for-each select = "*[position()>1]">
975         <xsl:apply-templates select = "." mode="semantics"/>
976       </xsl:for-each>
977     </m:mfenced>
978   </m:mrow>
979 </xsl:template>
980
981 <xsl:template match = "m:apply[m:and[1]]">
982   <xsl:param name="IN_PREC" select="$NO_PREC"/>
983   <xsl:param name="PAREN" select="$PAR_NO"/>
984   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
985   <xsl:choose>
986     <xsl:when test="$IN_PREC &gt; $AND_PREC">
987       <m:mfenced separators="">
988         <xsl:call-template name="insert_xref"/>
989         <xsl:apply-templates select="." mode="and">
990           <xsl:with-param name="PARAM" select="$IN_PREC"/>
991           <xsl:with-param name="PAREN" select="$PAR_YES"/>
992         </xsl:apply-templates>
993       </m:mfenced>
994     </xsl:when>
995     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC and not($SEM_SW=2)">
996       <xsl:apply-templates select="." mode="and">
997         <xsl:with-param name="PARAM" select="$IN_PREC"/>
998         <xsl:with-param name="PAREN" select="$PAREN"/>
999         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1000       </xsl:apply-templates>
1001     </xsl:when>
1002     <xsl:otherwise>
1003       <m:mrow>
1004         <xsl:call-template name="insert_xref"/>
1005         <xsl:apply-templates select="." mode="and">
1006           <xsl:with-param name="PARAM" select="$IN_PREC"/>
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       </m:mrow>
1011     </xsl:otherwise>
1012   </xsl:choose>
1013 </xsl:template>
1014
1015 <xsl:template match = "m:apply[m:and[1]]" mode="and">
1016   <xsl:param name="PARAM" select="$NO_PARAM"/>
1017   <xsl:param name="PAREN" select="$PAR_NO"/>
1018   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1019   <xsl:apply-templates select="*[2]" mode = "semantics">
1020     <xsl:with-param name="IN_PREC" select="$AND_PREC"/>
1021     <xsl:with-param name="PARAM" select="$PARAM"/>
1022     <xsl:with-param name="PAREN" select="$PAREN"/>
1023     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1024   </xsl:apply-templates>
1025   <xsl:for-each select = "*[position()>2]">
1026     <m:mo><xsl:call-template name="insert2"/> <mchar name="wedge"/> </m:mo>
1027     <xsl:apply-templates select="." mode = "semantics">
1028       <xsl:with-param name="IN_PREC" select="$AND_PREC"/>
1029       <xsl:with-param name="PAREN" select="$PAREN"/>
1030       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1031     </xsl:apply-templates>
1032   </xsl:for-each>
1033 </xsl:template>
1034
1035 <xsl:template match = "m:apply[m:or[1]]">
1036   <xsl:param name="IN_PREC" select="$NO_PREC"/>
1037   <xsl:param name="PAREN" select="$PAR_NO"/>
1038   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1039   <xsl:choose>
1040     <xsl:when test="$IN_PREC &gt; $OR_PREC">
1041       <m:mfenced separators="">
1042          <xsl:call-template name="insert_xref"/>
1043         <xsl:apply-templates select="." mode="or">
1044           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1045           <xsl:with-param name="PAREN" select="$PAR_YES"/>
1046         </xsl:apply-templates>
1047       </m:mfenced>
1048     </xsl:when>
1049     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC and not($SEM_SW=2)">
1050       <xsl:apply-templates select="." mode="or">
1051         <xsl:with-param name="PARAM" select="$IN_PREC"/>
1052         <xsl:with-param name="PAREN" select="$PAREN"/>
1053         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1054       </xsl:apply-templates>
1055     </xsl:when>
1056     <xsl:otherwise>
1057       <m:mrow>
1058         <xsl:call-template name="insert_xref"/>
1059         <xsl:apply-templates select="." mode="or">
1060           <xsl:with-param name="PARAM" select="$IN_PREC"/>
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       </m:mrow>
1065     </xsl:otherwise>
1066   </xsl:choose>
1067 </xsl:template>
1068
1069 <xsl:template match = "m:apply[m:or[1]]" mode="or">
1070   <xsl:param name="PARAM" select="$NO_PARAM"/>
1071   <xsl:param name="PAREN" select="$PAR_NO"/>
1072   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1073   <xsl:apply-templates select="*[2]" mode = "semantics">
1074     <xsl:with-param name="IN_PREC" select="$OR_PREC"/>
1075     <xsl:with-param name="PARAM" select="$PARAM"/>
1076     <xsl:with-param name="PAREN" select="$PAREN"/>
1077     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1078   </xsl:apply-templates>
1079   <xsl:for-each select = "*[position()>2]">
1080     <m:mo><xsl:call-template name="insert2"/> <mchar name="vee"/> </m:mo>
1081     <xsl:apply-templates select="." mode = "semantics">
1082       <xsl:with-param name="IN_PREC" select="$OR_PREC"/>
1083       <xsl:with-param name="PAREN" select="$PAREN"/>
1084       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1085     </xsl:apply-templates>
1086   </xsl:for-each>
1087 </xsl:template>
1088
1089 <xsl:template match = "m:apply[m:xor[1]]">
1090   <xsl:param name="IN_PREC" select="$NO_PREC"/>
1091   <xsl:param name="PAREN" select="$PAR_NO"/>
1092   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1093   <xsl:choose>
1094     <xsl:when test="$IN_PREC &gt; $XOR_PREC">
1095       <m:mfenced separators="">
1096         <xsl:call-template name="insert_xref"/>
1097         <xsl:apply-templates select="." mode="xor">
1098           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1099           <xsl:with-param name="PAREN" select="$PAR_YES"/>
1100           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1101         </xsl:apply-templates>
1102       </m:mfenced>
1103     </xsl:when>
1104     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC and not($SEM_SW=2)">
1105       <xsl:apply-templates select="." mode="xor">
1106         <xsl:with-param name="PARAM" select="$IN_PREC"/>
1107         <xsl:with-param name="PAREN" select="$PAREN"/>
1108       </xsl:apply-templates>
1109     </xsl:when>
1110     <xsl:otherwise>
1111       <m:mrow>
1112         <xsl:call-template name="insert_xref"/>
1113         <xsl:apply-templates select="." mode="xor">
1114           <xsl:with-param name="PARAM" select="$IN_PREC"/>
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       </m:mrow>
1119     </xsl:otherwise>
1120   </xsl:choose>
1121 </xsl:template>
1122
1123 <xsl:template match = "m:apply[m:xor[1]]" mode="xor">
1124   <xsl:param name="PARAM" select="$NO_PARAM"/>
1125   <xsl:param name="PAREN" select="$PAR_NO"/>
1126   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1127   <xsl:apply-templates select="*[2]" mode = "semantics">
1128     <xsl:with-param name="IN_PREC" select="$XOR_PREC"/>
1129     <xsl:with-param name="PARAM" select="$PARAM"/>
1130     <xsl:with-param name="PAREN" select="$PAREN"/>
1131     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1132   </xsl:apply-templates>
1133   <xsl:for-each select = "*[position()>2]">
1134     <m:mo><xsl:call-template name="insert2"/> <mchar name="xor"/> </m:mo>
1135     <xsl:apply-templates select="." mode = "semantics">
1136       <xsl:with-param name="IN_PREC" select="$XOR_PREC"/>
1137       <xsl:with-param name="PAREN" select="$PAREN"/>
1138       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1139     </xsl:apply-templates>
1140   </xsl:for-each>
1141 </xsl:template>
1142
1143 <xsl:template match = "m:apply[m:not[1]]">
1144   <m:mrow>
1145     <xsl:call-template name="insert_xref"/>
1146     <m:mo><xsl:call-template name="insert1"/>not</m:mo>
1147     <xsl:apply-templates select = "*[2]" mode = "semantics">
1148       <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
1149     </xsl:apply-templates>
1150   </m:mrow>
1151 </xsl:template>
1152
1153 <xsl:template match = "m:apply[m:forall[1]]">
1154   <m:mrow>
1155     <xsl:call-template name="insert_xref"/>
1156     <m:mo><xsl:call-template name="insert1"/>for all</m:mo>
1157     <m:mfenced separators=",">
1158       <xsl:for-each select = "m:bvar">
1159         <xsl:apply-templates select = "." mode="semantics"/>
1160       </xsl:for-each>
1161     </m:mfenced>
1162     <xsl:if test="m:condition">
1163       <m:mo>:</m:mo>
1164       <xsl:apply-templates select = "m:condition/*" mode = "semantics"/>
1165       <m:mo>,</m:mo>
1166     </xsl:if>
1167     <xsl:apply-templates select = "*[position()>1 and not(self::m:bvar) and not(self::m:condition)]" mode = "semantics"/>
1168   </m:mrow>
1169 </xsl:template>
1170
1171 <xsl:template match = "m:apply[m:exists[1]]">
1172   <m:mrow>
1173     <xsl:call-template name="insert_xref"/>
1174     <m:mo><xsl:call-template name="insert1"/> <mchar name="Exists"/> </m:mo>
1175     <m:mfenced separators=",">
1176       <xsl:for-each select = "m:bvar">
1177         <xsl:apply-templates select = "." mode="semantics"/>
1178       </xsl:for-each>
1179     </m:mfenced>
1180     <xsl:if test="m:condition">
1181       <m:mo>,</m:mo>
1182       <xsl:apply-templates select = "m:condition/*" mode = "semantics"/>
1183     </xsl:if>
1184     <m:mo>:</m:mo>
1185     <xsl:apply-templates select = "*[position()>1 and not(self::m:bvar) and not(self::m:condition)]" mode = "semantics"/>
1186   </m:mrow>
1187 </xsl:template>
1188
1189 <xsl:template match = "m:apply[m:abs[1]]">
1190   <xsl:if test="not(parent::m:apply[m:power[1]])">
1191     <m:mfenced open="|" close="|" separators="">
1192       <xsl:call-template name="insert_xref"/>
1193       <xsl:apply-templates select = "*[position()>1]" mode = "semantics"/>
1194     </m:mfenced>
1195   </xsl:if>
1196   <xsl:if test="parent::m:apply[m:power[1]]">
1197     <m:msup>
1198       <m:mfenced open="|" close="|" separators="">
1199         <xsl:call-template name="insert_xref"/>
1200         <xsl:apply-templates select = "*[position()>1]" mode = "semantics"/>
1201       </m:mfenced>
1202       <xsl:apply-templates select = "../*[3]" mode = "semantics"/>
1203     </m:msup>
1204   </xsl:if>
1205 </xsl:template>
1206
1207 <xsl:template match = "m:apply[m:conjugate[1]]">
1208   <m:mover>
1209     <m:mrow>
1210       <xsl:apply-templates select = "*[position()>1]" mode = "semantics"/>
1211     </m:mrow>
1212     <m:mo><xsl:call-template name="insert1"/> <mchar name="UnderBar"/> </m:mo>
1213   </m:mover>
1214 </xsl:template>
1215
1216 <xsl:template match = "m:apply[m:arg[1] | m:real[1] | m:imaginary[1]]">
1217   <m:mrow>
1218     <xsl:call-template name="insert_xref"/>
1219     <xsl:choose>
1220       <xsl:when test="m:arg">
1221         <m:mo><xsl:call-template name="insert1"/>arg</m:mo>
1222       </xsl:when>
1223       <xsl:when test="m:real">
1224         <m:mo><xsl:call-template name="insert1"/>Real</m:mo>
1225       </xsl:when>
1226       <xsl:when test="m:imaginary">
1227         <m:mo><xsl:call-template name="insert1"/>Imaginary</m:mo>
1228       </xsl:when>
1229     </xsl:choose>
1230     <m:mfenced separators="">
1231       <xsl:apply-templates select = "*[2]" mode = "semantics"/>
1232     </m:mfenced>
1233   </m:mrow>
1234 </xsl:template>
1235
1236
1237 <!-- RELATIONS -->
1238
1239 <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]">
1240   <m:mrow>
1241     <xsl:call-template name="insert_xref"/>
1242     <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">
1243       <xsl:apply-templates select = "*[2]" mode = "semantics"/>
1244       <xsl:if test="*[1]=m:neq">
1245         <m:mo><xsl:call-template name="insert1"/> <mchar name="NotEqual"/> </m:mo>
1246       </xsl:if>
1247       <xsl:if test="*[1]=m:approx">
1248         <m:mo><xsl:call-template name="insert1"/> <mchar name="approxeq"/> </m:mo>
1249       </xsl:if>
1250       <xsl:if test="*[1]=m:tendsto">
1251         <m:mo><xsl:call-template name="insert1"/> <mchar name="RightArrow"/> </m:mo>
1252       </xsl:if>
1253       <xsl:if test="*[1]=m:implies">
1254         <m:mo><xsl:call-template name="insert1"/> <mchar name="DoubleRightArrow"/> </m:mo>
1255       </xsl:if>
1256       <xsl:if test="*[1]=m:in">
1257         <m:mo><xsl:call-template name="insert1"/>
1258         <mchar name="Element"/> 
1259        </m:mo>
1260       </xsl:if>
1261       <xsl:if test="*[1]=m:notin">
1262         <m:mo><xsl:call-template name="insert1"/> <mchar name="NotElement"/> </m:mo>
1263       </xsl:if>
1264       <xsl:if test="*[1]=m:notsubset">
1265         <m:mo> <xsl:call-template name="insert1"/> <mchar name="NotSubset"/> </m:mo>
1266       </xsl:if>
1267       <xsl:if test="*[1]=m:notprsubset">
1268         <m:mo> <xsl:call-template name="insert1"/> <mchar name="NotSubsetEqual"/> </m:mo>
1269       </xsl:if>
1270       <xsl:apply-templates select = "*[3]" mode = "semantics"/>
1271       <xsl:if test="*[1]=m:tendsto and m:tendsto[1][@type='below']">
1272         <m:mo><xsl:call-template name="insert1"/>-</m:mo>
1273       </xsl:if>
1274       <xsl:if test="*[1]=m:tendsto and m:tendsto[1][@type='above']">
1275         <m:mo><xsl:call-template name="insert1"/>+</m:mo>
1276       </xsl:if>
1277     </xsl:if>
1278     <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">
1279       <xsl:apply-templates select = "*[2]" mode="semantics"/>
1280       <xsl:for-each select = "*[position()>2]">
1281         <xsl:if test="../*[self::m:subset][1]">
1282           <m:mo> <xsl:call-template name="insert2"/> <mchar name="SubsetEqual"/> </m:mo>
1283         </xsl:if>
1284         <xsl:if test="../*[self::m:prsubset][1]">
1285           <m:mo> <xsl:call-template name="insert2"/><mchar name="subset"/> </m:mo>
1286         </xsl:if>
1287         <xsl:if test="../*[self::m:eq][1]">
1288           <m:mo><xsl:call-template name="insert2"/>=</m:mo>
1289         </xsl:if>
1290         <xsl:if test="../*[self::m:gt][1]">
1291           <m:mo><xsl:call-template name="insert2"/>&gt;</m:mo>
1292         </xsl:if>
1293         <xsl:if test="../*[self::m:lt][1]">
1294           <m:mo><xsl:call-template name="insert2"/>&lt;</m:mo>
1295         </xsl:if>
1296         <xsl:if test="../*[self::m:geq][1]">
1297           <m:mo><xsl:call-template name="insert2"/> <mchar name="geq"/> </m:mo>
1298         </xsl:if>
1299         <xsl:if test="../*[self::m:leq][1]">
1300           <m:mo><xsl:call-template name="insert2"/> <mchar name="leq"/> </m:mo>
1301         </xsl:if>
1302         <xsl:if test="../*[self::m:equivalent][1]">
1303           <m:mo><xsl:call-template name="insert2"/> <mchar name="Congruent"/> </m:mo>
1304         </xsl:if>
1305         <xsl:apply-templates select = "." mode="semantics"/>
1306       </xsl:for-each>
1307     </xsl:if>
1308   </m:mrow>
1309 </xsl:template>
1310
1311
1312 <!-- CALCULUS -->
1313
1314 <xsl:template match = "m:apply[*[1][self::m:ln]]">
1315   <m:mrow>
1316     <xsl:call-template name="insert_xref"/>
1317     <xsl:choose>
1318       <xsl:when test="parent::m:apply[m:power[1]]">
1319         <m:msup>
1320           <m:mo><xsl:call-template name="insert1"/>ln</m:mo>
1321           <xsl:apply-templates select = "../*[3]" mode = "semantics"/>
1322         </m:msup>
1323       </xsl:when>
1324       <xsl:otherwise>
1325         <m:mo><xsl:call-template name="insert1"/>ln</m:mo>
1326       </xsl:otherwise>
1327     </xsl:choose>
1328     <xsl:apply-templates select = "*[2]" mode = "semantics">
1329       <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
1330     </xsl:apply-templates>
1331   </m:mrow>
1332 </xsl:template>
1333
1334 <xsl:template match = "m:apply[m:log[1]]">
1335   <m:mrow>
1336     <xsl:call-template name="insert_xref"/>
1337     <xsl:choose>
1338       <xsl:when test="parent::m:apply[m:power[1]]">
1339         <xsl:if test="not(*[2]=m:logbase)">
1340           <m:msup>
1341             <m:mo><xsl:call-template name="insert1"/>log</m:mo>
1342             <xsl:apply-templates select = "../*[3]" mode = "semantics"/>
1343           </m:msup>
1344         </xsl:if>
1345         <xsl:if test="*[2]=m:logbase">
1346           <m:msubsup>
1347             <m:mo><xsl:call-template name="insert1"/>log</m:mo>
1348             <xsl:apply-templates select = "../*[3]" mode = "semantics"/>
1349             <xsl:apply-templates select = "m:logbase" mode = "semantics"/>
1350           </m:msubsup>
1351         </xsl:if>
1352       </xsl:when>
1353       <xsl:otherwise>
1354         <xsl:if test="not(*[2]=m:logbase)">
1355           <m:mo><xsl:call-template name="insert1"/>log</m:mo>
1356         </xsl:if>
1357         <xsl:if test="*[2]=m:logbase">
1358           <m:msub>
1359             <m:mo><xsl:call-template name="insert1"/>log</m:mo>
1360             <xsl:apply-templates select = "m:logbase" mode = "semantics"/>
1361           </m:msub>
1362         </xsl:if>
1363       </xsl:otherwise>
1364     </xsl:choose>
1365     <xsl:if test="*[2]=m:logbase">
1366       <xsl:apply-templates select = "*[3]" mode = "semantics">
1367         <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
1368       </xsl:apply-templates>
1369     </xsl:if>
1370     <xsl:if test="not(*[2]=m:logbase)">
1371       <xsl:apply-templates select = "*[2]" mode = "semantics">
1372         <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
1373       </xsl:apply-templates>
1374     </xsl:if>
1375   </m:mrow>
1376 </xsl:template>
1377
1378 <xsl:template match = "m:apply[m:diff[1]]">
1379   <m:mrow>
1380     <xsl:call-template name="insert_xref"/>
1381     <xsl:if test="*[2]=m:bvar and m:bvar[*[2]=m:degree]">
1382       <m:mfrac><xsl:call-template name="insert1"/>
1383         <m:msup>
1384           <m:mo>d</m:mo>
1385           <xsl:apply-templates select = "m:bvar/m:degree" mode = "semantics"/>
1386         </m:msup>
1387         <m:mrow>
1388           <m:mo>d</m:mo>
1389           <m:msup>
1390             <xsl:apply-templates select = "m:bvar/*[1]" mode = "semantics"/>
1391             <xsl:apply-templates select = "m:bvar/m:degree" mode = "semantics"/>
1392           </m:msup>
1393         </m:mrow>
1394       </m:mfrac>
1395     </xsl:if>
1396     <xsl:if test="*[2]=m:bvar and not(m:bvar[*[2]=m:degree])">
1397       <m:mfrac><xsl:call-template name="insert1"/>
1398         <m:mo>d</m:mo>
1399         <m:mrow>
1400           <m:mo>d</m:mo>
1401           <xsl:apply-templates select = "m:bvar/*[1]" mode = "semantics"/>
1402         </m:mrow>
1403       </m:mfrac>
1404     </xsl:if>
1405     <xsl:apply-templates select = "*[3]" mode = "semantics"/>
1406   </m:mrow>
1407 </xsl:template>
1408
1409 <xsl:template match = "m:apply[m:partialdiff[1]]">
1410   <m:mrow>
1411     <xsl:call-template name="insert_xref"/>
1412     <xsl:for-each select = "m:bvar">
1413       <xsl:if test="*[last()]=m:degree">
1414         <m:mfrac><xsl:call-template name="insert1"/>
1415           <m:msup>
1416              <m:mo>d</m:mo>
1417              <xsl:apply-templates select = "m:degree" mode = "semantics"/>
1418           </m:msup>
1419           <m:mrow>
1420             <m:mo>d</m:mo>
1421             <m:msup>
1422               <xsl:apply-templates select = "*[1]" mode = "semantics"/>
1423               <xsl:apply-templates select = "m:degree" mode = "semantics"/>
1424             </m:msup>
1425           </m:mrow>
1426         </m:mfrac>
1427       </xsl:if>
1428       <xsl:if test="not(*[last()]=m:degree)">
1429         <m:mfrac><xsl:call-template name="insert1"/>
1430           <m:mo>d</m:mo>
1431           <m:mrow>
1432             <m:mo>d</m:mo>
1433             <xsl:apply-templates select = "*[1]" mode = "semantics"/>
1434           </m:mrow>
1435         </m:mfrac>
1436       </xsl:if>
1437     </xsl:for-each>
1438     <xsl:apply-templates select = "*[last()]" mode = "semantics"/>
1439   </m:mrow>
1440 </xsl:template>
1441
1442 <xsl:template match = "m:lowlimit | m:uplimit | m:bvar | m:degree | m:logbase">
1443   <xsl:apply-templates mode = "semantics"/>
1444 </xsl:template>
1445
1446 <xsl:template match = "m:apply[m:divergence[1] | m:grad[1] | m:curl[1]]">
1447   <m:mrow>
1448     <xsl:call-template name="insert_xref"/>
1449     <xsl:if test="*[1]=m:divergence">
1450       <m:mo><xsl:call-template name="insert1"/>div</m:mo>
1451     </xsl:if>
1452     <xsl:if test="*[1]=m:grad">
1453     <m:mo><xsl:call-template name="insert1"/>grad</m:mo>
1454     </xsl:if>
1455     <xsl:if test="*[1]=m:curl">
1456     <m:mo><xsl:call-template name="insert1"/>curl</m:mo>
1457     </xsl:if>
1458     <xsl:choose>
1459       <xsl:when test="*[2]=m:ci">
1460         <xsl:apply-templates select = "*[2]" mode = "semantics"/>
1461       </xsl:when>
1462       <xsl:otherwise>
1463         <m:mfenced separators="">
1464           <xsl:apply-templates select = "*[2]" mode = "semantics"/>
1465         </m:mfenced>
1466       </xsl:otherwise>
1467     </xsl:choose>
1468   </m:mrow>
1469 </xsl:template>
1470
1471 <xsl:template match = "m:apply[m:laplacian[1]]">
1472   <m:mrow>
1473     <xsl:call-template name="insert_xref"/>
1474     <m:msup><xsl:call-template name="insert1"/>
1475       <m:mo> &#x0394; </m:mo>
1476       <m:mn>2</m:mn>
1477     </m:msup>
1478     <xsl:apply-templates select = "*[2]" mode = "semantics"/>
1479   </m:mrow>
1480 </xsl:template>
1481
1482
1483 <!-- SET THEORY -->
1484
1485 <xsl:template match = "m:set | m:list">
1486   <m:mfenced open="{{" close="}}" separators="">
1487     <xsl:call-template name="insert_xref"/>
1488     <xsl:if test="*[1]=m:bvar and *[2]=m:condition">
1489       <xsl:apply-templates select="m:bvar" mode = "semantics"/>
1490       <m:mo>|</m:mo>
1491       <xsl:apply-templates select="m:condition" mode = "semantics"/>
1492     </xsl:if>
1493     <xsl:if test="*[1]=m:condition and not(child::m:bvar)">
1494       <m:mfenced open="" close="" separators=",">
1495         <xsl:for-each select = "*[not(self::m:condition) and not(self::m:bvar)]">
1496           <xsl:apply-templates select = "." mode="semantics"/>
1497         </xsl:for-each>
1498       </m:mfenced>
1499       <m:mo>|</m:mo>
1500       <xsl:apply-templates select="m:condition" mode = "semantics"/>
1501     </xsl:if>
1502     <xsl:if test="not(child::m:bvar) and not(child::m:condition)">
1503       <m:mfenced open="" close="" separators=",">
1504         <xsl:for-each select = "*">
1505           <xsl:apply-templates select = "." mode="semantics"/>
1506         </xsl:for-each>
1507       </m:mfenced>
1508     </xsl:if>
1509   </m:mfenced>
1510 </xsl:template>
1511
1512 <xsl:template match = "m:apply[m:union[1]]">
1513   <xsl:param name="IN_PREC" select="$NO_PREC"/>
1514   <xsl:param name="PARAM" select="$NO_PARAM"/>
1515   <xsl:param name="PAREN" select="$PAR_NO"/>
1516   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1517   <xsl:choose>
1518     <xsl:when test="$IN_PREC &gt; $UNION_PREC or $IN_PREC=$UNION_PREC and $PARAM=$PAR_SAME">
1519       <m:mfenced separators="" helm:xref="{@helm:xref}">
1520         <xsl:call-template name="insert_xref"/>
1521         <xsl:apply-templates select="." mode="union">
1522           <xsl:with-param name="PARAM" select="$PARAM"/>
1523           <xsl:with-param name="PAREN" select="$PAREN"/>
1524           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1525         </xsl:apply-templates>
1526       </m:mfenced>
1527     </xsl:when>
1528     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC and not($SEM_SW=2)">
1529       <xsl:apply-templates select="." mode="union">
1530         <xsl:with-param name="PARAM" select="$PARAM"/>
1531         <xsl:with-param name="PAREN" select="$PAREN"/>
1532         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1533       </xsl:apply-templates>
1534     </xsl:when>
1535     <xsl:otherwise>
1536       <m:mrow>
1537         <xsl:call-template name="insert_xref"/>
1538         <xsl:apply-templates select="." mode="union">
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       </m:mrow>
1544     </xsl:otherwise>
1545   </xsl:choose>
1546 </xsl:template>
1547
1548 <xsl:template match = "m:apply[m:union[1]]" mode="union">
1549   <xsl:param name="PARAM" select="$NO_PARAM"/>
1550   <xsl:param name="PAREN" select="$PAR_NO"/>
1551   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1552   <xsl:apply-templates select = "*[2]" mode="semantics">
1553     <xsl:with-param name="IN_PREC" select="$UNION_PREC"/>
1554     <xsl:with-param name="PARAM" select="$PARAM"/>
1555     <xsl:with-param name="PAREN" select="$PAREN"/>
1556     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1557   </xsl:apply-templates>
1558   <xsl:for-each select = "*[position()>2]">
1559     <m:mo><xsl:call-template name="insert2"/> <mchar name="Union"/> </m:mo>
1560     <xsl:apply-templates select = "." mode="semantics">
1561       <xsl:with-param name="IN_PREC" select="$UNION_PREC"/>
1562       <xsl:with-param name="PAREN" select="$PAREN"/>
1563       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1564     </xsl:apply-templates>
1565   </xsl:for-each>
1566 </xsl:template>
1567
1568 <xsl:template match = "m:apply[m:intersect[1]]">
1569   <xsl:param name="IN_PREC" select="$NO_PREC"/>
1570   <xsl:param name="PARAM" select="$NO_PARAM"/>
1571   <xsl:param name="PAREN" select="$PAR_NO"/>
1572   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1573   <xsl:choose>
1574     <xsl:when test="$IN_PREC &gt; $INTERSECT_PREC">
1575       <m:mfenced separators="" helm:xref="{@helm:xref}">
1576         <xsl:call-template name="insert_xref"/>
1577         <xsl:apply-templates select="." mode="intersect">
1578           <xsl:with-param name="PARAM" select="$PARAM"/>
1579           <xsl:with-param name="PAREN" select="$PAREN"/>
1580           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1581         </xsl:apply-templates>
1582       </m:mfenced>
1583     </xsl:when>
1584     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC and not($SEM_SW=2)">
1585       <xsl:apply-templates select="." mode="intersect">
1586         <xsl:with-param name="PARAM" select="$PARAM"/>
1587         <xsl:with-param name="PAREN" select="$PAREN"/>
1588         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1589       </xsl:apply-templates>
1590     </xsl:when>
1591     <xsl:otherwise>
1592       <m:mrow>
1593         <xsl:call-template name="insert_xref"/>
1594         <xsl:apply-templates select="." mode="intersect">
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       </m:mrow>
1600     </xsl:otherwise>
1601   </xsl:choose>
1602 </xsl:template>
1603
1604 <xsl:template match = "m:apply[m:intersect[1]]" mode="intersect">
1605   <xsl:param name="PARAM" select="$NO_PARAM"/>
1606   <xsl:param name="PAREN" select="$PAR_NO"/>
1607   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1608   <xsl:apply-templates select = "*[2]" mode="semantics">
1609     <xsl:with-param name="IN_PREC" select="$INTERSECT_PREC"/>
1610     <xsl:with-param name="PARAM" select="$PARAM"/>
1611     <xsl:with-param name="PAREN" select="$PAREN"/>
1612     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1613   </xsl:apply-templates>
1614   <xsl:for-each select = "*[position()>2]">
1615     <m:mo><xsl:call-template name="insert2"/> <mchar name="Intersection"/> </m:mo>
1616     <xsl:apply-templates select = "." mode="semantics">
1617       <xsl:with-param name="IN_PREC" select="$INTERSECT_PREC"/>
1618       <xsl:with-param name="PAREN" select="$PAREN"/>
1619       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1620     </xsl:apply-templates>
1621   </xsl:for-each>
1622 </xsl:template>
1623
1624 <xsl:template match = "m:apply[m:setdiff[1]]">
1625   <xsl:param name="IN_PREC" select="$NO_PREC"/>
1626   <xsl:param name="PARAM" select="$NO_PARAM"/>
1627   <xsl:param name="PAREN" select="$PAR_NO"/>
1628   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1629   <xsl:choose>
1630     <xsl:when test="$IN_PREC &gt; $SETDIFF_PREC or $IN_PREC=$SETDIFF_PREC and $PARAM=$PAR_SAME">
1631       <m:mfenced separators="">
1632         <xsl:call-template name="insert_xref"/>
1633         <xsl:apply-templates select="." mode="setdiff">
1634           <xsl:with-param name="PARAM" select="$PARAM"/>
1635           <xsl:with-param name="PAREN" select="$PAREN"/>
1636           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1637         </xsl:apply-templates>
1638       </m:mfenced>
1639     </xsl:when>
1640     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC and not($SEM_SW=2)">
1641       <xsl:apply-templates select="." mode="setdiff">
1642         <xsl:with-param name="PARAM" select="$PARAM"/>
1643         <xsl:with-param name="PAREN" select="$PAREN"/>
1644         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1645       </xsl:apply-templates>
1646     </xsl:when>
1647     <xsl:otherwise>
1648       <m:mrow>
1649         <xsl:call-template name="insert_xref"/>
1650         <xsl:apply-templates select="." mode="setdiff">
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:mrow>
1656     </xsl:otherwise>
1657   </xsl:choose>
1658 </xsl:template>
1659
1660 <xsl:template match = "m:apply[m:setdiff[1]]" mode="setdiff">
1661   <xsl:param name="PARAM" select="$NO_PARAM"/>
1662   <xsl:param name="PAREN" select="$PAR_NO"/>
1663   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1664   <xsl:apply-templates select = "*[2]" mode = "semantics">
1665     <xsl:with-param name="IN_PREC" select="$SETDIFF_PREC"/>
1666     <xsl:with-param name="PARAM" select="$PARAM"/>
1667     <xsl:with-param name="PAREN" select="$PAREN"/>
1668     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1669   </xsl:apply-templates>
1670   <m:mo><xsl:call-template name="insert1"/>\</m:mo>
1671   <xsl:apply-templates select = "*[3]" mode = "semantics">
1672     <xsl:with-param name="IN_PREC" select="$SETDIFF_PREC"/>
1673     <xsl:with-param name="PARAM" select="$PAR_SAME"/>
1674     <xsl:with-param name="PAREN" select="$PAREN"/>
1675     <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1676   </xsl:apply-templates>
1677 </xsl:template>
1678
1679 <xsl:template match = "m:apply[m:card[1]]">
1680   <m:mfenced open="|" close="|" separators=",">
1681     <xsl:call-template name="insert_xref"/>
1682     <xsl:for-each select = "*[position()>1]">
1683       <xsl:apply-templates select = "." mode="semantics"/>
1684     </xsl:for-each>
1685   </m:mfenced>
1686 </xsl:template>
1687
1688
1689 <!-- SEQUENCES AND SERIES -->
1690
1691 <xsl:template match = "m:apply[m:sum[1] | m:product[1]]">
1692   <m:mrow>
1693     <xsl:call-template name="insert_xref"/>
1694     <xsl:choose>
1695       <xsl:when test="*[2]=m:bvar and m:lowlimit and m:uplimit">
1696         <m:munderover>
1697           <xsl:if test="*[1]=m:sum">
1698             <m:mo><xsl:call-template name="insert1"/> <mchar name="Sum"/> </m:mo>
1699           </xsl:if>
1700           <xsl:if test="*[1]=m:product">
1701             <m:mo><xsl:call-template name="insert1"/> <mchar name="Product"/> </m:mo>
1702           </xsl:if>
1703           <m:mrow>
1704             <xsl:apply-templates select = "*[2]" mode = "semantics"/>
1705             <m:mo>=</m:mo>
1706             <xsl:apply-templates select = "m:lowlimit" mode = "semantics"/>
1707           </m:mrow>
1708           <xsl:apply-templates select = "m:uplimit" mode = "semantics"/>
1709         </m:munderover>
1710         <xsl:apply-templates select = "*[5]" mode = "semantics"/>
1711       </xsl:when>
1712       <xsl:when test="*[2]=m:bvar and *[3]=m:condition">
1713         <m:munder>
1714           <xsl:if test="*[1]=m:sum">
1715             <m:mo><xsl:call-template name="insert1"/> <mchar name="Sum"/> </m:mo>
1716           </xsl:if>
1717           <xsl:if test="*[1]=m:product">
1718             <m:mo><xsl:call-template name="insert1"/> <mchar name="Product"/> </m:mo>
1719           </xsl:if>
1720           <xsl:apply-templates select = "*[3]" mode = "semantics"/>
1721         </m:munder>
1722         <xsl:apply-templates select = "*[4]" mode = "semantics"/>
1723       </xsl:when>
1724     </xsl:choose>
1725   </m:mrow>
1726 </xsl:template>
1727
1728 <xsl:template match = "m:apply[m:limit[1]]">
1729   <m:mrow>
1730     <xsl:call-template name="insert_xref"/>
1731     <m:munder>
1732       <m:mo><xsl:call-template name="insert1"/>lim</m:mo>
1733       <m:mrow>
1734         <xsl:if test="*[2]=m:bvar and *[3]=m:lowlimit">
1735             <xsl:apply-templates select = "*[2]" mode = "semantics"/>
1736             <m:mo> <mchar name="RightArrow"/> </m:mo>
1737             <xsl:apply-templates select = "*[3]" mode = "semantics"/>
1738         </xsl:if>
1739         <xsl:if test="*[2]=m:bvar and *[3]=m:condition">
1740           <xsl:apply-templates select = "*[3]" mode = "semantics"/>
1741         </xsl:if>
1742       </m:mrow>
1743     </m:munder>
1744     <xsl:apply-templates select = "*[4]" mode = "semantics"/>
1745   </m:mrow>
1746 </xsl:template>
1747
1748
1749 <!-- TRIGONOMETRY -->
1750
1751 <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]]">
1752   <m:mrow>
1753     <xsl:call-template name="insert_xref"/>
1754     <xsl:if test="not(parent::m:apply[m:power[1]])">
1755       <xsl:apply-templates select = "*[1]" mode = "trigonometry"/>
1756     </xsl:if>
1757     <xsl:if test="parent::m:apply[m:power[1]]">
1758       <m:msup>
1759         <xsl:apply-templates select = "*[1]" mode = "trigonometry"/>
1760         <xsl:apply-templates select = "../*[3]" mode = "semantics"/>
1761       </m:msup>
1762     </xsl:if>
1763     <xsl:apply-templates select = "*[2]" mode = "semantics">
1764       <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
1765       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1766     </xsl:apply-templates>
1767   </m:mrow>
1768 </xsl:template>
1769
1770 <xsl:template match = "m:*" mode = "trigonometry">
1771     <xsl:choose>
1772       <xsl:when test="self::m:sin">
1773         <m:mo>sin</m:mo>
1774       </xsl:when>
1775       <xsl:when test="self::m:cos">
1776         <m:mo>cos</m:mo>
1777       </xsl:when>
1778       <xsl:when test="self::m:tan">
1779         <m:mo>tan</m:mo>
1780       </xsl:when>
1781       <xsl:when test="self::m:sec">
1782         <m:mo>sec</m:mo>
1783       </xsl:when>
1784       <xsl:when test="self::m:csc">
1785         <m:mo>csc</m:mo>
1786       </xsl:when>
1787       <xsl:when test="self::m:cot">
1788         <m:mo>cot</m:mo>
1789       </xsl:when>
1790       <xsl:when test="self::m:sinh">
1791         <m:mo>sinh</m:mo>
1792       </xsl:when>
1793       <xsl:when test="self::m:cosh">
1794         <m:mo>cosh</m:mo>
1795       </xsl:when>
1796       <xsl:when test="self::m:tanh">
1797         <m:mo>tanh</m:mo>
1798       </xsl:when>
1799       <xsl:when test="self::m:sech">
1800         <m:mo>sech</m:mo>
1801       </xsl:when>
1802       <xsl:when test="self::m:csch">
1803         <m:mo>csch</m:mo>
1804       </xsl:when>
1805       <xsl:when test="self::m:coth">
1806         <m:mo>coth</m:mo>
1807       </xsl:when>
1808       <xsl:when test="self::m:arcsin">
1809         <m:mo>arcsin</m:mo>
1810       </xsl:when>
1811       <xsl:when test="self::m:arccos">
1812         <m:mo>arccos</m:mo>
1813       </xsl:when>
1814       <xsl:when test="self::m:arctan">
1815         <m:mo>arctan</m:mo>
1816       </xsl:when>
1817     </xsl:choose>
1818 </xsl:template>
1819
1820
1821 <!-- STATISTICS -->
1822
1823 <xsl:template match = "m:apply[m:mean[1]]">
1824   <m:mfenced open="&lt;" close="&gt;" separators=",">
1825     <xsl:call-template name="insert_xref"/>
1826     <xsl:for-each select = "*[position()>1]">
1827       <xsl:apply-templates select = "." mode="semantics"/>
1828     </xsl:for-each>
1829   </m:mfenced>
1830 </xsl:template>
1831
1832 <xsl:template match = "m:apply[m:sdev[1]]">
1833   <m:mrow>
1834     <xsl:call-template name="insert_xref"/>
1835     <m:mo><xsl:call-template name="insert1"/> &#x03c3; </m:mo>
1836     <m:mfenced separators=",">
1837       <xsl:for-each select = "*[position()>1]">
1838         <xsl:apply-templates select = "." mode="semantics"/>
1839       </xsl:for-each>
1840     </m:mfenced>
1841   </m:mrow>
1842 </xsl:template>
1843
1844 <xsl:template match = "m:apply[m:variance[1]]">
1845   <m:mrow>
1846     <xsl:call-template name="insert_xref"/>
1847     <m:mo><xsl:call-template name="insert1"/> &#x03c3; </m:mo>
1848     <m:msup>
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:mn>2</m:mn>
1855     </m:msup>
1856   </m:mrow>
1857 </xsl:template>
1858
1859 <xsl:template match = "m:apply[m:median[1]]">
1860   <m:mrow>
1861     <xsl:call-template name="insert_xref"/>
1862     <m:mo><xsl:call-template name="insert1"/>median</m:mo>
1863     <m:mfenced separators=",">
1864       <xsl:for-each select = "*[position()>1]">
1865         <xsl:apply-templates select = "." mode="semantics"/>
1866       </xsl:for-each>
1867     </m:mfenced>
1868   </m:mrow>
1869 </xsl:template>
1870
1871 <xsl:template match = "m:apply[m:mode[1]]">
1872   <m:mrow>
1873     <xsl:call-template name="insert_xref"/>
1874     <m:mo><xsl:call-template name="insert1"/>mode</m:mo>
1875     <m:mfenced separators=",">
1876       <xsl:for-each select = "*[position()>1]">
1877         <xsl:apply-templates select = "." mode="semantics"/>
1878       </xsl:for-each>
1879     </m:mfenced>
1880   </m:mrow>
1881 </xsl:template>
1882
1883 <xsl:template match = "m:apply[m:moment[1]]">
1884   <xsl:call-template name="insert_xref"/>
1885   <m:mfenced open="&lt;" close="&gt;" separators="">
1886     <xsl:if test="*[2]=m:degree">
1887       <m:msup>
1888         <xsl:apply-templates select="*[3]" mode = "semantics"/>
1889         <xsl:apply-templates select="*[2]" mode = "semantics"/>
1890       </m:msup>
1891     </xsl:if>
1892     <xsl:if test="not(*[2]=m:degree)">
1893       <xsl:for-each select = "*[position()>1]">
1894         <xsl:apply-templates select = "." mode="semantics"/>
1895       </xsl:for-each>
1896     </xsl:if>
1897   </m:mfenced>
1898 </xsl:template>
1899
1900
1901 <!-- LINEAR ALGEBRA -->
1902
1903 <xsl:template match="m:vector">
1904   <m:mfenced separators="">
1905     <m:mtable>
1906       <xsl:for-each select="*">
1907         <m:mtd>
1908           <xsl:apply-templates select="." mode = "semantics"/>
1909         </m:mtd>
1910       </xsl:for-each>
1911     </m:mtable>
1912   </m:mfenced>
1913 </xsl:template>
1914
1915 <xsl:template match = "m:matrix">
1916   <m:mfenced separators="">
1917     <m:mtable>
1918       <xsl:apply-templates mode = "semantics"/>
1919     </m:mtable>
1920   </m:mfenced>
1921 </xsl:template>
1922
1923 <xsl:template match = "m:matrixrow">
1924   <m:mtr>
1925     <xsl:for-each select="*">
1926       <m:mtd>
1927         <xsl:apply-templates select="." mode = "semantics"/>
1928       </m:mtd>
1929     </xsl:for-each>
1930   </m:mtr>
1931 </xsl:template>
1932
1933 <xsl:template match = "m:apply[m:determinant[1]]">
1934   <m:mrow>
1935     <xsl:call-template name="insert_xref"/>
1936     <m:mo><xsl:call-template name="insert1"/>det</m:mo>
1937     <xsl:apply-templates select = "*[2]" mode = "semantics"/>
1938   </m:mrow>
1939 </xsl:template>
1940
1941 <xsl:template match = "m:apply[m:transpose[1]]">
1942   <m:msup>
1943     <xsl:apply-templates select = "*[2]" mode = "semantics"/>
1944     <m:mo>T</m:mo>
1945   </m:msup>
1946 </xsl:template>
1947
1948 <xsl:template match = "m:apply[m:selector[1]]">
1949   <xsl:if test="*[2]=m:matrix and *[3]=m:cn">
1950       <xsl:variable name="m" select = "*[3]"/>
1951       <xsl:choose>
1952         <xsl:when test="*[4]=m:cn">
1953           <xsl:variable name="n" select = "*[4]"/>
1954           <xsl:copy-of select = "m:matrix/*[position()=$m]/*[position()=$n]"/>
1955         </xsl:when>
1956         <xsl:otherwise>
1957           <xsl:copy-of select = "m:matrix/*[position()=$m]"/>
1958         </xsl:otherwise>
1959       </xsl:choose>
1960   </xsl:if>
1961   <xsl:if test="(*[2]=m:vector or *[2]=m:list) and *[3]=m:cn">
1962     <xsl:variable name="m" select = "*[3]"/>
1963     <xsl:copy-of select = "*[2]/*[position()=$m]"/>
1964   </xsl:if>
1965 </xsl:template>
1966
1967 <xsl:template match = "m:apply[m:vectorproduct[1] | m:scalarproduct[1] | m:outerproduct[1]]">
1968   <m:mrow>
1969     <xsl:call-template name="insert_xref"/>
1970     <xsl:apply-templates select="*[2]" mode = "semantics"/>
1971     <xsl:choose>
1972       <xsl:when test="m:vectorproduct[1]">
1973         <m:mo><xsl:call-template name="insert1"/> <mchar name="Cross"/> </m:mo>
1974       </xsl:when>
1975       <xsl:when test="m:scalarproduct[1] | m:outerproduct[1]">
1976         <m:mo><xsl:call-template name="insert1"/>.</m:mo>
1977       </xsl:when>
1978     </xsl:choose>
1979     <xsl:apply-templates select="*[3]" mode = "semantics"/>
1980   </m:mrow>
1981 </xsl:template>
1982
1983 </xsl:stylesheet>
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999