4 This file is part of EdiTeX, an editor of mathematical
5 expressions based on TeX syntax.
7 Copyright (C) 2002-2003 Luca Padovani <lpadovan@cs.unibo.it>,
8 2003 Paolo Marinelli <pmarinel@cs.unibo.it>.
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2.1 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 For more information, please visit the project's home page
25 http://helm.cs.unibo.it/editex/
26 or send an email to <lpadovan@cs.unibo.it>
30 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
31 xmlns:tml="http://helm.cs.unibo.it/2002/TML"
32 xmlns:m="http://www.w3.org/1998/Math/MathML"
33 exclude-result-prefixes="tml"
36 <xsl:output indent="yes"/>
38 <xsl:param name="id" select="/.."/>
40 <xsl:template match="/">
44 <xsl:apply-templates select="descendant::*[@id=$id]"/>
47 <xsl:apply-templates/>
53 <xsl:template match="tml:tex[not(tml:math)]">
54 <!-- This is an empty TeX document. We generate the corresponding -->
55 <!-- empty MathML document. -->
58 <xsl:template match="tml:math">
59 <m:mstyle mathvariant="normal">
61 <xsl:attribute name="xref">
62 <xsl:value-of select="@id"/>
65 <xsl:if test="@display='1'">
66 <xsl:attribute name="display">block</xsl:attribute>
68 <xsl:attribute name="display">block</xsl:attribute>
69 <xsl:apply-templates select="*"/>
73 <xsl:template match="tml:i">
76 <xsl:attribute name="xref">
77 <xsl:value-of select="@id"/>
80 <xsl:value-of select="@val"/>
84 <xsl:template match="tml:n">
87 <xsl:attribute name="xref">
88 <xsl:value-of select="@id"/>
91 <xsl:value-of select="@val"/>
95 <xsl:template match="tml:o">
98 <xsl:attribute name="xref">
99 <xsl:value-of select="@id"/>
102 <xsl:value-of select="@val"/>
106 <xsl:template match="tml:s">
107 <!-- this template is used only for testing purpose and should not be here-->
108 <m:mspace width="veryverythickmathspace">
110 <xsl:attribute name="xref">
111 <xsl:value-of select="@id"/>
118 <xsl:template name="cursor">
120 <xsl:when test="contains(@val, '\')">
123 <xsl:attribute name="xref">
124 <xsl:value-of select="@id"/>
127 <xsl:if test="substring-before(@val, '\')">
128 <m:mtext><xsl:value-of select="substring-before(@val, '\')"/></m:mtext>
130 <m:mo stretchy="false">〈</m:mo>
131 <m:mtext mathcolor="blue"><xsl:value-of select="concat('\', substring-after(@val, '\'))"/></m:mtext>
132 <m:mo stretchy="false">〉</m:mo>
135 <xsl:when test="string-length(@val)>=1">
138 <xsl:attribute name="xref">
139 <xsl:value-of select="@id"/>
143 <xsl:when test="contains('0123456789', substring(@val, 1, 1))">
145 <xsl:value-of select="@val"/>
150 <xsl:value-of select="@val"/>
154 <m:mtext mathcolor="blue">I</m:mtext>
158 <m:mtext mathcolor="blue">
160 <xsl:attribute name="xref">
161 <xsl:value-of select="@id"/>
169 <xsl:template match="tml:o[@val='-']">
172 <xsl:attribute name="xref">
173 <xsl:value-of select="@id"/>
180 <xsl:template match="tml:cursor">
182 <xsl:when test="substring(@val,1,1)='\'">
185 <xsl:attribute name="xref">
186 <xsl:value-of select="@id"/>
189 <m:mo stretchy="false">〈</m:mo>
190 <m:mtext mathcolor="blue"><xsl:value-of select="@val"/></m:mtext>
191 <m:mo stretchy="false">〉</m:mo>
194 <xsl:when test="string-length(@val)>=1">
197 <xsl:attribute name="xref">
198 <xsl:value-of select="@id"/>
202 <xsl:when test="contains('0123456789', substring(@val, 1, 1))">
204 <xsl:value-of select="@val"/>
209 <xsl:value-of select="@val"/>
213 <xsl:if test="@visible='1'">
214 <m:mtext mathcolor="blue">I</m:mtext>
219 <xsl:if test="@visible='1'">
220 <m:mtext mathcolor="blue">
222 <xsl:attribute name="xref">
223 <xsl:value-of select="@id"/>
226 <xsl:text>I</xsl:text>
233 <xsl:template match="tml:sb[@under='1'][*[1]/tml:sp[@over='1']]">
236 <xsl:attribute name="xref">
237 <xsl:value-of select="@id"/>
240 <xsl:apply-templates select="*[1]/*[1]"/>
241 <xsl:apply-templates select="*[2]"/>
242 <xsl:apply-templates select="*[1]/*[2]"/>
246 <xsl:template match="tml:sb[@under='1']">
249 <xsl:attribute name="xref">
250 <xsl:value-of select="@id"/>
253 <xsl:apply-templates select="*[1]"/>
254 <xsl:apply-templates select="*[2]"/>
258 <xsl:template match="tml:sb[*[1][self::tml:sp[not(@over) or @over='0']]]">
261 <xsl:attribute name="xref">
262 <xsl:value-of select="@id"/>
265 <xsl:apply-templates select="*[1]/*[1]"/>
266 <xsl:apply-templates select="*[2]"/>
267 <xsl:apply-templates select="*[1]/*[2]"/>
271 <xsl:template match="tml:sb">
274 <xsl:attribute name="xref">
275 <xsl:value-of select="@id"/>
278 <xsl:apply-templates select="*[1]"/>
279 <xsl:apply-templates select="*[2]"/>
283 <xsl:template match="tml:sp[@over='1'][*[1]/tml:sb[@under='1']]">
286 <xsl:attribute name="xref">
287 <xsl:value-of select="@id"/>
290 <xsl:apply-templates select="*[1]/*[1]"/>
291 <xsl:apply-templates select="*[1]/*[2]"/>
292 <xsl:apply-templates select="*[2]"/>
296 <xsl:template match="tml:sp[@over='1']">
299 <xsl:attribute name="xref">
300 <xsl:value-of select="@id"/>
303 <xsl:apply-templates select="*[1]"/>
304 <xsl:apply-templates select="*[2]"/>
308 <xsl:template match="tml:sp[*[1][self::tml:sb[not(@over) or @over='0']]]">
311 <xsl:attribute name="xref">
312 <xsl:value-of select="@id"/>
315 <xsl:apply-templates select="*[1]/*[1]"/>
316 <xsl:apply-templates select="*[1]/*[2]"/>
317 <xsl:apply-templates select="*[2]"/>
321 <xsl:template match="tml:sp">
324 <xsl:attribute name="xref">
325 <xsl:value-of select="@id"/>
328 <xsl:apply-templates select="*[1]"/>
329 <xsl:apply-templates select="*[2]"/>
333 <xsl:template match="tml:g">
335 <xsl:when test="not(@id) and count(*) = 1">
336 <xsl:apply-templates select="*[1]"/>
338 <xsl:when test="tml:cursor">
339 <m:mstyle mathbackground="#e0e0e0">
341 <xsl:attribute name="xref">
342 <xsl:value-of select="@id"/>
346 <xsl:apply-templates select="*"/>
353 <xsl:attribute name="xref">
354 <xsl:value-of select="@id"/>
357 <xsl:apply-templates select="*"/>
363 <xsl:template match="tml:row">
365 <xsl:apply-templates select="cell"/>
369 <xsl:template match="tml:cell">
371 <xsl:apply-templates select="*"/>
375 <!--/// CONTROL SEQUENCES ///-->
377 <xsl:template match="tml:c">
380 <xsl:attribute name="xref">
381 <xsl:value-of select="@id"/>
384 <m:mtext mathcolor="blue">\<xsl:value-of select="@name"/></m:mtext>
385 <xsl:apply-templates select="*"/>
389 <xsl:template match="tml:c[@name='fun' and count(*)=3]">
392 <xsl:attribute name="xref">
393 <xsl:value-of select="@id"/>
396 <m:mo mathcolor="red">λ</m:mo>
397 <xsl:apply-templates select="*[1]"/>
399 <xsl:apply-templates select="*[2]"/>
401 <xsl:apply-templates select="*[3]"/>
405 <xsl:template match="tml:c[@name='not'][*[1][self::tml:o]]">
409 <xsl:attribute name="xref">
410 <xsl:value-of select="@id"/>
413 <xsl:value-of select="*[1]/@val"/≯</m:mo>
416 <xsl:template match="tml:c[@name='buildrel']">
420 <xsl:attribute name="xref">
421 <xsl:value-of select="@id"/>
424 <xsl:apply-templates select="*[2]"/>
425 <xsl:apply-templates select="*[1]"/>
429 <xsl:template match="tml:c[@name='left' or @name='right'][*[1][self::tml:o]]">
431 <m:mo stretchy="true">
433 <xsl:attribute name="xref">
434 <xsl:value-of select="@id"/>
437 <xsl:value-of select="*[1]/@val"/>
441 <xsl:template match="tml:c[@name='bigl' or @name='bigr' or @name='bigm' or @name='big'][*[1][self::tml:o]]">
443 <m:mo stretchy="true" minsize="8.5pt">
445 <xsl:attribute name="xref">
446 <xsl:value-of select="@id"/>
449 <xsl:value-of select="*[1]/@val"/>
453 <xsl:template match="tml:c[@name='Bigl' or @name='Bigr' or @name='Bigm'][*[1][self::tml:o]]">
455 <m:mo stretchy="true" minsize="11.5pt">
457 <xsl:attribute name="xref">
458 <xsl:value-of select="@id"/>
461 <xsl:value-of select="*[1]/@val"/>
465 <xsl:template match="tml:c[@name='biggl' or @name='biggr' or @name='biggm'][*[1][self::tml:o]]">
467 <m:mo stretchy="true" minsize="14.5pt">
469 <xsl:attribute name="xref">
470 <xsl:value-of select="@id"/>
473 <xsl:value-of select="*[1]/@val"/>
477 <xsl:template match="tml:c[@name='Biggl' or @name='Biggr' or @name='Biggm'][*[1][self::tml:o]]">
479 <m:mo stretchy="true" minsize="17.5pt">
481 <xsl:attribute name="xref">
482 <xsl:value-of select="@id"/>
485 <xsl:value-of select="*[1]/@val"/>
489 <xsl:template match="tml:c[@name='hat']">
491 <m:mover accent="true">
493 <xsl:attribute name="xref">
494 <xsl:value-of select="@id"/>
497 <xsl:apply-templates select="*[1]"/>
498 <m:mo>̂</m:mo>
502 <xsl:template match="tml:c[@name='widehat']">
504 <m:mover accent="false">
506 <xsl:attribute name="xref">
507 <xsl:value-of select="@id"/>
510 <xsl:apply-templates select="*[1]"/>
511 <m:mo stretchy="true">̂</m:mo>
515 <xsl:template match="tml:c[@name='check']">
517 <m:mover accent="true">
519 <xsl:attribute name="xref">
520 <xsl:value-of select="@id"/>
523 <xsl:apply-templates select="*[1]"/>
524 <m:mo>̌</m:mo>
528 <xsl:template match="tml:c[@name='tilde']">
530 <m:mover accent="true">
532 <xsl:attribute name="xref">
533 <xsl:value-of select="@id"/>
536 <xsl:apply-templates select="*[1]"/>
537 <m:mo>̃</m:mo>
541 <xsl:template match="tml:c[@name='widetilde']">
545 <xsl:attribute name="xref">
546 <xsl:value-of select="@id"/>
549 <xsl:apply-templates select="*[1]"/>
550 <m:mo stretchy="true">̃</m:mo>
554 <xsl:template match="tml:c[@name='acute']">
556 <m:mover accent="true">
558 <xsl:attribute name="xref">
559 <xsl:value-of select="@id"/>
562 <xsl:apply-templates select="*[1]"/>
563 <m:mo>́</m:mo>
567 <xsl:template match="tml:c[@name='grave']">
569 <m:mover accent="true">
571 <xsl:attribute name="xref">
572 <xsl:value-of select="@id"/>
575 <xsl:apply-templates select="*[1]"/>
576 <m:mo>̀</m:mo>
580 <xsl:template match="tml:c[@name='dot']">
582 <m:mover accent="true">
584 <xsl:attribute name="xref">
585 <xsl:value-of select="@id"/>
588 <xsl:apply-templates select="*[1]"/>
589 <m:mo>̇</m:mo>
593 <xsl:template match="tml:c[@name='ddot']">
595 <m:mover accent="true">
597 <xsl:attribute name="xref">
598 <xsl:value-of select="@id"/>
601 <xsl:apply-templates select="*[1]"/>
602 <m:mo>̈</m:mo>
606 <xsl:template match="tml:c[@name='breve']">
608 <m:mover accent="true">
610 <xsl:attribute name="xref">
611 <xsl:value-of select="@id"/>
614 <xsl:apply-templates select="*[1]"/>
615 <m:mo>̆</m:mo>
619 <xsl:template match="tml:c[@name='bar']">
621 <m:mover accent="true">
623 <xsl:attribute name="xref">
624 <xsl:value-of select="@id"/>
627 <xsl:apply-templates select="*[1]"/>
628 <m:mo>̄</m:mo>
632 <xsl:template match="tml:c[@name='vec']">
634 <m:mover accent="true">
636 <xsl:attribute name="xref">
637 <xsl:value-of select="@id"/>
640 <xsl:apply-templates select="*[1]"/>
641 <m:mo>⃗</m:mo>
645 <xsl:template match="tml:c[@name='overline']">
649 <xsl:attribute name="xref">
650 <xsl:value-of select="@id"/>
653 <xsl:apply-templates select="*[1]"/>
654 <m:mo stretchy="true">̅</m:mo>
658 <xsl:template match="tml:c[@name='underline']">
662 <xsl:attribute name="xref">
663 <xsl:value-of select="@id"/>
666 <xsl:apply-templates select="*[1]"/>
667 <m:mo stretchy="true">̲</m:mo>
671 <xsl:template match="tml:c[@name='sqrt']">
675 <xsl:attribute name="xref">
676 <xsl:value-of select="@id"/>
679 <xsl:apply-templates select="*"/>
683 <xsl:template match="tml:c[@name='root']">
687 <xsl:attribute name="xref">
688 <xsl:value-of select="@id"/>
692 <xsl:when test="count(*) < 2">
694 <xsl:apply-templates select="*[1]"/>
697 <xsl:apply-templates select="*[2]"/>
698 <xsl:apply-templates select="*[1]"/>
704 <xsl:template match="tml:c[@name='frac']">
708 <xsl:attribute name="xref">
709 <xsl:value-of select="@id"/>
712 <xsl:apply-templates select="*[1]"/>
713 <xsl:apply-templates select="*[2]"/>
717 <xsl:template match="tml:c[@name='over']">
721 <xsl:attribute name="xref">
722 <xsl:value-of select="@id"/>
725 <xsl:apply-templates select="*[1]"/>
726 <xsl:apply-templates select="*[2]"/>
730 <xsl:template match="tml:c[@name='atop']">
732 <m:mfrac linethickness="0">
734 <xsl:attribute name="xref">
735 <xsl:value-of select="@id"/>
738 <xsl:apply-templates select="*[1]"/>
739 <xsl:apply-templates select="*[2]"/>
743 <xsl:template match="tml:c[@name='choose']">
747 <xsl:attribute name="xref">
748 <xsl:value-of select="@id"/>
751 <m:mo stretchy="true">(</m:mo>
752 <m:mfrac linethickness="0">
753 <xsl:apply-templates select="*[1]"/>
754 <xsl:apply-templates select="*[2]"/>
756 <m:mo stretchy="true">)</m:mo>
760 <xsl:template match="tml:c[@name='brace']">
764 <xsl:attribute name="xref">
765 <xsl:value-of select="@id"/>
768 <m:mo stretchy="true">{</m:mo>
769 <m:mfrac linethickness="0">
770 <xsl:apply-templates select="*[1]"/>
771 <xsl:apply-templates select="*[2]"/>
773 <m:mo stretchy="true">}</m:mo>
777 <xsl:template match="tml:c[@name='brack']">
781 <xsl:attribute name="xref">
782 <xsl:value-of select="@id"/>
785 <m:mo stretchy="true">[</m:mo>
786 <m:mfrac linethickness="0">
787 <xsl:apply-templates select="*[1]"/>
788 <xsl:apply-templates select="*[2]"/>
790 <m:mo stretchy="true">]</m:mo>
794 <xsl:template match="tml:c[@name='displaystyle']">
795 <!-- displaystyle -->
796 <m:mstyle displaystyle="true">
798 <xsl:attribute name="xref">
799 <xsl:value-of select="@id"/>
802 <xsl:apply-templates select="*[1]"/>
806 <xsl:template match="tml:c[@name='textstyle']">
808 <m:mstyle scriptlevel="0">
810 <xsl:attribute name="xref">
811 <xsl:value-of select="@id"/>
814 <xsl:apply-templates select="*[1]"/>
815 <xsl:if test="tml:g/tml:cursor[@visible='1']">
817 <m:mtext mathcolor="#808080">}</m:mtext>
818 <m:mtext><xsl:value-of select="@name"/></m:mtext>
824 <xsl:template match="tml:c[@name='scriptstyle']">
826 <m:mstyle scriptlevel="1">
828 <xsl:attribute name="xref">
829 <xsl:value-of select="@id"/>
832 <xsl:apply-templates select="*[1]"/>
836 <xsl:template match="tml:c[@name='scriptscriptstyle']">
837 <!-- scriptscriptstyle -->
838 <m:mstyle scriptlevel="2">
840 <xsl:attribute name="xref">
841 <xsl:value-of select="@id"/>
844 <xsl:apply-templates select="*[1]"/>
848 <xsl:template match="tml:c[@name='pmod']">
852 <xsl:attribute name="xref">
853 <xsl:value-of select="@id"/>
859 <xsl:apply-templates select="*[1]"/>
865 <xsl:template match="tml:c[@name='rm']">
867 <m:mstyle mathvariant="normal">
869 <xsl:attribute name="xref">
870 <xsl:value-of select="@id"/>
873 <xsl:apply-templates select="*[1]"/>
877 <xsl:template match="tml:c[@name='bf']">
879 <m:mstyle mathvariant="bold">
881 <xsl:attribute name="xref">
882 <xsl:value-of select="@id"/>
885 <xsl:apply-templates select="*[1]"/>
889 <xsl:template match="tml:c[@name='tt']">
891 <m:mstyle mathvariant="monospace">
893 <xsl:attribute name="xref">
894 <xsl:value-of select="@id"/>
897 <xsl:apply-templates select="*[1]"/>
901 <xsl:template match="tml:c[@name='sl']">
903 <m:mstyle mathvariant="italic">
905 <xsl:attribute name="xref">
906 <xsl:value-of select="@id"/>
909 <xsl:apply-templates select="*[1]"/>
913 <xsl:template match="tml:c[@name='it']">
915 <m:mstyle mathvariant="italic">
917 <xsl:attribute name="xref">
918 <xsl:value-of select="@id"/>
921 <xsl:apply-templates select="*[1]"/>
925 <xsl:template match="tml:c[@name='_']">
929 <xsl:attribute name="xref">
930 <xsl:value-of select="@id"/>
933 <xsl:text>_</xsl:text>
937 <xsl:template match="tml:c[@name=',']">
939 <m:mspace width="thinmathspace">
941 <xsl:attribute name="xref">
942 <xsl:value-of select="@id"/>
948 <xsl:template match="tml:c[@name='>']">
950 <m:mspace width="mediummathspace">
952 <xsl:attribute name="xref">
953 <xsl:value-of select="@id"/>
959 <xsl:template match="tml:c[@name=';']">
961 <m:mspace width="thickmathspace">
963 <xsl:attribute name="xref">
964 <xsl:value-of select="@id"/>
970 <xsl:template match="tml:c[@name='!']">
972 <m:mspace width="-0.166667em">
974 <xsl:attribute name="xref">
975 <xsl:value-of select="@id"/>
981 <xsl:template name="table-content">
983 <xsl:when test="tml:row">
984 <xsl:apply-templates select="tml:row"/>
989 <xsl:apply-templates select="*"/>
996 <xsl:template match="tml:c[@name='matrix']">
1000 <xsl:attribute name="xref">
1001 <xsl:value-of select="@id"/>
1004 <xsl:call-template name="table-content"/>
1008 <xsl:template match="tml:row">
1010 <xsl:apply-templates select="tml:cell"/>
1014 <xsl:template match="tml:cell">
1016 <xsl:apply-templates select="*"/>
1020 <xsl:template match="tml:c[@name='pmatrix']">
1024 <xsl:attribute name="xref">
1025 <xsl:value-of select="@id"/>
1028 <m:mo stretchy="true">(</m:mo>
1030 <xsl:call-template name="table-content"/>
1032 <m:mo stretchy="true">)</m:mo>
1036 <xsl:template match="tml:c[@name='bordermatrix']">
1037 <!-- bordermatrix -->
1040 <xsl:attribute name="xref">
1041 <xsl:value-of select="@id"/>
1045 <xsl:apply-templates select="tml:row[1]/tml:cell[1]"/>
1047 <xsl:apply-templates select="tml:row[1]/tml:cell[position() > 1]"/>
1050 <xsl:for-each select="tml:row[position() > 1]">
1052 <xsl:apply-templates select="tml:cell[1]"/>
1053 <xsl:if test="position() = 1">
1054 <m:mtd rowspan="{count(../tml:row) - 1}">
1055 <m:mo stretchy="true">(</m:mo>
1058 <xsl:apply-templates select="tml:cell[position() > 1]"/>
1059 <xsl:if test="position() = 1">
1060 <m:mtd rowspan="{count(../tml:row) - 1}">
1061 <m:mo stretchy="true">)</m:mo>
1069 <xsl:template match="tml:c[@name='overbrace']">
1073 <xsl:attribute name="xref">
1074 <xsl:value-of select="@id"/>
1077 <xsl:apply-templates select="*[1]"/>
1078 <m:mo stretchy="true">????</m:mo>
1082 <xsl:template match="tml:c[@name='underbrace']">
1086 <xsl:attribute name="xref">
1087 <xsl:value-of select="@id"/>
1090 <xsl:apply-templates select="*[1]"/>
1091 <m:mo stretchy="true">????</m:mo>
1095 <xsl:template match="tml:c[@name='cases']">
1099 <xsl:attribute name="xref">
1100 <xsl:value-of select="@id"/>
1103 <m:mo stretchy="true">{</m:mo>
1105 <xsl:call-template name="table-content"/>
1110 <xsl:template match="tml:c[@name='red']">
1112 <m:mstyle mathcolor="red">
1114 <xsl:attribute name="xref">
1115 <xsl:value-of select="@id"/>
1117 <xsl:apply-templates/>
1122 <xsl:template match="tml:c[@name='green']">
1124 <m:mstyle mathcolor="green">
1126 <xsl:attribute name="xref">
1127 <xsl:value-of select="@id"/>
1129 <xsl:apply-templates/>
1134 <xsl:template match="tml:c[@name='duedelim']">
1138 <xsl:attribute name="xref">
1139 <xsl:value-of select="@id"/>
1142 <xsl:apply-templates select="*[1]"/>
1143 <xsl:apply-templates select="*[2]"/>
1147 <xsl:template match="tml:c[@name='nodeside']">
1151 <xsl:attribute name="xref">
1152 <xsl:value-of select="@id"/>
1155 <xsl:apply-templates select="*[1]"/>
1156 <xsl:apply-templates select="*[2]"/>