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"
8 <xsl:output indent="yes"/>
10 <xsl:param name="id" select="/.."/>
12 <xsl:template match="/">
15 <xsl:apply-templates select="descendant::*[@id=$id]"/>
18 <xsl:apply-templates/>
23 <xsl:template match="tml:math">
26 <xsl:attribute name="xref">
27 <xsl:value-of select="@id"/>
30 <xsl:if test="@display='1'">
31 <xsl:attribute name="display">block</xsl:attribute>
33 <xsl:attribute name="display">block</xsl:attribute>
34 <xsl:apply-templates select="*"/>
38 <xsl:template match="tml:i">
41 <xsl:attribute name="xref">
42 <xsl:value-of select="@id"/>
45 <xsl:value-of select="@val"/>
49 <xsl:template match="tml:n">
52 <xsl:attribute name="xref">
53 <xsl:value-of select="@id"/>
56 <xsl:value-of select="@val"/>
60 <xsl:template match="tml:o">
63 <xsl:attribute name="xref">
64 <xsl:value-of select="@id"/>
67 <xsl:value-of select="@val"/>
71 <xsl:template match="tml:cursor">
73 <xsl:when test="substring(@val,1,1)='\'">
76 <xsl:attribute name="xref">
77 <xsl:value-of select="@id"/>
80 <m:mo stretchy="false">〈</m:mo>
81 <m:mtext mathcolor="blue"><xsl:value-of select="@val"/></m:mtext>
82 <m:mo stretchy="false">〉</m:mo>
86 <m:mtext mathcolor="blue">
88 <xsl:attribute name="xref">
89 <xsl:value-of select="@id"/>
92 <xsl:value-of select="@val"/>
98 <xsl:template match="tml:sb[@under='1'][*[1]/tml:sp[@over='1']]">
101 <xsl:attribute name="xref">
102 <xsl:value-of select="@id"/>
105 <xsl:apply-templates select="*[1]/*[1]"/>
106 <xsl:apply-templates select="*[2]"/>
107 <xsl:apply-templates select="*[1]/*[2]"/>
111 <xsl:template match="tml:sb[@under='1']">
114 <xsl:attribute name="xref">
115 <xsl:value-of select="@id"/>
118 <xsl:apply-templates select="*[1]"/>
119 <xsl:apply-templates select="*[2]"/>
123 <xsl:template match="tml:sb[*[1][self::tml:sp[not(@over) or @over='0']]]">
126 <xsl:attribute name="xref">
127 <xsl:value-of select="@id"/>
130 <xsl:apply-templates select="*[1]/*[1]"/>
131 <xsl:apply-templates select="*[2]"/>
132 <xsl:apply-templates select="*[1]/*[2]"/>
136 <xsl:template match="tml:sb">
139 <xsl:attribute name="xref">
140 <xsl:value-of select="@id"/>
143 <xsl:apply-templates select="*[1]"/>
144 <xsl:apply-templates select="*[2]"/>
148 <xsl:template match="tml:sp[@over='1'][*[1]/tml:sb[@under='1']]">
151 <xsl:attribute name="xref">
152 <xsl:value-of select="@id"/>
155 <xsl:apply-templates select="*[1]/*[1]"/>
156 <xsl:apply-templates select="*[1]/*[2]"/>
157 <xsl:apply-templates select="*[2]"/>
161 <xsl:template match="tml:sp[@over='1']">
164 <xsl:attribute name="xref">
165 <xsl:value-of select="@id"/>
168 <xsl:apply-templates select="*[1]"/>
169 <xsl:apply-templates select="*[2]"/>
173 <xsl:template match="tml:sp[*[1][self::tml:sb[not(@over) or @over='0']]]">
176 <xsl:attribute name="xref">
177 <xsl:value-of select="@id"/>
180 <xsl:apply-templates select="*[1]/*[1]"/>
181 <xsl:apply-templates select="*[1]/*[2]"/>
182 <xsl:apply-templates select="*[2]"/>
186 <xsl:template match="tml:sp">
189 <xsl:attribute name="xref">
190 <xsl:value-of select="@id"/>
193 <xsl:apply-templates select="*[1]"/>
194 <xsl:apply-templates select="*[2]"/>
198 <xsl:template match="tml:g">
200 <xsl:when test="not(@id) and count(*) = 1">
201 <xsl:apply-templates select="*[1]"/>
203 <xsl:when test="tml:cursor">
204 <m:mstyle mathbackground="#e0e0e0">
206 <xsl:attribute name="xref">
207 <xsl:value-of select="@id"/>
211 <xsl:apply-templates select="*"/>
218 <xsl:attribute name="xref">
219 <xsl:value-of select="@id"/>
222 <xsl:apply-templates select="*"/>
228 <xsl:template match="tml:row">
230 <xsl:apply-templates select="cell"/>
234 <xsl:template match="tml:cell">
236 <xsl:apply-templates select="*"/>
240 <!--/// CONTROL SEQUENCES ///-->
242 <xsl:template match="tml:c">
245 <xsl:attribute name="xref">
246 <xsl:value-of select="@id"/>
249 <m:mtext mathcolor="blue">\<xsl:value-of select="@name"/></m:mtext>
250 <xsl:apply-templates select="*"/>
254 <xsl:template match="tml:c[@name='fun' and count(*)=3]">
257 <xsl:attribute name="xref">
258 <xsl:value-of select="@id"/>
261 <m:mo mathcolor="red">λ</m:mo>
262 <xsl:apply-templates select="*[1]"/>
264 <xsl:apply-templates select="*[2]"/>
266 <xsl:apply-templates select="*[3]"/>
270 <xsl:template match="tml:c[@name='not'][*[1][self::tml:o]]">
274 <xsl:attribute name="xref">
275 <xsl:value-of select="@id"/>
278 <xsl:value-of select="*[1]/@val"/≯</m:mo>
281 <xsl:template match="tml:c[@name='buildrel']">
285 <xsl:attribute name="xref">
286 <xsl:value-of select="@id"/>
289 <xsl:apply-templates select="*[2]"/>
290 <xsl:apply-templates select="*[1]"/>
294 <xsl:template match="tml:c[@name='left' or @name='right'][*[1][self::tml:o]]">
296 <m:mo stretchy="true">
298 <xsl:attribute name="xref">
299 <xsl:value-of select="@id"/>
302 <xsl:value-of select="*[1]/@val"/>
306 <xsl:template match="tml:c[@name='bigl' or @name='bigr' or @name='bigm' or @name='big'][*[1][self::tml:o]]">
308 <m:mo stretchy="true" minsize="8.5pt">
310 <xsl:attribute name="xref">
311 <xsl:value-of select="@id"/>
314 <xsl:value-of select="*[1]/@val"/>
318 <xsl:template match="tml:c[@name='Bigl' or @name='Bigr' or @name='Bigm'][*[1][self::tml:o]]">
320 <m:mo stretchy="true" minsize="11.5pt">
322 <xsl:attribute name="xref">
323 <xsl:value-of select="@id"/>
326 <xsl:value-of select="*[1]/@val"/>
330 <xsl:template match="tml:c[@name='biggl' or @name='biggr' or @name='biggm'][*[1][self::tml:o]]">
332 <m:mo stretchy="true" minsize="14.5pt">
334 <xsl:attribute name="xref">
335 <xsl:value-of select="@id"/>
338 <xsl:value-of select="*[1]/@val"/>
342 <xsl:template match="tml:c[@name='Biggl' or @name='Biggr' or @name='Biggm'][*[1][self::tml:o]]">
344 <m:mo stretchy="true" minsize="17.5pt">
346 <xsl:attribute name="xref">
347 <xsl:value-of select="@id"/>
350 <xsl:value-of select="*[1]/@val"/>
354 <xsl:template match="tml:c[@name='hat']">
356 <m:mover accent="true">
358 <xsl:attribute name="xref">
359 <xsl:value-of select="@id"/>
362 <xsl:apply-templates select="*[1]"/>
363 <m:mo>̂</m:mo>
367 <xsl:template match="tml:c[@name='widehat']">
369 <m:mover accent="false">
371 <xsl:attribute name="xref">
372 <xsl:value-of select="@id"/>
375 <xsl:apply-templates select="*[1]"/>
376 <m:mo stretchy="true">̂</m:mo>
380 <xsl:template match="tml:c[@name='check']">
382 <m:mover accent="true">
384 <xsl:attribute name="xref">
385 <xsl:value-of select="@id"/>
388 <xsl:apply-templates select="*[1]"/>
389 <m:mo>̌</m:mo>
393 <xsl:template match="tml:c[@name='tilde']">
395 <m:mover accent="true">
397 <xsl:attribute name="xref">
398 <xsl:value-of select="@id"/>
401 <xsl:apply-templates select="*[1]"/>
402 <m:mo>̃</m:mo>
406 <xsl:template match="tml:c[@name='widetilde']">
410 <xsl:attribute name="xref">
411 <xsl:value-of select="@id"/>
414 <xsl:apply-templates select="*[1]"/>
415 <m:mo stretchy="true">̃</m:mo>
419 <xsl:template match="tml:c[@name='acute']">
421 <m:mover accent="true">
423 <xsl:attribute name="xref">
424 <xsl:value-of select="@id"/>
427 <xsl:apply-templates select="*[1]"/>
428 <m:mo>́</m:mo>
432 <xsl:template match="tml:c[@name='grave']">
434 <m:mover accent="true">
436 <xsl:attribute name="xref">
437 <xsl:value-of select="@id"/>
440 <xsl:apply-templates select="*[1]"/>
441 <m:mo>̀</m:mo>
445 <xsl:template match="tml:c[@name='dot']">
447 <m:mover accent="true">
449 <xsl:attribute name="xref">
450 <xsl:value-of select="@id"/>
453 <xsl:apply-templates select="*[1]"/>
454 <m:mo>̇</m:mo>
458 <xsl:template match="tml:c[@name='ddot']">
460 <m:mover accent="true">
462 <xsl:attribute name="xref">
463 <xsl:value-of select="@id"/>
466 <xsl:apply-templates select="*[1]"/>
467 <m:mo>̈</m:mo>
471 <xsl:template match="tml:c[@name='breve']">
473 <m:mover accent="true">
475 <xsl:attribute name="xref">
476 <xsl:value-of select="@id"/>
479 <xsl:apply-templates select="*[1]"/>
480 <m:mo>̆</m:mo>
484 <xsl:template match="tml:c[@name='bar']">
486 <m:mover accent="true">
488 <xsl:attribute name="xref">
489 <xsl:value-of select="@id"/>
492 <xsl:apply-templates select="*[1]"/>
493 <m:mo>̄</m:mo>
497 <xsl:template match="tml:c[@name='vec']">
499 <m:mover accent="true">
501 <xsl:attribute name="xref">
502 <xsl:value-of select="@id"/>
505 <xsl:apply-templates select="*[1]"/>
506 <m:mo>⃗</m:mo>
510 <xsl:template match="tml:c[@name='overline']">
514 <xsl:attribute name="xref">
515 <xsl:value-of select="@id"/>
518 <xsl:apply-templates select="*[1]"/>
519 <m:mo stretchy="true">̅</m:mo>
523 <xsl:template match="tml:c[@name='underline']">
527 <xsl:attribute name="xref">
528 <xsl:value-of select="@id"/>
531 <xsl:apply-templates select="*[1]"/>
532 <m:mo stretchy="true">̲</m:mo>
536 <xsl:template match="tml:c[@name='sqrt']">
540 <xsl:attribute name="xref">
541 <xsl:value-of select="@id"/>
544 <xsl:apply-templates select="*"/>
548 <xsl:template match="tml:c[@name='root']">
552 <xsl:attribute name="xref">
553 <xsl:value-of select="@id"/>
556 <xsl:apply-templates select="*[2]"/>
557 <xsl:apply-templates select="*[1]"/>
561 <xsl:template match="tml:c[@name='frac']">
565 <xsl:attribute name="xref">
566 <xsl:value-of select="@id"/>
569 <xsl:apply-templates select="*[1]"/>
570 <xsl:apply-templates select="*[2]"/>
574 <xsl:template match="tml:c[@name='over']">
578 <xsl:attribute name="xref">
579 <xsl:value-of select="@id"/>
582 <xsl:apply-templates select="*[1]"/>
583 <xsl:apply-templates select="*[2]"/>
587 <xsl:template match="tml:c[@name='atop']">
589 <m:mfrac linethickness="0">
591 <xsl:attribute name="xref">
592 <xsl:value-of select="@id"/>
595 <xsl:apply-templates select="*[1]"/>
596 <xsl:apply-templates select="*[2]"/>
600 <xsl:template match="tml:c[@name='choose']">
604 <xsl:attribute name="xref">
605 <xsl:value-of select="@id"/>
608 <m:mo stretchy="true">(</m:mo>
609 <m:mfrac linethickness="0">
610 <xsl:apply-templates select="*[1]"/>
611 <xsl:apply-templates select="*[2]"/>
613 <m:mo stretchy="true">)</m:mo>
617 <xsl:template match="tml:c[@name='brace']">
621 <xsl:attribute name="xref">
622 <xsl:value-of select="@id"/>
625 <m:mo stretchy="true">{</m:mo>
626 <m:mfrac linethickness="0">
627 <xsl:apply-templates select="*[1]"/>
628 <xsl:apply-templates select="*[2]"/>
630 <m:mo stretchy="true">}</m:mo>
634 <xsl:template match="tml:c[@name='brack']">
638 <xsl:attribute name="xref">
639 <xsl:value-of select="@id"/>
642 <m:mo stretchy="true">[</m:mo>
643 <m:mfrac linethickness="0">
644 <xsl:apply-templates select="*[1]"/>
645 <xsl:apply-templates select="*[2]"/>
647 <m:mo stretchy="true">]</m:mo>
651 <xsl:template match="tml:c[@name='displaystyle']">
652 <!-- displaystyle -->
653 <m:mstyle displaystyle="true">
655 <xsl:attribute name="xref">
656 <xsl:value-of select="@id"/>
659 <xsl:apply-templates select="*[1]"/>
663 <xsl:template match="tml:c[@name='textstyle']">
665 <m:mstyle scriptlevel="0">
667 <xsl:attribute name="xref">
668 <xsl:value-of select="@id"/>
671 <xsl:apply-templates select="*[1]"/>
675 <xsl:template match="tml:c[@name='scriptstyle']">
677 <m:mstyle scriptlevel="1">
679 <xsl:attribute name="xref">
680 <xsl:value-of select="@id"/>
683 <xsl:apply-templates select="*[1]"/>
687 <xsl:template match="tml:c[@name='scriptscriptstyle']">
688 <!-- scriptscriptstyle -->
689 <m:mstyle scriptlevel="2">
691 <xsl:attribute name="xref">
692 <xsl:value-of select="@id"/>
695 <xsl:apply-templates select="*[1]"/>
699 <xsl:template match="tml:c[@name='pmod']">
703 <xsl:attribute name="xref">
704 <xsl:value-of select="@id"/>
710 <xsl:apply-templates select="*[1]"/>
716 <xsl:template match="tml:c[@name='rm']">
718 <m:mstyle mathvariant="normal">
720 <xsl:attribute name="xref">
721 <xsl:value-of select="@id"/>
724 <xsl:apply-templates select="*[1]"/>
728 <xsl:template match="tml:c[@name='bf']">
730 <m:mstyle mathvariant="bold">
732 <xsl:attribute name="xref">
733 <xsl:value-of select="@id"/>
736 <xsl:apply-templates select="*[1]"/>
740 <xsl:template match="tml:c[@name='tt']">
742 <m:mstyle mathvariant="monospace">
744 <xsl:attribute name="xref">
745 <xsl:value-of select="@id"/>
748 <xsl:apply-templates select="*[1]"/>
752 <xsl:template match="tml:c[@name='sl']">
754 <m:mstyle mathvariant="italic">
756 <xsl:attribute name="xref">
757 <xsl:value-of select="@id"/>
760 <xsl:apply-templates select="*[1]"/>
764 <xsl:template match="tml:c[@name='it']">
766 <m:mstyle mathvariant="italic">
768 <xsl:attribute name="xref">
769 <xsl:value-of select="@id"/>
772 <xsl:apply-templates select="*[1]"/>
776 <xsl:template match="tml:c[@name=',']">
778 <m:mspace width="thinmathspace">
780 <xsl:attribute name="xref">
781 <xsl:value-of select="@id"/>
787 <xsl:template match="tml:c[@name='>']">
789 <m:mspace width="mediummathspace">
791 <xsl:attribute name="xref">
792 <xsl:value-of select="@id"/>
798 <xsl:template match="tml:c[@name=';']">
800 <m:mspace width="thickmathspace">
802 <xsl:attribute name="xref">
803 <xsl:value-of select="@id"/>
809 <xsl:template match="tml:c[@name='!']">
811 <m:mspace width="-0.166667em">
813 <xsl:attribute name="xref">
814 <xsl:value-of select="@id"/>
820 <xsl:template name="table-content">
822 <xsl:when test="tml:row">
823 <xsl:apply-templates select="tml:row"/>
828 <xsl:apply-templates select="*"/>
835 <xsl:template match="tml:c[@name='matrix']">
839 <xsl:attribute name="xref">
840 <xsl:value-of select="@id"/>
843 <xsl:call-template name="table-content"/>
847 <xsl:template match="tml:row">
849 <xsl:apply-templates select="tml:cell"/>
853 <xsl:template match="tml:cell">
855 <xsl:apply-templates select="*"/>
859 <xsl:template match="tml:c[@name='pmatrix']">
863 <xsl:attribute name="xref">
864 <xsl:value-of select="@id"/>
867 <m:mo stretchy="true">(</m:mo>
869 <xsl:call-template name="table-content"/>
871 <m:mo stretchy="true">)</m:mo>
875 <xsl:template match="tml:c[@name='bordermatrix']">
876 <!-- bordermatrix -->
879 <xsl:attribute name="xref">
880 <xsl:value-of select="@id"/>
884 <xsl:apply-templates select="tml:row[1]/tml:cell[1]"/>
886 <xsl:apply-templates select="tml:row[1]/tml:cell[position() > 1]"/>
889 <xsl:for-each select="tml:row[position() > 1]">
891 <xsl:apply-templates select="tml:cell[1]"/>
892 <xsl:if test="position() = 1">
893 <m:mtd rowspan="{count(../tml:row) - 1}">
894 <m:mo stretchy="true">(</m:mo>
897 <xsl:apply-templates select="tml:cell[position() > 1]"/>
898 <xsl:if test="position() = 1">
899 <m:mtd rowspan="{count(../tml:row) - 1}">
900 <m:mo stretchy="true">)</m:mo>
908 <xsl:template match="tml:c[@name='overbrace']">
912 <xsl:attribute name="xref">
913 <xsl:value-of select="@id"/>
916 <xsl:apply-templates select="*[1]"/>
917 <m:mo stretchy="true">????</m:mo>
921 <xsl:template match="tml:c[@name='underbrace']">
925 <xsl:attribute name="xref">
926 <xsl:value-of select="@id"/>
929 <xsl:apply-templates select="*[1]"/>
930 <m:mo stretchy="true">????</m:mo>
934 <xsl:template match="tml:c[@name='cases']">
938 <xsl:attribute name="xref">
939 <xsl:value-of select="@id"/>
942 <m:mo stretchy="true">{</m:mo>
944 <xsl:call-template name="table-content"/>