]> matita.cs.unibo.it Git - helm.git/blob - helm/style/mmlctop.xsl-0.14
Modified Files:
[helm.git] / helm / style / mmlctop.xsl-0.14
1 <?xml version="1.0"?>
2
3 <!-- ******************************************************
4     
5      XSL Transform of MathML content to MathML presentation
6                                                     
7      Version 0.14, Dec. 13, 2000       
8      Authors Igor Rodionov <igor@csd.uwo.ca>,
9              Stephen Watt  <watt@csd.uwo.ca>.
10     
11      (C) Copyright 2000  Symbolic Computation Laboratory,
12                          University of Western Ontario,
13                          London, Canada N6A 5B7.
14      ****************************************************** -->
15
16
17 <!-- ====================================================== -->
18 <!--  April,28 2001 - HELM group:                           -->
19 <!--  Added the namespace prefix to all the output elements -->
20 <!--  Added the namespace prefix to all the xref attributes -->
21 <!--  Changed the mml prefix into m                         -->
22 <!--  Added m:xref to every mo element                      -->
23 <!--  First draft: April 27 2001, Irene Schena              -->
24 <!-- ====================================================== -->
25
26 <!-- Mostly complies with the W3C MathML 2.0 Candidate Recommenation 
27      of November 13, 2000.  The main difference is the use of <mchar>
28      which was removed from MathML 2.0 in the last working draft.
29   -->
30
31 <xsl:stylesheet id="mmlctop.xsl"
32                 version="1.0"
33                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
34                 xmlns:m="http://www.w3.org/1998/Math/MathML">
35
36 <!-- HELM: we don't have a default namespace.
37      Removed xmlns="http://www.w3.org/1998/Math/MathML" -->
38
39 <xsl:output method="xml" indent="yes"/>
40
41 <xsl:strip-space elements="apply semantics annotation-xml
42         csymbol fn cn ci interval matrix matrixrow vector
43         lambda bvar condition logbase degree set list
44         lowlimit uplimit"/>
45
46
47 <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
48 <!--         Parameters, variables and constants           -->
49 <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
50
51 <!-- ~~~~~~~~ Semantics related *constants*: ~~~~~~~~ -->
52
53 <!-- Strip off semantics -->
54 <xsl:variable name="SEM_STRIP" select="-1"/>
55
56 <!-- Pass semantics "as is" -->
57 <xsl:variable name="SEM_PASS" select="0"/>
58
59 <!-- Add semantics at top level only -->
60 <xsl:variable name="SEM_TOP" select="1"/>
61
62 <!-- Add semantics at all levels -->
63 <xsl:variable name="SEM_ALL" select="2"/>
64
65 <!-- Semantics at top level only, with id refs -->
66 <!-- NOTE: ids have to be already present in the
67            input for this feature to work. -->
68 <xsl:variable name="SEM_XREF" select="3"/>
69
70 <!-- No semantics at top level, with id refs -->
71 <!-- NOTE: ids have to be already present in the
72            input for this feature to work. -->
73 <xsl:variable name="SEM_XREF_EXT" select="4"/>
74
75
76 <!-- ~~~~~~~~~~ Stylesheet *parameter*: SEM_SW ~~~~~~~~~~~~~~ -->
77 <!-- Assumes one of the above values; SEM_PASS is the default -->
78 <!-- The default can be overridden by specifying different    -->
79 <!-- value on the command line when the stylesheet is invoked -->
80
81 <!-- HELM: $SEM_SW was SEM_PASS (error!) -->
82 <xsl:param name="SEM_SW" select="$SEM_XREF"/>
83
84 <!-- ~~~~~~ Operator precedence definitions ~~~~~~ -->
85
86 <xsl:variable name="NO_PREC" select="0"/>
87 <xsl:variable name="UNION_PREC" select="1"/>
88 <xsl:variable name="SETDIFF_PREC" select="1"/>
89 <xsl:variable name="INTERSECT_PREC" select="3"/>
90 <xsl:variable name="OR_PREC" select="5"/>
91 <xsl:variable name="XOR_PREC" select="5"/>
92 <xsl:variable name="AND_PREC" select="7"/>
93 <xsl:variable name="PLUS_PREC" select="9"/>
94 <xsl:variable name="MINUS_PREC" select="9"/>
95 <xsl:variable name="MUL_PREC" select="11"/>
96 <xsl:variable name="DIV_PREC" select="11"/>
97 <xsl:variable name="NEG_PREC" select="13"/>
98 <xsl:variable name="FUNCTION_PREC" select="99"/>
99
100 <!-- ~~~~~ Miscellaneous constant definitions ~~~~~ -->
101
102 <xsl:variable name="YES" select="1"/>
103 <xsl:variable name="NO" select="0"/>
104 <xsl:variable name="NO_PARAM" select="-1"/>
105 <xsl:variable name="PAR_SAME" select="-3"/>
106 <xsl:variable name="PAR_YES" select="-5"/>
107 <xsl:variable name="PAR_NO" select="-7"/>
108
109
110 <!-- +++++++++++++++++ INDEX OF TEMPLATES +++++++++++++++++++ -->
111
112 <!-- All templates are subdivided into the following categories
113      (listed in the order of appearance in the stylesheet):
114
115 THE TOPMOST ELEMENT: MATH
116  math
117
118 SEMANTICS HANDLING
119  semantics
120
121 BASIC CONTAINER ELEMENTS
122  cn, ci, csymbol
123
124 BASIC CONTENT ELEMENTS
125  fn, interval, inverse, sep, condition, declare, lambda, compose, ident
126
127 ARITHMETIC, ALGEBRA & LOGIC
128  quotient, exp, factorial, max, min, minus, plus, power, rem, divide,
129  times, root, gcd, and, or, xor, not, forall, exists, abs, conjugate,
130  arg, real, imaginary
131
132 RELATIONS
133  neq, approx, tendsto, implies, in, notin, notsubset, notprsubset,
134  subset, prsubset, eq, gt, lt, geq, leq, equivalent
135
136 CALCULUS
137  ln, log, diff, partialdiff, lowlimit, uplimit, bvar, degree,
138  logbase, divergence, grad, curl, laplacian
139
140 SET THEORY
141  set, list, union, intersect, setdiff, card
142
143 SEQUENCES AND SERIES
144  sum, product, limit
145
146 TRIGONOMETRY
147  sin, cos, tan, sec, csc, cot, sinh, cosh, tanh, sech, csch, coth,
148  arcsin, arccos, arctan
149
150 STATISTICS
151  mean, sdev, variance, median, mode, moment
152
153 LINEAR ALGEBRA
154  vector, matrix, matrixrow, determinant, transpose, selector,
155  vectorproduct, scalarproduct, outerproduct
156 -->
157
158
159 <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
160 <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~ TEMPLATES ~~~~~~~~~~~~~~~~~~~~~~~~~ -->
161 <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
162
163
164 <!-- ***************** THE TOPMOST ELEMENT: MATH ***************** -->
165
166 <xsl:template match = "m:math">
167   <xsl:choose>
168     <xsl:when test="$SEM_SW=$SEM_TOP or $SEM_SW=$SEM_ALL and *[2] or
169                                                     $SEM_SW=$SEM_XREF">
170       <m:semantics>
171         <m:mrow>
172           <xsl:apply-templates mode = "semantics"/>
173         </m:mrow>
174         <m:annotation-xml encoding="MathML">
175           <xsl:copy-of select="*"/>
176         </m:annotation-xml>
177       </m:semantics>
178     </xsl:when>
179     <xsl:otherwise>
180       <m:mrow>
181         <xsl:apply-templates mode = "semantics"/>
182       </m:mrow>  
183     </xsl:otherwise>
184   </xsl:choose>
185 </xsl:template>
186
187
188 <!-- ***************** SEMANTICS HANDLING ***************** -->
189
190 <!-- This template is called recursively.  At each level   -->
191 <!-- in the source tree it decides whether to strip off,   -->
192 <!-- pass or add semantics at that level (depending on the -->
193 <!-- value of SEM_SW parameter).  Then the actual template -->
194 <!-- is applied to the node.                               -->
195
196 <xsl:template match = "m:*" mode = "semantics">
197   <xsl:param name="IN_PREC" select="$NO_PREC"/>
198   <xsl:param name="PARAM" select="$NO_PARAM"/>
199   <xsl:param name="PAREN" select="$PAR_NO"/>
200   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
201   <xsl:choose>
202     <xsl:when test="$SEM_SW=$SEM_STRIP and self::m:semantics">
203       <xsl:apply-templates select="m:annotation-xml[@encoding='MathML']">
204         <xsl:with-param name="IN_PREC" select="$IN_PREC"/>
205         <xsl:with-param name="PARAM" select="$PARAM"/>
206         <xsl:with-param name="PAREN" select="$PAREN"/>
207         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
208       </xsl:apply-templates>
209     </xsl:when>
210     <xsl:when test="($SEM_SW=$SEM_PASS or $SEM_SW=$SEM_TOP) and self::m:semantics">
211       <m:semantics>
212         <xsl:apply-templates select="*[1]">
213           <xsl:with-param name="IN_PREC" select="$IN_PREC"/>
214           <xsl:with-param name="PARAM" select="$PARAM"/>
215           <xsl:with-param name="PAREN" select="$PAREN"/>
216           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
217         </xsl:apply-templates>
218         <xsl:copy-of select="m:annotation-xml"/>
219       </m:semantics>
220     </xsl:when>
221     <xsl:when test="$SEM_SW=$SEM_ALL">
222       <m:semantics>
223         <xsl:choose>
224           <xsl:when test="self::m:semantics">
225             <xsl:apply-templates select="*[1]">
226               <xsl:with-param name="IN_PREC" select="$IN_PREC"/>
227               <xsl:with-param name="PARAM" select="$PARAM"/>
228               <xsl:with-param name="PAREN" select="$PAREN"/>
229               <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
230             </xsl:apply-templates>
231             <xsl:copy-of select="m:annotation-xml"/>
232           </xsl:when>
233           <xsl:otherwise>
234             <xsl:apply-templates select=".">
235               <xsl:with-param name="IN_PREC" select="$IN_PREC"/>
236               <xsl:with-param name="PARAM" select="$PARAM"/>
237               <xsl:with-param name="PAREN" select="$PAREN"/>
238               <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
239             </xsl:apply-templates>
240             <m:annotation-xml encoding="MathML">
241               <xsl:copy-of select="."/>
242             </m:annotation-xml>
243           </xsl:otherwise>
244         </xsl:choose>
245       </m:semantics>
246     </xsl:when>
247     <xsl:when test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
248       <xsl:choose>
249 <!-- HELM: syntax error: sematics -->
250         <xsl:when test="self::m:semantics">
251           <xsl:copy>
252             <xsl:copy-of select="@*"/>
253             <xsl:attribute name="m:xref">
254               <xsl:value-of select="@id"/>
255             </xsl:attribute>
256             <xsl:copy-of select="*[1]"/>
257             <xsl:copy-of select="m:annotation-xml"/>
258           </xsl:copy>
259         </xsl:when>
260         <xsl:otherwise>
261           <xsl:apply-templates select=".">
262             <xsl:with-param name="IN_PREC" select="$IN_PREC"/>
263             <xsl:with-param name="PARAM" select="$PARAM"/>
264             <xsl:with-param name="PAREN" select="$PAREN"/>
265             <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
266           </xsl:apply-templates>
267         </xsl:otherwise>
268       </xsl:choose>
269     </xsl:when>
270     <xsl:otherwise>
271       <xsl:choose>
272         <xsl:when test="self::m:semantics">
273           <xsl:copy-of select="."/>
274         </xsl:when>
275         <xsl:otherwise>
276           <xsl:apply-templates select=".">
277             <xsl:with-param name="IN_PREC" select="$IN_PREC"/>
278             <xsl:with-param name="PARAM" select="$PARAM"/>
279             <xsl:with-param name="PAREN" select="$PAREN"/>
280             <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
281           </xsl:apply-templates>
282         </xsl:otherwise>
283       </xsl:choose>
284     </xsl:otherwise>
285   </xsl:choose>
286 </xsl:template>
287
288 <xsl:template match = "m:semantics">
289   <xsl:apply-templates select="." mode = "semantics"/>
290 </xsl:template>
291
292
293 <!-- ***************** BASIC CONTAINER ELEMENTS ***************** -->
294
295 <!-- HELM: cn could not contain MAthML presentation -->
296 <xsl:template match = "m:cn">
297   <xsl:param name="IN_PREC" select="$NO_PREC"/>
298   <xsl:param name="PAREN" select="$PAR_NO"/>
299   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
300 <!-- HELM: added -->
301 <xsl:choose>
302   <xsl:when test="child::text()">
303 <!-- HELM -->
304   <xsl:choose>
305     <xsl:when test=". &lt; 0 and $IN_PREC &gt; $NO_PREC and $PAREN=$PAR_NO
306                                                    and $PAR_NO_IGNORE=$NO">
307       <m:mfenced separators="">
308         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
309           <xsl:attribute name="m:xref">
310             <xsl:value-of select="@id"/>
311           </xsl:attribute>
312         </xsl:if>
313         <xsl:apply-templates select="." mode="cn"/>
314       </m:mfenced>
315     </xsl:when>
316     <xsl:otherwise>
317       <xsl:choose>
318         <xsl:when test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
319           <xsl:apply-templates select="." mode="cnid"/>
320         </xsl:when>
321         <xsl:otherwise>
322           <xsl:apply-templates select="." mode="cn"/>
323         </xsl:otherwise>
324       </xsl:choose>
325     </xsl:otherwise>
326   </xsl:choose>
327 <!-- HELM: added -->
328   </xsl:when>
329   <xsl:otherwise>
330    <m:mrow>
331     <xsl:attribute name="m:xref">
332      <xsl:value-of select="@id"/>
333     </xsl:attribute>
334     <xsl:copy-of select="*"/>
335    </m:mrow> 
336   </xsl:otherwise>
337  </xsl:choose>
338 <!-- HELM -->
339 </xsl:template>
340
341 <xsl:template match = "m:cn" mode="cn">
342   <xsl:choose>
343     <xsl:when test="@base and (not(@type) or @type='integer' or @type='real')">
344       <m:msub>
345         <m:mn> <xsl:apply-templates mode = "semantics"/> </m:mn>
346         <m:mn> <xsl:value-of select="@base"/> </m:mn>
347       </m:msub>
348     </xsl:when>
349     <xsl:when test="@type='complex' and not(@base) and child::m:sep[1]">
350       <m:mfenced separators="">
351         <m:mn> <xsl:apply-templates select="text()[1]" mode = "semantics"/> </m:mn>
352         <xsl:if test="text()[2] &lt; 0">
353           <m:mo>-</m:mo>
354           <m:mn> <xsl:value-of select="-text()[2]"/> </m:mn>
355         </xsl:if>
356         <xsl:if test="not(text()[2] &lt; 0)">
357           <m:mo>+</m:mo>
358           <m:mn> <xsl:value-of select="text()[2]"/> </m:mn>
359         </xsl:if>
360         <m:mo> <m:mchar name="InvisibleTimes"/> </m:mo>
361         <m:mo>i</m:mo>
362       </m:mfenced>
363     </xsl:when>
364     <xsl:when test="@type='complex' and @base and child::m:sep[1]">
365       <m:msub>
366         <m:mfenced separators="">
367           <m:mn> <xsl:apply-templates select="text()[1]"/> </m:mn>
368           <xsl:if test="text()[2] &lt; 0">
369             <m:mo>-</m:mo>
370             <m:mn> <xsl:value-of select="-text()[2]"/> </m:mn>
371           </xsl:if>
372           <xsl:if test="not(text()[2] &lt; 0)">
373             <m:mo>+</m:mo>
374             <m:mn> <xsl:apply-templates select="text()[2]"/> </m:mn>
375           </xsl:if>
376           <m:mo> <m:mchar name="InvisibleTimes"/> </m:mo>
377           <m:mo>i</m:mo>
378         </m:mfenced>
379         <m:mn> <xsl:value-of select="@base"/> </m:mn>
380       </m:msub>
381     </xsl:when>
382     <xsl:when test="@type='rational' and not(@base) and child::m:sep[1]">
383       <m:mfrac>
384         <m:mn> <xsl:apply-templates select="text()[1]"/> </m:mn>
385         <m:mn> <xsl:apply-templates select="text()[2]"/> </m:mn>
386       </m:mfrac>
387     </xsl:when>
388     <xsl:when test="@type='rational' and @base and child::m:sep[1]">
389       <m:msub>
390         <m:mfenced>
391           <m:mfrac>
392             <m:mn> <xsl:apply-templates select="text()[1]"/> </m:mn>
393             <m:mn> <xsl:apply-templates select="text()[2]"/> </m:mn>
394           </m:mfrac>
395         </m:mfenced>
396         <m:mn> <xsl:value-of select="@base"/> </m:mn>
397       </m:msub>
398     </xsl:when>
399     <xsl:when test="@type='polar' and not(@base) and child::m:sep[1]">
400       <m:mrow>
401         <m:mo>Polar</m:mo>
402         <m:mo> <m:mchar name="InvisibleTimes"/> </m:mo>
403         <m:mfenced separators=",">
404           <m:mn> <xsl:apply-templates select="text()[1]"/> </m:mn>
405           <m:mn> <xsl:apply-templates select="text()[2]"/> </m:mn>
406         </m:mfenced>
407       </m:mrow>
408     </xsl:when>
409     <xsl:when test="@type='polar' and @base and child::m:sep[1]">
410       <m:msub>
411         <m:mrow>
412           <m:mo>Polar</m:mo>
413           <m:mo> <m:mchar name="InvisibleTimes"/> </m:mo>
414           <m:mfenced separators=",">
415             <m:mn> <xsl:apply-templates select="text()[1]"/> </m:mn>
416             <m:mn> <xsl:apply-templates select="text()[2]"/> </m:mn>
417           </m:mfenced>
418         </m:mrow>
419         <m:mn> <xsl:value-of select="@base"/> </m:mn>
420       </m:msub>
421    </xsl:when>
422     <xsl:otherwise>
423       <m:mn> <xsl:apply-templates mode = "semantics"/> </m:mn>
424     </xsl:otherwise>
425   </xsl:choose>
426 </xsl:template>
427
428 <xsl:template match = "m:cn" mode="cnid">
429   <xsl:choose>
430     <xsl:when test="@base and (not(@type) or @type='integer' or @type='real')">
431       <m:msub m:xref="{@id}">
432         <m:mn> <xsl:apply-templates mode = "semantics"/> </m:mn>
433         <m:mn> <xsl:value-of select="@base"/> </m:mn>
434       </m:msub>
435     </xsl:when>
436     <xsl:when test="@type='complex' and not(@base) and child::m:sep[1]">
437       <m:mfenced separators="" m:xref="{@id}">
438         <m:mn> <xsl:apply-templates select="text()[1]" mode = "semantics"/> </m:mn>
439         <xsl:if test="text()[2] &lt; 0">
440           <m:mo>-</m:mo>
441           <m:mn> <xsl:value-of select="-text()[2]"/> </m:mn>
442         </xsl:if>
443         <xsl:if test="not(text()[2] &lt; 0)">
444           <m:mo>+</m:mo>
445           <m:mn> <xsl:value-of select="text()[2]"/> </m:mn>
446         </xsl:if>
447         <m:mo> <m:mchar name="InvisibleTimes"/> </m:mo>
448         <m:mo>i</m:mo>
449       </m:mfenced>
450     </xsl:when>
451     <xsl:when test="@type='complex' and @base and child::m:sep[1]">
452       <m:msub m:xref="{@id}">
453         <m:mfenced separators="">
454           <m:mn> <xsl:apply-templates select="text()[1]"/> </m:mn>
455           <xsl:if test="text()[2] &lt; 0">
456             <m:mo>-</m:mo>
457             <m:mn> <xsl:value-of select="-text()[2]"/> </m:mn>
458           </xsl:if>
459           <xsl:if test="not(text()[2] &lt; 0)">
460             <m:mo>+</m:mo>
461             <m:mn> <xsl:apply-templates select="text()[2]"/> </m:mn>
462           </xsl:if>
463           <m:mo> <m:mchar name="InvisibleTimes"/> </m:mo>
464           <m:mo>i</m:mo>
465         </m:mfenced>
466         <m:mn> <xsl:value-of select="@base"/> </m:mn>
467       </m:msub>
468     </xsl:when>
469     <xsl:when test="@type='rational' and not(@base) and child::m:sep[1]">
470       <m:mfrac m:xref="{@id}">
471         <m:mn> <xsl:apply-templates select="text()[1]"/> </m:mn>
472         <m:mn> <xsl:apply-templates select="text()[2]"/> </m:mn>
473       </m:mfrac>
474     </xsl:when>
475     <xsl:when test="@type='rational' and @base and child::m:sep[1]">
476       <m:msub m:xref="{@id}">
477         <m:mfenced>
478           <m:mfrac>
479             <m:mn> <xsl:apply-templates select="text()[1]"/> </m:mn>
480             <m:mn> <xsl:apply-templates select="text()[2]"/> </m:mn>
481           </m:mfrac>
482         </m:mfenced>
483         <m:mn> <xsl:value-of select="@base"/> </m:mn>
484       </m:msub>
485     </xsl:when>
486     <xsl:when test="@type='polar' and not(@base) and child::m:sep[1]">
487       <m:mrow m:xref="{@id}">
488         <m:mo>Polar</m:mo>
489         <m:mo> <m:mchar name="InvisibleTimes"/> </m:mo>
490         <m:mfenced separators=",">
491           <m:mn> <xsl:apply-templates select="text()[1]"/> </m:mn>
492           <m:mn> <xsl:apply-templates select="text()[2]"/> </m:mn>
493         </m:mfenced>
494       </m:mrow>
495     </xsl:when>
496     <xsl:when test="@type='polar' and @base and child::m:sep[1]">
497       <m:msub m:xref="{@id}">
498         <m:mrow>
499           <m:mo>Polar</m:mo>
500           <m:mo> <m:mchar name="InvisibleTimes"/> </m:mo>
501           <m:mfenced separators=",">
502             <m:mn> <xsl:apply-templates select="text()[1]"/> </m:mn>
503             <m:mn> <xsl:apply-templates select="text()[2]"/> </m:mn>
504           </m:mfenced>
505         </m:mrow>
506         <m:mn> <xsl:value-of select="@base"/> </m:mn>
507       </m:msub>
508    </xsl:when>
509     <xsl:otherwise>
510       <m:mn m:xref="{@id}"> <xsl:apply-templates mode = "semantics"/> </m:mn>
511     </xsl:otherwise>
512   </xsl:choose>
513 </xsl:template>
514
515 <!-- HELM: ci could not contain MAthML presentation -->
516 <xsl:template match = "m:ci">
517 <!-- HELM: added -->
518 <xsl:choose>
519   <xsl:when test="child::text()">
520 <!-- HELM -->
521   <xsl:choose>
522     <xsl:when test="@type='vector' or @type=matrix or @type=set">
523       <m:mi fontweight="bold">
524         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
525           <xsl:attribute name="m:xref">
526             <xsl:value-of select="@id"/>
527           </xsl:attribute>
528         </xsl:if>
529         <xsl:apply-templates mode = "semantics"/>
530       </m:mi>
531     </xsl:when>
532     <xsl:when test="child::text() and not(child::*[1])">
533       <m:mi>
534         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
535           <xsl:attribute name="m:xref">
536             <xsl:value-of select="@id"/>
537           </xsl:attribute>
538         </xsl:if>
539 <!-- HELM: added mode=semantics -->
540         <xsl:apply-templates mode = "semantics"/>
541       </m:mi>
542     </xsl:when>
543     <xsl:when test="child::text() and *[1] and not(*[1]=m:sep)">
544       <m:mrow>
545         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
546           <xsl:attribute name="m:xref">
547             <xsl:value-of select="@id"/>
548           </xsl:attribute>
549         </xsl:if>
550 <!-- HELM: added mode=semantics -->
551         <xsl:apply-templates mode = "semantics"/>
552       </m:mrow>
553     </xsl:when>
554     <xsl:otherwise>
555       <xsl:if test="*[2]">
556         <m:mrow>
557           <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
558             <xsl:attribute name="m:xref">
559               <xsl:value-of select="@id"/>
560             </xsl:attribute>
561           </xsl:if>
562           <xsl:apply-templates select="*"/>
563         </m:mrow>
564       </xsl:if>
565       <xsl:if test="not(*[2])">
566         <xsl:apply-templates select="*[1]"/>
567       </xsl:if>
568     </xsl:otherwise>
569   </xsl:choose>
570 <!-- HELM: added -->
571 </xsl:when>
572   <xsl:otherwise>
573    <m:mrow>
574     <xsl:copy-of select="*"/>
575     <xsl:attribute name="m:xref">
576      <xsl:value-of select="@id"/>
577     </xsl:attribute>
578    </m:mrow> 
579   </xsl:otherwise>
580  </xsl:choose>
581 <!-- HELM -->
582 </xsl:template>
583
584 <xsl:template match = "m:ci/m:*[not(self::m:sep)]">
585   <xsl:copy-of select = "."/>
586 </xsl:template>
587
588 <!-- HELM: previous Version x.xx from Feb. 18, 2000 -->
589 <xsl:template match = "m:csymbol">
590 <!-- HELM: added -->
591    <m:mrow>
592     <xsl:attribute name="m:xref">
593      <xsl:value-of select="@id"/>
594     </xsl:attribute>
595 <!-- HELM -->
596    <xsl:choose>
597     <xsl:when test="*[1]">
598      <xsl:copy-of select = "*"/>
599     </xsl:when>
600    <xsl:otherwise>
601     <m:mo>
602      <xsl:apply-templates mode = "semantics"/>
603     </m:mo>
604    </xsl:otherwise>
605   </xsl:choose>
606  </m:mrow>
607 </xsl:template>
608
609
610 <!-- HELM: csymbol cannot contain ci or cn elements, but only text or 
611 presentation elements. PCDATA should render as if it were wrapped in 
612 an mo. Mixed content: mrow which contains mo + presentation elements -->
613 <!--<xsl:template match = "m:csymbol/m:*">
614   <xsl:choose>
615     <xsl:when test="self::m:cn or self::m:ci">
616       <xsl:apply-templates mode = "semantics"/>
617     </xsl:when>
618     <xsl:otherwise>
619       <xsl:copy-of select = "."/>
620     </xsl:otherwise>
621   </xsl:choose>
622 </xsl:template>
623
624 <xsl:template match = "m:csymbol/text()">
625   <xsl:choose>
626     <xsl:when test=". &lt; 0 or . = 0 or . &gt; 0">
627       <mn> <xsl:copy-of select = "."/> </mn>
628     </xsl:when>
629     <xsl:otherwise>
630       <mi> <xsl:copy-of select = "."/> </mi>
631     </xsl:otherwise>
632   </xsl:choose>
633 </xsl:template>-->
634
635
636 <!-- ***************** BASIC CONTENT ELEMENTS ***************** -->
637
638 <xsl:template match = "m:apply[m:*[1][self::m:fn]]">
639   <m:mrow>
640     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
641       <xsl:attribute name="m:xref">
642         <xsl:value-of select="@id"/>
643       </xsl:attribute>
644     </xsl:if>
645     <xsl:apply-templates select = "m:fn[1]" mode = "semantics"/>
646     <m:mo> 
647 <!-- HELM: added -->        
648         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
649           <xsl:attribute name="m:xref">
650             <xsl:value-of select="m:fn/@id"/>
651           </xsl:attribute>
652         </xsl:if>
653     <m:mchar name='ApplyFunction'/> </m:mo>
654     <m:mfenced separators=",">
655       <xsl:apply-templates select = "*[position()>1]" mode = "semantics"/>
656     </m:mfenced>
657   </m:mrow>
658 </xsl:template>
659
660 <xsl:template match = "m:fn">
661   <xsl:apply-templates select = "*[1]" mode = "semantics">
662     <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
663   </xsl:apply-templates>
664 </xsl:template>
665
666 <xsl:template match = "m:interval">
667   <m:mfenced separators=",">
668     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
669       <xsl:attribute name="m:xref">
670         <xsl:value-of select="@id"/>
671       </xsl:attribute>
672     </xsl:if>
673     <xsl:if test="@closure='closed' or @closure='closed-open'">
674       <xsl:attribute name="open">[</xsl:attribute>
675     </xsl:if>
676     <xsl:if test="@closure='closed' or @closure='open-closed'">
677       <xsl:attribute name="close">]</xsl:attribute>
678     </xsl:if>
679     <xsl:apply-templates select="*" mode = "semantics"/>
680   </m:mfenced>
681 </xsl:template>
682
683 <xsl:template match = "m:apply[m:*[1][self::m:apply[m:inverse[1]]]]">
684   <m:mrow>
685     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
686       <xsl:attribute name="m:xref">
687         <xsl:value-of select="@id"/>
688       </xsl:attribute>
689     </xsl:if>
690     <xsl:apply-templates select = "*[1]" mode = "semantics"/>
691     <m:mo> <m:mchar name='ApplyFunction'/> </m:mo>
692     <m:mfenced separators=",">
693       <xsl:apply-templates select = "*[position()>1]" mode = "semantics"/>
694     </m:mfenced>
695  </m:mrow>
696 </xsl:template>
697
698 <xsl:template match = "m:apply[*[1][self::m:inverse]]">
699   <xsl:choose>
700     <xsl:when test="*[2]=m:exp or *[2]=m:ln or *[2]=m:sin or *[2]=m:cos or
701                     *[2]=m:tan or *[2]=m:sec or *[2]=m:csc or *[2]=m:cot or
702                     *[2]=m:sinh or *[2]=m:cosh or *[2]=m:tanh or *[2]=m:sech or
703                     *[2]=m:csch or *[2]=m:coth or *[2]=m:arcsin or
704                     *[2]=m:arccos or *[2]=m:arctan">
705       <m:mo>
706         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
707           <xsl:attribute name="m:xref">
708             <xsl:value-of select="@id"/>
709           </xsl:attribute>
710         </xsl:if>
711         <xsl:apply-templates select="*[2]" mode="inverse"/>
712       </m:mo>
713     </xsl:when>
714     <xsl:otherwise>
715       <m:msup>
716         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
717           <xsl:attribute name="m:xref">
718             <xsl:value-of select="@id"/>
719           </xsl:attribute>
720         </xsl:if>
721         <xsl:apply-templates select = "*[2]"/>
722         <m:mfenced>
723           <m:mn>-1</m:mn>
724         </m:mfenced>
725       </m:msup>
726     </xsl:otherwise>
727   </xsl:choose>
728 </xsl:template>
729
730 <xsl:template match = "*" mode="inverse">
731   <xsl:choose>
732     <xsl:when test="self::m:exp">
733       <xsl:value-of select="'ln'"/>
734     </xsl:when>
735     <xsl:when test="self::m:ln">
736       <xsl:value-of select="'exp'"/>
737     </xsl:when>
738     <xsl:when test="self::m:sin">
739       <xsl:value-of select="'arcsin'"/>
740     </xsl:when>
741     <xsl:when test="self::m:cos">
742       <xsl:value-of select="'arccos'"/>
743     </xsl:when>
744     <xsl:when test="self::m:tan">
745       <xsl:value-of select="'arctan'"/>
746     </xsl:when>
747     <xsl:when test="self::m:sec">
748       <xsl:value-of select="'arcsec'"/>
749     </xsl:when>
750     <xsl:when test="self::m:csc">
751       <xsl:value-of select="'arccsc'"/>
752     </xsl:when>
753     <xsl:when test="self::m:cot">
754       <xsl:value-of select="'arccot'"/>
755     </xsl:when>
756     <xsl:when test="self::m:sinh">
757       <xsl:value-of select="'arcsinh'"/>
758     </xsl:when>
759     <xsl:when test="self::m:cosh">
760       <xsl:value-of select="'arccosh'"/>
761     </xsl:when>
762     <xsl:when test="self::m:tanh">
763       <xsl:value-of select="'arctanh'"/>
764     </xsl:when>
765     <xsl:when test="self::m:sech">
766       <xsl:value-of select="'arcsech'"/>
767     </xsl:when>
768     <xsl:when test="self::m:csch">
769       <xsl:value-of select="'arccsch'"/>
770     </xsl:when>
771     <xsl:when test="self::m:coth">
772       <xsl:value-of select="'arccoth'"/>
773     </xsl:when>
774     <xsl:when test="self::m:arcsin">
775       <xsl:value-of select="'sin'"/>
776     </xsl:when>
777     <xsl:when test="self::m:arccos">
778       <xsl:value-of select="'cos'"/>
779     </xsl:when>
780     <xsl:when test="self::m:arctan">
781       <xsl:value-of select="'tan'"/>
782     </xsl:when>
783   </xsl:choose>
784 </xsl:template>
785
786 <xsl:template match = "m:sep"/>
787
788 <xsl:template match = "m:condition">
789   <xsl:choose>
790     <xsl:when test="parent::m:apply[m:forall[1]]"/>
791     <xsl:otherwise>
792       <xsl:choose>
793         <xsl:when test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
794           <m:mrow m:xref="{@id}">
795             <xsl:apply-templates select="*" mode = "semantics"/>
796           </m:mrow>
797         </xsl:when>
798         <xsl:otherwise>
799           <xsl:if test="not(*[2])">
800             <xsl:apply-templates select="*" mode = "semantics"/>
801           </xsl:if>
802           <xsl:if test="*[2]">
803             <m:mrow>
804               <xsl:apply-templates select="*" mode = "semantics"/>
805             </m:mrow>
806           </xsl:if>
807         </xsl:otherwise>
808       </xsl:choose>
809     </xsl:otherwise>
810   </xsl:choose>
811 </xsl:template>
812
813 <xsl:template match = "m:declare"/>
814
815 <xsl:template match = "m:lambda">
816   <m:mrow>
817     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
818       <xsl:attribute name="m:xref">
819         <xsl:value-of select="@id"/>
820       </xsl:attribute>
821     </xsl:if>
822     <m:mo> <m:mchar name='Lambda'/> </m:mo>
823     <m:mo> <m:mchar name='ApplyFunction'/> </m:mo>
824     <m:mfenced separators=",">
825       <xsl:for-each select = "*">
826         <xsl:choose>
827           <xsl:when test="self::m:ci or self::m:cn">
828             <xsl:apply-templates select = "." mode="semantics"/>
829           </xsl:when>
830           <xsl:otherwise>
831             <m:mrow>
832               <xsl:apply-templates select = "." mode="semantics"/>
833             </m:mrow>
834           </xsl:otherwise>
835         </xsl:choose>
836       </xsl:for-each>
837     </m:mfenced>
838   </m:mrow>
839 </xsl:template>
840
841 <xsl:template match = "m:apply[*[1][self::m:apply[m:compose[1]]]]">
842   <m:mrow>
843     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
844       <xsl:attribute name="m:xref">
845         <xsl:value-of select="@id"/>
846       </xsl:attribute>
847     </xsl:if>
848     <xsl:apply-templates select = "*[1]" mode = "semantics"/>
849     <m:mo> <m:mchar name='ApplyFunction'/> </m:mo>
850     <m:mfenced separators=",">
851       <xsl:apply-templates select = "*[position()>1]" mode = "semantics"/>
852     </m:mfenced>
853  </m:mrow>
854 </xsl:template>
855
856 <xsl:template match = "m:apply[*[1][self::m:compose]]">
857   <m:mfenced separators="">
858     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
859       <xsl:attribute name="m:xref">
860         <xsl:value-of select="@id"/>
861       </xsl:attribute>
862     </xsl:if>
863     <xsl:apply-templates select = "m:*[2][self::m:ci[@type='fn'] |
864                                        self::m:fn]" mode="semantics"/>
865     <xsl:for-each select = "m:*[position()>2][self::m:ci[@type='fn'] |
866                                                             self::m:fn]">
867       <m:mo>
868  <!-- HELM: added -->        
869         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
870           <xsl:attribute name="m:xref">
871             <xsl:value-of select="../m:compose/@id"/>
872           </xsl:attribute>
873         </xsl:if>
874       <m:mchar name="SmallCircle"/> </m:mo>
875       <xsl:apply-templates select = "." mode="semantics"/>
876     </xsl:for-each>
877   </m:mfenced>
878 </xsl:template>
879
880 <xsl:template match = "m:ident">
881   <xsl:choose>
882     <xsl:when test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
883       <m:mo m:xref="{@id}">id</m:mo>
884     </xsl:when>
885     <xsl:otherwise>
886       <m:mo>id</m:mo>
887     </xsl:otherwise>
888   </xsl:choose>
889 </xsl:template>
890
891
892 <!-- ***************** ARITHMETIC, ALGEBRA & LOGIC ***************** -->
893
894 <xsl:template match = "m:apply[m:quotient[1]]">
895   <m:mrow>
896     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
897       <xsl:attribute name="m:xref">
898         <xsl:value-of select="@id"/>
899       </xsl:attribute>
900     </xsl:if>
901     <m:mo form="prefix" fence="true" stretchy="true" lspace="0em" rspace="0em">
902       <m:mchar name="LeftFloor"/>
903     </m:mo>
904     <m:mfrac>
905 <!-- HELM: added -->        
906         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
907           <xsl:attribute name="m:xref">
908             <xsl:value-of select="m:quotient/@id"/>
909           </xsl:attribute>
910         </xsl:if>
911       <m:mrow>
912         <xsl:apply-templates select="*[2]" mode = "semantics">
913           <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
914         </xsl:apply-templates>
915       </m:mrow>
916       <m:mrow>
917         <xsl:apply-templates select="*[3]" mode = "semantics">
918           <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
919           <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
920         </xsl:apply-templates>
921       </m:mrow>
922     </m:mfrac>
923     <m:mo form="postfix" fence="true" stretchy="true" lspace="0em" rspace="0em">
924       <m:mchar name="LeftFloor"/>
925     </m:mo>
926   </m:mrow>
927 </xsl:template>
928
929 <xsl:template match = "m:apply[*[1][self::m:exp]]">
930   <m:msup>
931     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
932       <xsl:attribute name="m:xref">
933         <xsl:value-of select="@id"/>
934       </xsl:attribute>
935     </xsl:if>
936     <m:mo>
937     <!-- HELM: added -->        
938         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
939           <xsl:attribute name="m:xref">
940             <xsl:value-of select="m:exp/@id"/>
941           </xsl:attribute>
942         </xsl:if>e</m:mo>
943     <xsl:apply-templates select = "*[2]" mode = "semantics"/>
944   </m:msup>
945 </xsl:template>
946
947 <xsl:template match = "m:apply[m:factorial[1]]">
948   <m:mrow>
949     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
950       <xsl:attribute name="m:xref">
951         <xsl:value-of select="@id"/>
952       </xsl:attribute>
953     </xsl:if>
954     <xsl:apply-templates select = "*[2]" mode = "semantics">
955       <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
956       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
957     </xsl:apply-templates>
958     <m:mo>
959 <!-- HELM: added -->        
960         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
961           <xsl:attribute name="m:xref">
962             <xsl:value-of select="m:factorial/@id"/>
963           </xsl:attribute>
964         </xsl:if>!</m:mo>
965   </m:mrow>
966 </xsl:template>
967
968 <xsl:template match = "m:apply[m:max[1] | m:min[1]]">
969   <m:mrow>
970     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
971       <xsl:attribute name="m:xref">
972         <xsl:value-of select="@id"/>
973       </xsl:attribute>
974     </xsl:if>
975     <xsl:if test="*[2]=m:bvar">
976       <m:munder>
977         <xsl:if test="*[1]=m:max">
978           <m:mo>
979 <!-- HELM: added -->        
980         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
981           <xsl:attribute name="m:xref">
982             <xsl:value-of select="m:max/@id"/>
983           </xsl:attribute>
984         </xsl:if>max</m:mo>
985         </xsl:if>
986         <xsl:if test="*[1]=m:min">
987           <m:mo>
988 <!-- HELM: added -->        
989         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
990           <xsl:attribute name="m:xref">
991             <xsl:value-of select="m:min/@id"/>
992           </xsl:attribute>
993         </xsl:if>min</m:mo>
994         </xsl:if>
995         <xsl:apply-templates select="*[2]" mode = "semantics"/>
996       </m:munder>
997       <xsl:if test="*[3]=m:condition">
998         <m:mfenced open="{{" close="}}" separators="">
999           <m:mfenced open="" close="" separators=",">
1000             <xsl:for-each select = "*[position()>3]">
1001               <xsl:apply-templates select = "." mode="semantics"/>
1002             </xsl:for-each>
1003           </m:mfenced>
1004           <m:mo>|</m:mo>
1005           <xsl:apply-templates select="*[3]" mode = "semantics"/>
1006         </m:mfenced>
1007       </xsl:if>
1008       <xsl:if test="not(*[3]=m:condition)">
1009         <m:mfenced open="{{" close="}}" separators=",">
1010           <xsl:for-each select = "*[position()>2]">
1011             <xsl:apply-templates select = "." mode="semantics"/>
1012           </xsl:for-each>
1013         </m:mfenced>
1014       </xsl:if>
1015     </xsl:if>
1016     <xsl:if test="*[2]=m:condition">
1017       <xsl:if test="*[1]=m:max">
1018         <m:mo>max</m:mo>
1019       </xsl:if>
1020       <xsl:if test="*[1]=m:min">
1021         <m:mo>min</m:mo>
1022       </xsl:if>
1023       <m:mfenced open="{{" close="}}" separators="">
1024         <xsl:if test="*[3]">
1025           <m:mfenced open="" close="" separators=",">
1026             <xsl:for-each select = "*[position()>2]">
1027               <xsl:apply-templates select = "." mode="semantics"/>
1028             </xsl:for-each>
1029           </m:mfenced>
1030           <m:mo>|</m:mo>
1031         </xsl:if>
1032         <xsl:apply-templates select="*[2]" mode = "semantics"/>
1033       </m:mfenced>
1034     </xsl:if>
1035     <xsl:if test="not(*[2]=m:condition) and not(*[2]=m:bvar)">
1036       <xsl:if test="*[1]=m:max">
1037         <m:mo>max</m:mo>
1038       </xsl:if>
1039       <xsl:if test="*[1]=m:min">
1040         <m:mo>min</m:mo>
1041       </xsl:if>
1042       <m:mfenced open="{{" close="}}" separators=",">
1043         <xsl:for-each select = "*[position()>1]">
1044           <xsl:apply-templates select = "." mode="semantics"/>
1045         </xsl:for-each>
1046       </m:mfenced>
1047     </xsl:if>
1048   </m:mrow>
1049 </xsl:template>
1050
1051 <xsl:template match = "m:apply[m:minus[1]]">
1052   <xsl:param name="IN_PREC" select="$NO_PREC"/>
1053   <xsl:param name="PARAM" select="$NO_PARAM"/>
1054   <xsl:param name="PAREN" select="$PAR_NO"/>
1055   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1056   <xsl:choose>
1057     <xsl:when test="$IN_PREC &gt; $MINUS_PREC or $IN_PREC=$MINUS_PREC and
1058                                                         $PARAM=$PAR_SAME">
1059       <m:mfenced separators="">
1060         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1061           <xsl:attribute name="m:xref">
1062             <xsl:value-of select="@id"/>
1063           </xsl:attribute>
1064         </xsl:if>
1065         <xsl:apply-templates select="." mode="minus">
1066           <xsl:with-param name="PARAM" select="$PARAM"/>
1067           <xsl:with-param name="PAREN" select="$PAR_YES"/>
1068           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1069         </xsl:apply-templates>
1070       </m:mfenced>
1071     </xsl:when>
1072     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC
1073                     and not($SEM_SW=$SEM_ALL) and not($SEM_SW=$SEM_XREF)
1074                     and not($SEM_SW=$SEM_XREF_EXT)">
1075       <xsl:apply-templates select="." mode="minus">
1076         <xsl:with-param name="PARAM" select="$PARAM"/>
1077         <xsl:with-param name="PAREN" select="$PAREN"/>
1078         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1079       </xsl:apply-templates>
1080     </xsl:when>
1081     <xsl:otherwise>
1082       <m:mrow>
1083         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1084           <xsl:attribute name="m:xref">
1085             <xsl:value-of select="@id"/>
1086           </xsl:attribute>
1087         </xsl:if>
1088         <xsl:apply-templates select="." mode="minus">
1089           <xsl:with-param name="PARAM" select="$PARAM"/>
1090           <xsl:with-param name="PAREN" select="$PAREN"/>
1091           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1092         </xsl:apply-templates>
1093       </m:mrow>
1094     </xsl:otherwise>
1095   </xsl:choose>
1096 </xsl:template>
1097
1098 <xsl:template match = "m:apply[m:minus[1]]" mode="minus">
1099   <xsl:param name="PARAM" select="$NO_PARAM"/>
1100   <xsl:param name="PAREN" select="$PAR_NO"/>
1101   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1102   <xsl:if test="not(*[3])">
1103     <m:mo>
1104 <!-- HELM: added -->        
1105         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1106           <xsl:attribute name="m:xref">
1107             <xsl:value-of select="m:minus/@id"/>
1108           </xsl:attribute>
1109         </xsl:if>-</m:mo>
1110     <xsl:apply-templates select="*[2]" mode = "semantics">
1111       <xsl:with-param name="IN_PREC" select="$NEG_PREC"/>
1112       <xsl:with-param name="PAREN" select="$PAREN"/>
1113       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1114     </xsl:apply-templates>
1115   </xsl:if>
1116   <xsl:if test="*[3]">
1117     <xsl:apply-templates select="*[2]" mode = "semantics">
1118       <xsl:with-param name="IN_PREC" select="$MINUS_PREC"/>
1119       <xsl:with-param name="PARAM" select="$PARAM"/>
1120       <xsl:with-param name="PAREN" select="$PAREN"/>
1121       <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1122     </xsl:apply-templates>
1123     <m:mo>
1124 <!-- HELM: added -->        
1125         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1126           <xsl:attribute name="m:xref">
1127             <xsl:value-of select="m:minus/@id"/>
1128           </xsl:attribute>
1129         </xsl:if>-</m:mo>
1130     <xsl:apply-templates select="*[3]" mode = "semantics">
1131       <xsl:with-param name="IN_PREC" select="$MINUS_PREC"/>
1132       <xsl:with-param name="PARAM" select="$PAR_SAME"/>
1133       <xsl:with-param name="PAREN" select="$PAREN"/>
1134       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1135     </xsl:apply-templates>
1136   </xsl:if>
1137 </xsl:template>
1138
1139 <xsl:template match = "m:apply[m:plus[1]]">
1140   <xsl:param name="IN_PREC" select="$NO_PREC"/>
1141   <xsl:param name="PARAM" select="$NO_PARAM"/>
1142   <xsl:param name="PAREN" select="$PAR_NO"/>
1143   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1144   <xsl:choose>
1145     <xsl:when test="$IN_PREC &gt; $PLUS_PREC or $IN_PREC=$PLUS_PREC and
1146                                                       $PARAM=$PAR_SAME">
1147       <m:mfenced separators="">
1148         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1149           <xsl:attribute name="m:xref">
1150             <xsl:value-of select="@id"/>
1151           </xsl:attribute>
1152         </xsl:if>
1153         <xsl:apply-templates select="." mode="plus">
1154           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1155           <xsl:with-param name="PAREN" select="$PAR_YES"/>
1156           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1157         </xsl:apply-templates>
1158       </m:mfenced>
1159     </xsl:when>
1160     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC
1161                     and not($SEM_SW=$SEM_ALL) and not($SEM_SW=$SEM_XREF)
1162                     and not($SEM_SW=$SEM_XREF_EXT)">
1163       <xsl:apply-templates select="." mode="plus">
1164         <xsl:with-param name="PARAM" select="$PARAM"/>
1165         <xsl:with-param name="PAREN" select="$PAREN"/>
1166         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1167       </xsl:apply-templates>
1168     </xsl:when>
1169     <xsl:otherwise>
1170       <m:mrow>
1171         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1172           <xsl:attribute name="m:xref">
1173             <xsl:value-of select="@id"/>
1174           </xsl:attribute>
1175         </xsl:if>
1176         <xsl:apply-templates select="." mode="plus">
1177           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1178           <xsl:with-param name="PAREN" select="$PAREN"/>
1179           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1180         </xsl:apply-templates>
1181       </m:mrow>
1182     </xsl:otherwise>
1183   </xsl:choose>
1184 </xsl:template>
1185
1186 <xsl:template match = "m:apply[m:plus[1]]" mode="plus">
1187   <xsl:param name="PARAM" select="$NO_PARAM"/>
1188   <xsl:param name="PAREN" select="$PAR_NO"/>
1189   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1190   <xsl:if test="*[2]">
1191     <xsl:apply-templates select="*[2]" mode = "semantics">
1192       <xsl:with-param name="IN_PREC" select="$PLUS_PREC"/>
1193       <xsl:with-param name="PARAM" select="$PARAM"/>
1194       <xsl:with-param name="PAREN" select="$PAREN"/>
1195       <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1196     </xsl:apply-templates>
1197     <xsl:for-each select = "*[position()>2]">
1198       <xsl:choose>
1199         <xsl:when test=". &lt; 0">
1200           <m:mo>-</m:mo>
1201           <m:mn> <xsl:value-of select="-."/> </m:mn>
1202         </xsl:when>
1203         <xsl:when test="self::m:apply[m:minus[1]] and not(*[3])">
1204           <xsl:apply-templates select="." mode = "semantics">
1205             <xsl:with-param name="IN_PREC" select="$PLUS_PREC"/>
1206             <xsl:with-param name="PAREN" select="$PAREN"/>
1207             <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1208           </xsl:apply-templates>
1209         </xsl:when>
1210         <xsl:otherwise>
1211           <m:mo>
1212 <!-- HELM: added -->        
1213         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1214           <xsl:attribute name="m:xref">
1215             <xsl:value-of select="../m:plus/@id"/>
1216           </xsl:attribute>
1217         </xsl:if>+</m:mo>
1218           <xsl:apply-templates select="." mode = "semantics">
1219             <xsl:with-param name="IN_PREC" select="$PLUS_PREC"/>
1220             <xsl:with-param name="PAREN" select="$PAREN"/>
1221             <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1222           </xsl:apply-templates>
1223         </xsl:otherwise>
1224       </xsl:choose>
1225     </xsl:for-each>
1226   </xsl:if>
1227 </xsl:template>
1228
1229 <xsl:template match = "m:apply[m:power[1]]">
1230   <xsl:choose>
1231     <xsl:when test="*[2]=m:apply[m:ln[1] | m:log[1] | m:abs[1] |
1232                          m:gcd[1] | m:sin[1] | m:cos[1] | m:tan[1] |
1233                          m:sec[1] | m:csc[1] | m:cot[1] | m:sinh[1] |
1234                          m:cosh[1] | m:tanh[1] | m:sech[1] | m:csch[1] |
1235                          m:coth[1] | m:arcsin[1] | m:arccos[1] |
1236                          m:arctan[1]]">
1237       <xsl:apply-templates select="*[2]" mode = "semantics"/>
1238     </xsl:when>
1239     <xsl:otherwise>
1240       <m:msup>
1241         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1242           <xsl:attribute name="m:xref">
1243             <xsl:value-of select="@id"/>
1244           </xsl:attribute>
1245         </xsl:if>
1246         <xsl:apply-templates select = "*[2]" mode = "semantics">
1247           <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
1248           <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1249         </xsl:apply-templates>
1250         <xsl:apply-templates select = "*[3]" mode = "semantics"/>
1251       </m:msup>
1252     </xsl:otherwise>
1253   </xsl:choose>
1254 </xsl:template>
1255
1256 <xsl:template match = "m:apply[m:rem[1] | m:divide[1]]">
1257   <xsl:param name="IN_PREC" select="$NO_PREC"/>
1258   <xsl:param name="PARAM" select="$NO_PARAM"/>
1259   <xsl:param name="PAREN" select="$PAR_NO"/>
1260   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1261   <xsl:choose>
1262     <xsl:when test="$IN_PREC &gt; $DIV_PREC or $IN_PREC=$DIV_PREC and
1263                                                     $PARAM=$PAR_SAME">
1264       <m:mfenced separators="">
1265         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1266           <xsl:attribute name="m:xref">
1267             <xsl:value-of select="@id"/>
1268           </xsl:attribute>
1269         </xsl:if>
1270         <xsl:apply-templates select="." mode="remdiv">
1271           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1272           <xsl:with-param name="PAREN" select="$PAR_YES"/>
1273           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1274         </xsl:apply-templates>
1275       </m:mfenced>
1276     </xsl:when>
1277     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC
1278                     and not($SEM_SW=$SEM_ALL) and not($SEM_SW=$SEM_XREF)
1279                     and not($SEM_SW=$SEM_XREF_EXT)">
1280       <xsl:apply-templates select="." mode="remdiv">
1281         <xsl:with-param name="PARAM" select="$PARAM"/>
1282         <xsl:with-param name="PAREN" select="$PAREN"/>
1283         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1284       </xsl:apply-templates>
1285     </xsl:when>
1286     <xsl:otherwise>
1287       <m:mrow>
1288         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1289           <xsl:attribute name="m:xref">
1290             <xsl:value-of select="@id"/>
1291           </xsl:attribute>
1292         </xsl:if>
1293         <xsl:apply-templates select="." mode="remdiv">
1294           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1295           <xsl:with-param name="PAREN" select="$PAREN"/>
1296           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1297         </xsl:apply-templates>
1298       </m:mrow>
1299     </xsl:otherwise>
1300   </xsl:choose>
1301 </xsl:template>
1302
1303 <xsl:template match = "m:apply[m:rem[1] | m:divide[1]]" mode="remdiv">
1304   <xsl:param name="PARAM" select="$NO_PARAM"/>
1305   <xsl:param name="PAREN" select="$PAR_NO"/>
1306   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1307   <xsl:apply-templates select = "*[2]" mode = "semantics">
1308     <xsl:with-param name="IN_PREC" select="$DIV_PREC"/>
1309       <xsl:with-param name="PARAM" select="$PARAM"/>
1310       <xsl:with-param name="PAREN" select="$PAREN"/>
1311       <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1312   </xsl:apply-templates>
1313   <m:mo>
1314     <xsl:if test="m:rem">
1315 <!-- HELM: added -->        
1316         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1317           <xsl:attribute name="m:xref">
1318             <xsl:value-of select="m:rem/@id"/>
1319           </xsl:attribute>
1320         </xsl:if>
1321       <xsl:value-of select="'%'"/>
1322     </xsl:if>
1323     <xsl:if test="m:divide">
1324 <!-- HELM: added -->        
1325         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1326           <xsl:attribute name="m:xref">
1327             <xsl:value-of select="m:divide/@id"/>
1328           </xsl:attribute>
1329         </xsl:if>
1330       <xsl:value-of select="'/'"/>
1331     </xsl:if>
1332   </m:mo>
1333   <xsl:apply-templates select = "*[3]" mode = "semantics">
1334     <xsl:with-param name="IN_PREC" select="$DIV_PREC"/>
1335     <xsl:with-param name="PARAM" select="$PAR_SAME"/>
1336     <xsl:with-param name="PAREN" select="$PAREN"/>
1337     <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1338   </xsl:apply-templates>
1339 </xsl:template>
1340
1341 <xsl:template match = "m:apply[m:times[1]]">
1342   <xsl:param name="IN_PREC" select="$NO_PREC"/>
1343   <xsl:param name="PARAM" select="$NO_PARAM"/>
1344   <xsl:param name="PAREN" select="$PAR_NO"/>
1345   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1346   <xsl:choose>
1347     <xsl:when test="$IN_PREC &gt; $MUL_PREC or $IN_PREC=$MUL_PREC and
1348                                                     $PARAM=$PAR_SAME">
1349       <m:mfenced separators="">
1350         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1351           <xsl:attribute name="m:xref">
1352             <xsl:value-of select="@id"/>
1353           </xsl:attribute>
1354         </xsl:if>
1355         <xsl:apply-templates select="." mode="times">
1356           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1357           <xsl:with-param name="PAREN" select="$PAR_YES"/>
1358           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1359         </xsl:apply-templates>
1360       </m:mfenced>
1361     </xsl:when>
1362     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC
1363                     and not($SEM_SW=$SEM_ALL) and not($SEM_SW=$SEM_XREF)
1364                     and not($SEM_SW=$SEM_XREF_EXT)">
1365       <xsl:apply-templates select="." mode="times">
1366         <xsl:with-param name="PARAM" select="$PARAM"/>
1367         <xsl:with-param name="PAREN" select="$PAREN"/>
1368         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1369       </xsl:apply-templates>
1370     </xsl:when>
1371     <xsl:otherwise>
1372       <m:mrow>
1373         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1374           <xsl:attribute name="m:xref">
1375             <xsl:value-of select="@id"/>
1376           </xsl:attribute>
1377         </xsl:if>
1378         <xsl:apply-templates select="." mode="times">
1379           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1380           <xsl:with-param name="PAREN" select="$PAREN"/>
1381           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1382         </xsl:apply-templates>
1383       </m:mrow>
1384     </xsl:otherwise>
1385   </xsl:choose>
1386 </xsl:template>
1387
1388 <xsl:template match = "m:apply[m:times[1]]" mode="times">
1389   <xsl:param name="PARAM" select="$NO_PARAM"/>
1390   <xsl:param name="PAREN" select="$PAR_NO"/>
1391   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1392   <xsl:apply-templates select="*[2]" mode = "semantics">
1393     <xsl:with-param name="IN_PREC" select="$MUL_PREC"/>
1394     <xsl:with-param name="PARAM" select="$PARAM"/>
1395     <xsl:with-param name="PAREN" select="$PAREN"/>
1396     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1397   </xsl:apply-templates>
1398   <xsl:if test="*[3]">
1399     <xsl:for-each select = "*[position()>2]">
1400 <!-- HELM: to distinguish between * and the application -->
1401 <!--      <m:mo> <mchar name="InvisibleTimes"/> </m:mo> -->
1402       <m:mo>
1403 <!-- HELM: added -->        
1404         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1405           <xsl:attribute name="m:xref">
1406             <xsl:value-of select="../m:times/@id"/>
1407           </xsl:attribute>
1408         </xsl:if>*</m:mo>
1409       <xsl:apply-templates select="." mode = "semantics">
1410         <xsl:with-param name="IN_PREC" select="$MUL_PREC"/>
1411         <xsl:with-param name="PAREN" select="$PAREN"/>
1412         <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1413       </xsl:apply-templates>
1414     </xsl:for-each>
1415   </xsl:if>
1416 </xsl:template>
1417
1418 <xsl:template match = "m:apply[m:root[1]]">
1419   <m:msqrt>
1420     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1421       <xsl:attribute name="m:xref">
1422         <xsl:value-of select="@id"/>
1423       </xsl:attribute>
1424     </xsl:if>
1425     <xsl:if test="*[2]=m:degree">
1426       <xsl:apply-templates select="*[3]" mode = "semantics">
1427         <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
1428         <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1429       </xsl:apply-templates>
1430       <xsl:apply-templates select="*[2]" mode = "semantics"/>
1431     </xsl:if>
1432     <xsl:if test="not(*[2]=m:degree)">
1433       <xsl:apply-templates select="*[2]" mode = "semantics">
1434         <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
1435         <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1436       </xsl:apply-templates>
1437       <m:mn>2</m:mn>
1438     </xsl:if>
1439   </m:msqrt>
1440 </xsl:template>
1441
1442 <xsl:template match = "m:apply[m:gcd[1]]">
1443   <m:mrow>
1444     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1445       <xsl:attribute name="m:xref">
1446         <xsl:value-of select="@id"/>
1447       </xsl:attribute>
1448     </xsl:if>
1449     <xsl:if test="not(parent::m:apply[m:power[1]])">
1450       <m:mo>
1451 <!-- HELM: added -->        
1452         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1453           <xsl:attribute name="m:xref">
1454             <xsl:value-of select="m:gcd/@id"/>
1455           </xsl:attribute>
1456         </xsl:if>gcd</m:mo>
1457     </xsl:if>
1458     <xsl:if test="parent::m:apply[m:power[1]]">
1459       <m:msup>
1460         <m:mo>
1461 <!-- HELM: added -->        
1462         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1463           <xsl:attribute name="m:xref">
1464             <xsl:value-of select="m:gcd/@id"/>
1465           </xsl:attribute>
1466         </xsl:if>gcd</m:mo>
1467         <xsl:apply-templates select = "../*[3]" mode = "semantics"/>
1468       </m:msup>
1469     </xsl:if>
1470     <m:mfenced separators=",">
1471       <xsl:for-each select = "*[position()>1]">
1472         <xsl:apply-templates select = "." mode="semantics"/>
1473       </xsl:for-each>
1474     </m:mfenced>
1475   </m:mrow>
1476 </xsl:template>
1477
1478 <xsl:template match = "m:apply[m:and[1]]">
1479   <xsl:param name="IN_PREC" select="$NO_PREC"/>
1480   <xsl:param name="PAREN" select="$PAR_NO"/>
1481   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1482   <xsl:choose>
1483     <xsl:when test="$IN_PREC &gt; $AND_PREC">
1484       <m:mfenced separators="">
1485         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1486           <xsl:attribute name="m:xref">
1487             <xsl:value-of select="@id"/>
1488           </xsl:attribute>
1489         </xsl:if>
1490         <xsl:apply-templates select="." mode="and">
1491           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1492           <xsl:with-param name="PAREN" select="$PAR_YES"/>
1493         </xsl:apply-templates>
1494       </m:mfenced>
1495     </xsl:when>
1496     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC
1497                     and not($SEM_SW=$SEM_ALL) and not($SEM_SW=$SEM_XREF)
1498                     and not($SEM_SW=$SEM_XREF_EXT)">
1499       <xsl:apply-templates select="." mode="and">
1500         <xsl:with-param name="PARAM" select="$IN_PREC"/>
1501         <xsl:with-param name="PAREN" select="$PAREN"/>
1502         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1503       </xsl:apply-templates>
1504     </xsl:when>
1505     <xsl:otherwise>
1506       <m:mrow>
1507         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1508           <xsl:attribute name="m:xref">
1509             <xsl:value-of select="@id"/>
1510           </xsl:attribute>
1511         </xsl:if>
1512         <xsl:apply-templates select="." mode="and">
1513           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1514           <xsl:with-param name="PAREN" select="$PAREN"/>
1515           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1516         </xsl:apply-templates>
1517       </m:mrow>
1518     </xsl:otherwise>
1519   </xsl:choose>
1520 </xsl:template>
1521
1522 <xsl:template match = "m:apply[m:and[1]]" mode="and">
1523   <xsl:param name="PARAM" select="$NO_PARAM"/>
1524   <xsl:param name="PAREN" select="$PAR_NO"/>
1525   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1526   <xsl:apply-templates select="*[2]" mode = "semantics">
1527     <xsl:with-param name="IN_PREC" select="$AND_PREC"/>
1528     <xsl:with-param name="PARAM" select="$PARAM"/>
1529     <xsl:with-param name="PAREN" select="$PAREN"/>
1530     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1531   </xsl:apply-templates>
1532   <xsl:for-each select = "*[position()>2]">
1533     <m:mo>
1534 <!-- HELM: added -->        
1535         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1536           <xsl:attribute name="m:xref">
1537             <xsl:value-of select="../m:and/@id"/>
1538           </xsl:attribute>
1539         </xsl:if>
1540  <m:mchar name="wedge"/></m:mo>
1541     <xsl:apply-templates select="." mode = "semantics">
1542       <xsl:with-param name="IN_PREC" select="$AND_PREC"/>
1543       <xsl:with-param name="PAREN" select="$PAREN"/>
1544       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1545     </xsl:apply-templates>
1546   </xsl:for-each>
1547 </xsl:template>
1548
1549 <xsl:template match = "m:apply[m:or[1]]">
1550   <xsl:param name="IN_PREC" select="$NO_PREC"/>
1551   <xsl:param name="PAREN" select="$PAR_NO"/>
1552   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1553   <xsl:choose>
1554     <xsl:when test="$IN_PREC &gt; $OR_PREC">
1555       <m:mfenced separators="">
1556         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1557           <xsl:attribute name="m:xref">
1558             <xsl:value-of select="@id"/>
1559           </xsl:attribute>
1560         </xsl:if>
1561         <xsl:apply-templates select="." mode="or">
1562           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1563           <xsl:with-param name="PAREN" select="$PAR_YES"/>
1564         </xsl:apply-templates>
1565       </m:mfenced>
1566     </xsl:when>
1567     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC
1568                     and not($SEM_SW=$SEM_ALL) and not($SEM_SW=$SEM_XREF)
1569                     and not($SEM_SW=$SEM_XREF_EXT)">
1570       <xsl:apply-templates select="." mode="or">
1571         <xsl:with-param name="PARAM" select="$IN_PREC"/>
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:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1579           <xsl:attribute name="m:xref">
1580             <xsl:value-of select="@id"/>
1581           </xsl:attribute>
1582         </xsl:if>
1583         <xsl:apply-templates select="." mode="or">
1584           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1585           <xsl:with-param name="PAREN" select="$PAREN"/>
1586           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1587         </xsl:apply-templates>
1588       </m:mrow>
1589     </xsl:otherwise>
1590   </xsl:choose>
1591 </xsl:template>
1592
1593 <xsl:template match = "m:apply[m:or[1]]" mode="or">
1594   <xsl:param name="PARAM" select="$NO_PARAM"/>
1595   <xsl:param name="PAREN" select="$PAR_NO"/>
1596   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1597   <xsl:apply-templates select="*[2]" mode = "semantics">
1598     <xsl:with-param name="IN_PREC" select="$OR_PREC"/>
1599     <xsl:with-param name="PARAM" select="$PARAM"/>
1600     <xsl:with-param name="PAREN" select="$PAREN"/>
1601     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1602   </xsl:apply-templates>
1603   <xsl:for-each select = "*[position()>2]">
1604     <m:mo> 
1605 <!-- HELM: added -->        
1606         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1607           <xsl:attribute name="m:xref">
1608             <xsl:value-of select="../m:or/@id"/>
1609           </xsl:attribute>
1610         </xsl:if>
1611     <m:mchar name="vee"/> </m:mo>
1612     <xsl:apply-templates select="." mode = "semantics">
1613       <xsl:with-param name="IN_PREC" select="$OR_PREC"/>
1614       <xsl:with-param name="PAREN" select="$PAREN"/>
1615       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1616     </xsl:apply-templates>
1617   </xsl:for-each>
1618 </xsl:template>
1619
1620 <xsl:template match = "m:apply[m:xor[1]]">
1621   <xsl:param name="IN_PREC" select="$NO_PREC"/>
1622   <xsl:param name="PAREN" select="$PAR_NO"/>
1623   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1624   <xsl:choose>
1625     <xsl:when test="$IN_PREC &gt; $XOR_PREC">
1626       <m:mfenced separators="">
1627         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1628           <xsl:attribute name="m:xref">
1629             <xsl:value-of select="@id"/>
1630           </xsl:attribute>
1631         </xsl:if>
1632         <xsl:apply-templates select="." mode="xor">
1633           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1634           <xsl:with-param name="PAREN" select="$PAR_YES"/>
1635           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1636         </xsl:apply-templates>
1637       </m:mfenced>
1638     </xsl:when>
1639     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC
1640                                                 and not($SEM_SW=$SEM_ALL)">
1641       <xsl:apply-templates select="." mode="xor">
1642         <xsl:with-param name="PARAM" select="$IN_PREC"/>
1643         <xsl:with-param name="PAREN" select="$PAREN"/>
1644       </xsl:apply-templates>
1645     </xsl:when>
1646     <xsl:otherwise>
1647       <m:mrow>
1648         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1649           <xsl:attribute name="m:xref">
1650             <xsl:value-of select="@id"/>
1651           </xsl:attribute>
1652         </xsl:if>
1653         <xsl:apply-templates select="." mode="xor">
1654           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1655           <xsl:with-param name="PAREN" select="$PAREN"/>
1656           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1657         </xsl:apply-templates>
1658       </m:mrow>
1659     </xsl:otherwise>
1660   </xsl:choose>
1661 </xsl:template>
1662
1663 <xsl:template match = "m:apply[m:xor[1]]" mode="xor">
1664   <xsl:param name="PARAM" select="$NO_PARAM"/>
1665   <xsl:param name="PAREN" select="$PAR_NO"/>
1666   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1667   <xsl:apply-templates select="*[2]" mode = "semantics">
1668     <xsl:with-param name="IN_PREC" select="$XOR_PREC"/>
1669     <xsl:with-param name="PARAM" select="$PARAM"/>
1670     <xsl:with-param name="PAREN" select="$PAREN"/>
1671     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1672   </xsl:apply-templates>
1673   <xsl:for-each select = "*[position()>2]">
1674     <m:mo>
1675  <!-- HELM: added -->        
1676         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1677           <xsl:attribute name="m:xref">
1678             <xsl:value-of select="../m:xor/@id"/>
1679           </xsl:attribute>
1680         </xsl:if>
1681     <m:mchar name="xor"/> </m:mo>
1682     <xsl:apply-templates select="." mode = "semantics">
1683       <xsl:with-param name="IN_PREC" select="$XOR_PREC"/>
1684       <xsl:with-param name="PAREN" select="$PAREN"/>
1685       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1686     </xsl:apply-templates>
1687   </xsl:for-each>
1688 </xsl:template>
1689
1690 <xsl:template match = "m:apply[m:not[1]]">
1691   <m:mrow>
1692     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1693       <xsl:attribute name="m:xref">
1694         <xsl:value-of select="@id"/>
1695       </xsl:attribute>
1696     </xsl:if>
1697 <!-- HELM: was <m:mo>not</m:mo> -->
1698     <m:mo>
1699 <!-- HELM: added -->        
1700         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1701           <xsl:attribute name="m:xref">
1702             <xsl:value-of select="m:not/@id"/>
1703           </xsl:attribute>
1704         </xsl:if><m:mchar name="not"/></m:mo>
1705     <xsl:apply-templates select = "*[2]" mode = "semantics">
1706       <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
1707     </xsl:apply-templates>
1708   </m:mrow>
1709 </xsl:template>
1710
1711 <xsl:template match = "m:apply[m:forall[1]]">
1712   <m:mrow>
1713     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1714       <xsl:attribute name="m:xref">
1715         <xsl:value-of select="@id"/>
1716       </xsl:attribute>
1717     </xsl:if>
1718     <m:mo>
1719 <!-- HELM: added -->        
1720         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1721           <xsl:attribute name="m:xref">
1722             <xsl:value-of select="m:forall/@id"/>
1723           </xsl:attribute>
1724         </xsl:if>for all</m:mo>
1725     <xsl:if test="count(m:bvar) &gt; 1">
1726       <m:mfenced separators=",">
1727         <xsl:for-each select = "m:bvar">
1728           <xsl:apply-templates select = "." mode="semantics"/>
1729         </xsl:for-each>
1730       </m:mfenced>
1731     </xsl:if>
1732     <xsl:if test="count(m:bvar)=1">
1733       <xsl:apply-templates select = "m:bvar" mode="semantics"/>
1734     </xsl:if>
1735     <xsl:if test="m:condition">
1736       <m:mo>:</m:mo>
1737       <xsl:apply-templates select = "m:condition/*" mode = "semantics"/>
1738       <m:mo>,</m:mo>
1739     </xsl:if>
1740     <xsl:apply-templates select = "*[position()>1 and not(self::m:bvar) and
1741                                 not(self::m:condition)]" mode = "semantics"/>
1742   </m:mrow>
1743 </xsl:template>
1744
1745 <xsl:template match = "m:apply[m:exists[1]]">
1746   <m:mrow>
1747     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1748       <xsl:attribute name="m:xref">
1749         <xsl:value-of select="@id"/>
1750       </xsl:attribute>
1751     </xsl:if>
1752     <m:mo> 
1753 <!-- HELM: added -->        
1754         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1755           <xsl:attribute name="m:xref">
1756             <xsl:value-of select="m:exists/@id"/>
1757           </xsl:attribute>
1758         </xsl:if>
1759     <m:mchar name="Exists"/> </m:mo>
1760     <xsl:if test="count(m:bvar) &gt; 1">
1761       <m:mfenced separators=",">
1762         <xsl:for-each select = "m:bvar">
1763           <xsl:apply-templates select = "." mode="semantics"/>
1764         </xsl:for-each>
1765       </m:mfenced>
1766     </xsl:if>
1767     <xsl:if test="count(m:bvar)=1">
1768       <xsl:apply-templates select = "m:bvar" mode="semantics"/>
1769     </xsl:if>
1770     <xsl:if test="m:condition">
1771       <m:mo>,</m:mo>
1772       <xsl:apply-templates select = "m:condition/*" mode = "semantics"/>
1773     </xsl:if>
1774     <xsl:if test="*[position()>1 and not(self::m:bvar) and not(self::m:condition)]">
1775       <m:mo>:</m:mo>
1776       <xsl:apply-templates select = "*[position()>1 and not(self::m:bvar) and
1777                                 not(self::m:condition)]" mode = "semantics"/>
1778     </xsl:if>
1779   </m:mrow>
1780 </xsl:template>
1781
1782 <xsl:template match = "m:apply[m:abs[1]]">
1783   <xsl:if test="not(parent::m:apply[m:power[1]])">
1784     <m:mfenced open="|" close="|" separators="">
1785       <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1786         <xsl:attribute name="m:xref">
1787           <xsl:value-of select="@id"/>
1788         </xsl:attribute>
1789       </xsl:if>
1790       <xsl:apply-templates select = "*[position()>1]" mode = "semantics"/>
1791     </m:mfenced>
1792   </xsl:if>
1793   <xsl:if test="parent::m:apply[m:power[1]]">
1794     <m:msup>
1795       <m:mfenced open="|" close="|" separators="">
1796         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1797           <xsl:attribute name="m:xref">
1798             <xsl:value-of select="@id"/>
1799           </xsl:attribute>
1800         </xsl:if>
1801         <xsl:apply-templates select = "*[position()>1]" mode = "semantics"/>
1802       </m:mfenced>
1803       <xsl:apply-templates select = "../*[3]" mode = "semantics"/>
1804     </m:msup>
1805   </xsl:if>
1806 </xsl:template>
1807
1808 <xsl:template match = "m:apply[m:conjugate[1]]">
1809   <m:mover>
1810     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1811       <xsl:attribute name="m:xref">
1812         <xsl:value-of select="@id"/>
1813       </xsl:attribute>
1814     </xsl:if>
1815     <m:mrow>
1816       <xsl:apply-templates select = "*[position()>1]" mode = "semantics"/>
1817     </m:mrow>
1818     <m:mo>
1819  <!-- HELM: added -->        
1820         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1821           <xsl:attribute name="m:xref">
1822             <xsl:value-of select="m:conjugate/@id"/>
1823           </xsl:attribute>
1824         </xsl:if>
1825     <m:mchar name="UnderBar"/> </m:mo>
1826   </m:mover>
1827 </xsl:template>
1828
1829 <xsl:template match = "m:apply[m:arg[1] | m:real[1] | m:imaginary[1]]">
1830   <m:mrow>
1831     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1832       <xsl:attribute name="m:xref">
1833         <xsl:value-of select="@id"/>
1834       </xsl:attribute>
1835     </xsl:if>
1836     <m:mo>
1837       <xsl:if test="m:arg">
1838 <!-- HELM: added -->        
1839         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1840           <xsl:attribute name="m:xref">
1841             <xsl:value-of select="m:arg/@id"/>
1842           </xsl:attribute>
1843         </xsl:if>
1844         <xsl:value-of select="'Arg'"/>
1845       </xsl:if>
1846       <xsl:if test="m:real">
1847 <!-- HELM: added -->        
1848         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1849           <xsl:attribute name="m:xref">
1850             <xsl:value-of select="m:real/@id"/>
1851           </xsl:attribute>
1852         </xsl:if>
1853         <xsl:value-of select="'Re'"/>
1854       </xsl:if>
1855       <xsl:if test="m:imaginary">
1856 <!-- HELM: added -->        
1857         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1858           <xsl:attribute name="m:xref">
1859             <xsl:value-of select="m:imaginary/@id"/>
1860           </xsl:attribute>
1861         </xsl:if>
1862         <xsl:value-of select="'Im'"/>
1863       </xsl:if>
1864     </m:mo>
1865     <m:mfenced separators="">
1866       <xsl:apply-templates select = "*[2]" mode = "semantics"/>
1867     </m:mfenced>
1868   </m:mrow>
1869 </xsl:template>
1870
1871
1872 <!-- ***************** RELATIONS ***************** -->
1873
1874 <xsl:template match = "m:apply[m:neq | m:approx | m:tendsto | m:implies
1875                      | m:in | m:notin | m:notsubset | m:notprsubset
1876                      | m:subset | m:prsubset | m:eq | m:gt | m:lt
1877                      | m:geq | m:leq | m:equivalent]">
1878   <m:mrow>
1879     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1880       <xsl:attribute name="m:xref">
1881         <xsl:value-of select="@id"/>
1882       </xsl:attribute>
1883     </xsl:if>
1884     <xsl:if test="*[1]=m:neq or *[1]=m:approx or *[1]=m:tendsto or
1885                   *[1]=m:implies or *[1]=m:in or *[1]=m:notin or
1886                   *[1]=m:notsubset or *[1]=m:notprsubset">
1887       <xsl:apply-templates select = "*[2]" mode = "semantics"/>
1888       <m:mo>
1889         <xsl:if test="*[1]=m:neq">
1890 <!-- HELM: added -->        
1891         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1892           <xsl:attribute name="m:xref">
1893             <xsl:value-of select="m:neq/@id"/>
1894           </xsl:attribute>
1895         </xsl:if>
1896           <m:mchar name="NotEqual"/>
1897         </xsl:if>
1898         <xsl:if test="*[1]=m:approx">
1899 <!-- HELM: added -->        
1900         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1901           <xsl:attribute name="m:xref">
1902             <xsl:value-of select="m:approx/@id"/>
1903           </xsl:attribute>
1904         </xsl:if>
1905           <m:mchar name="approxeq"/>
1906         </xsl:if>
1907         <xsl:if test="*[1]=m:tendsto">
1908 <!-- HELM: added -->        
1909         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1910           <xsl:attribute name="m:xref">
1911             <xsl:value-of select="m:tendsto/@id"/>
1912           </xsl:attribute>
1913         </xsl:if>
1914           <m:mchar name="RightArrow"/>
1915         </xsl:if>
1916         <xsl:if test="*[1]=m:implies">
1917 <!-- HELM: added -->        
1918         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1919           <xsl:attribute name="m:xref">
1920             <xsl:value-of select="m:implies/@id"/>
1921           </xsl:attribute>
1922         </xsl:if>
1923           <m:mchar name="DoubleRightArrow"/>
1924         </xsl:if>
1925         <xsl:if test="*[1]=m:in">
1926 <!-- HELM: added -->        
1927         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1928           <xsl:attribute name="m:xref">
1929             <xsl:value-of select="m:in/@id"/>
1930           </xsl:attribute>
1931         </xsl:if>
1932           <m:mchar name="Element"/>
1933         </xsl:if>
1934         <xsl:if test="*[1]=m:notin">
1935 <!-- HELM: added -->        
1936         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1937           <xsl:attribute name="m:xref">
1938             <xsl:value-of select="m:notin/@id"/>
1939           </xsl:attribute>
1940         </xsl:if>
1941           <m:mchar name="NotElement"/>
1942         </xsl:if>
1943         <xsl:if test="*[1]=m:notsubset">
1944 <!-- HELM: added -->        
1945         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1946           <xsl:attribute name="m:xref">
1947             <xsl:value-of select="m:notsubset/@id"/>
1948           </xsl:attribute>
1949         </xsl:if>
1950           <m:mchar name="NotSubset"/>
1951         </xsl:if>
1952         <xsl:if test="*[1]=m:notprsubset">
1953 <!-- HELM: added -->        
1954         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1955           <xsl:attribute name="m:xref">
1956             <xsl:value-of select="m:notprsubset/@id"/>
1957           </xsl:attribute>
1958         </xsl:if>
1959           <m:mchar name="NotSubsetEqual"/>
1960         </xsl:if>
1961       </m:mo>
1962       <xsl:apply-templates select = "*[3]" mode = "semantics"/>
1963       <xsl:if test="*[1]=m:tendsto and m:tendsto[1][@type='below']">
1964         <m:mo>
1965 <!-- HELM: added -->        
1966         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1967           <xsl:attribute name="m:xref">
1968             <xsl:value-of select="m:tendsto/@id"/>
1969           </xsl:attribute>
1970         </xsl:if>-</m:mo>
1971       </xsl:if>
1972       <xsl:if test="*[1]=m:tendsto and m:tendsto[1][@type='above']">
1973         <m:mo>
1974 <!-- HELM: added -->        
1975         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1976           <xsl:attribute name="m:xref">
1977             <xsl:value-of select="m:tendsto/@id"/>
1978           </xsl:attribute>
1979         </xsl:if>+</m:mo>
1980       </xsl:if>
1981     </xsl:if>
1982     <xsl:if test="*[1]=m:subset or *[1]=m:prsubset or *[1]=m:eq or *[1]=m:gt
1983                or *[1]=m:lt or *[1]=m:geq or *[1]=m:leq or *[1]=m:equivalent">
1984       <xsl:apply-templates select = "*[2]" mode="semantics"/>
1985       <xsl:for-each select = "*[position()>2]">
1986         <m:mo>
1987           <xsl:if test="../*[self::m:subset][1]">
1988 <!-- HELM: added -->        
1989         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1990           <xsl:attribute name="m:xref">
1991             <xsl:value-of select="../m:subset/@id"/>
1992           </xsl:attribute>
1993         </xsl:if>
1994             <m:mchar name="SubsetEqual"/>
1995           </xsl:if>
1996           <xsl:if test="../*[self::m:prsubset][1]">
1997 <!-- HELM: added -->        
1998         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1999           <xsl:attribute name="m:xref">
2000             <xsl:value-of select="../m:prsubset/@id"/>
2001           </xsl:attribute>
2002         </xsl:if>
2003             <m:mchar name="subset"/>
2004           </xsl:if>
2005           <xsl:if test="../*[self::m:eq][1]">
2006 <!-- HELM: added -->        
2007         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2008           <xsl:attribute name="m:xref">
2009             <xsl:value-of select="../m:eq/@id"/>
2010           </xsl:attribute>
2011         </xsl:if>
2012             <xsl:value-of select="'='"/>
2013           </xsl:if>
2014           <xsl:if test="../*[self::m:gt][1]">
2015 <!-- HELM: added -->        
2016         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2017           <xsl:attribute name="m:xref">
2018             <xsl:value-of select="../m:gt/@id"/>
2019           </xsl:attribute>
2020         </xsl:if>
2021             <xsl:value-of select="'&gt;'"/>
2022           </xsl:if>
2023           <xsl:if test="../*[self::m:lt][1]">
2024 <!-- HELM: added -->        
2025         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2026           <xsl:attribute name="m:xref">
2027             <xsl:value-of select="../m:lt/@id"/>
2028           </xsl:attribute>
2029         </xsl:if>
2030             <xsl:value-of select="'&lt;'"/>
2031           </xsl:if>
2032           <xsl:if test="../*[self::m:geq][1]">
2033 <!-- HELM: added -->        
2034         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2035           <xsl:attribute name="m:xref">
2036             <xsl:value-of select="../m:geq/@id"/>
2037           </xsl:attribute>
2038         </xsl:if>
2039             <m:mchar name="geq"/>
2040           </xsl:if>
2041           <xsl:if test="../*[self::m:leq][1]">
2042 <!-- HELM: added -->        
2043         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2044           <xsl:attribute name="m:xref">
2045             <xsl:value-of select="../m:leq/@id"/>
2046           </xsl:attribute>
2047         </xsl:if>
2048             <m:mchar name="leq"/>
2049           </xsl:if>
2050           <xsl:if test="../*[self::m:equivalent][1]">
2051 <!-- HELM: added -->        
2052         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2053           <xsl:attribute name="m:xref">
2054             <xsl:value-of select="../m:equivalent/@id"/>
2055           </xsl:attribute>
2056         </xsl:if>
2057             <m:mchar name="Congruent"/>
2058           </xsl:if>
2059         </m:mo>
2060         <xsl:apply-templates select = "." mode="semantics"/>
2061       </xsl:for-each>
2062     </xsl:if>
2063   </m:mrow>
2064 </xsl:template>
2065
2066
2067 <!-- ***************** CALCULUS ***************** -->
2068
2069 <xsl:template match = "m:apply[*[1][self::m:ln]]">
2070   <m:mrow>
2071     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2072       <xsl:attribute name="m:xref">
2073         <xsl:value-of select="@id"/>
2074       </xsl:attribute>
2075     </xsl:if>
2076     <xsl:choose>
2077       <xsl:when test="parent::m:apply[m:power[1]]">
2078         <m:msup>
2079           <m:mo>
2080 <!-- HELM: added -->        
2081         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2082           <xsl:attribute name="m:xref">
2083             <xsl:value-of select="m:ln/@id"/>
2084           </xsl:attribute>
2085         </xsl:if>ln</m:mo>
2086           <xsl:apply-templates select = "../*[3]" mode = "semantics"/>
2087         </m:msup>
2088       </xsl:when>
2089       <xsl:otherwise>
2090         <m:mo>
2091 <!-- HELM: added -->        
2092         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2093           <xsl:attribute name="m:xref">
2094             <xsl:value-of select="m:ln/@id"/>
2095           </xsl:attribute>
2096         </xsl:if>ln</m:mo>
2097       </xsl:otherwise>
2098     </xsl:choose>
2099     <m:mo> <m:mchar name='ApplyFunction'/> </m:mo>
2100     <xsl:apply-templates select = "*[2]" mode = "semantics">
2101       <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
2102     </xsl:apply-templates>
2103   </m:mrow>
2104 </xsl:template>
2105
2106 <xsl:template match = "m:apply[m:log[1]]">
2107   <m:mrow>
2108     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2109       <xsl:attribute name="m:xref">
2110         <xsl:value-of select="@id"/>
2111       </xsl:attribute>
2112     </xsl:if>
2113     <xsl:choose>
2114       <xsl:when test="parent::m:apply[m:power[1]]">
2115         <xsl:if test="not(*[2]=m:logbase)">
2116           <m:msup>
2117             <m:mo>
2118 <!-- HELM: added -->        
2119         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2120           <xsl:attribute name="m:xref">
2121             <xsl:value-of select="m:log/@id"/>
2122           </xsl:attribute>
2123         </xsl:if>log</m:mo>
2124             <xsl:apply-templates select = "../*[3]" mode = "semantics"/>
2125           </m:msup>
2126         </xsl:if>
2127         <xsl:if test="*[2]=m:logbase">
2128           <m:msubsup>
2129             <m:mo>
2130 <!-- HELM: added -->        
2131         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2132           <xsl:attribute name="m:xref">
2133             <xsl:value-of select="m:log/@id"/>
2134           </xsl:attribute>
2135         </xsl:if>log</m:mo>
2136             <xsl:apply-templates select = "../*[3]" mode = "semantics"/>
2137             <xsl:apply-templates select = "m:logbase" mode = "semantics"/>
2138           </m:msubsup>
2139         </xsl:if>
2140       </xsl:when>
2141       <xsl:otherwise>
2142         <xsl:if test="not(*[2]=m:logbase)">
2143           <m:mo>log</m:mo>
2144         </xsl:if>
2145         <xsl:if test="*[2]=m:logbase">
2146           <m:msub>
2147             <m:mo>
2148 <!-- HELM: added -->        
2149         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2150           <xsl:attribute name="m:xref">
2151             <xsl:value-of select="m:log/@id"/>
2152           </xsl:attribute>
2153         </xsl:if>log</m:mo>
2154             <xsl:apply-templates select = "m:logbase" mode = "semantics"/>
2155           </m:msub>
2156         </xsl:if>
2157       </xsl:otherwise>
2158     </xsl:choose>
2159     <m:mo> <m:mchar name='ApplyFunction'/> </m:mo>
2160     <xsl:if test="*[2]=m:logbase">
2161       <xsl:apply-templates select = "*[3]" mode = "semantics">
2162         <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
2163       </xsl:apply-templates>
2164     </xsl:if>
2165     <xsl:if test="not(*[2]=m:logbase)">
2166       <xsl:apply-templates select = "*[2]" mode = "semantics">
2167         <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
2168       </xsl:apply-templates>
2169     </xsl:if>
2170   </m:mrow>
2171 </xsl:template>
2172
2173 <xsl:template match = "m:apply[m:diff[1]]">
2174   <m:mrow>
2175     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2176       <xsl:attribute name="m:xref">
2177         <xsl:value-of select="@id"/>
2178       </xsl:attribute>
2179     </xsl:if>
2180     <xsl:if test="*[2]=m:bvar and m:bvar[*[2]=m:degree]">
2181       <m:mfrac>
2182 <!-- HELM: added -->        
2183         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2184           <xsl:attribute name="m:xref">
2185             <xsl:value-of select="m:diff/@id"/>
2186           </xsl:attribute>
2187         </xsl:if>
2188         <m:msup>
2189           <m:mo>d</m:mo>
2190           <xsl:apply-templates select = "m:bvar/m:degree" mode = "semantics"/>
2191         </m:msup>
2192         <m:mrow>
2193           <m:mo>d</m:mo>
2194           <m:msup>
2195             <xsl:apply-templates select = "m:bvar/*[1]" mode = "semantics"/>
2196             <xsl:apply-templates select = "m:bvar/m:degree" mode = "semantics"/>
2197           </m:msup>
2198         </m:mrow>
2199       </m:mfrac>
2200     </xsl:if>
2201     <xsl:if test="*[2]=m:bvar and not(m:bvar[*[2]=m:degree])">
2202       <m:mfrac>
2203 <!-- HELM: added -->        
2204         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2205           <xsl:attribute name="m:xref">
2206             <xsl:value-of select="m:diff/@id"/>
2207           </xsl:attribute>
2208         </xsl:if>
2209         <m:mo>d</m:mo>
2210         <m:mrow>
2211           <m:mo>d</m:mo>
2212           <xsl:apply-templates select = "m:bvar/*[1]" mode = "semantics"/>
2213         </m:mrow>
2214       </m:mfrac>
2215     </xsl:if>
2216     <xsl:apply-templates select = "*[3]" mode = "semantics"/>
2217   </m:mrow>
2218 </xsl:template>
2219
2220 <xsl:template match = "m:apply[m:partialdiff[1]]">
2221   <m:mrow>
2222     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2223       <xsl:attribute name="m:xref">
2224         <xsl:value-of select="@id"/>
2225       </xsl:attribute>
2226     </xsl:if>
2227     <xsl:for-each select = "m:bvar">
2228       <xsl:if test="*[last()]=m:degree">
2229         <m:mfrac>
2230 <!-- HELM: added -->        
2231         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2232           <xsl:attribute name="m:xref">
2233             <xsl:value-of select="m:partialdiff/@id"/>
2234           </xsl:attribute>
2235         </xsl:if>
2236           <m:msup>
2237              <m:mo>d</m:mo>
2238              <xsl:apply-templates select = "m:degree" mode = "semantics"/>
2239           </m:msup>
2240           <m:mrow>
2241             <m:mo>d</m:mo>
2242             <m:msup>
2243               <xsl:apply-templates select = "*[1]" mode = "semantics"/>
2244               <xsl:apply-templates select = "m:degree" mode = "semantics"/>
2245             </m:msup>
2246           </m:mrow>
2247         </m:mfrac>
2248       </xsl:if>
2249       <xsl:if test="not(*[last()]=m:degree)">
2250         <m:mfrac>
2251 <!-- HELM: added -->        
2252         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2253           <xsl:attribute name="m:xref">
2254             <xsl:value-of select="m:partialdiff/@id"/>
2255           </xsl:attribute>
2256         </xsl:if>
2257           <m:mo>d</m:mo>
2258           <m:mrow>
2259             <m:mo>d</m:mo>
2260             <xsl:apply-templates select = "*[1]" mode = "semantics"/>
2261           </m:mrow>
2262         </m:mfrac>
2263       </xsl:if>
2264     </xsl:for-each>
2265     <xsl:apply-templates select = "*[last()]" mode = "semantics"/>
2266   </m:mrow>
2267 </xsl:template>
2268
2269 <xsl:template match = "m:lowlimit | m:uplimit | m:bvar | m:degree |
2270                                                                m:logbase">
2271   <xsl:apply-templates select="*" mode = "semantics"/>
2272 </xsl:template>
2273
2274 <xsl:template match = "m:apply[m:divergence[1] | m:grad[1] | m:curl[1]]">
2275   <m:mrow>
2276     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2277       <xsl:attribute name="m:xref">
2278         <xsl:value-of select="@id"/>
2279       </xsl:attribute>
2280     </xsl:if>
2281     <m:mo>
2282       <xsl:if test="*[1]=m:divergence">
2283 <!-- HELM: added -->        
2284         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2285           <xsl:attribute name="m:xref">
2286             <xsl:value-of select="m:divergence/@id"/>
2287           </xsl:attribute>
2288         </xsl:if>
2289         <xsl:value-of select="'div'"/>
2290       </xsl:if>
2291       <xsl:if test="*[1]=m:grad">
2292 <!-- HELM: added -->        
2293         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2294           <xsl:attribute name="m:xref">
2295             <xsl:value-of select="m:grad/@id"/>
2296           </xsl:attribute>
2297         </xsl:if>
2298         <xsl:value-of select="'grad'"/>
2299       </xsl:if>
2300       <xsl:if test="*[1]=m:curl">
2301 <!-- HELM: added -->        
2302         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2303           <xsl:attribute name="m:xref">
2304             <xsl:value-of select="m:curl/@id"/>
2305           </xsl:attribute>
2306         </xsl:if>
2307         <xsl:value-of select="'curl'"/>
2308       </xsl:if>
2309     </m:mo>
2310     <xsl:choose>
2311       <xsl:when test="*[2]=m:ci">
2312         <xsl:apply-templates select = "*[2]" mode = "semantics"/>
2313       </xsl:when>
2314       <xsl:otherwise>
2315         <m:mfenced separators="">
2316           <xsl:apply-templates select = "*[2]" mode = "semantics"/>
2317         </m:mfenced>
2318       </xsl:otherwise>
2319     </xsl:choose>
2320   </m:mrow>
2321 </xsl:template>
2322
2323 <xsl:template match = "m:apply[m:laplacian[1]]">
2324   <m:mrow>
2325     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2326       <xsl:attribute name="m:xref">
2327         <xsl:value-of select="@id"/>
2328       </xsl:attribute>
2329     </xsl:if>
2330     <m:msup>
2331 <!-- HELM: added -->        
2332         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2333           <xsl:attribute name="m:xref">
2334             <xsl:value-of select="m:laplacian/@id"/>
2335           </xsl:attribute>
2336         </xsl:if>
2337       <m:mo> <m:mchar name="Delta"/> </m:mo>
2338       <m:mn>2</m:mn>
2339     </m:msup>
2340     <xsl:apply-templates select = "*[2]" mode = "semantics"/>
2341   </m:mrow>
2342 </xsl:template>
2343
2344
2345 <!-- ***************** SET THEORY ***************** -->
2346
2347 <xsl:template match = "m:set | m:list">
2348   <m:mfenced open="{{" close="}}" separators="">
2349     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2350       <xsl:attribute name="m:xref">
2351         <xsl:value-of select="@id"/>
2352       </xsl:attribute>
2353     </xsl:if>
2354     <xsl:if test="*[1]=m:bvar and *[2]=m:condition">
2355       <xsl:apply-templates select="m:bvar" mode = "semantics"/>
2356       <m:mo>|</m:mo>
2357       <xsl:apply-templates select="m:condition" mode = "semantics"/>
2358     </xsl:if>
2359     <xsl:if test="*[1]=m:condition and not(child::m:bvar)">
2360       <m:mfenced open="" close="" separators=",">
2361         <xsl:for-each select = "*[not(self::m:condition) and not(self::m:bvar)]">
2362           <xsl:apply-templates select = "." mode="semantics"/>
2363         </xsl:for-each>
2364       </m:mfenced>
2365       <m:mo>|</m:mo>
2366       <xsl:apply-templates select="m:condition" mode = "semantics"/>
2367     </xsl:if>
2368     <xsl:if test="not(child::m:bvar) and not(child::m:condition)">
2369       <m:mfenced open="" close="" separators=",">
2370         <xsl:for-each select = "*">
2371           <xsl:apply-templates select = "." mode="semantics"/>
2372         </xsl:for-each>
2373       </m:mfenced>
2374     </xsl:if>
2375   </m:mfenced>
2376 </xsl:template>
2377
2378 <xsl:template match = "m:apply[m:union[1]]">
2379   <xsl:param name="IN_PREC" select="$NO_PREC"/>
2380   <xsl:param name="PARAM" select="$NO_PARAM"/>
2381   <xsl:param name="PAREN" select="$PAR_NO"/>
2382   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
2383   <xsl:choose>
2384     <xsl:when test="$IN_PREC &gt; $UNION_PREC or $IN_PREC=$UNION_PREC
2385                     and $PARAM=$PAR_SAME">
2386       <m:mfenced separators="">
2387         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2388           <xsl:attribute name="m:xref">
2389             <xsl:value-of select="@id"/>
2390           </xsl:attribute>
2391         </xsl:if>
2392         <xsl:apply-templates select="." mode="union">
2393           <xsl:with-param name="PARAM" select="$PARAM"/>
2394           <xsl:with-param name="PAREN" select="$PAREN"/>
2395           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
2396         </xsl:apply-templates>
2397       </m:mfenced>
2398     </xsl:when>
2399     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC
2400                     and not($SEM_SW=$SEM_ALL) and not($SEM_SW=$SEM_XREF)
2401                     and not($SEM_SW=$SEM_XREF_EXT)">
2402       <xsl:apply-templates select="." mode="union">
2403         <xsl:with-param name="PARAM" select="$PARAM"/>
2404         <xsl:with-param name="PAREN" select="$PAREN"/>
2405         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
2406       </xsl:apply-templates>
2407     </xsl:when>
2408     <xsl:otherwise>
2409       <m:mrow>
2410         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2411           <xsl:attribute name="m:xref">
2412             <xsl:value-of select="@id"/>
2413           </xsl:attribute>
2414         </xsl:if>
2415         <xsl:apply-templates select="." mode="union">
2416           <xsl:with-param name="PARAM" select="$PARAM"/>
2417           <xsl:with-param name="PAREN" select="$PAREN"/>
2418           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
2419         </xsl:apply-templates>
2420       </m:mrow>
2421     </xsl:otherwise>
2422   </xsl:choose>
2423 </xsl:template>
2424
2425 <xsl:template match = "m:apply[m:union[1]]" mode="union">
2426   <xsl:param name="PARAM" select="$NO_PARAM"/>
2427   <xsl:param name="PAREN" select="$PAR_NO"/>
2428   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
2429   <xsl:apply-templates select = "*[2]" mode="semantics">
2430     <xsl:with-param name="IN_PREC" select="$UNION_PREC"/>
2431     <xsl:with-param name="PARAM" select="$PARAM"/>
2432     <xsl:with-param name="PAREN" select="$PAREN"/>
2433     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
2434   </xsl:apply-templates>
2435   <xsl:for-each select = "*[position()>2]">
2436     <m:mo>
2437 <!-- HELM: added -->        
2438         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2439           <xsl:attribute name="m:xref">
2440             <xsl:value-of select="../m:union/@id"/>
2441           </xsl:attribute>
2442         </xsl:if>
2443     <m:mchar name="Union"/> </m:mo>
2444     <xsl:apply-templates select = "." mode="semantics">
2445       <xsl:with-param name="IN_PREC" select="$UNION_PREC"/>
2446       <xsl:with-param name="PAREN" select="$PAREN"/>
2447       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
2448     </xsl:apply-templates>
2449   </xsl:for-each>
2450 </xsl:template>
2451
2452 <xsl:template match = "m:apply[m:intersect[1]]">
2453   <xsl:param name="IN_PREC" select="$NO_PREC"/>
2454   <xsl:param name="PARAM" select="$NO_PARAM"/>
2455   <xsl:param name="PAREN" select="$PAR_NO"/>
2456   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
2457   <xsl:choose>
2458     <xsl:when test="$IN_PREC &gt; $INTERSECT_PREC">
2459       <m:mfenced separators="">
2460         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2461           <xsl:attribute name="m:xref">
2462             <xsl:value-of select="@id"/>
2463           </xsl:attribute>
2464         </xsl:if>
2465         <xsl:apply-templates select="." mode="intersect">
2466           <xsl:with-param name="PARAM" select="$PARAM"/>
2467           <xsl:with-param name="PAREN" select="$PAREN"/>
2468           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
2469         </xsl:apply-templates>
2470       </m:mfenced>
2471     </xsl:when>
2472     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC
2473                     and not($SEM_SW=$SEM_ALL) and not($SEM_SW=$SEM_XREF)
2474                     and not($SEM_SW=$SEM_XREF_EXT)">
2475       <xsl:apply-templates select="." mode="intersect">
2476         <xsl:with-param name="PARAM" select="$PARAM"/>
2477         <xsl:with-param name="PAREN" select="$PAREN"/>
2478         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
2479       </xsl:apply-templates>
2480     </xsl:when>
2481     <xsl:otherwise>
2482       <m:mrow>
2483         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2484           <xsl:attribute name="m:xref">
2485             <xsl:value-of select="@id"/>
2486           </xsl:attribute>
2487         </xsl:if>
2488         <xsl:apply-templates select="." mode="intersect">
2489           <xsl:with-param name="PARAM" select="$PARAM"/>
2490           <xsl:with-param name="PAREN" select="$PAREN"/>
2491           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
2492         </xsl:apply-templates>
2493       </m:mrow>
2494     </xsl:otherwise>
2495   </xsl:choose>
2496 </xsl:template>
2497
2498 <xsl:template match = "m:apply[m:intersect[1]]" mode="intersect">
2499   <xsl:param name="PARAM" select="$NO_PARAM"/>
2500   <xsl:param name="PAREN" select="$PAR_NO"/>
2501   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
2502   <xsl:apply-templates select = "*[2]" mode="semantics">
2503     <xsl:with-param name="IN_PREC" select="$INTERSECT_PREC"/>
2504     <xsl:with-param name="PARAM" select="$PARAM"/>
2505     <xsl:with-param name="PAREN" select="$PAREN"/>
2506     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
2507   </xsl:apply-templates>
2508   <xsl:for-each select = "*[position()>2]">
2509     <m:mo>
2510 <!-- HELM: added -->        
2511         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2512           <xsl:attribute name="m:xref">
2513             <xsl:value-of select="../m:intersect/@id"/>
2514           </xsl:attribute>
2515         </xsl:if>
2516     <m:mchar name="Intersection"/> </m:mo>
2517     <xsl:apply-templates select = "." mode="semantics">
2518       <xsl:with-param name="IN_PREC" select="$INTERSECT_PREC"/>
2519       <xsl:with-param name="PAREN" select="$PAREN"/>
2520       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
2521     </xsl:apply-templates>
2522   </xsl:for-each>
2523 </xsl:template>
2524
2525 <xsl:template match = "m:apply[m:setdiff[1]]">
2526   <xsl:param name="IN_PREC" select="$NO_PREC"/>
2527   <xsl:param name="PARAM" select="$NO_PARAM"/>
2528   <xsl:param name="PAREN" select="$PAR_NO"/>
2529   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
2530   <xsl:choose>
2531     <xsl:when test="$IN_PREC &gt; $SETDIFF_PREC or $IN_PREC=$SETDIFF_PREC
2532                     and $PARAM=$PAR_SAME">
2533       <m:mfenced separators="">
2534         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2535           <xsl:attribute name="m:xref">
2536             <xsl:value-of select="@id"/>
2537           </xsl:attribute>
2538         </xsl:if>
2539         <xsl:apply-templates select="." mode="setdiff">
2540           <xsl:with-param name="PARAM" select="$PARAM"/>
2541           <xsl:with-param name="PAREN" select="$PAREN"/>
2542           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
2543         </xsl:apply-templates>
2544       </m:mfenced>
2545     </xsl:when>
2546     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC
2547                     and not($SEM_SW=$SEM_ALL) and not($SEM_SW=$SEM_XREF)
2548                     and not($SEM_SW=$SEM_XREF_EXT)">
2549       <xsl:apply-templates select="." mode="setdiff">
2550         <xsl:with-param name="PARAM" select="$PARAM"/>
2551         <xsl:with-param name="PAREN" select="$PAREN"/>
2552         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
2553       </xsl:apply-templates>
2554     </xsl:when>
2555     <xsl:otherwise>
2556       <m:mrow>
2557         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2558           <xsl:attribute name="m:xref">
2559             <xsl:value-of select="@id"/>
2560           </xsl:attribute>
2561         </xsl:if>
2562         <xsl:apply-templates select="." mode="setdiff">
2563           <xsl:with-param name="PARAM" select="$PARAM"/>
2564           <xsl:with-param name="PAREN" select="$PAREN"/>
2565           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
2566         </xsl:apply-templates>
2567       </m:mrow>
2568     </xsl:otherwise>
2569   </xsl:choose>
2570 </xsl:template>
2571
2572 <xsl:template match = "m:apply[m:setdiff[1]]" mode="setdiff">
2573   <xsl:param name="PARAM" select="$NO_PARAM"/>
2574   <xsl:param name="PAREN" select="$PAR_NO"/>
2575   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
2576   <xsl:apply-templates select = "*[2]" mode = "semantics">
2577     <xsl:with-param name="IN_PREC" select="$SETDIFF_PREC"/>
2578     <xsl:with-param name="PARAM" select="$PARAM"/>
2579     <xsl:with-param name="PAREN" select="$PAREN"/>
2580     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
2581   </xsl:apply-templates>
2582   <m:mo>
2583 <!-- HELM: added -->        
2584         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2585           <xsl:attribute name="m:xref">
2586             <xsl:value-of select="m:setdiff/@id"/>
2587           </xsl:attribute>
2588         </xsl:if>\</m:mo>
2589   <xsl:apply-templates select = "*[3]" mode = "semantics">
2590     <xsl:with-param name="IN_PREC" select="$SETDIFF_PREC"/>
2591     <xsl:with-param name="PARAM" select="$PAR_SAME"/>
2592     <xsl:with-param name="PAREN" select="$PAREN"/>
2593     <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
2594   </xsl:apply-templates>
2595 </xsl:template>
2596
2597 <xsl:template match = "m:apply[m:card[1]]">
2598   <m:mfenced open="|" close="|" separators=",">
2599     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2600       <xsl:attribute name="m:xref">
2601         <xsl:value-of select="@id"/>
2602       </xsl:attribute>
2603     </xsl:if>
2604     <xsl:for-each select = "*[position()>1]">
2605       <xsl:apply-templates select = "." mode="semantics"/>
2606     </xsl:for-each>
2607   </m:mfenced>
2608 </xsl:template>
2609
2610
2611 <!-- ***************** SEQUENCES AND SERIES ***************** -->
2612
2613 <xsl:template match = "m:apply[m:sum[1] | m:product[1]]">
2614   <m:mrow>
2615     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2616       <xsl:attribute name="m:xref">
2617         <xsl:value-of select="@id"/>
2618       </xsl:attribute>
2619     </xsl:if>
2620     <xsl:choose>
2621       <xsl:when test="*[2]=m:bvar and m:lowlimit and m:uplimit">
2622         <m:munderover>
2623           <m:mo>
2624             <xsl:if test="*[1]=m:sum">
2625 <!-- HELM: added -->        
2626         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2627           <xsl:attribute name="m:xref">
2628             <xsl:value-of select="m:sum/@id"/>
2629           </xsl:attribute>
2630         </xsl:if>
2631               <m:mchar name="Sum"/>
2632             </xsl:if>
2633             <xsl:if test="*[1]=m:product">
2634 <!-- HELM: added -->        
2635         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2636           <xsl:attribute name="m:xref">
2637             <xsl:value-of select="m:product/@id"/>
2638           </xsl:attribute>
2639         </xsl:if>
2640               <m:mchar name="Product"/>
2641             </xsl:if>
2642           </m:mo>
2643           <m:mrow>
2644             <xsl:apply-templates select = "*[2]" mode = "semantics"/>
2645             <m:mo>=</m:mo>
2646             <xsl:apply-templates select = "m:lowlimit" mode = "semantics"/>
2647           </m:mrow>
2648           <xsl:apply-templates select = "m:uplimit" mode = "semantics"/>
2649         </m:munderover>
2650         <xsl:apply-templates select = "*[5]" mode = "semantics"/>
2651       </xsl:when>
2652       <xsl:when test="*[2]=m:bvar and *[3]=m:condition">
2653         <m:munder>
2654           <m:mo>
2655             <xsl:if test="*[1]=m:sum">
2656 <!-- HELM: added -->        
2657         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2658           <xsl:attribute name="m:xref">
2659             <xsl:value-of select="m:sum/@id"/>
2660           </xsl:attribute>
2661         </xsl:if>
2662               <m:mchar name="Sum"/>
2663             </xsl:if>
2664             <xsl:if test="*[1]=m:product">
2665 <!-- HELM: added -->        
2666         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2667           <xsl:attribute name="m:xref">
2668             <xsl:value-of select="m:product/@id"/>
2669           </xsl:attribute>
2670         </xsl:if>
2671               <m:mchar name="Product"/>
2672             </xsl:if>
2673           </m:mo>
2674           <xsl:apply-templates select = "*[3]" mode = "semantics"/>
2675         </m:munder>
2676         <xsl:apply-templates select = "*[4]" mode = "semantics"/>
2677       </xsl:when>
2678     </xsl:choose>
2679   </m:mrow>
2680 </xsl:template>
2681
2682 <xsl:template match = "m:apply[m:limit[1]]">
2683   <m:mrow>
2684     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2685       <xsl:attribute name="m:xref">
2686         <xsl:value-of select="@id"/>
2687       </xsl:attribute>
2688     </xsl:if>
2689     <m:munder>
2690       <m:mo>
2691 <!-- HELM: added -->        
2692         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2693           <xsl:attribute name="m:xref">
2694             <xsl:value-of select="m:lim/@id"/>
2695           </xsl:attribute>
2696         </xsl:if>lim</m:mo>
2697       <m:mrow>
2698         <xsl:if test="*[2]=m:bvar and *[3]=m:lowlimit">
2699             <xsl:apply-templates select = "*[2]" mode = "semantics"/>
2700             <m:mo> <m:mchar name="RightArrow"/> </m:mo>
2701             <xsl:apply-templates select = "*[3]" mode = "semantics"/>
2702         </xsl:if>
2703         <xsl:if test="*[2]=m:bvar and *[3]=m:condition">
2704           <xsl:apply-templates select = "*[3]" mode = "semantics"/>
2705         </xsl:if>
2706       </m:mrow>
2707     </m:munder>
2708     <xsl:apply-templates select = "*[4]" mode = "semantics"/>
2709   </m:mrow>
2710 </xsl:template>
2711
2712
2713 <!-- ***************** TRIGONOMETRY ***************** -->
2714
2715 <xsl:template match = "m:apply[*[1][self::m:sin | self::m:cos |
2716                        self::m:tan | self::m:sec | self::m:csc |
2717                        self::m:cot | self::m:sinh | self::m:cosh |
2718                        self::m:tanh | self::m:sech | self::m:csch |
2719                        self::m:coth | self::m:arcsin | self::m:arccos |
2720                        self::m:arctan]]">
2721   <m:mrow>
2722     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2723       <xsl:attribute name="m:xref">
2724         <xsl:value-of select="@id"/>
2725       </xsl:attribute>
2726     </xsl:if>
2727     <xsl:if test="not(parent::m:apply[m:power[1]])">
2728       <xsl:apply-templates select = "*[1]" mode = "trigonometry"/>
2729     </xsl:if>
2730     <xsl:if test="parent::m:apply[m:power[1]]">
2731       <m:msup>
2732         <xsl:apply-templates select = "*[1]" mode = "trigonometry"/>
2733         <xsl:apply-templates select = "../*[3]" mode = "semantics"/>
2734       </m:msup>
2735     </xsl:if>
2736     <m:mo> <m:mchar name='ApplyFunction'/> </m:mo>
2737     <xsl:apply-templates select = "*[2]" mode = "semantics">
2738       <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
2739       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
2740     </xsl:apply-templates>
2741   </m:mrow>
2742 </xsl:template>
2743
2744 <xsl:template match = "*" mode="trigonometry">
2745   <m:mo>
2746     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2747       <xsl:attribute name="m:xref">
2748         <xsl:value-of select="@id"/>
2749       </xsl:attribute>
2750     </xsl:if>
2751     <xsl:choose>
2752       <xsl:when test="self::m:sin">
2753         <xsl:value-of select="'sin'"/>
2754       </xsl:when>
2755       <xsl:when test="self::m:cos">
2756         <xsl:value-of select="'cos'"/>
2757       </xsl:when>
2758       <xsl:when test="self::m:tan">
2759         <xsl:value-of select="'tan'"/>
2760       </xsl:when>
2761       <xsl:when test="self::m:sec">
2762         <xsl:value-of select="'sec'"/>
2763       </xsl:when>
2764       <xsl:when test="self::m:csc">
2765         <xsl:value-of select="'csc'"/>
2766       </xsl:when>
2767       <xsl:when test="self::m:cot">
2768         <xsl:value-of select="'cot'"/>
2769       </xsl:when>
2770       <xsl:when test="self::m:sinh">
2771         <xsl:value-of select="'sinh'"/>
2772       </xsl:when>
2773       <xsl:when test="self::m:cosh">
2774         <xsl:value-of select="'cosh'"/>
2775       </xsl:when>
2776       <xsl:when test="self::m:tanh">
2777         <xsl:value-of select="'tanh'"/>
2778       </xsl:when>
2779       <xsl:when test="self::m:sech">
2780         <xsl:value-of select="'sech'"/>
2781       </xsl:when>
2782       <xsl:when test="self::m:csch">
2783         <xsl:value-of select="'csch'"/>
2784       </xsl:when>
2785       <xsl:when test="self::m:coth">
2786         <xsl:value-of select="'coth'"/>
2787       </xsl:when>
2788       <xsl:when test="self::m:arcsin">
2789         <xsl:value-of select="'arcsin'"/>
2790       </xsl:when>
2791       <xsl:when test="self::m:arccos">
2792         <xsl:value-of select="'arccos'"/>
2793       </xsl:when>
2794       <xsl:when test="self::m:arctan">
2795         <xsl:value-of select="'arctan'"/>
2796       </xsl:when>
2797     </xsl:choose>
2798   </m:mo>
2799 </xsl:template>
2800
2801
2802 <!-- ***************** STATISTICS ***************** -->
2803
2804 <xsl:template match = "m:apply[m:mean[1]]">
2805   <m:mfenced open="&lt;" close="&gt;" separators=",">
2806     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2807       <xsl:attribute name="m:xref">
2808         <xsl:value-of select="@id"/>
2809       </xsl:attribute>
2810     </xsl:if>
2811     <xsl:for-each select = "*[position()>1]">
2812       <xsl:apply-templates select = "." mode="semantics"/>
2813     </xsl:for-each>
2814   </m:mfenced>
2815 </xsl:template>
2816
2817 <xsl:template match = "m:apply[m:sdev[1]]">
2818   <m:mrow>
2819     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2820       <xsl:attribute name="m:xref">
2821         <xsl:value-of select="@id"/>
2822       </xsl:attribute>
2823     </xsl:if>
2824     <m:mo>
2825 <!-- HELM: added -->        
2826         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2827           <xsl:attribute name="m:xref">
2828             <xsl:value-of select="m:sdev/@id"/>
2829           </xsl:attribute>
2830         </xsl:if>
2831     <m:mchar name="sigma"/> </m:mo>
2832     <m:mfenced separators=",">
2833       <xsl:for-each select = "*[position()>1]">
2834         <xsl:apply-templates select = "." mode="semantics"/>
2835       </xsl:for-each>
2836     </m:mfenced>
2837   </m:mrow>
2838 </xsl:template>
2839
2840 <xsl:template match = "m:apply[m:variance[1]]">
2841   <m:mrow>
2842     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2843       <xsl:attribute name="m:xref">
2844         <xsl:value-of select="@id"/>
2845       </xsl:attribute>
2846     </xsl:if>
2847     <m:mo>
2848 <!-- HELM: added -->        
2849         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2850           <xsl:attribute name="m:xref">
2851             <xsl:value-of select="m:variance/@id"/>
2852           </xsl:attribute>
2853         </xsl:if>
2854     <m:mchar name="sigma"/> </m:mo>
2855     <m:msup>
2856       <m:mfenced separators=",">
2857         <xsl:for-each select = "*[position()>1]">
2858           <xsl:apply-templates select = "." mode="semantics"/>
2859         </xsl:for-each>
2860       </m:mfenced>
2861       <m:mn>2</m:mn>
2862     </m:msup>
2863   </m:mrow>
2864 </xsl:template>
2865
2866 <xsl:template match = "m:apply[m:median[1]]">
2867   <m:mrow>
2868     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2869       <xsl:attribute name="m:xref">
2870         <xsl:value-of select="@id"/>
2871       </xsl:attribute>
2872     </xsl:if>
2873     <m:mo>
2874 <!-- HELM: added -->        
2875         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2876           <xsl:attribute name="m:xref">
2877             <xsl:value-of select="m:median/@id"/>
2878           </xsl:attribute>
2879         </xsl:if>median</m:mo>
2880     <m:mfenced separators=",">
2881       <xsl:for-each select = "*[position()>1]">
2882         <xsl:apply-templates select = "." mode="semantics"/>
2883       </xsl:for-each>
2884     </m:mfenced>
2885   </m:mrow>
2886 </xsl:template>
2887
2888 <xsl:template match = "m:apply[m:mode[1]]">
2889   <m:mrow>
2890     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2891       <xsl:attribute name="m:xref">
2892         <xsl:value-of select="@id"/>
2893       </xsl:attribute>
2894     </xsl:if>
2895     <m:mo>
2896 <!-- HELM: added -->        
2897         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2898           <xsl:attribute name="m:xref">
2899             <xsl:value-of select="m:mode/@id"/>
2900           </xsl:attribute>
2901         </xsl:if>mode</m:mo>
2902     <m:mfenced separators=",">
2903       <xsl:for-each select = "*[position()>1]">
2904         <xsl:apply-templates select = "." mode="semantics"/>
2905       </xsl:for-each>
2906     </m:mfenced>
2907   </m:mrow>
2908 </xsl:template>
2909
2910 <xsl:template match = "m:apply[m:moment[1]]">
2911   <m:mfenced open="&lt;" close="&gt;" separators="">
2912     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2913       <xsl:attribute name="m:xref">
2914         <xsl:value-of select="@id"/>
2915       </xsl:attribute>
2916     </xsl:if>
2917     <xsl:if test="*[2]=m:degree">
2918       <m:msup>
2919         <xsl:apply-templates select="*[3]" mode = "semantics"/>
2920         <xsl:apply-templates select="*[2]" mode = "semantics"/>
2921       </m:msup>
2922     </xsl:if>
2923     <xsl:if test="not(*[2]=m:degree)">
2924       <xsl:for-each select = "*[position()>1]">
2925         <xsl:apply-templates select = "." mode="semantics"/>
2926       </xsl:for-each>
2927     </xsl:if>
2928   </m:mfenced>
2929 </xsl:template>
2930
2931
2932 <!-- ***************** LINEAR ALGEBRA ***************** -->
2933
2934 <xsl:template match="m:vector">
2935   <m:mfenced separators="">
2936     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2937       <xsl:attribute name="m:xref">
2938         <xsl:value-of select="@id"/>
2939       </xsl:attribute>
2940     </xsl:if>
2941     <m:mtable>
2942       <xsl:for-each select="*">
2943         <m:mtd>
2944           <xsl:apply-templates select="." mode = "semantics"/>
2945         </m:mtd>
2946       </xsl:for-each>
2947     </m:mtable>
2948   </m:mfenced>
2949 </xsl:template>
2950
2951 <xsl:template match = "m:matrix">
2952   <m:mfenced separators="">
2953     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2954       <xsl:attribute name="m:xref">
2955         <xsl:value-of select="@id"/>
2956       </xsl:attribute>
2957     </xsl:if>
2958     <m:mtable>
2959       <xsl:apply-templates select="*" mode = "semantics"/>
2960     </m:mtable>
2961   </m:mfenced>
2962 </xsl:template>
2963
2964 <xsl:template match = "m:matrixrow">
2965   <m:mtr>
2966     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2967       <xsl:attribute name="m:xref">
2968         <xsl:value-of select="@id"/>
2969       </xsl:attribute>
2970     </xsl:if>
2971     <xsl:for-each select="*">
2972       <m:mtd>
2973         <xsl:apply-templates select="." mode = "semantics"/>
2974       </m:mtd>
2975     </xsl:for-each>
2976   </m:mtr>
2977 </xsl:template>
2978
2979 <xsl:template match = "m:apply[m:determinant[1]]">
2980   <m:mrow>
2981     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2982       <xsl:attribute name="m:xref">
2983         <xsl:value-of select="@id"/>
2984       </xsl:attribute>
2985     </xsl:if>
2986     <m:mo>
2987 <!-- HELM: added -->        
2988         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2989           <xsl:attribute name="m:xref">
2990             <xsl:value-of select="m:determinant/@id"/>
2991           </xsl:attribute>
2992         </xsl:if>det</m:mo>
2993     <xsl:apply-templates select = "*[2]" mode = "semantics"/>
2994   </m:mrow>
2995 </xsl:template>
2996
2997 <xsl:template match = "m:apply[m:transpose[1]]">
2998   <m:msup>
2999     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
3000       <xsl:attribute name="m:xref">
3001         <xsl:value-of select="@id"/>
3002       </xsl:attribute>
3003     </xsl:if>
3004     <xsl:apply-templates select = "*[2]" mode = "semantics"/>
3005     <m:mo>
3006 <!-- HELM: added -->        
3007         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
3008           <xsl:attribute name="m:xref">
3009             <xsl:value-of select="m:transpose/@id"/>
3010           </xsl:attribute>
3011         </xsl:if>T</m:mo>
3012   </m:msup>
3013 </xsl:template>
3014
3015 <xsl:template match = "m:apply[m:selector[1]]">
3016   <xsl:if test="*[2]=m:matrix and *[3]=m:cn">
3017       <xsl:variable name="m" select = "*[3]"/>
3018       <xsl:choose>
3019         <xsl:when test="*[4]=m:cn">
3020           <xsl:variable name="n" select = "*[4]"/>
3021           <xsl:copy-of select = "m:matrix/*[position()=$m]/*[position()=$n]"/>
3022         </xsl:when>
3023         <xsl:otherwise>
3024           <xsl:copy-of select = "m:matrix/*[position()=$m]"/>
3025         </xsl:otherwise>
3026       </xsl:choose>
3027   </xsl:if>
3028   <xsl:if test="(*[2]=m:vector or *[2]=m:list) and *[3]=m:cn">
3029     <xsl:variable name="m" select = "*[3]"/>
3030     <xsl:copy-of select = "*[2]/*[position()=$m]"/>
3031   </xsl:if>
3032 </xsl:template>
3033
3034 <xsl:template match = "m:apply[m:vectorproduct[1] |
3035                                  m:scalarproduct[1] | m:outerproduct[1]]">
3036   <m:mrow>
3037     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
3038       <xsl:attribute name="m:xref">
3039         <xsl:value-of select="@id"/>
3040       </xsl:attribute>
3041     </xsl:if>
3042     <xsl:apply-templates select="*[2]" mode = "semantics"/>
3043     <m:mo>
3044       <xsl:if test="m:vectorproduct[1]">
3045 <!-- HELM: added -->        
3046         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
3047           <xsl:attribute name="m:xref">
3048             <xsl:value-of select="m:vectorproduct/@id"/>
3049           </xsl:attribute>
3050         </xsl:if>
3051         <m:mchar name="Cross"/>
3052       </xsl:if>
3053       <xsl:if test="m:scalarproduct[1] | m:outerproduct[1]">
3054 <!-- HELM: added -->        
3055         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
3056           <xsl:attribute name="m:xref">
3057             <xsl:value-of select="*[1]/@id"/>
3058           </xsl:attribute>
3059         </xsl:if>
3060         <xsl:value-of select="'.'"/>
3061       </xsl:if>
3062     </m:mo>
3063     <xsl:apply-templates select="*[3]" mode = "semantics"/>
3064   </m:mrow>
3065 </xsl:template>
3066
3067 </xsl:stylesheet>