]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/xsl/tml-mmlp.xsl
* changed handling of ' (\primes) with a few patches in the stylesheets
[helm.git] / helm / DEVEL / mathml_editor / xsl / tml-mmlp.xsl
1 <?xml version="1.0"?>
2 <xsl:stylesheet
3      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
4      xmlns:tml="http://helm.cs.unibo.it/2002/TML"
5      xmlns:m="http://www.w3.org/1998/Math/MathML"
6      exclude-result-prefixes="tml"
7      version="1.0">
8
9   <xsl:output indent="yes"/>
10
11   <xsl:param name="id" select="/.."/>
12
13   <xsl:template match="/">
14     <xsl:choose>
15       <xsl:when test="$id">
16         <xsl:apply-templates select="descendant::*[@id=$id]"/>
17       </xsl:when>
18       <xsl:otherwise>
19         <xsl:apply-templates/>
20       </xsl:otherwise>
21     </xsl:choose>
22   </xsl:template>
23
24   <xsl:template match="tml:math">
25     <m:math>
26       <xsl:if test="@id">
27         <xsl:attribute name="xref">
28           <xsl:value-of select="@id"/>
29         </xsl:attribute>
30       </xsl:if>
31        <xsl:if test="@display='1'">
32         <xsl:attribute name="display">block</xsl:attribute>
33       </xsl:if>
34       <xsl:attribute name="display">block</xsl:attribute>
35       <xsl:apply-templates select="*"/>
36     </m:math>
37   </xsl:template>
38
39   <xsl:template match="tml:i">
40     <m:mi>
41       <xsl:if test="@id">
42         <xsl:attribute name="xref">
43           <xsl:value-of select="@id"/>
44         </xsl:attribute>
45       </xsl:if>
46       <xsl:value-of select="@val"/>
47     </m:mi>
48   </xsl:template>
49
50   <xsl:template match="tml:n">
51     <m:mn>
52       <xsl:if test="@id">
53         <xsl:attribute name="xref">
54           <xsl:value-of select="@id"/>
55         </xsl:attribute>
56       </xsl:if>
57       <xsl:value-of select="@val"/>
58     </m:mn>
59   </xsl:template>
60
61   <xsl:template match="tml:o">
62     <m:mo>
63       <xsl:if test="@id">
64         <xsl:attribute name="xref">
65           <xsl:value-of select="@id"/>
66         </xsl:attribute>
67       </xsl:if>
68       <xsl:value-of select="@val"/>
69     </m:mo>
70   </xsl:template>
71
72   <xsl:template match="tml:o[@val='-']">
73     <m:mo>
74       <xsl:if test="@id">
75         <xsl:attribute name="xref">
76           <xsl:value-of select="@id"/>
77         </xsl:attribute>
78       </xsl:if>
79       &#x2212;
80     </m:mo>
81   </xsl:template>
82
83   <xsl:template match="tml:cursor[@visible='1']">
84     <xsl:choose>
85       <xsl:when test="substring(@val,1,1)='\'">
86         <m:mrow>
87           <xsl:if test="@id">
88             <xsl:attribute name="xref">
89               <xsl:value-of select="@id"/>
90             </xsl:attribute>
91           </xsl:if>
92           <m:mo stretchy="false">&#x2329;</m:mo>
93           <m:mtext mathcolor="blue"><xsl:value-of select="@val"/></m:mtext>
94           <m:mo stretchy="false">&#x232a;</m:mo>
95         </m:mrow>
96       </xsl:when>
97       <xsl:otherwise>
98         <m:mtext mathcolor="blue">
99          <xsl:if test="@id">
100            <xsl:attribute name="xref">
101              <xsl:value-of select="@id"/>
102            </xsl:attribute>
103          </xsl:if><xsl:value-of select="@val"/>I</m:mtext>
104       </xsl:otherwise>
105     </xsl:choose>
106   </xsl:template>
107
108   <xsl:template match="tml:cursor[not(@visible) or @visible='0']">
109   </xsl:template>
110
111   <xsl:template match="tml:sb[@under='1'][*[1]/tml:sp[@over='1']]">
112     <m:munderover>
113       <xsl:if test="@id">
114         <xsl:attribute name="xref">
115           <xsl:value-of select="@id"/>
116         </xsl:attribute>
117       </xsl:if>
118       <xsl:apply-templates select="*[1]/*[1]"/>
119       <xsl:apply-templates select="*[2]"/>
120       <xsl:apply-templates select="*[1]/*[2]"/>
121     </m:munderover>
122   </xsl:template>
123
124   <xsl:template match="tml:sb[@under='1']">
125     <m:munder>
126       <xsl:if test="@id">
127         <xsl:attribute name="xref">
128           <xsl:value-of select="@id"/>
129         </xsl:attribute>
130       </xsl:if>
131       <xsl:apply-templates select="*[1]"/>
132       <xsl:apply-templates select="*[2]"/>
133     </m:munder>
134   </xsl:template>
135
136   <xsl:template match="tml:sb[*[1][self::tml:sp[not(@over) or @over='0']]]">
137     <m:msubsup>
138       <xsl:if test="@id">
139         <xsl:attribute name="xref">
140           <xsl:value-of select="@id"/>
141         </xsl:attribute>
142       </xsl:if>
143       <xsl:apply-templates select="*[1]/*[1]"/>
144       <xsl:apply-templates select="*[2]"/>
145       <xsl:apply-templates select="*[1]/*[2]"/>
146     </m:msubsup>
147   </xsl:template>
148
149   <xsl:template match="tml:sb">
150     <m:msub>
151       <xsl:if test="@id">
152         <xsl:attribute name="xref">
153           <xsl:value-of select="@id"/>
154         </xsl:attribute>
155       </xsl:if>
156       <xsl:apply-templates select="*[1]"/>
157       <xsl:apply-templates select="*[2]"/>
158     </m:msub>
159   </xsl:template>
160
161   <xsl:template match="tml:sp[@over='1'][*[1]/tml:sb[@under='1']]">
162     <m:munderover>
163       <xsl:if test="@id">
164         <xsl:attribute name="xref">
165           <xsl:value-of select="@id"/>
166         </xsl:attribute>
167       </xsl:if>
168       <xsl:apply-templates select="*[1]/*[1]"/>
169       <xsl:apply-templates select="*[1]/*[2]"/>
170       <xsl:apply-templates select="*[2]"/>
171     </m:munderover>
172   </xsl:template>
173
174   <xsl:template match="tml:sp[@over='1']">
175     <m:mover>
176       <xsl:if test="@id">
177         <xsl:attribute name="xref">
178           <xsl:value-of select="@id"/>
179         </xsl:attribute>
180       </xsl:if>
181       <xsl:apply-templates select="*[1]"/>
182       <xsl:apply-templates select="*[2]"/>
183     </m:mover>
184   </xsl:template>
185
186   <xsl:template match="tml:sp[*[1][self::tml:sb[not(@over) or @over='0']]]">
187     <m:msubsup>
188       <xsl:if test="@id">
189         <xsl:attribute name="xref">
190           <xsl:value-of select="@id"/>
191         </xsl:attribute>
192       </xsl:if>
193       <xsl:apply-templates select="*[1]/*[1]"/>
194       <xsl:apply-templates select="*[1]/*[2]"/>
195       <xsl:apply-templates select="*[2]"/>
196     </m:msubsup>
197   </xsl:template>
198
199   <xsl:template match="tml:sp">
200     <m:msup>
201       <xsl:if test="@id">
202         <xsl:attribute name="xref">
203           <xsl:value-of select="@id"/>
204         </xsl:attribute>
205       </xsl:if>
206       <xsl:apply-templates select="*[1]"/>
207       <xsl:apply-templates select="*[2]"/>
208     </m:msup>
209   </xsl:template>
210
211   <xsl:template match="tml:g">
212     <xsl:choose>
213       <xsl:when test="not(@id) and count(*) = 1">
214         <xsl:apply-templates select="*[1]"/>
215       </xsl:when>
216       <xsl:when test="tml:cursor">
217         <m:mstyle mathbackground="#e0e0e0">
218           <xsl:if test="@id">
219             <xsl:attribute name="xref">
220               <xsl:value-of select="@id"/>
221             </xsl:attribute>
222           </xsl:if>
223           <m:mrow>
224             <xsl:apply-templates select="*"/>
225           </m:mrow>
226         </m:mstyle>
227       </xsl:when>
228        <xsl:otherwise>
229         <m:mrow>
230           <xsl:if test="@id">
231             <xsl:attribute name="xref">
232               <xsl:value-of select="@id"/>
233             </xsl:attribute>
234           </xsl:if>
235           <xsl:apply-templates select="*"/>
236         </m:mrow>
237       </xsl:otherwise>
238     </xsl:choose>
239   </xsl:template>
240
241   <xsl:template match="tml:row">
242     <m:mtr>
243       <xsl:apply-templates select="cell"/>
244     </m:mtr>
245   </xsl:template>
246
247   <xsl:template match="tml:cell">
248     <m:mtd>
249       <xsl:apply-templates select="*"/>
250     </m:mtd>
251   </xsl:template>
252
253 <!--/// CONTROL SEQUENCES ///-->
254
255   <xsl:template match="tml:c">
256     <m:mrow>
257       <xsl:if test="@id">
258         <xsl:attribute name="xref">
259           <xsl:value-of select="@id"/>
260         </xsl:attribute>
261       </xsl:if>
262       <m:mtext mathcolor="blue">\<xsl:value-of select="@name"/></m:mtext>
263       <xsl:apply-templates select="*"/>
264     </m:mrow>
265   </xsl:template>
266
267   <xsl:template match="tml:c[@name='fun' and count(*)=3]">
268     <m:mrow>
269       <xsl:if test="@id">
270         <xsl:attribute name="xref">
271           <xsl:value-of select="@id"/>
272         </xsl:attribute>
273       </xsl:if>
274       <m:mo mathcolor="red">&#x03bb;</m:mo>
275       <xsl:apply-templates select="*[1]"/>
276       <m:mo>:</m:mo>
277       <xsl:apply-templates select="*[2]"/>
278       <m:mo>.</m:mo>
279       <xsl:apply-templates select="*[3]"/>
280     </m:mrow>
281   </xsl:template>
282
283   <xsl:template match="tml:c[@name='not'][*[1][self::tml:o]]">
284 <!-- not -->
285     <m:mo>
286       <xsl:if test="@id">
287         <xsl:attribute name="xref">
288           <xsl:value-of select="@id"/>
289         </xsl:attribute>
290       </xsl:if>
291       <xsl:value-of select="*[1]/@val"/>&#x0338;</m:mo>
292   </xsl:template>
293
294   <xsl:template match="tml:c[@name='buildrel']">
295 <!-- buildrel -->
296     <m:mover>
297       <xsl:if test="@id">
298         <xsl:attribute name="xref">
299           <xsl:value-of select="@id"/>
300         </xsl:attribute>
301       </xsl:if>
302       <xsl:apply-templates select="*[2]"/>
303       <xsl:apply-templates select="*[1]"/>
304     </m:mover>
305   </xsl:template>
306
307   <xsl:template match="tml:c[@name='left' or @name='right'][*[1][self::tml:o]]">
308 <!-- left -->
309     <m:mo stretchy="true">
310       <xsl:if test="@id">
311         <xsl:attribute name="xref">
312           <xsl:value-of select="@id"/>
313         </xsl:attribute>
314       </xsl:if>
315       <xsl:value-of select="*[1]/@val"/>
316     </m:mo>
317   </xsl:template>
318
319   <xsl:template match="tml:c[@name='bigl' or @name='bigr' or @name='bigm' or @name='big'][*[1][self::tml:o]]">
320 <!-- bigl -->
321     <m:mo stretchy="true" minsize="8.5pt">
322       <xsl:if test="@id">
323         <xsl:attribute name="xref">
324           <xsl:value-of select="@id"/>
325         </xsl:attribute>
326       </xsl:if>
327       <xsl:value-of select="*[1]/@val"/>
328     </m:mo>
329   </xsl:template>
330
331   <xsl:template match="tml:c[@name='Bigl' or @name='Bigr' or @name='Bigm'][*[1][self::tml:o]]">
332 <!-- Bigl -->
333     <m:mo stretchy="true" minsize="11.5pt">
334       <xsl:if test="@id">
335         <xsl:attribute name="xref">
336           <xsl:value-of select="@id"/>
337         </xsl:attribute>
338       </xsl:if>
339       <xsl:value-of select="*[1]/@val"/>
340     </m:mo>
341   </xsl:template>
342
343   <xsl:template match="tml:c[@name='biggl' or @name='biggr' or @name='biggm'][*[1][self::tml:o]]">
344 <!-- biggl -->
345     <m:mo stretchy="true" minsize="14.5pt">
346       <xsl:if test="@id">
347         <xsl:attribute name="xref">
348           <xsl:value-of select="@id"/>
349         </xsl:attribute>
350       </xsl:if>
351       <xsl:value-of select="*[1]/@val"/>
352     </m:mo>
353   </xsl:template>
354
355   <xsl:template match="tml:c[@name='Biggl' or @name='Biggr' or @name='Biggm'][*[1][self::tml:o]]">
356 <!-- biggl -->
357     <m:mo stretchy="true" minsize="17.5pt">
358       <xsl:if test="@id">
359         <xsl:attribute name="xref">
360           <xsl:value-of select="@id"/>
361         </xsl:attribute>
362       </xsl:if>
363       <xsl:value-of select="*[1]/@val"/>
364     </m:mo>
365   </xsl:template>
366
367   <xsl:template match="tml:c[@name='hat']">
368 <!-- hat -->
369     <m:mover accent="true">
370       <xsl:if test="@id">
371         <xsl:attribute name="xref">
372           <xsl:value-of select="@id"/>
373         </xsl:attribute>
374       </xsl:if>
375       <xsl:apply-templates select="*[1]"/>
376       <m:mo>&#x0302;</m:mo>
377     </m:mover>
378   </xsl:template>
379
380   <xsl:template match="tml:c[@name='widehat']">
381 <!-- widehat -->
382     <m:mover accent="false">
383       <xsl:if test="@id">
384         <xsl:attribute name="xref">
385           <xsl:value-of select="@id"/>
386         </xsl:attribute>
387       </xsl:if>
388       <xsl:apply-templates select="*[1]"/>
389       <m:mo stretchy="true">&#x0302;</m:mo>
390     </m:mover>
391   </xsl:template>
392
393   <xsl:template match="tml:c[@name='check']">
394 <!-- check -->
395     <m:mover accent="true">
396       <xsl:if test="@id">
397         <xsl:attribute name="xref">
398           <xsl:value-of select="@id"/>
399         </xsl:attribute>
400       </xsl:if>
401       <xsl:apply-templates select="*[1]"/>
402       <m:mo>&#x030c;</m:mo>
403     </m:mover>
404   </xsl:template>
405
406   <xsl:template match="tml:c[@name='tilde']">
407 <!-- tilde -->
408     <m:mover accent="true">
409       <xsl:if test="@id">
410         <xsl:attribute name="xref">
411           <xsl:value-of select="@id"/>
412         </xsl:attribute>
413       </xsl:if>
414       <xsl:apply-templates select="*[1]"/>
415       <m:mo>&#x0303;</m:mo>
416     </m:mover>
417   </xsl:template>
418
419   <xsl:template match="tml:c[@name='widetilde']">
420 <!-- widetilde -->
421     <m:mover>
422       <xsl:if test="@id">
423         <xsl:attribute name="xref">
424           <xsl:value-of select="@id"/>
425         </xsl:attribute>
426       </xsl:if>
427       <xsl:apply-templates select="*[1]"/>
428       <m:mo stretchy="true">&#x0303;</m:mo>
429     </m:mover>>
430   </xsl:template>
431
432   <xsl:template match="tml:c[@name='acute']">
433 <!-- acute -->
434     <m:mover accent="true">
435       <xsl:if test="@id">
436         <xsl:attribute name="xref">
437           <xsl:value-of select="@id"/>
438         </xsl:attribute>
439       </xsl:if>
440       <xsl:apply-templates select="*[1]"/>
441       <m:mo>&#x0301;</m:mo>
442     </m:mover>
443   </xsl:template>
444
445   <xsl:template match="tml:c[@name='grave']">
446 <!-- grave -->
447     <m:mover accent="true">
448       <xsl:if test="@id">
449         <xsl:attribute name="xref">
450           <xsl:value-of select="@id"/>
451         </xsl:attribute>
452       </xsl:if>
453       <xsl:apply-templates select="*[1]"/>
454       <m:mo>&#x0300;</m:mo>
455     </m:mover>>
456   </xsl:template>
457
458   <xsl:template match="tml:c[@name='dot']">
459 <!-- dot -->
460     <m:mover accent="true">
461       <xsl:if test="@id">
462         <xsl:attribute name="xref">
463           <xsl:value-of select="@id"/>
464         </xsl:attribute>
465       </xsl:if>
466       <xsl:apply-templates select="*[1]"/>
467       <m:mo>&#x0307;</m:mo>
468     </m:mover>
469   </xsl:template>
470
471   <xsl:template match="tml:c[@name='ddot']">
472 <!-- ddot -->
473     <m:mover accent="true">
474       <xsl:if test="@id">
475         <xsl:attribute name="xref">
476           <xsl:value-of select="@id"/>
477         </xsl:attribute>
478       </xsl:if>
479       <xsl:apply-templates select="*[1]"/>
480       <m:mo>&#x0308;</m:mo>
481     </m:mover>
482   </xsl:template>
483
484   <xsl:template match="tml:c[@name='breve']">
485 <!-- breve -->
486     <m:mover accent="true">
487       <xsl:if test="@id">
488         <xsl:attribute name="xref">
489           <xsl:value-of select="@id"/>
490         </xsl:attribute>
491       </xsl:if>
492       <xsl:apply-templates select="*[1]"/>
493       <m:mo>&#x0306;</m:mo>
494     </m:mover>
495   </xsl:template>
496
497   <xsl:template match="tml:c[@name='bar']">
498 <!-- bar -->
499     <m:mover accent="true">
500       <xsl:if test="@id">
501         <xsl:attribute name="xref">
502           <xsl:value-of select="@id"/>
503         </xsl:attribute>
504       </xsl:if>
505       <xsl:apply-templates select="*[1]"/>
506       <m:mo>&#x0304;</m:mo>
507     </m:mover>
508   </xsl:template>
509
510   <xsl:template match="tml:c[@name='vec']">
511 <!-- vec -->
512     <m:mover accent="true">
513       <xsl:if test="@id">
514         <xsl:attribute name="xref">
515           <xsl:value-of select="@id"/>
516         </xsl:attribute>
517       </xsl:if>
518       <xsl:apply-templates select="*[1]"/>
519       <m:mo>&#x20d7;</m:mo>
520     </m:mover>
521   </xsl:template>
522
523   <xsl:template match="tml:c[@name='overline']">
524 <!-- overline -->
525     <m:mover>
526       <xsl:if test="@id">
527         <xsl:attribute name="xref">
528           <xsl:value-of select="@id"/>
529         </xsl:attribute>
530       </xsl:if>
531       <xsl:apply-templates select="*[1]"/>
532       <m:mo stretchy="true">&#x0305;</m:mo>
533     </m:mover>
534   </xsl:template>
535
536   <xsl:template match="tml:c[@name='underline']">
537 <!-- underline -->
538     <m:munder>
539       <xsl:if test="@id">
540         <xsl:attribute name="xref">
541           <xsl:value-of select="@id"/>
542         </xsl:attribute>
543       </xsl:if>
544       <xsl:apply-templates select="*[1]"/>
545       <m:mo stretchy="true">&#x0332;</m:mo>
546     </m:munder>
547   </xsl:template>
548
549   <xsl:template match="tml:c[@name='sqrt']">
550 <!-- sqrt -->
551     <m:msqrt>
552       <xsl:if test="@id">
553         <xsl:attribute name="xref">
554           <xsl:value-of select="@id"/>
555         </xsl:attribute>
556       </xsl:if>
557       <xsl:apply-templates select="*"/>
558     </m:msqrt>
559   </xsl:template>
560
561   <xsl:template match="tml:c[@name='root']">
562 <!-- root -->
563     <m:mroot>
564       <xsl:if test="@id">
565         <xsl:attribute name="xref">
566           <xsl:value-of select="@id"/>
567         </xsl:attribute>
568       </xsl:if>
569       <xsl:choose>
570         <xsl:when test="count(*) &lt; 2">
571           <m:mrow/>
572           <xsl:apply-templates select="*[1]"/>
573         </xsl:when>
574         <xsl:otherwise>
575           <xsl:apply-templates select="*[2]"/>
576           <xsl:apply-templates select="*[1]"/>
577         </xsl:otherwise>
578       </xsl:choose>
579     </m:mroot>
580   </xsl:template>
581
582   <xsl:template match="tml:c[@name='frac']">
583 <!-- frac -->
584     <m:mfrac>
585       <xsl:if test="@id">
586         <xsl:attribute name="xref">
587           <xsl:value-of select="@id"/>
588         </xsl:attribute>
589       </xsl:if>
590       <xsl:apply-templates select="*[1]"/>
591       <xsl:apply-templates select="*[2]"/>
592     </m:mfrac>
593   </xsl:template>
594
595   <xsl:template match="tml:c[@name='over']">
596 <!-- over -->
597     <m:mfrac>
598       <xsl:if test="@id">
599         <xsl:attribute name="xref">
600           <xsl:value-of select="@id"/>
601         </xsl:attribute>
602       </xsl:if>
603       <xsl:apply-templates select="*[1]"/>
604       <xsl:apply-templates select="*[2]"/>
605     </m:mfrac>
606   </xsl:template>
607
608   <xsl:template match="tml:c[@name='atop']">
609 <!-- atop -->
610     <m:mfrac linethickness="0">
611       <xsl:if test="@id">
612         <xsl:attribute name="xref">
613           <xsl:value-of select="@id"/>
614         </xsl:attribute>
615       </xsl:if>
616       <xsl:apply-templates select="*[1]"/>
617       <xsl:apply-templates select="*[2]"/>
618     </m:mfrac>
619   </xsl:template>
620
621   <xsl:template match="tml:c[@name='choose']">
622 <!-- choose -->
623     <m:mrow>
624       <xsl:if test="@id">
625         <xsl:attribute name="xref">
626           <xsl:value-of select="@id"/>
627         </xsl:attribute>
628       </xsl:if>
629       <m:mo stretchy="true">(</m:mo>
630       <m:mfrac linethickness="0">
631         <xsl:apply-templates select="*[1]"/>
632         <xsl:apply-templates select="*[2]"/>
633       </m:mfrac>
634       <m:mo stretchy="true">)</m:mo>
635     </m:mrow>
636   </xsl:template>
637
638   <xsl:template match="tml:c[@name='brace']">
639 <!-- brace -->
640     <m:mrow>
641       <xsl:if test="@id">
642         <xsl:attribute name="xref">
643           <xsl:value-of select="@id"/>
644         </xsl:attribute>
645       </xsl:if>
646       <m:mo stretchy="true">{</m:mo>
647       <m:mfrac linethickness="0">
648         <xsl:apply-templates select="*[1]"/>
649         <xsl:apply-templates select="*[2]"/>
650       </m:mfrac>
651       <m:mo stretchy="true">}</m:mo>
652     </m:mrow>
653   </xsl:template>
654
655   <xsl:template match="tml:c[@name='brack']">
656 <!-- brack -->
657     <m:mrow>
658       <xsl:if test="@id">
659         <xsl:attribute name="xref">
660           <xsl:value-of select="@id"/>
661         </xsl:attribute>
662       </xsl:if>
663       <m:mo stretchy="true">[</m:mo>
664       <m:mfrac linethickness="0">
665         <xsl:apply-templates select="*[1]"/>
666         <xsl:apply-templates select="*[2]"/>
667       </m:mfrac>
668       <m:mo stretchy="true">]</m:mo>
669     </m:mrow>
670   </xsl:template>
671
672   <xsl:template match="tml:c[@name='displaystyle']">
673 <!-- displaystyle -->
674     <m:mstyle displaystyle="true">
675       <xsl:if test="@id">
676         <xsl:attribute name="xref">
677           <xsl:value-of select="@id"/>
678         </xsl:attribute>
679       </xsl:if>
680       <xsl:apply-templates select="*[1]"/>
681     </m:mstyle>
682   </xsl:template>
683
684   <xsl:template match="tml:c[@name='textstyle']">
685 <!-- textstyle -->
686     <m:mstyle scriptlevel="0">
687       <xsl:if test="@id">
688         <xsl:attribute name="xref">
689           <xsl:value-of select="@id"/>
690         </xsl:attribute>
691       </xsl:if>
692       <xsl:apply-templates select="*[1]"/>
693       <xsl:if test="tml:g/tml:cursor[@visible='1']">
694         <m:msub>
695           <m:mtext mathcolor="#808080">}</m:mtext>
696           <m:mtext><xsl:value-of select="@name"/></m:mtext>
697         </m:msub>
698       </xsl:if>
699     </m:mstyle>
700   </xsl:template>
701
702   <xsl:template match="tml:c[@name='scriptstyle']">
703 <!-- scriptstyle -->
704     <m:mstyle scriptlevel="1">
705       <xsl:if test="@id">
706         <xsl:attribute name="xref">
707           <xsl:value-of select="@id"/>
708         </xsl:attribute>
709       </xsl:if>
710       <xsl:apply-templates select="*[1]"/>
711     </m:mstyle>
712   </xsl:template>
713
714   <xsl:template match="tml:c[@name='scriptscriptstyle']">
715 <!-- scriptscriptstyle -->
716     <m:mstyle scriptlevel="2">
717       <xsl:if test="@id">
718         <xsl:attribute name="xref">
719           <xsl:value-of select="@id"/>
720         </xsl:attribute>
721       </xsl:if>
722       <xsl:apply-templates select="*[1]"/>
723     </m:mstyle>
724   </xsl:template>
725
726   <xsl:template match="tml:c[@name='pmod']">
727 <!-- pmod -->
728     <m:mrow>
729       <xsl:if test="@id">
730         <xsl:attribute name="xref">
731           <xsl:value-of select="@id"/>
732         </xsl:attribute>
733       </xsl:if>
734       <m:mo>(</m:mo>
735       <m:mrow>
736         <m:mo>mod</m:mo>
737         <xsl:apply-templates select="*[1]"/>
738       </m:mrow>
739       <m:mo>)</m:mo>
740     </m:mrow>
741   </xsl:template>
742
743   <xsl:template match="tml:c[@name='rm']">
744 <!-- rm -->
745     <m:mstyle mathvariant="normal">
746       <xsl:if test="@id">
747         <xsl:attribute name="xref">
748           <xsl:value-of select="@id"/>
749         </xsl:attribute>
750       </xsl:if>
751       <xsl:apply-templates select="*[1]"/>
752     </m:mstyle>
753   </xsl:template>
754
755   <xsl:template match="tml:c[@name='bf']">
756 <!-- bf -->
757     <m:mstyle mathvariant="bold">
758       <xsl:if test="@id">
759         <xsl:attribute name="xref">
760           <xsl:value-of select="@id"/>
761         </xsl:attribute>
762       </xsl:if>
763       <xsl:apply-templates select="*[1]"/>
764     </m:mstyle>
765   </xsl:template>
766
767   <xsl:template match="tml:c[@name='tt']">
768 <!-- tt -->
769     <m:mstyle mathvariant="monospace">
770       <xsl:if test="@id">
771         <xsl:attribute name="xref">
772           <xsl:value-of select="@id"/>
773         </xsl:attribute>
774       </xsl:if>
775       <xsl:apply-templates select="*[1]"/>
776     </m:mstyle>
777   </xsl:template>
778
779   <xsl:template match="tml:c[@name='sl']">
780 <!-- sl -->
781     <m:mstyle mathvariant="italic">
782       <xsl:if test="@id">
783         <xsl:attribute name="xref">
784           <xsl:value-of select="@id"/>
785         </xsl:attribute>
786       </xsl:if>
787       <xsl:apply-templates select="*[1]"/>
788     </m:mstyle>
789   </xsl:template>
790
791   <xsl:template match="tml:c[@name='it']">
792 <!-- it -->
793     <m:mstyle mathvariant="italic">
794       <xsl:if test="@id">
795         <xsl:attribute name="xref">
796           <xsl:value-of select="@id"/>
797         </xsl:attribute>
798       </xsl:if>
799       <xsl:apply-templates select="*[1]"/>
800     </m:mstyle>
801   </xsl:template>
802
803   <xsl:template match="tml:c[@name=',']">
804 <!-- , -->
805     <m:mspace width="thinmathspace">
806       <xsl:if test="@id">
807         <xsl:attribute name="xref">
808           <xsl:value-of select="@id"/>
809         </xsl:attribute>
810       </xsl:if>
811     </m:mspace>
812   </xsl:template>
813
814   <xsl:template match="tml:c[@name='&gt;']">
815 <!-- > -->
816     <m:mspace width="mediummathspace">
817       <xsl:if test="@id">
818         <xsl:attribute name="xref">
819           <xsl:value-of select="@id"/>
820         </xsl:attribute>
821       </xsl:if>
822     </m:mspace>
823   </xsl:template>
824
825   <xsl:template match="tml:c[@name=';']">
826 <!-- ; -->
827     <m:mspace width="thickmathspace">
828       <xsl:if test="@id">
829         <xsl:attribute name="xref">
830           <xsl:value-of select="@id"/>
831         </xsl:attribute>
832       </xsl:if>
833     </m:mspace>
834   </xsl:template>
835
836   <xsl:template match="tml:c[@name='!']">
837 <!-- ! -->
838     <m:mspace width="-0.166667em">
839       <xsl:if test="@id">
840         <xsl:attribute name="xref">
841           <xsl:value-of select="@id"/>
842         </xsl:attribute>
843       </xsl:if>
844     </m:mspace>
845   </xsl:template>
846
847   <xsl:template name="table-content">
848       <xsl:choose>
849         <xsl:when test="tml:row">
850           <xsl:apply-templates select="tml:row"/>
851         </xsl:when>
852         <xsl:otherwise>
853           <m:mtr>
854             <m:mtd>
855               <xsl:apply-templates select="*"/>
856             </m:mtd>
857           </m:mtr>
858         </xsl:otherwise>
859       </xsl:choose>
860   </xsl:template>
861
862   <xsl:template match="tml:c[@name='matrix']">
863 <!-- matrix -->
864     <m:mtable>
865       <xsl:if test="@id">
866         <xsl:attribute name="xref">
867           <xsl:value-of select="@id"/>
868         </xsl:attribute>
869       </xsl:if>
870       <xsl:call-template name="table-content"/>
871     </m:mtable>
872   </xsl:template>
873
874   <xsl:template match="tml:row">
875     <m:mtr>
876       <xsl:apply-templates select="tml:cell"/>
877     </m:mtr>
878   </xsl:template>
879
880   <xsl:template match="tml:cell">
881     <m:mtd>
882       <xsl:apply-templates select="*"/>
883     </m:mtd>
884   </xsl:template>
885
886   <xsl:template match="tml:c[@name='pmatrix']">
887 <!-- pmatrix -->
888     <m:mrow>
889       <xsl:if test="@id">
890         <xsl:attribute name="xref">
891           <xsl:value-of select="@id"/>
892         </xsl:attribute>
893       </xsl:if>
894       <m:mo stretchy="true">(</m:mo>
895       <m:mtable>
896         <xsl:call-template name="table-content"/>
897       </m:mtable>
898       <m:mo stretchy="true">)</m:mo>
899     </m:mrow>
900   </xsl:template>
901
902   <xsl:template match="tml:c[@name='bordermatrix']">
903 <!-- bordermatrix -->
904     <m:mtable>
905       <xsl:if test="@id">
906         <xsl:attribute name="xref">
907           <xsl:value-of select="@id"/>
908         </xsl:attribute>
909       </xsl:if>
910       <m:mtr>
911         <xsl:apply-templates select="tml:row[1]/tml:cell[1]"/>
912         <m:mtd/>
913         <xsl:apply-templates select="tml:row[1]/tml:cell[position() &gt; 1]"/>
914         <m:mtd/>
915       </m:mtr>
916       <xsl:for-each select="tml:row[position() &gt; 1]">
917         <m:mtr>
918           <xsl:apply-templates select="tml:cell[1]"/>
919           <xsl:if test="position() = 1">
920             <m:mtd rowspan="{count(../tml:row) - 1}">
921               <m:mo stretchy="true">(</m:mo>
922             </m:mtd>
923           </xsl:if>
924           <xsl:apply-templates select="tml:cell[position() &gt; 1]"/>
925           <xsl:if test="position() = 1">
926             <m:mtd rowspan="{count(../tml:row) - 1}">
927               <m:mo stretchy="true">)</m:mo>
928             </m:mtd>
929           </xsl:if>         
930         </m:mtr>
931       </xsl:for-each>      
932     </m:mtable>
933   </xsl:template>
934
935   <xsl:template match="tml:c[@name='overbrace']">
936 <!-- overbrace -->
937     <m:mover>
938       <xsl:if test="@id">
939         <xsl:attribute name="xref">
940           <xsl:value-of select="@id"/>
941         </xsl:attribute>
942       </xsl:if>
943       <xsl:apply-templates select="*[1]"/>
944       <m:mo stretchy="true">????</m:mo>
945     </m:mover>>
946   </xsl:template>
947
948   <xsl:template match="tml:c[@name='underbrace']">
949 <!-- underbrace -->
950     <m:munder>
951       <xsl:if test="@id">
952         <xsl:attribute name="xref">
953           <xsl:value-of select="@id"/>
954         </xsl:attribute>
955       </xsl:if>
956       <xsl:apply-templates select="*[1]"/>
957       <m:mo stretchy="true">????</m:mo>
958     </m:munder>
959   </xsl:template>
960
961   <xsl:template match="tml:c[@name='cases']">
962 <!-- cases -->
963     <m:mrow>
964       <xsl:if test="@id">
965         <xsl:attribute name="xref">
966           <xsl:value-of select="@id"/>
967         </xsl:attribute>
968       </xsl:if>
969       <m:mo stretchy="true">{</m:mo>
970       <m:mtable>
971         <xsl:call-template name="table-content"/>
972       </m:mtable>
973     </m:mrow>
974   </xsl:template>
975
976   <xsl:template match="tml:c[@name='red']">
977 <!-- red  -->
978     <m:mstyle mathcolor="red">
979       <xsl:if test="@id">
980         <xsl:attribute name="xref">
981           <xsl:value-of select="@id"/>
982         </xsl:attribute>
983         <xsl:apply-templates/>
984       </xsl:if>
985     </m:mstyle>
986   </xsl:template>
987
988   <xsl:template match="tml:c[@name='green']">
989 <!-- green  -->
990     <m:mstyle mathcolor="green">
991       <xsl:if test="@id">
992         <xsl:attribute name="xref">
993           <xsl:value-of select="@id"/>
994         </xsl:attribute>
995         <xsl:apply-templates/>
996       </xsl:if>
997     </m:mstyle>
998   </xsl:template>
999
1000   <xsl:template match="tml:c[@name='duedelim']">
1001 <!-- duedelim  -->
1002     <m:mfrac>
1003       <xsl:if test="@id">
1004         <xsl:attribute name="xref">
1005           <xsl:value-of select="@id"/>
1006         </xsl:attribute>
1007       </xsl:if>
1008       <xsl:apply-templates select="*[1]"/>
1009       <xsl:apply-templates select="*[2]"/>
1010     </m:mfrac>
1011   </xsl:template>
1012
1013   <xsl:template match="tml:c[@name='space']">
1014     <m:mspace width="veryverythickmathspace">
1015     </m:mspace>
1016   </xsl:template>
1017
1018 </xsl:stylesheet>