3 Copyright (C) 2002-2003, Luca Padovani <luca.padovani@cs.unibo.it>,
4 2003, Paolo Marinelli <pmarinel@cs.unibo.it>.
6 This file is part of EdiTeX, an editor of mathematical
7 expressions based on TeX syntax
9 EdiTeX is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
14 EdiTeX is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with EdiTeX; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 For details, see the EdiTeX World-Wide-Web page,
24 http://helm.cs.unibo.it/editex, or send a mail to
25 <luca.padovani@cs.unibo.it>
28 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
29 xmlns:tml="http://helm.cs.unibo.it/2002/TML"
30 xmlns:m="http://www.w3.org/1998/Math/MathML"
31 exclude-result-prefixes="tml"
34 <xsl:output indent="yes"/>
36 <xsl:param name="id" select="/.."/>
38 <xsl:template match="/">
41 <xsl:apply-templates select="descendant::*[@id=$id]"/>
44 <xsl:apply-templates/>
49 <xsl:template match="tml:math">
52 <xsl:attribute name="xref">
53 <xsl:value-of select="@id"/>
56 <xsl:if test="@display='1'">
57 <xsl:attribute name="display">block</xsl:attribute>
59 <xsl:attribute name="display">block</xsl:attribute>
60 <xsl:apply-templates select="*"/>
64 <xsl:template match="tml:i">
67 <xsl:attribute name="xref">
68 <xsl:value-of select="@id"/>
71 <xsl:value-of select="@val"/>
75 <xsl:template match="tml:n">
78 <xsl:attribute name="xref">
79 <xsl:value-of select="@id"/>
82 <xsl:value-of select="@val"/>
86 <xsl:template match="tml:o">
89 <xsl:attribute name="xref">
90 <xsl:value-of select="@id"/>
93 <xsl:value-of select="@val"/>
97 <xsl:template match="tml:o[@val='-']">
100 <xsl:attribute name="xref">
101 <xsl:value-of select="@id"/>
108 <xsl:template match="tml:cursor[@visible='1']">
110 <xsl:when test="substring(@val,1,1)='\'">
113 <xsl:attribute name="xref">
114 <xsl:value-of select="@id"/>
117 <m:mo stretchy="false">〈</m:mo>
118 <m:mtext mathcolor="blue"><xsl:value-of select="@val"/></m:mtext>
119 <m:mo stretchy="false">〉</m:mo>
123 <m:mtext mathcolor="blue">
125 <xsl:attribute name="xref">
126 <xsl:value-of select="@id"/>
128 </xsl:if><xsl:value-of select="@val"/>I</m:mtext>
133 <xsl:template match="tml:cursor[not(@visible) or @visible='0']">
136 <xsl:template match="tml:sb[@under='1'][*[1]/tml:sp[@over='1']]">
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[@under='1']">
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:sb[*[1][self::tml:sp[not(@over) or @over='0']]]">
164 <xsl:attribute name="xref">
165 <xsl:value-of select="@id"/>
168 <xsl:apply-templates select="*[1]/*[1]"/>
169 <xsl:apply-templates select="*[2]"/>
170 <xsl:apply-templates select="*[1]/*[2]"/>
174 <xsl:template match="tml:sb">
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[@over='1'][*[1]/tml:sb[@under='1']]">
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[@over='1']">
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:sp[*[1][self::tml:sb[not(@over) or @over='0']]]">
214 <xsl:attribute name="xref">
215 <xsl:value-of select="@id"/>
218 <xsl:apply-templates select="*[1]/*[1]"/>
219 <xsl:apply-templates select="*[1]/*[2]"/>
220 <xsl:apply-templates select="*[2]"/>
224 <xsl:template match="tml:sp">
227 <xsl:attribute name="xref">
228 <xsl:value-of select="@id"/>
231 <xsl:apply-templates select="*[1]"/>
232 <xsl:apply-templates select="*[2]"/>
236 <xsl:template match="tml:g">
238 <xsl:when test="not(@id) and count(*) = 1">
239 <xsl:apply-templates select="*[1]"/>
241 <xsl:when test="tml:cursor">
242 <m:mstyle mathbackground="#e0e0e0">
244 <xsl:attribute name="xref">
245 <xsl:value-of select="@id"/>
249 <xsl:apply-templates select="*"/>
256 <xsl:attribute name="xref">
257 <xsl:value-of select="@id"/>
260 <xsl:apply-templates select="*"/>
266 <xsl:template match="tml:row">
268 <xsl:apply-templates select="cell"/>
272 <xsl:template match="tml:cell">
274 <xsl:apply-templates select="*"/>
278 <!--/// CONTROL SEQUENCES ///-->
280 <xsl:template match="tml:c">
283 <xsl:attribute name="xref">
284 <xsl:value-of select="@id"/>
287 <m:mtext mathcolor="blue">\<xsl:value-of select="@name"/></m:mtext>
288 <xsl:apply-templates select="*"/>
292 <xsl:template match="tml:c[@name='fun' and count(*)=3]">
295 <xsl:attribute name="xref">
296 <xsl:value-of select="@id"/>
299 <m:mo mathcolor="red">λ</m:mo>
300 <xsl:apply-templates select="*[1]"/>
302 <xsl:apply-templates select="*[2]"/>
304 <xsl:apply-templates select="*[3]"/>
308 <xsl:template match="tml:c[@name='not'][*[1][self::tml:o]]">
312 <xsl:attribute name="xref">
313 <xsl:value-of select="@id"/>
316 <xsl:value-of select="*[1]/@val"/≯</m:mo>
319 <xsl:template match="tml:c[@name='buildrel']">
323 <xsl:attribute name="xref">
324 <xsl:value-of select="@id"/>
327 <xsl:apply-templates select="*[2]"/>
328 <xsl:apply-templates select="*[1]"/>
332 <xsl:template match="tml:c[@name='left' or @name='right'][*[1][self::tml:o]]">
334 <m:mo stretchy="true">
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' or @name='big'][*[1][self::tml:o]]">
346 <m:mo stretchy="true" minsize="8.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='Bigl' or @name='Bigr' or @name='Bigm'][*[1][self::tml:o]]">
358 <m:mo stretchy="true" minsize="11.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="14.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='Biggl' or @name='Biggr' or @name='Biggm'][*[1][self::tml:o]]">
382 <m:mo stretchy="true" minsize="17.5pt">
384 <xsl:attribute name="xref">
385 <xsl:value-of select="@id"/>
388 <xsl:value-of select="*[1]/@val"/>
392 <xsl:template match="tml:c[@name='hat']">
394 <m:mover accent="true">
396 <xsl:attribute name="xref">
397 <xsl:value-of select="@id"/>
400 <xsl:apply-templates select="*[1]"/>
401 <m:mo>̂</m:mo>
405 <xsl:template match="tml:c[@name='widehat']">
407 <m:mover accent="false">
409 <xsl:attribute name="xref">
410 <xsl:value-of select="@id"/>
413 <xsl:apply-templates select="*[1]"/>
414 <m:mo stretchy="true">̂</m:mo>
418 <xsl:template match="tml:c[@name='check']">
420 <m:mover accent="true">
422 <xsl:attribute name="xref">
423 <xsl:value-of select="@id"/>
426 <xsl:apply-templates select="*[1]"/>
427 <m:mo>̌</m:mo>
431 <xsl:template match="tml:c[@name='tilde']">
433 <m:mover accent="true">
435 <xsl:attribute name="xref">
436 <xsl:value-of select="@id"/>
439 <xsl:apply-templates select="*[1]"/>
440 <m:mo>̃</m:mo>
444 <xsl:template match="tml:c[@name='widetilde']">
448 <xsl:attribute name="xref">
449 <xsl:value-of select="@id"/>
452 <xsl:apply-templates select="*[1]"/>
453 <m:mo stretchy="true">̃</m:mo>
457 <xsl:template match="tml:c[@name='acute']">
459 <m:mover accent="true">
461 <xsl:attribute name="xref">
462 <xsl:value-of select="@id"/>
465 <xsl:apply-templates select="*[1]"/>
466 <m:mo>́</m:mo>
470 <xsl:template match="tml:c[@name='grave']">
472 <m:mover accent="true">
474 <xsl:attribute name="xref">
475 <xsl:value-of select="@id"/>
478 <xsl:apply-templates select="*[1]"/>
479 <m:mo>̀</m:mo>
483 <xsl:template match="tml:c[@name='dot']">
485 <m:mover accent="true">
487 <xsl:attribute name="xref">
488 <xsl:value-of select="@id"/>
491 <xsl:apply-templates select="*[1]"/>
492 <m:mo>̇</m:mo>
496 <xsl:template match="tml:c[@name='ddot']">
498 <m:mover accent="true">
500 <xsl:attribute name="xref">
501 <xsl:value-of select="@id"/>
504 <xsl:apply-templates select="*[1]"/>
505 <m:mo>̈</m:mo>
509 <xsl:template match="tml:c[@name='breve']">
511 <m:mover accent="true">
513 <xsl:attribute name="xref">
514 <xsl:value-of select="@id"/>
517 <xsl:apply-templates select="*[1]"/>
518 <m:mo>̆</m:mo>
522 <xsl:template match="tml:c[@name='bar']">
524 <m:mover accent="true">
526 <xsl:attribute name="xref">
527 <xsl:value-of select="@id"/>
530 <xsl:apply-templates select="*[1]"/>
531 <m:mo>̄</m:mo>
535 <xsl:template match="tml:c[@name='vec']">
537 <m:mover accent="true">
539 <xsl:attribute name="xref">
540 <xsl:value-of select="@id"/>
543 <xsl:apply-templates select="*[1]"/>
544 <m:mo>⃗</m:mo>
548 <xsl:template match="tml:c[@name='overline']">
552 <xsl:attribute name="xref">
553 <xsl:value-of select="@id"/>
556 <xsl:apply-templates select="*[1]"/>
557 <m:mo stretchy="true">̅</m:mo>
561 <xsl:template match="tml:c[@name='underline']">
565 <xsl:attribute name="xref">
566 <xsl:value-of select="@id"/>
569 <xsl:apply-templates select="*[1]"/>
570 <m:mo stretchy="true">̲</m:mo>
574 <xsl:template match="tml:c[@name='sqrt']">
578 <xsl:attribute name="xref">
579 <xsl:value-of select="@id"/>
582 <xsl:apply-templates select="*"/>
586 <xsl:template match="tml:c[@name='root']">
590 <xsl:attribute name="xref">
591 <xsl:value-of select="@id"/>
595 <xsl:when test="count(*) < 2">
597 <xsl:apply-templates select="*[1]"/>
600 <xsl:apply-templates select="*[2]"/>
601 <xsl:apply-templates select="*[1]"/>
607 <xsl:template match="tml:c[@name='frac']">
611 <xsl:attribute name="xref">
612 <xsl:value-of select="@id"/>
615 <xsl:apply-templates select="*[1]"/>
616 <xsl:apply-templates select="*[2]"/>
620 <xsl:template match="tml:c[@name='over']">
624 <xsl:attribute name="xref">
625 <xsl:value-of select="@id"/>
628 <xsl:apply-templates select="*[1]"/>
629 <xsl:apply-templates select="*[2]"/>
633 <xsl:template match="tml:c[@name='atop']">
635 <m:mfrac linethickness="0">
637 <xsl:attribute name="xref">
638 <xsl:value-of select="@id"/>
641 <xsl:apply-templates select="*[1]"/>
642 <xsl:apply-templates select="*[2]"/>
646 <xsl:template match="tml:c[@name='choose']">
650 <xsl:attribute name="xref">
651 <xsl:value-of select="@id"/>
654 <m:mo stretchy="true">(</m:mo>
655 <m:mfrac linethickness="0">
656 <xsl:apply-templates select="*[1]"/>
657 <xsl:apply-templates select="*[2]"/>
659 <m:mo stretchy="true">)</m:mo>
663 <xsl:template match="tml:c[@name='brace']">
667 <xsl:attribute name="xref">
668 <xsl:value-of select="@id"/>
671 <m:mo stretchy="true">{</m:mo>
672 <m:mfrac linethickness="0">
673 <xsl:apply-templates select="*[1]"/>
674 <xsl:apply-templates select="*[2]"/>
676 <m:mo stretchy="true">}</m:mo>
680 <xsl:template match="tml:c[@name='brack']">
684 <xsl:attribute name="xref">
685 <xsl:value-of select="@id"/>
688 <m:mo stretchy="true">[</m:mo>
689 <m:mfrac linethickness="0">
690 <xsl:apply-templates select="*[1]"/>
691 <xsl:apply-templates select="*[2]"/>
693 <m:mo stretchy="true">]</m:mo>
697 <xsl:template match="tml:c[@name='displaystyle']">
698 <!-- displaystyle -->
699 <m:mstyle displaystyle="true">
701 <xsl:attribute name="xref">
702 <xsl:value-of select="@id"/>
705 <xsl:apply-templates select="*[1]"/>
709 <xsl:template match="tml:c[@name='textstyle']">
711 <m:mstyle scriptlevel="0">
713 <xsl:attribute name="xref">
714 <xsl:value-of select="@id"/>
717 <xsl:apply-templates select="*[1]"/>
718 <xsl:if test="tml:g/tml:cursor[@visible='1']">
720 <m:mtext mathcolor="#808080">}</m:mtext>
721 <m:mtext><xsl:value-of select="@name"/></m:mtext>
727 <xsl:template match="tml:c[@name='scriptstyle']">
729 <m:mstyle scriptlevel="1">
731 <xsl:attribute name="xref">
732 <xsl:value-of select="@id"/>
735 <xsl:apply-templates select="*[1]"/>
739 <xsl:template match="tml:c[@name='scriptscriptstyle']">
740 <!-- scriptscriptstyle -->
741 <m:mstyle scriptlevel="2">
743 <xsl:attribute name="xref">
744 <xsl:value-of select="@id"/>
747 <xsl:apply-templates select="*[1]"/>
751 <xsl:template match="tml:c[@name='pmod']">
755 <xsl:attribute name="xref">
756 <xsl:value-of select="@id"/>
762 <xsl:apply-templates select="*[1]"/>
768 <xsl:template match="tml:c[@name='rm']">
770 <m:mstyle mathvariant="normal">
772 <xsl:attribute name="xref">
773 <xsl:value-of select="@id"/>
776 <xsl:apply-templates select="*[1]"/>
780 <xsl:template match="tml:c[@name='bf']">
782 <m:mstyle mathvariant="bold">
784 <xsl:attribute name="xref">
785 <xsl:value-of select="@id"/>
788 <xsl:apply-templates select="*[1]"/>
792 <xsl:template match="tml:c[@name='tt']">
794 <m:mstyle mathvariant="monospace">
796 <xsl:attribute name="xref">
797 <xsl:value-of select="@id"/>
800 <xsl:apply-templates select="*[1]"/>
804 <xsl:template match="tml:c[@name='sl']">
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='it']">
818 <m:mstyle mathvariant="italic">
820 <xsl:attribute name="xref">
821 <xsl:value-of select="@id"/>
824 <xsl:apply-templates select="*[1]"/>
828 <xsl:template match="tml:c[@name=',']">
830 <m:mspace width="thinmathspace">
832 <xsl:attribute name="xref">
833 <xsl:value-of select="@id"/>
839 <xsl:template match="tml:c[@name='>']">
841 <m:mspace width="mediummathspace">
843 <xsl:attribute name="xref">
844 <xsl:value-of select="@id"/>
850 <xsl:template match="tml:c[@name=';']">
852 <m:mspace width="thickmathspace">
854 <xsl:attribute name="xref">
855 <xsl:value-of select="@id"/>
861 <xsl:template match="tml:c[@name='!']">
863 <m:mspace width="-0.166667em">
865 <xsl:attribute name="xref">
866 <xsl:value-of select="@id"/>
872 <xsl:template name="table-content">
874 <xsl:when test="tml:row">
875 <xsl:apply-templates select="tml:row"/>
880 <xsl:apply-templates select="*"/>
887 <xsl:template match="tml:c[@name='matrix']">
891 <xsl:attribute name="xref">
892 <xsl:value-of select="@id"/>
895 <xsl:call-template name="table-content"/>
899 <xsl:template match="tml:row">
901 <xsl:apply-templates select="tml:cell"/>
905 <xsl:template match="tml:cell">
907 <xsl:apply-templates select="*"/>
911 <xsl:template match="tml:c[@name='pmatrix']">
915 <xsl:attribute name="xref">
916 <xsl:value-of select="@id"/>
919 <m:mo stretchy="true">(</m:mo>
921 <xsl:call-template name="table-content"/>
923 <m:mo stretchy="true">)</m:mo>
927 <xsl:template match="tml:c[@name='bordermatrix']">
928 <!-- bordermatrix -->
931 <xsl:attribute name="xref">
932 <xsl:value-of select="@id"/>
936 <xsl:apply-templates select="tml:row[1]/tml:cell[1]"/>
938 <xsl:apply-templates select="tml:row[1]/tml:cell[position() > 1]"/>
941 <xsl:for-each select="tml:row[position() > 1]">
943 <xsl:apply-templates select="tml:cell[1]"/>
944 <xsl:if test="position() = 1">
945 <m:mtd rowspan="{count(../tml:row) - 1}">
946 <m:mo stretchy="true">(</m:mo>
949 <xsl:apply-templates select="tml:cell[position() > 1]"/>
950 <xsl:if test="position() = 1">
951 <m:mtd rowspan="{count(../tml:row) - 1}">
952 <m:mo stretchy="true">)</m:mo>
960 <xsl:template match="tml:c[@name='overbrace']">
964 <xsl:attribute name="xref">
965 <xsl:value-of select="@id"/>
968 <xsl:apply-templates select="*[1]"/>
969 <m:mo stretchy="true">????</m:mo>
973 <xsl:template match="tml:c[@name='underbrace']">
977 <xsl:attribute name="xref">
978 <xsl:value-of select="@id"/>
981 <xsl:apply-templates select="*[1]"/>
982 <m:mo stretchy="true">????</m:mo>
986 <xsl:template match="tml:c[@name='cases']">
990 <xsl:attribute name="xref">
991 <xsl:value-of select="@id"/>
994 <m:mo stretchy="true">{</m:mo>
996 <xsl:call-template name="table-content"/>
1001 <xsl:template match="tml:c[@name='red']">
1003 <m:mstyle mathcolor="red">
1005 <xsl:attribute name="xref">
1006 <xsl:value-of select="@id"/>
1008 <xsl:apply-templates/>
1013 <xsl:template match="tml:c[@name='green']">
1015 <m:mstyle mathcolor="green">
1017 <xsl:attribute name="xref">
1018 <xsl:value-of select="@id"/>
1020 <xsl:apply-templates/>
1025 <xsl:template match="tml:c[@name='duedelim']">
1029 <xsl:attribute name="xref">
1030 <xsl:value-of select="@id"/>
1033 <xsl:apply-templates select="*[1]"/>
1034 <xsl:apply-templates select="*[2]"/>
1038 <xsl:template match="tml:c[@name='space']">
1039 <m:mspace width="veryverythickmathspace">