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"
9 <xsl:output indent="yes"/>
11 <xsl:param name="id" select="/.."/>
13 <xsl:template match="/">
16 <xsl:apply-templates select="descendant::*[@id=$id]"/>
19 <xsl:apply-templates/>
24 <xsl:template match="tml:math">
27 <xsl:attribute name="xref">
28 <xsl:value-of select="@id"/>
31 <xsl:if test="@display='1'">
32 <xsl:attribute name="display">block</xsl:attribute>
34 <xsl:attribute name="display">block</xsl:attribute>
35 <xsl:apply-templates select="*"/>
39 <xsl:template match="tml:i">
42 <xsl:attribute name="xref">
43 <xsl:value-of select="@id"/>
46 <xsl:value-of select="@val"/>
50 <xsl:template match="tml:n">
53 <xsl:attribute name="xref">
54 <xsl:value-of select="@id"/>
57 <xsl:value-of select="@val"/>
61 <xsl:template match="tml:o">
64 <xsl:attribute name="xref">
65 <xsl:value-of select="@id"/>
68 <xsl:value-of select="@val"/>
72 <xsl:template match="tml:o[@val='-']">
75 <xsl:attribute name="xref">
76 <xsl:value-of select="@id"/>
83 <xsl:template match="tml:cursor[@visible='1']">
85 <xsl:when test="substring(@val,1,1)='\'">
88 <xsl:attribute name="xref">
89 <xsl:value-of select="@id"/>
92 <m:mo stretchy="false">〈</m:mo>
93 <m:mtext mathcolor="blue"><xsl:value-of select="@val"/></m:mtext>
94 <m:mo stretchy="false">〉</m:mo>
98 <m:mtext mathcolor="blue">
100 <xsl:attribute name="xref">
101 <xsl:value-of select="@id"/>
103 </xsl:if><xsl:value-of select="@val"/>I</m:mtext>
108 <xsl:template match="tml:cursor[not(@visible) or @visible='0']">
111 <xsl:template match="tml:sb[@under='1'][*[1]/tml:sp[@over='1']]">
114 <xsl:attribute name="xref">
115 <xsl:value-of select="@id"/>
118 <xsl:apply-templates select="*[1]/*[1]"/>
119 <xsl:apply-templates select="*[2]"/>
120 <xsl:apply-templates select="*[1]/*[2]"/>
124 <xsl:template match="tml:sb[@under='1']">
127 <xsl:attribute name="xref">
128 <xsl:value-of select="@id"/>
131 <xsl:apply-templates select="*[1]"/>
132 <xsl:apply-templates select="*[2]"/>
136 <xsl:template match="tml:sb[*[1][self::tml:sp[not(@over) or @over='0']]]">
139 <xsl:attribute name="xref">
140 <xsl:value-of select="@id"/>
143 <xsl:apply-templates select="*[1]/*[1]"/>
144 <xsl:apply-templates select="*[2]"/>
145 <xsl:apply-templates select="*[1]/*[2]"/>
149 <xsl:template match="tml:sb">
152 <xsl:attribute name="xref">
153 <xsl:value-of select="@id"/>
156 <xsl:apply-templates select="*[1]"/>
157 <xsl:apply-templates select="*[2]"/>
161 <xsl:template match="tml:sp[@over='1'][*[1]/tml:sb[@under='1']]">
164 <xsl:attribute name="xref">
165 <xsl:value-of select="@id"/>
168 <xsl:apply-templates select="*[1]/*[1]"/>
169 <xsl:apply-templates select="*[1]/*[2]"/>
170 <xsl:apply-templates select="*[2]"/>
174 <xsl:template match="tml:sp[@over='1']">
177 <xsl:attribute name="xref">
178 <xsl:value-of select="@id"/>
181 <xsl:apply-templates select="*[1]"/>
182 <xsl:apply-templates select="*[2]"/>
186 <xsl:template match="tml:sp[*[1][self::tml:sb[not(@over) or @over='0']]]">
189 <xsl:attribute name="xref">
190 <xsl:value-of select="@id"/>
193 <xsl:apply-templates select="*[1]/*[1]"/>
194 <xsl:apply-templates select="*[1]/*[2]"/>
195 <xsl:apply-templates select="*[2]"/>
199 <xsl:template match="tml:sp">
202 <xsl:attribute name="xref">
203 <xsl:value-of select="@id"/>
206 <xsl:apply-templates select="*[1]"/>
207 <xsl:apply-templates select="*[2]"/>
211 <xsl:template match="tml:g">
213 <xsl:when test="not(@id) and count(*) = 1">
214 <xsl:apply-templates select="*[1]"/>
216 <xsl:when test="tml:cursor">
217 <m:mstyle mathbackground="#e0e0e0">
219 <xsl:attribute name="xref">
220 <xsl:value-of select="@id"/>
224 <xsl:apply-templates select="*"/>
231 <xsl:attribute name="xref">
232 <xsl:value-of select="@id"/>
235 <xsl:apply-templates select="*"/>
241 <xsl:template match="tml:row">
243 <xsl:apply-templates select="cell"/>
247 <xsl:template match="tml:cell">
249 <xsl:apply-templates select="*"/>
253 <!--/// CONTROL SEQUENCES ///-->
255 <xsl:template match="tml:c">
258 <xsl:attribute name="xref">
259 <xsl:value-of select="@id"/>
262 <m:mtext mathcolor="blue">\<xsl:value-of select="@name"/></m:mtext>
263 <xsl:apply-templates select="*"/>
267 <xsl:template match="tml:c[@name='fun' and count(*)=3]">
270 <xsl:attribute name="xref">
271 <xsl:value-of select="@id"/>
274 <m:mo mathcolor="red">λ</m:mo>
275 <xsl:apply-templates select="*[1]"/>
277 <xsl:apply-templates select="*[2]"/>
279 <xsl:apply-templates select="*[3]"/>
283 <xsl:template match="tml:c[@name='not'][*[1][self::tml:o]]">
287 <xsl:attribute name="xref">
288 <xsl:value-of select="@id"/>
291 <xsl:value-of select="*[1]/@val"/≯</m:mo>
294 <xsl:template match="tml:c[@name='buildrel']">
298 <xsl:attribute name="xref">
299 <xsl:value-of select="@id"/>
302 <xsl:apply-templates select="*[2]"/>
303 <xsl:apply-templates select="*[1]"/>
307 <xsl:template match="tml:c[@name='left' or @name='right'][*[1][self::tml:o]]">
309 <m:mo stretchy="true">
311 <xsl:attribute name="xref">
312 <xsl:value-of select="@id"/>
315 <xsl:value-of select="*[1]/@val"/>
319 <xsl:template match="tml:c[@name='bigl' or @name='bigr' or @name='bigm' or @name='big'][*[1][self::tml:o]]">
321 <m:mo stretchy="true" minsize="8.5pt">
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'][*[1][self::tml:o]]">
333 <m:mo stretchy="true" minsize="11.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='biggl' or @name='biggr' or @name='biggm'][*[1][self::tml:o]]">
345 <m:mo stretchy="true" minsize="14.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="17.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='hat']">
369 <m:mover accent="true">
371 <xsl:attribute name="xref">
372 <xsl:value-of select="@id"/>
375 <xsl:apply-templates select="*[1]"/>
376 <m:mo>̂</m:mo>
380 <xsl:template match="tml:c[@name='widehat']">
382 <m:mover accent="false">
384 <xsl:attribute name="xref">
385 <xsl:value-of select="@id"/>
388 <xsl:apply-templates select="*[1]"/>
389 <m:mo stretchy="true">̂</m:mo>
393 <xsl:template match="tml:c[@name='check']">
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='tilde']">
408 <m:mover accent="true">
410 <xsl:attribute name="xref">
411 <xsl:value-of select="@id"/>
414 <xsl:apply-templates select="*[1]"/>
415 <m:mo>̃</m:mo>
419 <xsl:template match="tml:c[@name='widetilde']">
423 <xsl:attribute name="xref">
424 <xsl:value-of select="@id"/>
427 <xsl:apply-templates select="*[1]"/>
428 <m:mo stretchy="true">̃</m:mo>
432 <xsl:template match="tml:c[@name='acute']">
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='grave']">
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='dot']">
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='ddot']">
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='breve']">
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='bar']">
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='vec']">
512 <m:mover accent="true">
514 <xsl:attribute name="xref">
515 <xsl:value-of select="@id"/>
518 <xsl:apply-templates select="*[1]"/>
519 <m:mo>⃗</m:mo>
523 <xsl:template match="tml:c[@name='overline']">
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='underline']">
540 <xsl:attribute name="xref">
541 <xsl:value-of select="@id"/>
544 <xsl:apply-templates select="*[1]"/>
545 <m:mo stretchy="true">̲</m:mo>
549 <xsl:template match="tml:c[@name='sqrt']">
553 <xsl:attribute name="xref">
554 <xsl:value-of select="@id"/>
557 <xsl:apply-templates select="*"/>
561 <xsl:template match="tml:c[@name='root']">
565 <xsl:attribute name="xref">
566 <xsl:value-of select="@id"/>
570 <xsl:when test="count(*) < 2">
572 <xsl:apply-templates select="*[1]"/>
575 <xsl:apply-templates select="*[2]"/>
576 <xsl:apply-templates select="*[1]"/>
582 <xsl:template match="tml:c[@name='frac']">
586 <xsl:attribute name="xref">
587 <xsl:value-of select="@id"/>
590 <xsl:apply-templates select="*[1]"/>
591 <xsl:apply-templates select="*[2]"/>
595 <xsl:template match="tml:c[@name='over']">
599 <xsl:attribute name="xref">
600 <xsl:value-of select="@id"/>
603 <xsl:apply-templates select="*[1]"/>
604 <xsl:apply-templates select="*[2]"/>
608 <xsl:template match="tml:c[@name='atop']">
610 <m:mfrac linethickness="0">
612 <xsl:attribute name="xref">
613 <xsl:value-of select="@id"/>
616 <xsl:apply-templates select="*[1]"/>
617 <xsl:apply-templates select="*[2]"/>
621 <xsl:template match="tml:c[@name='choose']">
625 <xsl:attribute name="xref">
626 <xsl:value-of select="@id"/>
629 <m:mo stretchy="true">(</m:mo>
630 <m:mfrac linethickness="0">
631 <xsl:apply-templates select="*[1]"/>
632 <xsl:apply-templates select="*[2]"/>
634 <m:mo stretchy="true">)</m:mo>
638 <xsl:template match="tml:c[@name='brace']">
642 <xsl:attribute name="xref">
643 <xsl:value-of select="@id"/>
646 <m:mo stretchy="true">{</m:mo>
647 <m:mfrac linethickness="0">
648 <xsl:apply-templates select="*[1]"/>
649 <xsl:apply-templates select="*[2]"/>
651 <m:mo stretchy="true">}</m:mo>
655 <xsl:template match="tml:c[@name='brack']">
659 <xsl:attribute name="xref">
660 <xsl:value-of select="@id"/>
663 <m:mo stretchy="true">[</m:mo>
664 <m:mfrac linethickness="0">
665 <xsl:apply-templates select="*[1]"/>
666 <xsl:apply-templates select="*[2]"/>
668 <m:mo stretchy="true">]</m:mo>
672 <xsl:template match="tml:c[@name='displaystyle']">
673 <!-- displaystyle -->
674 <m:mstyle displaystyle="true">
676 <xsl:attribute name="xref">
677 <xsl:value-of select="@id"/>
680 <xsl:apply-templates select="*[1]"/>
684 <xsl:template match="tml:c[@name='textstyle']">
686 <m:mstyle scriptlevel="0">
688 <xsl:attribute name="xref">
689 <xsl:value-of select="@id"/>
692 <xsl:apply-templates select="*[1]"/>
693 <xsl:if test="tml:g/tml:cursor[@visible='1']">
695 <m:mtext mathcolor="#808080">}</m:mtext>
696 <m:mtext><xsl:value-of select="@name"/></m:mtext>
702 <xsl:template match="tml:c[@name='scriptstyle']">
704 <m:mstyle scriptlevel="1">
706 <xsl:attribute name="xref">
707 <xsl:value-of select="@id"/>
710 <xsl:apply-templates select="*[1]"/>
714 <xsl:template match="tml:c[@name='scriptscriptstyle']">
715 <!-- scriptscriptstyle -->
716 <m:mstyle scriptlevel="2">
718 <xsl:attribute name="xref">
719 <xsl:value-of select="@id"/>
722 <xsl:apply-templates select="*[1]"/>
726 <xsl:template match="tml:c[@name='pmod']">
730 <xsl:attribute name="xref">
731 <xsl:value-of select="@id"/>
737 <xsl:apply-templates select="*[1]"/>
743 <xsl:template match="tml:c[@name='rm']">
745 <m:mstyle mathvariant="normal">
747 <xsl:attribute name="xref">
748 <xsl:value-of select="@id"/>
751 <xsl:apply-templates select="*[1]"/>
755 <xsl:template match="tml:c[@name='bf']">
757 <m:mstyle mathvariant="bold">
759 <xsl:attribute name="xref">
760 <xsl:value-of select="@id"/>
763 <xsl:apply-templates select="*[1]"/>
767 <xsl:template match="tml:c[@name='tt']">
769 <m:mstyle mathvariant="monospace">
771 <xsl:attribute name="xref">
772 <xsl:value-of select="@id"/>
775 <xsl:apply-templates select="*[1]"/>
779 <xsl:template match="tml:c[@name='sl']">
781 <m:mstyle mathvariant="italic">
783 <xsl:attribute name="xref">
784 <xsl:value-of select="@id"/>
787 <xsl:apply-templates select="*[1]"/>
791 <xsl:template match="tml:c[@name='it']">
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=',']">
805 <m:mspace width="thinmathspace">
807 <xsl:attribute name="xref">
808 <xsl:value-of select="@id"/>
814 <xsl:template match="tml:c[@name='>']">
816 <m:mspace width="mediummathspace">
818 <xsl:attribute name="xref">
819 <xsl:value-of select="@id"/>
825 <xsl:template match="tml:c[@name=';']">
827 <m:mspace width="thickmathspace">
829 <xsl:attribute name="xref">
830 <xsl:value-of select="@id"/>
836 <xsl:template match="tml:c[@name='!']">
838 <m:mspace width="-0.166667em">
840 <xsl:attribute name="xref">
841 <xsl:value-of select="@id"/>
847 <xsl:template name="table-content">
849 <xsl:when test="tml:row">
850 <xsl:apply-templates select="tml:row"/>
855 <xsl:apply-templates select="*"/>
862 <xsl:template match="tml:c[@name='matrix']">
866 <xsl:attribute name="xref">
867 <xsl:value-of select="@id"/>
870 <xsl:call-template name="table-content"/>
874 <xsl:template match="tml:row">
876 <xsl:apply-templates select="tml:cell"/>
880 <xsl:template match="tml:cell">
882 <xsl:apply-templates select="*"/>
886 <xsl:template match="tml:c[@name='pmatrix']">
890 <xsl:attribute name="xref">
891 <xsl:value-of select="@id"/>
894 <m:mo stretchy="true">(</m:mo>
896 <xsl:call-template name="table-content"/>
898 <m:mo stretchy="true">)</m:mo>
902 <xsl:template match="tml:c[@name='bordermatrix']">
903 <!-- bordermatrix -->
906 <xsl:attribute name="xref">
907 <xsl:value-of select="@id"/>
911 <xsl:apply-templates select="tml:row[1]/tml:cell[1]"/>
913 <xsl:apply-templates select="tml:row[1]/tml:cell[position() > 1]"/>
916 <xsl:for-each select="tml:row[position() > 1]">
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>
924 <xsl:apply-templates select="tml:cell[position() > 1]"/>
925 <xsl:if test="position() = 1">
926 <m:mtd rowspan="{count(../tml:row) - 1}">
927 <m:mo stretchy="true">)</m:mo>
935 <xsl:template match="tml:c[@name='overbrace']">
939 <xsl:attribute name="xref">
940 <xsl:value-of select="@id"/>
943 <xsl:apply-templates select="*[1]"/>
944 <m:mo stretchy="true">????</m:mo>
948 <xsl:template match="tml:c[@name='underbrace']">
952 <xsl:attribute name="xref">
953 <xsl:value-of select="@id"/>
956 <xsl:apply-templates select="*[1]"/>
957 <m:mo stretchy="true">????</m:mo>
961 <xsl:template match="tml:c[@name='cases']">
965 <xsl:attribute name="xref">
966 <xsl:value-of select="@id"/>
969 <m:mo stretchy="true">{</m:mo>
971 <xsl:call-template name="table-content"/>
976 <xsl:template match="tml:c[@name='red']">
978 <m:mstyle mathcolor="red">
980 <xsl:attribute name="xref">
981 <xsl:value-of select="@id"/>
983 <xsl:apply-templates/>
988 <xsl:template match="tml:c[@name='green']">
990 <m:mstyle mathcolor="green">
992 <xsl:attribute name="xref">
993 <xsl:value-of select="@id"/>
995 <xsl:apply-templates/>
1000 <xsl:template match="tml:c[@name='duedelim']">
1004 <xsl:attribute name="xref">
1005 <xsl:value-of select="@id"/>
1008 <xsl:apply-templates select="*[1]"/>
1009 <xsl:apply-templates select="*[2]"/>
1013 <xsl:template match="tml:c[@name='space']">
1014 <m:mspace width="veryverythickmathspace">