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 name="cursor">
74 <xsl:when test="substring(@val,1,1)='\'">
77 <xsl:attribute name="xref">
78 <xsl:value-of select="@id"/>
81 <m:mo stretchy="false">〈</m:mo>
82 <m:mtext mathcolor="blue"><xsl:value-of select="@val"/></m:mtext>
83 <m:mo stretchy="false">〉</m:mo>
87 <m:mtext mathcolor="blue">
89 <xsl:attribute name="xref">
90 <xsl:value-of select="@id"/>
97 <xsl:template match="tml:cursor[@visible='1']">
98 <xsl:param name="annotation" select="/.."/>
100 <xsl:when test="$annotation">
102 <xsl:call-template name="cursor"/>
104 <xsl:value-of select="$annotation"/>
109 <xsl:call-template name="cursor"/>
114 <xsl:template match="tml:cursor[not(@visible) or @visible='0']">
117 <xsl:template match="tml:sb[@under='1'][*[1]/tml:sp[@over='1']]">
120 <xsl:attribute name="xref">
121 <xsl:value-of select="@id"/>
124 <xsl:apply-templates select="*[1]/*[1]"/>
125 <xsl:apply-templates select="*[2]"/>
126 <xsl:apply-templates select="*[1]/*[2]"/>
130 <xsl:template match="tml:sb[@under='1']">
133 <xsl:attribute name="xref">
134 <xsl:value-of select="@id"/>
137 <xsl:apply-templates select="*[1]"/>
138 <xsl:apply-templates select="*[2]"/>
142 <xsl:template match="tml:sb[*[1][self::tml:sp[not(@over) or @over='0']]]">
145 <xsl:attribute name="xref">
146 <xsl:value-of select="@id"/>
149 <xsl:apply-templates select="*[1]/*[1]"/>
150 <xsl:apply-templates select="*[2]"/>
151 <xsl:apply-templates select="*[1]/*[2]"/>
155 <xsl:template match="tml:sb">
158 <xsl:attribute name="xref">
159 <xsl:value-of select="@id"/>
162 <xsl:apply-templates select="*[1]"/>
163 <xsl:apply-templates select="*[2]"/>
167 <xsl:template match="tml:sp[@over='1'][*[1]/tml:sb[@under='1']]">
170 <xsl:attribute name="xref">
171 <xsl:value-of select="@id"/>
174 <xsl:apply-templates select="*[1]/*[1]"/>
175 <xsl:apply-templates select="*[1]/*[2]"/>
176 <xsl:apply-templates select="*[2]"/>
180 <xsl:template match="tml:sp[@over='1']">
183 <xsl:attribute name="xref">
184 <xsl:value-of select="@id"/>
187 <xsl:apply-templates select="*[1]"/>
188 <xsl:apply-templates select="*[2]"/>
192 <xsl:template match="tml:sp[*[1][self::tml:sb[not(@over) or @over='0']]]">
195 <xsl:attribute name="xref">
196 <xsl:value-of select="@id"/>
199 <xsl:apply-templates select="*[1]/*[1]"/>
200 <xsl:apply-templates select="*[1]/*[2]"/>
201 <xsl:apply-templates select="*[2]"/>
205 <xsl:template match="tml:sp">
208 <xsl:attribute name="xref">
209 <xsl:value-of select="@id"/>
212 <xsl:apply-templates select="*[1]"/>
213 <xsl:apply-templates select="*[2]"/>
217 <xsl:template match="tml:g">
218 <xsl:param name="annotation" select="/.."/>
220 <xsl:when test="not(@id) and count(*) = 1">
221 <xsl:apply-templates select="*[1]">
222 <xsl:with-param name="annotation" select="$annotation"/>
223 </xsl:apply-templates>
225 <xsl:when test="tml:cursor">
226 <m:mstyle mathbackground="#e0e0e0">
228 <xsl:attribute name="xref">
229 <xsl:value-of select="@id"/>
233 <xsl:apply-templates select="*">
234 <xsl:with-param name="annotation" select="$annotation"/>
235 </xsl:apply-templates>
242 <xsl:attribute name="xref">
243 <xsl:value-of select="@id"/>
246 <xsl:apply-templates select="*">
247 <xsl:with-param name="annotation" select="$annotation"/>
248 </xsl:apply-templates>
254 <xsl:template match="tml:row">
256 <xsl:apply-templates select="cell"/>
260 <xsl:template match="tml:cell">
262 <xsl:apply-templates select="*"/>
266 <!--/// CONTROL SEQUENCES ///-->
268 <xsl:template match="tml:c">
271 <xsl:attribute name="xref">
272 <xsl:value-of select="@id"/>
275 <m:mtext mathcolor="blue">\<xsl:value-of select="@name"/></m:mtext>
276 <xsl:apply-templates select="*"/>
280 <xsl:template match="tml:c[@name='fun' and count(*)=3]">
283 <xsl:attribute name="xref">
284 <xsl:value-of select="@id"/>
287 <m:mo mathcolor="red">λ</m:mo>
288 <xsl:apply-templates select="*[1]"/>
290 <xsl:apply-templates select="*[2]"/>
292 <xsl:apply-templates select="*[3]"/>
296 <xsl:template match="tml:c[@name='not'][*[1][self::tml:o]]">
300 <xsl:attribute name="xref">
301 <xsl:value-of select="@id"/>
304 <xsl:value-of select="*[1]/@val"/≯</m:mo>
307 <xsl:template match="tml:c[@name='buildrel']">
311 <xsl:attribute name="xref">
312 <xsl:value-of select="@id"/>
315 <xsl:apply-templates select="*[2]"/>
316 <xsl:apply-templates select="*[1]"/>
320 <xsl:template match="tml:c[@name='left' or @name='right'][*[1][self::tml:o]]">
322 <m:mo stretchy="true">
324 <xsl:attribute name="xref">
325 <xsl:value-of select="@id"/>
328 <xsl:value-of select="*[1]/@val"/>
332 <xsl:template match="tml:c[@name='bigl' or @name='bigr' or @name='bigm' or @name='big'][*[1][self::tml:o]]">
334 <m:mo stretchy="true" minsize="8.5pt">
336 <xsl:attribute name="xref">
337 <xsl:value-of select="@id"/>
340 <xsl:value-of select="*[1]/@val"/>
344 <xsl:template match="tml:c[@name='Bigl' or @name='Bigr' or @name='Bigm'][*[1][self::tml:o]]">
346 <m:mo stretchy="true" minsize="11.5pt">
348 <xsl:attribute name="xref">
349 <xsl:value-of select="@id"/>
352 <xsl:value-of select="*[1]/@val"/>
356 <xsl:template match="tml:c[@name='biggl' or @name='biggr' or @name='biggm'][*[1][self::tml:o]]">
358 <m:mo stretchy="true" minsize="14.5pt">
360 <xsl:attribute name="xref">
361 <xsl:value-of select="@id"/>
364 <xsl:value-of select="*[1]/@val"/>
368 <xsl:template match="tml:c[@name='Biggl' or @name='Biggr' or @name='Biggm'][*[1][self::tml:o]]">
370 <m:mo stretchy="true" minsize="17.5pt">
372 <xsl:attribute name="xref">
373 <xsl:value-of select="@id"/>
376 <xsl:value-of select="*[1]/@val"/>
380 <xsl:template match="tml:c[@name='hat']">
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='widehat']">
395 <m:mover accent="false">
397 <xsl:attribute name="xref">
398 <xsl:value-of select="@id"/>
401 <xsl:apply-templates select="*[1]"/>
402 <m:mo stretchy="true">̂</m:mo>
406 <xsl:template match="tml:c[@name='check']">
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='tilde']">
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='widetilde']">
436 <xsl:attribute name="xref">
437 <xsl:value-of select="@id"/>
440 <xsl:apply-templates select="*[1]"/>
441 <m:mo stretchy="true">̃</m:mo>
445 <xsl:template match="tml:c[@name='acute']">
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='grave']">
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='dot']">
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='ddot']">
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='breve']">
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='bar']">
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='vec']">
525 <m:mover accent="true">
527 <xsl:attribute name="xref">
528 <xsl:value-of select="@id"/>
531 <xsl:apply-templates select="*[1]"/>
532 <m:mo>⃗</m:mo>
536 <xsl:template match="tml:c[@name='overline']">
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='underline']">
553 <xsl:attribute name="xref">
554 <xsl:value-of select="@id"/>
557 <xsl:apply-templates select="*[1]"/>
558 <m:mo stretchy="true">̲</m:mo>
562 <xsl:template match="tml:c[@name='sqrt']">
566 <xsl:attribute name="xref">
567 <xsl:value-of select="@id"/>
570 <xsl:apply-templates select="*"/>
574 <xsl:template match="tml:c[@name='root']">
578 <xsl:attribute name="xref">
579 <xsl:value-of select="@id"/>
583 <xsl:when test="count(*) < 2">
585 <xsl:apply-templates select="*[1]"/>
588 <xsl:apply-templates select="*[2]"/>
589 <xsl:apply-templates select="*[1]"/>
595 <xsl:template match="tml:c[@name='frac']">
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='over']">
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='atop']">
623 <m:mfrac linethickness="0">
625 <xsl:attribute name="xref">
626 <xsl:value-of select="@id"/>
629 <xsl:apply-templates select="*[1]"/>
630 <xsl:apply-templates select="*[2]"/>
634 <xsl:template match="tml:c[@name='choose']">
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='brace']">
655 <xsl:attribute name="xref">
656 <xsl:value-of select="@id"/>
659 <m:mo stretchy="true">{</m:mo>
660 <m:mfrac linethickness="0">
661 <xsl:apply-templates select="*[1]"/>
662 <xsl:apply-templates select="*[2]"/>
664 <m:mo stretchy="true">}</m:mo>
668 <xsl:template match="tml:c[@name='brack']">
672 <xsl:attribute name="xref">
673 <xsl:value-of select="@id"/>
676 <m:mo stretchy="true">[</m:mo>
677 <m:mfrac linethickness="0">
678 <xsl:apply-templates select="*[1]"/>
679 <xsl:apply-templates select="*[2]"/>
681 <m:mo stretchy="true">]</m:mo>
685 <xsl:template match="tml:c[@name='displaystyle']">
686 <!-- displaystyle -->
687 <m:mstyle displaystyle="true">
689 <xsl:attribute name="xref">
690 <xsl:value-of select="@id"/>
693 <xsl:apply-templates select="*[1]"/>
697 <xsl:template match="tml:c[@name='textstyle']">
699 <m:mstyle scriptlevel="0">
701 <xsl:attribute name="xref">
702 <xsl:value-of select="@id"/>
705 <xsl:apply-templates select="*[1]"/>
706 <xsl:if test="tml:g/tml:cursor[@visible='1']">
708 <m:mtext mathcolor="#808080">}</m:mtext>
709 <m:mtext><xsl:value-of select="@name"/></m:mtext>
715 <xsl:template match="tml:c[@name='scriptstyle']">
717 <m:mstyle scriptlevel="1">
719 <xsl:attribute name="xref">
720 <xsl:value-of select="@id"/>
723 <xsl:apply-templates select="*[1]"/>
727 <xsl:template match="tml:c[@name='scriptscriptstyle']">
728 <!-- scriptscriptstyle -->
729 <m:mstyle scriptlevel="2">
731 <xsl:attribute name="xref">
732 <xsl:value-of select="@id"/>
735 <xsl:apply-templates select="*[1]"/>
739 <xsl:template match="tml:c[@name='pmod']">
743 <xsl:attribute name="xref">
744 <xsl:value-of select="@id"/>
750 <xsl:apply-templates select="*[1]"/>
756 <xsl:template match="tml:c[@name='rm']">
758 <m:mstyle mathvariant="normal">
760 <xsl:attribute name="xref">
761 <xsl:value-of select="@id"/>
764 <xsl:apply-templates select="*[1]"/>
768 <xsl:template match="tml:c[@name='bf']">
770 <m:mstyle mathvariant="bold">
772 <xsl:attribute name="xref">
773 <xsl:value-of select="@id"/>
776 <xsl:apply-templates select="*[1]"/>
780 <xsl:template match="tml:c[@name='tt']">
782 <m:mstyle mathvariant="monospace">
784 <xsl:attribute name="xref">
785 <xsl:value-of select="@id"/>
788 <xsl:apply-templates select="*[1]"/>
792 <xsl:template match="tml:c[@name='sl']">
794 <m:mstyle mathvariant="italic">
796 <xsl:attribute name="xref">
797 <xsl:value-of select="@id"/>
800 <xsl:apply-templates select="*[1]"/>
804 <xsl:template match="tml:c[@name='it']">
806 <m:mstyle mathvariant="italic">
808 <xsl:attribute name="xref">
809 <xsl:value-of select="@id"/>
812 <xsl:apply-templates select="*[1]"/>
816 <xsl:template match="tml:c[@name=',']">
818 <m:mspace width="thinmathspace">
820 <xsl:attribute name="xref">
821 <xsl:value-of select="@id"/>
827 <xsl:template match="tml:c[@name='>']">
829 <m:mspace width="mediummathspace">
831 <xsl:attribute name="xref">
832 <xsl:value-of select="@id"/>
838 <xsl:template match="tml:c[@name=';']">
840 <m:mspace width="thickmathspace">
842 <xsl:attribute name="xref">
843 <xsl:value-of select="@id"/>
849 <xsl:template match="tml:c[@name='!']">
851 <m:mspace width="-0.166667em">
853 <xsl:attribute name="xref">
854 <xsl:value-of select="@id"/>
860 <xsl:template name="table-content">
862 <xsl:when test="tml:row">
863 <xsl:apply-templates select="tml:row"/>
868 <xsl:apply-templates select="*"/>
875 <xsl:template match="tml:c[@name='matrix']">
879 <xsl:attribute name="xref">
880 <xsl:value-of select="@id"/>
883 <xsl:call-template name="table-content"/>
887 <xsl:template match="tml:row">
889 <xsl:apply-templates select="tml:cell"/>
893 <xsl:template match="tml:cell">
895 <xsl:apply-templates select="*"/>
899 <xsl:template match="tml:c[@name='pmatrix']">
903 <xsl:attribute name="xref">
904 <xsl:value-of select="@id"/>
907 <m:mo stretchy="true">(</m:mo>
909 <xsl:call-template name="table-content"/>
911 <m:mo stretchy="true">)</m:mo>
915 <xsl:template match="tml:c[@name='bordermatrix']">
916 <!-- bordermatrix -->
919 <xsl:attribute name="xref">
920 <xsl:value-of select="@id"/>
924 <xsl:apply-templates select="tml:row[1]/tml:cell[1]"/>
926 <xsl:apply-templates select="tml:row[1]/tml:cell[position() > 1]"/>
929 <xsl:for-each select="tml:row[position() > 1]">
931 <xsl:apply-templates select="tml:cell[1]"/>
932 <xsl:if test="position() = 1">
933 <m:mtd rowspan="{count(../tml:row) - 1}">
934 <m:mo stretchy="true">(</m:mo>
937 <xsl:apply-templates select="tml:cell[position() > 1]"/>
938 <xsl:if test="position() = 1">
939 <m:mtd rowspan="{count(../tml:row) - 1}">
940 <m:mo stretchy="true">)</m:mo>
948 <xsl:template match="tml:c[@name='overbrace']">
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='underbrace']">
965 <xsl:attribute name="xref">
966 <xsl:value-of select="@id"/>
969 <xsl:apply-templates select="*[1]"/>
970 <m:mo stretchy="true">????</m:mo>
974 <xsl:template match="tml:c[@name='cases']">
978 <xsl:attribute name="xref">
979 <xsl:value-of select="@id"/>
982 <m:mo stretchy="true">{</m:mo>
984 <xsl:call-template name="table-content"/>
989 <xsl:template match="tml:c[@name='red']">
991 <m:mstyle mathcolor="red">
993 <xsl:attribute name="xref">
994 <xsl:value-of select="@id"/>
996 <xsl:apply-templates/>
1001 <xsl:template match="tml:c[@name='green']">
1003 <m:mstyle mathcolor="green">
1005 <xsl:attribute name="xref">
1006 <xsl:value-of select="@id"/>
1008 <xsl:apply-templates/>
1013 <xsl:template match="tml:c[@name='duedelim']">
1017 <xsl:attribute name="xref">
1018 <xsl:value-of select="@id"/>
1021 <xsl:apply-templates select="*[1]"/>
1022 <xsl:apply-templates select="*[2]"/>