]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/xsl/tml-tex.xsl
* added license and copyright to every source file
[helm.git] / helm / DEVEL / mathml_editor / xsl / tml-tex.xsl
1 <?xml version="1.0"?>
2 <!--
3  Copyright (C) 2002-2003, Luca Padovani <luca.padovani@cs.unibo.it>,
4                     2003, Paolo Marinelli <pmarinel@cs.unibo.it>.
5
6  This file is part of EdiTeX, an editor of mathematical
7  expressions based on TeX syntax
8  
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.
13
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.
18
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.
22  
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>
26 -->
27
28 <xsl:stylesheet
29      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
30      xmlns:tml="http://helm.cs.unibo.it/2002/TML"
31      xmlns:m="http://www.w3.org/1998/Math/MathML"
32      version="1.0">
33
34   <xsl:output method="text" indent="yes"/>
35
36   <xsl:param name="id" select="/.."/>
37
38   <xsl:template match="/">
39     <xsl:choose>
40       <xsl:when test="$id">
41         <xsl:apply-templates select="descendant::*[@id=$id]"/>
42       </xsl:when>
43       <xsl:otherwise>
44         <xsl:apply-templates select="*"/>
45       </xsl:otherwise>
46     </xsl:choose>
47   </xsl:template>
48
49   <xsl:template match="tml:tex">
50     <xsl:apply-templates select="*"/>
51   </xsl:template>
52
53   <xsl:template match="tml:math">
54     <xsl:choose>
55       <xsl:when test="@display='1'">$$<xsl:apply-templates select="*"/>$$</xsl:when>
56       <xsl:otherwise>$<xsl:apply-templates select="*"/>$</xsl:otherwise>
57     </xsl:choose>
58   </xsl:template>
59
60   <xsl:template match="tml:i">
61     <xsl:choose>
62       <xsl:when test="@name">\<xsl:value-of select="@name"/>
63         <xsl:if test="parent::tml:g and following-sibling::tml:i"><xsl:value-of select="' '"/></xsl:if>
64       </xsl:when>
65       <xsl:when test="string-length(@val)=1"><xsl:value-of select="@val"/></xsl:when>
66       <xsl:otherwise>{\it <xsl:value-of select="@val"/>}</xsl:otherwise>
67     </xsl:choose>
68   </xsl:template>
69
70   <xsl:template match="tml:n">
71     <xsl:choose>
72       <xsl:when test="@name">\<xsl:value-of select="@name"/>
73         <xsl:if test="parent::tml:g and following-sibling::tml:i"><xsl:value-of select="' '"/></xsl:if>
74       </xsl:when>
75       <xsl:when test="string-length(@val)=1"><xsl:value-of select="@val"/></xsl:when>
76       <xsl:otherwise>{\rm <xsl:value-of select="@val"/>}</xsl:otherwise>
77     </xsl:choose>
78   </xsl:template>
79
80   <xsl:template match="tml:o">
81     <xsl:choose>
82       <xsl:when test="@name">\<xsl:value-of select="@name"/>
83         <xsl:if test="parent::tml:g and following-sibling::tml:i"><xsl:value-of select="' '"/></xsl:if>
84       </xsl:when>
85       <xsl:when test="string-length(@val)=1"><xsl:value-of select="@val"/></xsl:when>
86       <xsl:otherwise><xsl:value-of select="@val"/></xsl:otherwise>
87     </xsl:choose>
88   </xsl:template>
89
90   <xsl:template match="tml:sb">
91     <xsl:choose>
92       <xsl:when test="@under='1'">
93         <xsl:apply-templates select="*[1]"/>__<xsl:apply-templates select="*[2]"/>
94       </xsl:when>
95       <xsl:otherwise>
96         <xsl:apply-templates select="*[1]"/>_<xsl:apply-templates select="*[2]"/>
97       </xsl:otherwise>
98     </xsl:choose>
99   </xsl:template>
100
101   <xsl:template match="tml:sp">
102     <xsl:choose>
103       <xsl:when test="@over='1'">
104         <xsl:apply-templates select="*[1]"/>^^<xsl:apply-templates select="*[2]"/>
105       </xsl:when>
106       <xsl:otherwise>
107         <xsl:apply-templates select="*[1]"/>^<xsl:apply-templates select="*[2]"/>
108       </xsl:otherwise>
109     </xsl:choose>
110   </xsl:template>
111
112   <xsl:template match="tml:g[@id]">{<xsl:apply-templates select="*"/>}</xsl:template>
113
114   <xsl:template match="tml:g[count(*)&gt;1]">{<xsl:apply-templates select="*"/>}</xsl:template>
115
116   <xsl:template match="tml:g">
117     <xsl:apply-templates select="*"/>
118   </xsl:template>
119
120   <xsl:template match="tml:row">
121     <xsl:apply-templates select="cell"/>\cr </xsl:template>
122
123   <xsl:template match="tml:cell">
124     <xsl:apply-templates select="*"/>
125     <xsl:if test="position() &lt; last()">&amp;</xsl:if>
126   </xsl:template>
127
128 <!--/// CONTROL SEQUENCES ///-->
129
130   <xsl:template match="tml:c[*[1][self::tml:g[@left-open='1']]]">
131     <xsl:apply-templates select="*[1]"/>\<xsl:value-of select="@name"/>
132     <xsl:if test="*[2][self::tml:i]"><xsl:value-of select="' '"/></xsl:if>
133     <xsl:apply-templates select="*[position()&gt;1]"/>
134   </xsl:template>
135
136   <xsl:template match="tml:c">\<xsl:value-of select="@name"/>
137     <xsl:if test="*[1][self::tml:i]"><xsl:value-of select="' '"/></xsl:if>
138     <xsl:apply-templates select="*"/>
139   </xsl:template>
140
141 </xsl:stylesheet>
142