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 name="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"/>
96 <xsl:template match="tml:cursor[@visible='1']">
97 <xsl:param name="annotation" select="/.."/>
99 <xsl:when test="$annotation">
101 <xsl:call-template name="cursor"/>
103 <xsl:value-of select="$annotation"/>
108 <xsl:call-template name="cursor"/>
113 <xsl:template match="tml:cursor[not(@visible) or @visible='0']">
116 <xsl:template match="tml:sb[@under='1'][*[1]/tml:sp[@over='1']]">
119 <xsl:attribute name="xref">
120 <xsl:value-of select="@id"/>
123 <xsl:apply-templates select="*[1]/*[1]"/>
124 <xsl:apply-templates select="*[2]"/>
125 <xsl:apply-templates select="*[1]/*[2]"/>
129 <xsl:template match="tml:sb[@under='1']">
132 <xsl:attribute name="xref">
133 <xsl:value-of select="@id"/>
136 <xsl:apply-templates select="*[1]"/>
137 <xsl:apply-templates select="*[2]"/>
141 <xsl:template match="tml:sb[*[1][self::tml:sp[not(@over) or @over='0']]]">
144 <xsl:attribute name="xref">
145 <xsl:value-of select="@id"/>
148 <xsl:apply-templates select="*[1]/*[1]"/>
149 <xsl:apply-templates select="*[2]"/>
150 <xsl:apply-templates select="*[1]/*[2]"/>
154 <xsl:template match="tml:sb">
157 <xsl:attribute name="xref">
158 <xsl:value-of select="@id"/>
161 <xsl:apply-templates select="*[1]"/>
162 <xsl:apply-templates select="*[2]"/>
166 <xsl:template match="tml:sp[@over='1'][*[1]/tml:sb[@under='1']]">
169 <xsl:attribute name="xref">
170 <xsl:value-of select="@id"/>
173 <xsl:apply-templates select="*[1]/*[1]"/>
174 <xsl:apply-templates select="*[1]/*[2]"/>
175 <xsl:apply-templates select="*[2]"/>
179 <xsl:template match="tml:sp[@over='1']">
182 <xsl:attribute name="xref">
183 <xsl:value-of select="@id"/>
186 <xsl:apply-templates select="*[1]"/>
187 <xsl:apply-templates select="*[2]"/>
191 <xsl:template match="tml:sp[*[1][self::tml:sb[not(@over) or @over='0']]]">
194 <xsl:attribute name="xref">
195 <xsl:value-of select="@id"/>
198 <xsl:apply-templates select="*[1]/*[1]"/>
199 <xsl:apply-templates select="*[1]/*[2]"/>
200 <xsl:apply-templates select="*[2]"/>
204 <xsl:template match="tml:sp">
207 <xsl:attribute name="xref">
208 <xsl:value-of select="@id"/>
211 <xsl:apply-templates select="*[1]"/>
212 <xsl:apply-templates select="*[2]"/>
216 <xsl:template match="tml:g">
217 <xsl:param name="annotation" select="/.."/>
219 <xsl:when test="not(@id) and count(*) = 1">
220 <xsl:apply-templates select="*[1]">
221 <xsl:with-param name="annotation" select="$annotation"/>
222 </xsl:apply-templates>
224 <xsl:when test="tml:cursor">
225 <m:mstyle mathbackground="#e0e0e0">
227 <xsl:attribute name="xref">
228 <xsl:value-of select="@id"/>
232 <xsl:apply-templates select="*">
233 <xsl:with-param name="annotation" select="$annotation"/>
234 </xsl:apply-templates>
241 <xsl:attribute name="xref">
242 <xsl:value-of select="@id"/>
245 <xsl:apply-templates select="*">
246 <xsl:with-param name="annotation" select="$annotation"/>
247 </xsl:apply-templates>
253 <xsl:template match="tml:row">
255 <xsl:apply-templates select="cell"/>
259 <xsl:template match="tml:cell">
261 <xsl:apply-templates select="*"/>
265 <!--/// CONTROL SEQUENCES ///-->
267 <xsl:template match="tml:c">
270 <xsl:attribute name="xref">
271 <xsl:value-of select="@id"/>
274 <m:mtext mathcolor="blue">\<xsl:value-of select="@name"/></m:mtext>
275 <xsl:apply-templates select="*"/>
279 <xsl:template match="tml:c[@name='fun' and count(*)=3]">
282 <xsl:attribute name="xref">
283 <xsl:value-of select="@id"/>
286 <m:mo mathcolor="red">λ</m:mo>
287 <xsl:apply-templates select="*[1]"/>
289 <xsl:apply-templates select="*[2]"/>
291 <xsl:apply-templates select="*[3]"/>
295 <xsl:template match="tml:c[@name='not'][*[1][self::tml:o]]">
299 <xsl:attribute name="xref">
300 <xsl:value-of select="@id"/>
303 <xsl:value-of select="*[1]/@val"/≯</m:mo>
306 <xsl:template match="tml:c[@name='buildrel']">
310 <xsl:attribute name="xref">
311 <xsl:value-of select="@id"/>
314 <xsl:apply-templates select="*[2]"/>
315 <xsl:apply-templates select="*[1]"/>
319 <xsl:template match="tml:c[@name='left' or @name='right'][*[1][self::tml:o]]">
321 <m:mo stretchy="true">
323 <xsl:attribute name="xref">
324 <xsl:value-of select="@id"/>
327 <xsl:value-of select="*[1]/@val"/>
331 <xsl:template match="tml:c[@name='bigl' or @name='bigr' or @name='bigm' or @name='big'][*[1][self::tml:o]]">
333 <m:mo stretchy="true" minsize="8.5pt">
335 <xsl:attribute name="xref">
336 <xsl:value-of select="@id"/>
339 <xsl:value-of select="*[1]/@val"/>
343 <xsl:template match="tml:c[@name='Bigl' or @name='Bigr' or @name='Bigm'][*[1][self::tml:o]]">
345 <m:mo stretchy="true" minsize="11.5pt">
347 <xsl:attribute name="xref">
348 <xsl:value-of select="@id"/>
351 <xsl:value-of select="*[1]/@val"/>
355 <xsl:template match="tml:c[@name='biggl' or @name='biggr' or @name='biggm'][*[1][self::tml:o]]">
357 <m:mo stretchy="true" minsize="14.5pt">
359 <xsl:attribute name="xref">
360 <xsl:value-of select="@id"/>
363 <xsl:value-of select="*[1]/@val"/>
367 <xsl:template match="tml:c[@name='Biggl' or @name='Biggr' or @name='Biggm'][*[1][self::tml:o]]">
369 <m:mo stretchy="true" minsize="17.5pt">
371 <xsl:attribute name="xref">
372 <xsl:value-of select="@id"/>
375 <xsl:value-of select="*[1]/@val"/>
379 <xsl:template match="tml:c[@name='hat']">
381 <m:mover accent="true">
383 <xsl:attribute name="xref">
384 <xsl:value-of select="@id"/>
387 <xsl:apply-templates select="*[1]"/>
388 <m:mo>̂</m:mo>
392 <xsl:template match="tml:c[@name='widehat']">
394 <m:mover accent="false">
396 <xsl:attribute name="xref">
397 <xsl:value-of select="@id"/>
400 <xsl:apply-templates select="*[1]"/>
401 <m:mo stretchy="true">̂</m:mo>
405 <xsl:template match="tml:c[@name='check']">
407 <m:mover accent="true">
409 <xsl:attribute name="xref">
410 <xsl:value-of select="@id"/>
413 <xsl:apply-templates select="*[1]"/>
414 <m:mo>̌</m:mo>
418 <xsl:template match="tml:c[@name='tilde']">
420 <m:mover accent="true">
422 <xsl:attribute name="xref">
423 <xsl:value-of select="@id"/>
426 <xsl:apply-templates select="*[1]"/>
427 <m:mo>̃</m:mo>
431 <xsl:template match="tml:c[@name='widetilde']">
435 <xsl:attribute name="xref">
436 <xsl:value-of select="@id"/>
439 <xsl:apply-templates select="*[1]"/>
440 <m:mo stretchy="true">̃</m:mo>
444 <xsl:template match="tml:c[@name='acute']">
446 <m:mover accent="true">
448 <xsl:attribute name="xref">
449 <xsl:value-of select="@id"/>
452 <xsl:apply-templates select="*[1]"/>
453 <m:mo>́</m:mo>
457 <xsl:template match="tml:c[@name='grave']">
459 <m:mover accent="true">
461 <xsl:attribute name="xref">
462 <xsl:value-of select="@id"/>
465 <xsl:apply-templates select="*[1]"/>
466 <m:mo>̀</m:mo>
470 <xsl:template match="tml:c[@name='dot']">
472 <m:mover accent="true">
474 <xsl:attribute name="xref">
475 <xsl:value-of select="@id"/>
478 <xsl:apply-templates select="*[1]"/>
479 <m:mo>̇</m:mo>
483 <xsl:template match="tml:c[@name='ddot']">
485 <m:mover accent="true">
487 <xsl:attribute name="xref">
488 <xsl:value-of select="@id"/>
491 <xsl:apply-templates select="*[1]"/>
492 <m:mo>̈</m:mo>
496 <xsl:template match="tml:c[@name='breve']">
498 <m:mover accent="true">
500 <xsl:attribute name="xref">
501 <xsl:value-of select="@id"/>
504 <xsl:apply-templates select="*[1]"/>
505 <m:mo>̆</m:mo>
509 <xsl:template match="tml:c[@name='bar']">
511 <m:mover accent="true">
513 <xsl:attribute name="xref">
514 <xsl:value-of select="@id"/>
517 <xsl:apply-templates select="*[1]"/>
518 <m:mo>̄</m:mo>
522 <xsl:template match="tml:c[@name='vec']">
524 <m:mover accent="true">
526 <xsl:attribute name="xref">
527 <xsl:value-of select="@id"/>
530 <xsl:apply-templates select="*[1]"/>
531 <m:mo>⃗</m:mo>
535 <xsl:template match="tml:c[@name='overline']">
539 <xsl:attribute name="xref">
540 <xsl:value-of select="@id"/>
543 <xsl:apply-templates select="*[1]"/>
544 <m:mo stretchy="true">̅</m:mo>
548 <xsl:template match="tml:c[@name='underline']">
552 <xsl:attribute name="xref">
553 <xsl:value-of select="@id"/>
556 <xsl:apply-templates select="*[1]"/>
557 <m:mo stretchy="true">̲</m:mo>
561 <xsl:template match="tml:c[@name='sqrt']">
565 <xsl:attribute name="xref">
566 <xsl:value-of select="@id"/>
569 <xsl:apply-templates select="*"/>
573 <xsl:template match="tml:c[@name='root']">
577 <xsl:attribute name="xref">
578 <xsl:value-of select="@id"/>
582 <xsl:when test="count(*) < 2">
584 <xsl:apply-templates select="*[1]"/>
587 <xsl:apply-templates select="*[2]"/>
588 <xsl:apply-templates select="*[1]"/>
594 <xsl:template match="tml:c[@name='frac']">
598 <xsl:attribute name="xref">
599 <xsl:value-of select="@id"/>
602 <xsl:apply-templates select="*[1]"/>
603 <xsl:apply-templates select="*[2]"/>
607 <xsl:template match="tml:c[@name='over']">
611 <xsl:attribute name="xref">
612 <xsl:value-of select="@id"/>
615 <xsl:apply-templates select="*[1]"/>
616 <xsl:apply-templates select="*[2]"/>
620 <xsl:template match="tml:c[@name='atop']">
622 <m:mfrac linethickness="0">
624 <xsl:attribute name="xref">
625 <xsl:value-of select="@id"/>
628 <xsl:apply-templates select="*[1]"/>
629 <xsl:apply-templates select="*[2]"/>
633 <xsl:template match="tml:c[@name='choose']">
637 <xsl:attribute name="xref">
638 <xsl:value-of select="@id"/>
641 <m:mo stretchy="true">(</m:mo>
642 <m:mfrac linethickness="0">
643 <xsl:apply-templates select="*[1]"/>
644 <xsl:apply-templates select="*[2]"/>
646 <m:mo stretchy="true">)</m:mo>
650 <xsl:template match="tml:c[@name='brace']">
654 <xsl:attribute name="xref">
655 <xsl:value-of select="@id"/>
658 <m:mo stretchy="true">{</m:mo>
659 <m:mfrac linethickness="0">
660 <xsl:apply-templates select="*[1]"/>
661 <xsl:apply-templates select="*[2]"/>
663 <m:mo stretchy="true">}</m:mo>
667 <xsl:template match="tml:c[@name='brack']">
671 <xsl:attribute name="xref">
672 <xsl:value-of select="@id"/>
675 <m:mo stretchy="true">[</m:mo>
676 <m:mfrac linethickness="0">
677 <xsl:apply-templates select="*[1]"/>
678 <xsl:apply-templates select="*[2]"/>
680 <m:mo stretchy="true">]</m:mo>
684 <xsl:template match="tml:c[@name='displaystyle']">
685 <!-- displaystyle -->
686 <m:mstyle displaystyle="true">
688 <xsl:attribute name="xref">
689 <xsl:value-of select="@id"/>
692 <xsl:apply-templates select="*[1]"/>
696 <xsl:template match="tml:c[@name='textstyle']">
698 <m:mstyle scriptlevel="0">
700 <xsl:attribute name="xref">
701 <xsl:value-of select="@id"/>
704 <xsl:apply-templates select="*[1]"/>
705 <xsl:if test="tml:g/tml:cursor[@visible='1']">
707 <m:mtext mathcolor="#808080">}</m:mtext>
708 <m:mtext><xsl:value-of select="@name"/></m:mtext>
714 <xsl:template match="tml:c[@name='scriptstyle']">
716 <m:mstyle scriptlevel="1">
718 <xsl:attribute name="xref">
719 <xsl:value-of select="@id"/>
722 <xsl:apply-templates select="*[1]"/>
726 <xsl:template match="tml:c[@name='scriptscriptstyle']">
727 <!-- scriptscriptstyle -->
728 <m:mstyle scriptlevel="2">
730 <xsl:attribute name="xref">
731 <xsl:value-of select="@id"/>
734 <xsl:apply-templates select="*[1]"/>
738 <xsl:template match="tml:c[@name='pmod']">
742 <xsl:attribute name="xref">
743 <xsl:value-of select="@id"/>
749 <xsl:apply-templates select="*[1]"/>
755 <xsl:template match="tml:c[@name='rm']">
757 <m:mstyle mathvariant="normal">
759 <xsl:attribute name="xref">
760 <xsl:value-of select="@id"/>
763 <xsl:apply-templates select="*[1]"/>
767 <xsl:template match="tml:c[@name='bf']">
769 <m:mstyle mathvariant="bold">
771 <xsl:attribute name="xref">
772 <xsl:value-of select="@id"/>
775 <xsl:apply-templates select="*[1]"/>
779 <xsl:template match="tml:c[@name='tt']">
781 <m:mstyle mathvariant="monospace">
783 <xsl:attribute name="xref">
784 <xsl:value-of select="@id"/>
787 <xsl:apply-templates select="*[1]"/>
791 <xsl:template match="tml:c[@name='sl']">
793 <m:mstyle mathvariant="italic">
795 <xsl:attribute name="xref">
796 <xsl:value-of select="@id"/>
799 <xsl:apply-templates select="*[1]"/>
803 <xsl:template match="tml:c[@name='it']">
805 <m:mstyle mathvariant="italic">
807 <xsl:attribute name="xref">
808 <xsl:value-of select="@id"/>
811 <xsl:apply-templates select="*[1]"/>
815 <xsl:template match="tml:c[@name=',']">
817 <m:mspace width="thinmathspace">
819 <xsl:attribute name="xref">
820 <xsl:value-of select="@id"/>
826 <xsl:template match="tml:c[@name='>']">
828 <m:mspace width="mediummathspace">
830 <xsl:attribute name="xref">
831 <xsl:value-of select="@id"/>
837 <xsl:template match="tml:c[@name=';']">
839 <m:mspace width="thickmathspace">
841 <xsl:attribute name="xref">
842 <xsl:value-of select="@id"/>
848 <xsl:template match="tml:c[@name='!']">
850 <m:mspace width="-0.166667em">
852 <xsl:attribute name="xref">
853 <xsl:value-of select="@id"/>
859 <xsl:template name="table-content">
861 <xsl:when test="tml:row">
862 <xsl:apply-templates select="tml:row"/>
867 <xsl:apply-templates select="*"/>
874 <xsl:template match="tml:c[@name='matrix']">
878 <xsl:attribute name="xref">
879 <xsl:value-of select="@id"/>
882 <xsl:call-template name="table-content"/>
886 <xsl:template match="tml:row">
888 <xsl:apply-templates select="tml:cell"/>
892 <xsl:template match="tml:cell">
894 <xsl:apply-templates select="*"/>
898 <xsl:template match="tml:c[@name='pmatrix']">
902 <xsl:attribute name="xref">
903 <xsl:value-of select="@id"/>
906 <m:mo stretchy="true">(</m:mo>
908 <xsl:call-template name="table-content"/>
910 <m:mo stretchy="true">)</m:mo>
914 <xsl:template match="tml:c[@name='bordermatrix']">
915 <!-- bordermatrix -->
918 <xsl:attribute name="xref">
919 <xsl:value-of select="@id"/>
923 <xsl:apply-templates select="tml:row[1]/tml:cell[1]"/>
925 <xsl:apply-templates select="tml:row[1]/tml:cell[position() > 1]"/>
928 <xsl:for-each select="tml:row[position() > 1]">
930 <xsl:apply-templates select="tml:cell[1]"/>
931 <xsl:if test="position() = 1">
932 <m:mtd rowspan="{count(../tml:row) - 1}">
933 <m:mo stretchy="true">(</m:mo>
936 <xsl:apply-templates select="tml:cell[position() > 1]"/>
937 <xsl:if test="position() = 1">
938 <m:mtd rowspan="{count(../tml:row) - 1}">
939 <m:mo stretchy="true">)</m:mo>
947 <xsl:template match="tml:c[@name='overbrace']">
951 <xsl:attribute name="xref">
952 <xsl:value-of select="@id"/>
955 <xsl:apply-templates select="*[1]"/>
956 <m:mo stretchy="true">????</m:mo>
960 <xsl:template match="tml:c[@name='underbrace']">
964 <xsl:attribute name="xref">
965 <xsl:value-of select="@id"/>
968 <xsl:apply-templates select="*[1]"/>
969 <m:mo stretchy="true">????</m:mo>
973 <xsl:template match="tml:c[@name='cases']">
977 <xsl:attribute name="xref">
978 <xsl:value-of select="@id"/>
981 <m:mo stretchy="true">{</m:mo>
983 <xsl:call-template name="table-content"/>
988 <xsl:template match="tml:c[@name='red']">
990 <m:mstyle mathcolor="red">
992 <xsl:attribute name="xref">
993 <xsl:value-of select="@id"/>
995 <xsl:apply-templates/>
1000 <xsl:template match="tml:c[@name='green']">
1002 <m:mstyle mathcolor="green">
1004 <xsl:attribute name="xref">
1005 <xsl:value-of select="@id"/>
1007 <xsl:apply-templates/>
1012 <xsl:template match="tml:c[@name='duedelim']">
1016 <xsl:attribute name="xref">
1017 <xsl:value-of select="@id"/>
1020 <xsl:apply-templates select="*[1]"/>
1021 <xsl:apply-templates select="*[2]"/>