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">
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:sb[@under='1'][*[1]/tml:sp[@over='1']]">
116 <xsl:attribute name="xref">
117 <xsl:value-of select="@id"/>
120 <xsl:apply-templates select="*[1]/*[1]"/>
121 <xsl:apply-templates select="*[2]"/>
122 <xsl:apply-templates select="*[1]/*[2]"/>
126 <xsl:template match="tml:sb[@under='1']">
129 <xsl:attribute name="xref">
130 <xsl:value-of select="@id"/>
133 <xsl:apply-templates select="*[1]"/>
134 <xsl:apply-templates select="*[2]"/>
138 <xsl:template match="tml:sb[*[1][self::tml:sp[not(@over) or @over='0']]]">
141 <xsl:attribute name="xref">
142 <xsl:value-of select="@id"/>
145 <xsl:apply-templates select="*[1]/*[1]"/>
146 <xsl:apply-templates select="*[2]"/>
147 <xsl:apply-templates select="*[1]/*[2]"/>
151 <xsl:template match="tml:sb">
154 <xsl:attribute name="xref">
155 <xsl:value-of select="@id"/>
158 <xsl:apply-templates select="*[1]"/>
159 <xsl:apply-templates select="*[2]"/>
163 <xsl:template match="tml:sp[@over='1'][*[1]/tml:sb[@under='1']]">
166 <xsl:attribute name="xref">
167 <xsl:value-of select="@id"/>
170 <xsl:apply-templates select="*[1]/*[1]"/>
171 <xsl:apply-templates select="*[1]/*[2]"/>
172 <xsl:apply-templates select="*[2]"/>
176 <xsl:template match="tml:sp[@over='1']">
179 <xsl:attribute name="xref">
180 <xsl:value-of select="@id"/>
183 <xsl:apply-templates select="*[1]"/>
184 <xsl:apply-templates select="*[2]"/>
188 <xsl:template match="tml:sp[*[1][self::tml:sb[not(@over) or @over='0']]]">
191 <xsl:attribute name="xref">
192 <xsl:value-of select="@id"/>
195 <xsl:apply-templates select="*[1]/*[1]"/>
196 <xsl:apply-templates select="*[1]/*[2]"/>
197 <xsl:apply-templates select="*[2]"/>
201 <xsl:template match="tml:sp">
204 <xsl:attribute name="xref">
205 <xsl:value-of select="@id"/>
208 <xsl:apply-templates select="*[1]"/>
209 <xsl:apply-templates select="*[2]"/>
213 <xsl:template match="tml:g">
214 <xsl:param name="annotation" select="/.."/>
216 <xsl:when test="not(@id) and count(*) = 1">
217 <xsl:apply-templates select="*[1]">
218 <xsl:with-param name="annotation" select="$annotation"/>
219 </xsl:apply-templates>
221 <xsl:when test="tml:cursor">
222 <m:mstyle mathbackground="#e0e0e0">
224 <xsl:attribute name="xref">
225 <xsl:value-of select="@id"/>
229 <xsl:apply-templates select="*">
230 <xsl:with-param name="annotation" select="$annotation"/>
231 </xsl:apply-templates>
238 <xsl:attribute name="xref">
239 <xsl:value-of select="@id"/>
242 <xsl:apply-templates select="*">
243 <xsl:with-param name="annotation" select="$annotation"/>
244 </xsl:apply-templates>
250 <xsl:template match="tml:row">
252 <xsl:apply-templates select="cell"/>
256 <xsl:template match="tml:cell">
258 <xsl:apply-templates select="*"/>
262 <!--/// CONTROL SEQUENCES ///-->
264 <xsl:template match="tml:c">
267 <xsl:attribute name="xref">
268 <xsl:value-of select="@id"/>
271 <m:mtext mathcolor="blue">\<xsl:value-of select="@name"/></m:mtext>
272 <xsl:apply-templates select="*"/>
276 <xsl:template match="tml:c[@name='fun' and count(*)=3]">
279 <xsl:attribute name="xref">
280 <xsl:value-of select="@id"/>
283 <m:mo mathcolor="red">λ</m:mo>
284 <xsl:apply-templates select="*[1]"/>
286 <xsl:apply-templates select="*[2]"/>
288 <xsl:apply-templates select="*[3]"/>
292 <xsl:template match="tml:c[@name='not'][*[1][self::tml:o]]">
296 <xsl:attribute name="xref">
297 <xsl:value-of select="@id"/>
300 <xsl:value-of select="*[1]/@val"/≯</m:mo>
303 <xsl:template match="tml:c[@name='buildrel']">
307 <xsl:attribute name="xref">
308 <xsl:value-of select="@id"/>
311 <xsl:apply-templates select="*[2]"/>
312 <xsl:apply-templates select="*[1]"/>
316 <xsl:template match="tml:c[@name='left' or @name='right'][*[1][self::tml:o]]">
318 <m:mo stretchy="true">
320 <xsl:attribute name="xref">
321 <xsl:value-of select="@id"/>
324 <xsl:value-of select="*[1]/@val"/>
328 <xsl:template match="tml:c[@name='bigl' or @name='bigr' or @name='bigm' or @name='big'][*[1][self::tml:o]]">
330 <m:mo stretchy="true" minsize="8.5pt">
332 <xsl:attribute name="xref">
333 <xsl:value-of select="@id"/>
336 <xsl:value-of select="*[1]/@val"/>
340 <xsl:template match="tml:c[@name='Bigl' or @name='Bigr' or @name='Bigm'][*[1][self::tml:o]]">
342 <m:mo stretchy="true" minsize="11.5pt">
344 <xsl:attribute name="xref">
345 <xsl:value-of select="@id"/>
348 <xsl:value-of select="*[1]/@val"/>
352 <xsl:template match="tml:c[@name='biggl' or @name='biggr' or @name='biggm'][*[1][self::tml:o]]">
354 <m:mo stretchy="true" minsize="14.5pt">
356 <xsl:attribute name="xref">
357 <xsl:value-of select="@id"/>
360 <xsl:value-of select="*[1]/@val"/>
364 <xsl:template match="tml:c[@name='Biggl' or @name='Biggr' or @name='Biggm'][*[1][self::tml:o]]">
366 <m:mo stretchy="true" minsize="17.5pt">
368 <xsl:attribute name="xref">
369 <xsl:value-of select="@id"/>
372 <xsl:value-of select="*[1]/@val"/>
376 <xsl:template match="tml:c[@name='hat']">
378 <m:mover accent="true">
380 <xsl:attribute name="xref">
381 <xsl:value-of select="@id"/>
384 <xsl:apply-templates select="*[1]"/>
385 <m:mo>̂</m:mo>
389 <xsl:template match="tml:c[@name='widehat']">
391 <m:mover accent="false">
393 <xsl:attribute name="xref">
394 <xsl:value-of select="@id"/>
397 <xsl:apply-templates select="*[1]"/>
398 <m:mo stretchy="true">̂</m:mo>
402 <xsl:template match="tml:c[@name='check']">
404 <m:mover accent="true">
406 <xsl:attribute name="xref">
407 <xsl:value-of select="@id"/>
410 <xsl:apply-templates select="*[1]"/>
411 <m:mo>̌</m:mo>
415 <xsl:template match="tml:c[@name='tilde']">
417 <m:mover accent="true">
419 <xsl:attribute name="xref">
420 <xsl:value-of select="@id"/>
423 <xsl:apply-templates select="*[1]"/>
424 <m:mo>̃</m:mo>
428 <xsl:template match="tml:c[@name='widetilde']">
432 <xsl:attribute name="xref">
433 <xsl:value-of select="@id"/>
436 <xsl:apply-templates select="*[1]"/>
437 <m:mo stretchy="true">̃</m:mo>
441 <xsl:template match="tml:c[@name='acute']">
443 <m:mover accent="true">
445 <xsl:attribute name="xref">
446 <xsl:value-of select="@id"/>
449 <xsl:apply-templates select="*[1]"/>
450 <m:mo>́</m:mo>
454 <xsl:template match="tml:c[@name='grave']">
456 <m:mover accent="true">
458 <xsl:attribute name="xref">
459 <xsl:value-of select="@id"/>
462 <xsl:apply-templates select="*[1]"/>
463 <m:mo>̀</m:mo>
467 <xsl:template match="tml:c[@name='dot']">
469 <m:mover accent="true">
471 <xsl:attribute name="xref">
472 <xsl:value-of select="@id"/>
475 <xsl:apply-templates select="*[1]"/>
476 <m:mo>̇</m:mo>
480 <xsl:template match="tml:c[@name='ddot']">
482 <m:mover accent="true">
484 <xsl:attribute name="xref">
485 <xsl:value-of select="@id"/>
488 <xsl:apply-templates select="*[1]"/>
489 <m:mo>̈</m:mo>
493 <xsl:template match="tml:c[@name='breve']">
495 <m:mover accent="true">
497 <xsl:attribute name="xref">
498 <xsl:value-of select="@id"/>
501 <xsl:apply-templates select="*[1]"/>
502 <m:mo>̆</m:mo>
506 <xsl:template match="tml:c[@name='bar']">
508 <m:mover accent="true">
510 <xsl:attribute name="xref">
511 <xsl:value-of select="@id"/>
514 <xsl:apply-templates select="*[1]"/>
515 <m:mo>̄</m:mo>
519 <xsl:template match="tml:c[@name='vec']">
521 <m:mover accent="true">
523 <xsl:attribute name="xref">
524 <xsl:value-of select="@id"/>
527 <xsl:apply-templates select="*[1]"/>
528 <m:mo>⃗</m:mo>
532 <xsl:template match="tml:c[@name='overline']">
536 <xsl:attribute name="xref">
537 <xsl:value-of select="@id"/>
540 <xsl:apply-templates select="*[1]"/>
541 <m:mo stretchy="true">̅</m:mo>
545 <xsl:template match="tml:c[@name='underline']">
549 <xsl:attribute name="xref">
550 <xsl:value-of select="@id"/>
553 <xsl:apply-templates select="*[1]"/>
554 <m:mo stretchy="true">̲</m:mo>
558 <xsl:template match="tml:c[@name='sqrt']">
562 <xsl:attribute name="xref">
563 <xsl:value-of select="@id"/>
566 <xsl:apply-templates select="*"/>
570 <xsl:template match="tml:c[@name='root']">
574 <xsl:attribute name="xref">
575 <xsl:value-of select="@id"/>
579 <xsl:when test="count(*) < 2">
581 <xsl:apply-templates select="*[1]"/>
584 <xsl:apply-templates select="*[2]"/>
585 <xsl:apply-templates select="*[1]"/>
591 <xsl:template match="tml:c[@name='frac']">
595 <xsl:attribute name="xref">
596 <xsl:value-of select="@id"/>
599 <xsl:apply-templates select="*[1]"/>
600 <xsl:apply-templates select="*[2]"/>
604 <xsl:template match="tml:c[@name='over']">
608 <xsl:attribute name="xref">
609 <xsl:value-of select="@id"/>
612 <xsl:apply-templates select="*[1]"/>
613 <xsl:apply-templates select="*[2]"/>
617 <xsl:template match="tml:c[@name='atop']">
619 <m:mfrac linethickness="0">
621 <xsl:attribute name="xref">
622 <xsl:value-of select="@id"/>
625 <xsl:apply-templates select="*[1]"/>
626 <xsl:apply-templates select="*[2]"/>
630 <xsl:template match="tml:c[@name='choose']">
634 <xsl:attribute name="xref">
635 <xsl:value-of select="@id"/>
638 <m:mo stretchy="true">(</m:mo>
639 <m:mfrac linethickness="0">
640 <xsl:apply-templates select="*[1]"/>
641 <xsl:apply-templates select="*[2]"/>
643 <m:mo stretchy="true">)</m:mo>
647 <xsl:template match="tml:c[@name='brace']">
651 <xsl:attribute name="xref">
652 <xsl:value-of select="@id"/>
655 <m:mo stretchy="true">{</m:mo>
656 <m:mfrac linethickness="0">
657 <xsl:apply-templates select="*[1]"/>
658 <xsl:apply-templates select="*[2]"/>
660 <m:mo stretchy="true">}</m:mo>
664 <xsl:template match="tml:c[@name='brack']">
668 <xsl:attribute name="xref">
669 <xsl:value-of select="@id"/>
672 <m:mo stretchy="true">[</m:mo>
673 <m:mfrac linethickness="0">
674 <xsl:apply-templates select="*[1]"/>
675 <xsl:apply-templates select="*[2]"/>
677 <m:mo stretchy="true">]</m:mo>
681 <xsl:template match="tml:c[@name='displaystyle']">
682 <!-- displaystyle -->
683 <m:mstyle displaystyle="true">
685 <xsl:attribute name="xref">
686 <xsl:value-of select="@id"/>
689 <xsl:apply-templates select="*[1]"/>
693 <xsl:template match="tml:c[@name='textstyle']">
695 <m:mstyle scriptlevel="0">
697 <xsl:attribute name="xref">
698 <xsl:value-of select="@id"/>
701 <xsl:apply-templates select="*[1]"/>
702 <xsl:if test="tml:g/tml:cursor">
704 <m:mtext mathcolor="#808080">}</m:mtext>
705 <m:mtext><xsl:value-of select="@name"/></m:mtext>
711 <xsl:template match="tml:c[@name='scriptstyle']">
713 <m:mstyle scriptlevel="1">
715 <xsl:attribute name="xref">
716 <xsl:value-of select="@id"/>
719 <xsl:apply-templates select="*[1]"/>
723 <xsl:template match="tml:c[@name='scriptscriptstyle']">
724 <!-- scriptscriptstyle -->
725 <m:mstyle scriptlevel="2">
727 <xsl:attribute name="xref">
728 <xsl:value-of select="@id"/>
731 <xsl:apply-templates select="*[1]"/>
735 <xsl:template match="tml:c[@name='pmod']">
739 <xsl:attribute name="xref">
740 <xsl:value-of select="@id"/>
746 <xsl:apply-templates select="*[1]"/>
752 <xsl:template match="tml:c[@name='rm']">
754 <m:mstyle mathvariant="normal">
756 <xsl:attribute name="xref">
757 <xsl:value-of select="@id"/>
760 <xsl:apply-templates select="*[1]"/>
764 <xsl:template match="tml:c[@name='bf']">
766 <m:mstyle mathvariant="bold">
768 <xsl:attribute name="xref">
769 <xsl:value-of select="@id"/>
772 <xsl:apply-templates select="*[1]"/>
776 <xsl:template match="tml:c[@name='tt']">
778 <m:mstyle mathvariant="monospace">
780 <xsl:attribute name="xref">
781 <xsl:value-of select="@id"/>
784 <xsl:apply-templates select="*[1]"/>
788 <xsl:template match="tml:c[@name='sl']">
790 <m:mstyle mathvariant="italic">
792 <xsl:attribute name="xref">
793 <xsl:value-of select="@id"/>
796 <xsl:apply-templates select="*[1]"/>
800 <xsl:template match="tml:c[@name='it']">
802 <m:mstyle mathvariant="italic">
804 <xsl:attribute name="xref">
805 <xsl:value-of select="@id"/>
808 <xsl:apply-templates select="*[1]"/>
812 <xsl:template match="tml:c[@name=',']">
814 <m:mspace width="thinmathspace">
816 <xsl:attribute name="xref">
817 <xsl:value-of select="@id"/>
823 <xsl:template match="tml:c[@name='>']">
825 <m:mspace width="mediummathspace">
827 <xsl:attribute name="xref">
828 <xsl:value-of select="@id"/>
834 <xsl:template match="tml:c[@name=';']">
836 <m:mspace width="thickmathspace">
838 <xsl:attribute name="xref">
839 <xsl:value-of select="@id"/>
845 <xsl:template match="tml:c[@name='!']">
847 <m:mspace width="-0.166667em">
849 <xsl:attribute name="xref">
850 <xsl:value-of select="@id"/>
856 <xsl:template name="table-content">
858 <xsl:when test="tml:row">
859 <xsl:apply-templates select="tml:row"/>
864 <xsl:apply-templates select="*"/>
871 <xsl:template match="tml:c[@name='matrix']">
875 <xsl:attribute name="xref">
876 <xsl:value-of select="@id"/>
879 <xsl:call-template name="table-content"/>
883 <xsl:template match="tml:row">
885 <xsl:apply-templates select="tml:cell"/>
889 <xsl:template match="tml:cell">
891 <xsl:apply-templates select="*"/>
895 <xsl:template match="tml:c[@name='pmatrix']">
899 <xsl:attribute name="xref">
900 <xsl:value-of select="@id"/>
903 <m:mo stretchy="true">(</m:mo>
905 <xsl:call-template name="table-content"/>
907 <m:mo stretchy="true">)</m:mo>
911 <xsl:template match="tml:c[@name='bordermatrix']">
912 <!-- bordermatrix -->
915 <xsl:attribute name="xref">
916 <xsl:value-of select="@id"/>
920 <xsl:apply-templates select="tml:row[1]/tml:cell[1]"/>
922 <xsl:apply-templates select="tml:row[1]/tml:cell[position() > 1]"/>
925 <xsl:for-each select="tml:row[position() > 1]">
927 <xsl:apply-templates select="tml:cell[1]"/>
928 <xsl:if test="position() = 1">
929 <m:mtd rowspan="{count(../tml:row) - 1}">
930 <m:mo stretchy="true">(</m:mo>
933 <xsl:apply-templates select="tml:cell[position() > 1]"/>
934 <xsl:if test="position() = 1">
935 <m:mtd rowspan="{count(../tml:row) - 1}">
936 <m:mo stretchy="true">)</m:mo>
944 <xsl:template match="tml:c[@name='overbrace']">
948 <xsl:attribute name="xref">
949 <xsl:value-of select="@id"/>
952 <xsl:apply-templates select="*[1]"/>
953 <m:mo stretchy="true">????</m:mo>
957 <xsl:template match="tml:c[@name='underbrace']">
961 <xsl:attribute name="xref">
962 <xsl:value-of select="@id"/>
965 <xsl:apply-templates select="*[1]"/>
966 <m:mo stretchy="true">????</m:mo>
970 <xsl:template match="tml:c[@name='cases']">
974 <xsl:attribute name="xref">
975 <xsl:value-of select="@id"/>
978 <m:mo stretchy="true">{</m:mo>
980 <xsl:call-template name="table-content"/>
985 <xsl:template match="tml:c[@name='red']">
987 <m:mstyle mathcolor="red">
989 <xsl:attribute name="xref">
990 <xsl:value-of select="@id"/>
992 <xsl:apply-templates/>
997 <xsl:template match="tml:c[@name='green']">
999 <m:mstyle mathcolor="green">
1001 <xsl:attribute name="xref">
1002 <xsl:value-of select="@id"/>
1004 <xsl:apply-templates/>
1009 <xsl:template match="tml:c[@name='duedelim']">
1013 <xsl:attribute name="xref">
1014 <xsl:value-of select="@id"/>
1017 <xsl:apply-templates select="*[1]"/>
1018 <xsl:apply-templates select="*[2]"/>