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 name="cursor">
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"/>
108 <xsl:template match="tml:cursor[@visible='1']">
109 <xsl:param name="annotation" select="/.."/>
111 <xsl:when test="$annotation">
113 <xsl:call-template name="cursor"/>
115 <xsl:value-of select="$annotation"/>
120 <xsl:call-template name="cursor"/>
125 <xsl:template match="tml:cursor[not(@visible) or @visible='0']">
128 <xsl:template match="tml:sb[@under='1'][*[1]/tml:sp[@over='1']]">
131 <xsl:attribute name="xref">
132 <xsl:value-of select="@id"/>
135 <xsl:apply-templates select="*[1]/*[1]"/>
136 <xsl:apply-templates select="*[2]"/>
137 <xsl:apply-templates select="*[1]/*[2]"/>
141 <xsl:template match="tml:sb[@under='1']">
144 <xsl:attribute name="xref">
145 <xsl:value-of select="@id"/>
148 <xsl:apply-templates select="*[1]"/>
149 <xsl:apply-templates select="*[2]"/>
153 <xsl:template match="tml:sb[*[1][self::tml:sp[not(@over) or @over='0']]]">
156 <xsl:attribute name="xref">
157 <xsl:value-of select="@id"/>
160 <xsl:apply-templates select="*[1]/*[1]"/>
161 <xsl:apply-templates select="*[2]"/>
162 <xsl:apply-templates select="*[1]/*[2]"/>
166 <xsl:template match="tml:sb">
169 <xsl:attribute name="xref">
170 <xsl:value-of select="@id"/>
173 <xsl:apply-templates select="*[1]"/>
174 <xsl:apply-templates select="*[2]"/>
178 <xsl:template match="tml:sp[@over='1'][*[1]/tml:sb[@under='1']]">
181 <xsl:attribute name="xref">
182 <xsl:value-of select="@id"/>
185 <xsl:apply-templates select="*[1]/*[1]"/>
186 <xsl:apply-templates select="*[1]/*[2]"/>
187 <xsl:apply-templates select="*[2]"/>
191 <xsl:template match="tml:sp[@over='1']">
194 <xsl:attribute name="xref">
195 <xsl:value-of select="@id"/>
198 <xsl:apply-templates select="*[1]"/>
199 <xsl:apply-templates select="*[2]"/>
203 <xsl:template match="tml:sp[*[1][self::tml:sb[not(@over) or @over='0']]]">
206 <xsl:attribute name="xref">
207 <xsl:value-of select="@id"/>
210 <xsl:apply-templates select="*[1]/*[1]"/>
211 <xsl:apply-templates select="*[1]/*[2]"/>
212 <xsl:apply-templates select="*[2]"/>
216 <xsl:template match="tml:sp">
219 <xsl:attribute name="xref">
220 <xsl:value-of select="@id"/>
223 <xsl:apply-templates select="*[1]"/>
224 <xsl:apply-templates select="*[2]"/>
228 <xsl:template match="tml:g">
229 <xsl:param name="annotation" select="/.."/>
231 <xsl:when test="not(@id) and count(*) = 1">
232 <xsl:apply-templates select="*[1]">
233 <xsl:with-param name="annotation" select="$annotation"/>
234 </xsl:apply-templates>
236 <xsl:when test="tml:cursor">
237 <m:mstyle mathbackground="#e0e0e0">
239 <xsl:attribute name="xref">
240 <xsl:value-of select="@id"/>
244 <xsl:apply-templates select="*">
245 <xsl:with-param name="annotation" select="$annotation"/>
246 </xsl:apply-templates>
253 <xsl:attribute name="xref">
254 <xsl:value-of select="@id"/>
257 <xsl:apply-templates select="*">
258 <xsl:with-param name="annotation" select="$annotation"/>
259 </xsl:apply-templates>
265 <xsl:template match="tml:row">
267 <xsl:apply-templates select="cell"/>
271 <xsl:template match="tml:cell">
273 <xsl:apply-templates select="*"/>
277 <!--/// CONTROL SEQUENCES ///-->
279 <xsl:template match="tml:c">
282 <xsl:attribute name="xref">
283 <xsl:value-of select="@id"/>
286 <m:mtext mathcolor="blue">\<xsl:value-of select="@name"/></m:mtext>
287 <xsl:apply-templates select="*"/>
291 <xsl:template match="tml:c[@name='fun' and count(*)=3]">
294 <xsl:attribute name="xref">
295 <xsl:value-of select="@id"/>
298 <m:mo mathcolor="red">λ</m:mo>
299 <xsl:apply-templates select="*[1]"/>
301 <xsl:apply-templates select="*[2]"/>
303 <xsl:apply-templates select="*[3]"/>
307 <xsl:template match="tml:c[@name='not'][*[1][self::tml:o]]">
311 <xsl:attribute name="xref">
312 <xsl:value-of select="@id"/>
315 <xsl:value-of select="*[1]/@val"/≯</m:mo>
318 <xsl:template match="tml:c[@name='buildrel']">
322 <xsl:attribute name="xref">
323 <xsl:value-of select="@id"/>
326 <xsl:apply-templates select="*[2]"/>
327 <xsl:apply-templates select="*[1]"/>
331 <xsl:template match="tml:c[@name='left' or @name='right'][*[1][self::tml:o]]">
333 <m:mo stretchy="true">
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' or @name='big'][*[1][self::tml:o]]">
345 <m:mo stretchy="true" minsize="8.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='Bigl' or @name='Bigr' or @name='Bigm'][*[1][self::tml:o]]">
357 <m:mo stretchy="true" minsize="11.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="14.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='Biggl' or @name='Biggr' or @name='Biggm'][*[1][self::tml:o]]">
381 <m:mo stretchy="true" minsize="17.5pt">
383 <xsl:attribute name="xref">
384 <xsl:value-of select="@id"/>
387 <xsl:value-of select="*[1]/@val"/>
391 <xsl:template match="tml:c[@name='hat']">
393 <m:mover accent="true">
395 <xsl:attribute name="xref">
396 <xsl:value-of select="@id"/>
399 <xsl:apply-templates select="*[1]"/>
400 <m:mo>̂</m:mo>
404 <xsl:template match="tml:c[@name='widehat']">
406 <m:mover accent="false">
408 <xsl:attribute name="xref">
409 <xsl:value-of select="@id"/>
412 <xsl:apply-templates select="*[1]"/>
413 <m:mo stretchy="true">̂</m:mo>
417 <xsl:template match="tml:c[@name='check']">
419 <m:mover accent="true">
421 <xsl:attribute name="xref">
422 <xsl:value-of select="@id"/>
425 <xsl:apply-templates select="*[1]"/>
426 <m:mo>̌</m:mo>
430 <xsl:template match="tml:c[@name='tilde']">
432 <m:mover accent="true">
434 <xsl:attribute name="xref">
435 <xsl:value-of select="@id"/>
438 <xsl:apply-templates select="*[1]"/>
439 <m:mo>̃</m:mo>
443 <xsl:template match="tml:c[@name='widetilde']">
447 <xsl:attribute name="xref">
448 <xsl:value-of select="@id"/>
451 <xsl:apply-templates select="*[1]"/>
452 <m:mo stretchy="true">̃</m:mo>
456 <xsl:template match="tml:c[@name='acute']">
458 <m:mover accent="true">
460 <xsl:attribute name="xref">
461 <xsl:value-of select="@id"/>
464 <xsl:apply-templates select="*[1]"/>
465 <m:mo>́</m:mo>
469 <xsl:template match="tml:c[@name='grave']">
471 <m:mover accent="true">
473 <xsl:attribute name="xref">
474 <xsl:value-of select="@id"/>
477 <xsl:apply-templates select="*[1]"/>
478 <m:mo>̀</m:mo>
482 <xsl:template match="tml:c[@name='dot']">
484 <m:mover accent="true">
486 <xsl:attribute name="xref">
487 <xsl:value-of select="@id"/>
490 <xsl:apply-templates select="*[1]"/>
491 <m:mo>̇</m:mo>
495 <xsl:template match="tml:c[@name='ddot']">
497 <m:mover accent="true">
499 <xsl:attribute name="xref">
500 <xsl:value-of select="@id"/>
503 <xsl:apply-templates select="*[1]"/>
504 <m:mo>̈</m:mo>
508 <xsl:template match="tml:c[@name='breve']">
510 <m:mover accent="true">
512 <xsl:attribute name="xref">
513 <xsl:value-of select="@id"/>
516 <xsl:apply-templates select="*[1]"/>
517 <m:mo>̆</m:mo>
521 <xsl:template match="tml:c[@name='bar']">
523 <m:mover accent="true">
525 <xsl:attribute name="xref">
526 <xsl:value-of select="@id"/>
529 <xsl:apply-templates select="*[1]"/>
530 <m:mo>̄</m:mo>
534 <xsl:template match="tml:c[@name='vec']">
536 <m:mover accent="true">
538 <xsl:attribute name="xref">
539 <xsl:value-of select="@id"/>
542 <xsl:apply-templates select="*[1]"/>
543 <m:mo>⃗</m:mo>
547 <xsl:template match="tml:c[@name='overline']">
551 <xsl:attribute name="xref">
552 <xsl:value-of select="@id"/>
555 <xsl:apply-templates select="*[1]"/>
556 <m:mo stretchy="true">̅</m:mo>
560 <xsl:template match="tml:c[@name='underline']">
564 <xsl:attribute name="xref">
565 <xsl:value-of select="@id"/>
568 <xsl:apply-templates select="*[1]"/>
569 <m:mo stretchy="true">̲</m:mo>
573 <xsl:template match="tml:c[@name='sqrt']">
577 <xsl:attribute name="xref">
578 <xsl:value-of select="@id"/>
581 <xsl:apply-templates select="*"/>
585 <xsl:template match="tml:c[@name='root']">
589 <xsl:attribute name="xref">
590 <xsl:value-of select="@id"/>
594 <xsl:when test="count(*) < 2">
596 <xsl:apply-templates select="*[1]"/>
599 <xsl:apply-templates select="*[2]"/>
600 <xsl:apply-templates select="*[1]"/>
606 <xsl:template match="tml:c[@name='frac']">
610 <xsl:attribute name="xref">
611 <xsl:value-of select="@id"/>
614 <xsl:apply-templates select="*[1]"/>
615 <xsl:apply-templates select="*[2]"/>
619 <xsl:template match="tml:c[@name='over']">
623 <xsl:attribute name="xref">
624 <xsl:value-of select="@id"/>
627 <xsl:apply-templates select="*[1]"/>
628 <xsl:apply-templates select="*[2]"/>
632 <xsl:template match="tml:c[@name='atop']">
634 <m:mfrac linethickness="0">
636 <xsl:attribute name="xref">
637 <xsl:value-of select="@id"/>
640 <xsl:apply-templates select="*[1]"/>
641 <xsl:apply-templates select="*[2]"/>
645 <xsl:template match="tml:c[@name='choose']">
649 <xsl:attribute name="xref">
650 <xsl:value-of select="@id"/>
653 <m:mo stretchy="true">(</m:mo>
654 <m:mfrac linethickness="0">
655 <xsl:apply-templates select="*[1]"/>
656 <xsl:apply-templates select="*[2]"/>
658 <m:mo stretchy="true">)</m:mo>
662 <xsl:template match="tml:c[@name='brace']">
666 <xsl:attribute name="xref">
667 <xsl:value-of select="@id"/>
670 <m:mo stretchy="true">{</m:mo>
671 <m:mfrac linethickness="0">
672 <xsl:apply-templates select="*[1]"/>
673 <xsl:apply-templates select="*[2]"/>
675 <m:mo stretchy="true">}</m:mo>
679 <xsl:template match="tml:c[@name='brack']">
683 <xsl:attribute name="xref">
684 <xsl:value-of select="@id"/>
687 <m:mo stretchy="true">[</m:mo>
688 <m:mfrac linethickness="0">
689 <xsl:apply-templates select="*[1]"/>
690 <xsl:apply-templates select="*[2]"/>
692 <m:mo stretchy="true">]</m:mo>
696 <xsl:template match="tml:c[@name='displaystyle']">
697 <!-- displaystyle -->
698 <m:mstyle displaystyle="true">
700 <xsl:attribute name="xref">
701 <xsl:value-of select="@id"/>
704 <xsl:apply-templates select="*[1]"/>
708 <xsl:template match="tml:c[@name='textstyle']">
710 <m:mstyle scriptlevel="0">
712 <xsl:attribute name="xref">
713 <xsl:value-of select="@id"/>
716 <xsl:apply-templates select="*[1]"/>
717 <xsl:if test="tml:g/tml:cursor[@visible='1']">
719 <m:mtext mathcolor="#808080">}</m:mtext>
720 <m:mtext><xsl:value-of select="@name"/></m:mtext>
726 <xsl:template match="tml:c[@name='scriptstyle']">
728 <m:mstyle scriptlevel="1">
730 <xsl:attribute name="xref">
731 <xsl:value-of select="@id"/>
734 <xsl:apply-templates select="*[1]"/>
738 <xsl:template match="tml:c[@name='scriptscriptstyle']">
739 <!-- scriptscriptstyle -->
740 <m:mstyle scriptlevel="2">
742 <xsl:attribute name="xref">
743 <xsl:value-of select="@id"/>
746 <xsl:apply-templates select="*[1]"/>
750 <xsl:template match="tml:c[@name='pmod']">
754 <xsl:attribute name="xref">
755 <xsl:value-of select="@id"/>
761 <xsl:apply-templates select="*[1]"/>
767 <xsl:template match="tml:c[@name='rm']">
769 <m:mstyle mathvariant="normal">
771 <xsl:attribute name="xref">
772 <xsl:value-of select="@id"/>
775 <xsl:apply-templates select="*[1]"/>
779 <xsl:template match="tml:c[@name='bf']">
781 <m:mstyle mathvariant="bold">
783 <xsl:attribute name="xref">
784 <xsl:value-of select="@id"/>
787 <xsl:apply-templates select="*[1]"/>
791 <xsl:template match="tml:c[@name='tt']">
793 <m:mstyle mathvariant="monospace">
795 <xsl:attribute name="xref">
796 <xsl:value-of select="@id"/>
799 <xsl:apply-templates select="*[1]"/>
803 <xsl:template match="tml:c[@name='sl']">
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='it']">
817 <m:mstyle mathvariant="italic">
819 <xsl:attribute name="xref">
820 <xsl:value-of select="@id"/>
823 <xsl:apply-templates select="*[1]"/>
827 <xsl:template match="tml:c[@name=',']">
829 <m:mspace width="thinmathspace">
831 <xsl:attribute name="xref">
832 <xsl:value-of select="@id"/>
838 <xsl:template match="tml:c[@name='>']">
840 <m:mspace width="mediummathspace">
842 <xsl:attribute name="xref">
843 <xsl:value-of select="@id"/>
849 <xsl:template match="tml:c[@name=';']">
851 <m:mspace width="thickmathspace">
853 <xsl:attribute name="xref">
854 <xsl:value-of select="@id"/>
860 <xsl:template match="tml:c[@name='!']">
862 <m:mspace width="-0.166667em">
864 <xsl:attribute name="xref">
865 <xsl:value-of select="@id"/>
871 <xsl:template name="table-content">
873 <xsl:when test="tml:row">
874 <xsl:apply-templates select="tml:row"/>
879 <xsl:apply-templates select="*"/>
886 <xsl:template match="tml:c[@name='matrix']">
890 <xsl:attribute name="xref">
891 <xsl:value-of select="@id"/>
894 <xsl:call-template name="table-content"/>
898 <xsl:template match="tml:row">
900 <xsl:apply-templates select="tml:cell"/>
904 <xsl:template match="tml:cell">
906 <xsl:apply-templates select="*"/>
910 <xsl:template match="tml:c[@name='pmatrix']">
914 <xsl:attribute name="xref">
915 <xsl:value-of select="@id"/>
918 <m:mo stretchy="true">(</m:mo>
920 <xsl:call-template name="table-content"/>
922 <m:mo stretchy="true">)</m:mo>
926 <xsl:template match="tml:c[@name='bordermatrix']">
927 <!-- bordermatrix -->
930 <xsl:attribute name="xref">
931 <xsl:value-of select="@id"/>
935 <xsl:apply-templates select="tml:row[1]/tml:cell[1]"/>
937 <xsl:apply-templates select="tml:row[1]/tml:cell[position() > 1]"/>
940 <xsl:for-each select="tml:row[position() > 1]">
942 <xsl:apply-templates select="tml:cell[1]"/>
943 <xsl:if test="position() = 1">
944 <m:mtd rowspan="{count(../tml:row) - 1}">
945 <m:mo stretchy="true">(</m:mo>
948 <xsl:apply-templates select="tml:cell[position() > 1]"/>
949 <xsl:if test="position() = 1">
950 <m:mtd rowspan="{count(../tml:row) - 1}">
951 <m:mo stretchy="true">)</m:mo>
959 <xsl:template match="tml:c[@name='overbrace']">
963 <xsl:attribute name="xref">
964 <xsl:value-of select="@id"/>
967 <xsl:apply-templates select="*[1]"/>
968 <m:mo stretchy="true">????</m:mo>
972 <xsl:template match="tml:c[@name='underbrace']">
976 <xsl:attribute name="xref">
977 <xsl:value-of select="@id"/>
980 <xsl:apply-templates select="*[1]"/>
981 <m:mo stretchy="true">????</m:mo>
985 <xsl:template match="tml:c[@name='cases']">
989 <xsl:attribute name="xref">
990 <xsl:value-of select="@id"/>
993 <m:mo stretchy="true">{</m:mo>
995 <xsl:call-template name="table-content"/>
1000 <xsl:template match="tml:c[@name='red']">
1002 <m:mstyle mathcolor="red">
1004 <xsl:attribute name="xref">
1005 <xsl:value-of select="@id"/>
1007 <xsl:apply-templates/>
1012 <xsl:template match="tml:c[@name='green']">
1014 <m:mstyle mathcolor="green">
1016 <xsl:attribute name="xref">
1017 <xsl:value-of select="@id"/>
1019 <xsl:apply-templates/>
1024 <xsl:template match="tml:c[@name='duedelim']">
1028 <xsl:attribute name="xref">
1029 <xsl:value-of select="@id"/>
1032 <xsl:apply-templates select="*[1]"/>
1033 <xsl:apply-templates select="*[2]"/>