[PLUGINS] +set de base
[lhc/web/www.git] / www / plugins / odt2spip_30 / inc / xsltml / tokens.xsl
1 <?xml version='1.0' encoding="UTF-8"?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:m="http://www.w3.org/1998/Math/MathML"
4 version='1.0'>
5
6 <!-- ====================================================================== -->
7 <!-- $id: tokens.xsl, 2002/22/11 Exp $
8 This file is part of the XSLT MathML Library distribution.
9 See ./README or http://www.raleigh.ru/MathML/mmltex for
10 copyright and other information -->
11 <!-- ====================================================================== -->
12
13 <xsl:template match="m:mi|m:mn|m:mo|m:mtext|m:ms">
14 <xsl:call-template name="CommonTokenAtr"/>
15 </xsl:template>
16
17 <xsl:template name="mi">
18 <xsl:choose>
19 <xsl:when test="string-length(normalize-space(.))>1 and not(@mathvariant)">
20 <xsl:text>\mathrm{</xsl:text>
21 <xsl:apply-templates/>
22 <xsl:text>}</xsl:text>
23 </xsl:when>
24 <xsl:otherwise>
25 <xsl:apply-templates/>
26 </xsl:otherwise>
27 </xsl:choose>
28 </xsl:template>
29
30 <xsl:template name="mn">
31 <xsl:apply-templates/>
32 </xsl:template>
33
34 <xsl:template name="mo">
35 <xsl:apply-templates/>
36 </xsl:template>
37
38 <xsl:template name="mtext">
39 <xsl:variable name="content">
40 <xsl:call-template name="replaceMtextEntities">
41 <xsl:with-param name="content" select="."/>
42 </xsl:call-template>
43 </xsl:variable>
44 <xsl:text>\text{</xsl:text>
45 <xsl:value-of select="$content"/>
46 <xsl:text>}</xsl:text>
47 </xsl:template>
48
49 <xsl:template match="m:mspace">
50 <xsl:text>\phantom{\rule</xsl:text>
51 <xsl:if test="@depth">
52 <xsl:text>[-</xsl:text>
53 <xsl:value-of select="@depth"/>
54 <xsl:text>]</xsl:text>
55 </xsl:if>
56 <xsl:text>{</xsl:text>
57 <xsl:if test="not(@width)">
58 <xsl:text>0ex</xsl:text>
59 </xsl:if>
60 <xsl:value-of select="@width"/>
61 <xsl:text>}{</xsl:text>
62 <xsl:if test="not(@height)">
63 <xsl:text>0ex</xsl:text>
64 </xsl:if>
65 <xsl:value-of select="@height"/>
66 <xsl:text>}}</xsl:text>
67 </xsl:template>
68
69 <xsl:template name="ms">
70 <xsl:choose>
71 <xsl:when test="@lquote"><xsl:value-of select="@lquote"/></xsl:when>
72 <xsl:otherwise><xsl:text>"</xsl:text></xsl:otherwise>
73 </xsl:choose><xsl:apply-templates/><xsl:choose>
74 <xsl:when test="@rquote"><xsl:value-of select="@rquote"/></xsl:when>
75 <xsl:otherwise><xsl:text>"</xsl:text></xsl:otherwise>
76 </xsl:choose>
77 </xsl:template>
78
79 <xsl:template name="CommonTokenAtr">
80 <xsl:if test="@mathbackground">
81 <xsl:text>\colorbox[rgb]{</xsl:text>
82 <xsl:call-template name="color">
83 <xsl:with-param name="color" select="@mathbackground"/>
84 </xsl:call-template>
85 <xsl:text>}{$</xsl:text>
86 </xsl:if>
87 <xsl:if test="@color or @mathcolor"> <!-- Note: @color is deprecated in MathML 2.0 -->
88 <xsl:text>\textcolor[rgb]{</xsl:text>
89 <xsl:call-template name="color">
90 <xsl:with-param name="color" select="@color|@mathcolor"/>
91 </xsl:call-template>
92 <xsl:text>}{</xsl:text>
93 </xsl:if>
94 <xsl:if test="@mathvariant">
95 <xsl:choose>
96 <xsl:when test="@mathvariant='normal'">
97 <xsl:text>\mathrm{</xsl:text>
98 </xsl:when>
99 <xsl:when test="@mathvariant='bold'">
100 <xsl:text>\mathbf{</xsl:text>
101 </xsl:when>
102 <xsl:when test="@mathvariant='italic'">
103 <xsl:text>\mathit{</xsl:text>
104 </xsl:when>
105 <xsl:when test="@mathvariant='bold-italic'"> <!-- Required definition -->
106 <xsl:text>\mathbit{</xsl:text>
107 </xsl:when>
108 <xsl:when test="@mathvariant='double-struck'"> <!-- Required amsfonts -->
109 <xsl:text>\mathbb{</xsl:text>
110 </xsl:when>
111 <xsl:when test="@mathvariant='bold-fraktur'"> <!-- Error -->
112 <xsl:text>{</xsl:text>
113 </xsl:when>
114 <xsl:when test="@mathvariant='script'">
115 <xsl:text>\mathcal{</xsl:text>
116 </xsl:when>
117 <xsl:when test="@mathvariant='bold-script'"> <!-- Error -->
118 <xsl:text>\mathsc{</xsl:text>
119 </xsl:when>
120 <xsl:when test="@mathvariant='fraktur'"> <!-- Required amsfonts -->
121 <xsl:text>\mathfrak{</xsl:text>
122 </xsl:when>
123 <xsl:when test="@mathvariant='sans-serif'">
124 <xsl:text>\mathsf{</xsl:text>
125 </xsl:when>
126 <xsl:when test="@mathvariant='bold-sans-serif'"> <!-- Required definition -->
127 <xsl:text>\mathbsf{</xsl:text>
128 </xsl:when>
129 <xsl:when test="@mathvariant='sans-serif-italic'"> <!-- Required definition -->
130 <xsl:text>\mathsfit{</xsl:text>
131 </xsl:when>
132 <xsl:when test="@mathvariant='sans-serif-bold-italic'"> <!-- Error -->
133 <xsl:text>\mathbsfit{</xsl:text>
134 </xsl:when>
135 <xsl:when test="@mathvariant='monospace'">
136 <xsl:text>\mathtt{</xsl:text>
137 </xsl:when>
138 <xsl:otherwise>
139 <xsl:text>{</xsl:text>
140 </xsl:otherwise>
141 </xsl:choose>
142 </xsl:if>
143 <xsl:call-template name="selectTemplate"/>
144 <xsl:if test="@mathvariant">
145 <xsl:text>}</xsl:text>
146 </xsl:if>
147 <xsl:if test="@color or @mathcolor">
148 <xsl:text>}</xsl:text>
149 </xsl:if>
150 <xsl:if test="@mathbackground">
151 <xsl:text>$}</xsl:text>
152 </xsl:if>
153 </xsl:template>
154
155 <xsl:template name="selectTemplate">
156 <!-- <xsl:variable name="name" select="local-name()"/>
157 <xsl:call-template name="{$name}"/>-->
158 <xsl:choose>
159 <xsl:when test="local-name(.)='mi'">
160 <xsl:call-template name="mi"/>
161 </xsl:when>
162 <xsl:when test="local-name(.)='mn'">
163 <xsl:call-template name="mn"/>
164 </xsl:when>
165 <xsl:when test="local-name(.)='mo'">
166 <xsl:call-template name="mo"/>
167 </xsl:when>
168 <xsl:when test="local-name(.)='mtext'">
169 <xsl:call-template name="mtext"/>
170 </xsl:when>
171 <xsl:when test="local-name(.)='ms'">
172 <xsl:call-template name="ms"/>
173 </xsl:when>
174 </xsl:choose>
175 </xsl:template>
176
177 <xsl:template name="color">
178 <!-- NB: Variables colora and valueColor{n} only for Sablotron -->
179 <xsl:param name="color"/>
180 <xsl:variable name="colora" select="translate($color,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')"/>
181 <xsl:choose>
182 <xsl:when test="starts-with($colora,'#') and string-length($colora)=4">
183 <xsl:variable name="valueColor">
184 <xsl:call-template name="Hex2Decimal">
185 <xsl:with-param name="arg" select="substring($colora,2,1)"/>
186 </xsl:call-template>
187 </xsl:variable>
188 <xsl:value-of select="$valueColor div 15"/><xsl:text>,</xsl:text>
189 <xsl:variable name="valueColor1">
190 <xsl:call-template name="Hex2Decimal">
191 <xsl:with-param name="arg" select="substring($colora,3,1)"/>
192 </xsl:call-template>
193 </xsl:variable>
194 <xsl:value-of select="$valueColor1 div 15"/><xsl:text>,</xsl:text>
195 <xsl:variable name="valueColor2">
196 <xsl:call-template name="Hex2Decimal">
197 <xsl:with-param name="arg" select="substring($colora,4,1)"/>
198 </xsl:call-template>
199 </xsl:variable>
200 <xsl:value-of select="$valueColor2 div 15"/>
201 </xsl:when>
202 <xsl:when test="starts-with($colora,'#') and string-length($colora)=7">
203 <xsl:variable name="valueColor1">
204 <xsl:call-template name="Hex2Decimal">
205 <xsl:with-param name="arg" select="substring($colora,2,1)"/>
206 </xsl:call-template>
207 </xsl:variable>
208 <xsl:variable name="valueColor2">
209 <xsl:call-template name="Hex2Decimal">
210 <xsl:with-param name="arg" select="substring($colora,3,1)"/>
211 </xsl:call-template>
212 </xsl:variable>
213 <xsl:value-of select="($valueColor1*16 + $valueColor2) div 255"/><xsl:text>,</xsl:text>
214 <xsl:variable name="valueColor1a">
215 <xsl:call-template name="Hex2Decimal">
216 <xsl:with-param name="arg" select="substring($colora,4,1)"/>
217 </xsl:call-template>
218 </xsl:variable>
219 <xsl:variable name="valueColor2a">
220 <xsl:call-template name="Hex2Decimal">
221 <xsl:with-param name="arg" select="substring($colora,5,1)"/>
222 </xsl:call-template>
223 </xsl:variable>
224 <xsl:value-of select="($valueColor1a*16 + $valueColor2a) div 255"/><xsl:text>,</xsl:text>
225 <xsl:variable name="valueColor1b">
226 <xsl:call-template name="Hex2Decimal">
227 <xsl:with-param name="arg" select="substring($colora,6,1)"/>
228 </xsl:call-template>
229 </xsl:variable>
230 <xsl:variable name="valueColor2b">
231 <xsl:call-template name="Hex2Decimal">
232 <xsl:with-param name="arg" select="substring($colora,7,1)"/>
233 </xsl:call-template>
234 </xsl:variable>
235 <xsl:value-of select="($valueColor1b*16 + $valueColor2b) div 255"/>
236 </xsl:when>
237 <!-- ======================= if color specifed as an html-color-name ========================================== -->
238 <xsl:when test="$colora='aqua'"><xsl:text>0,1,1</xsl:text></xsl:when>
239 <xsl:when test="$colora='black'"><xsl:text>0,0,0</xsl:text></xsl:when>
240 <xsl:when test="$colora='blue'"><xsl:text>0,0,1</xsl:text></xsl:when>
241 <xsl:when test="$colora='fuchsia'"><xsl:text>1,0,1</xsl:text></xsl:when>
242 <xsl:when test="$colora='gray'"><xsl:text>.5,.5,.5</xsl:text></xsl:when>
243 <xsl:when test="$colora='green'"><xsl:text>0,.5,0</xsl:text></xsl:when>
244 <xsl:when test="$colora='lime'"><xsl:text>0,1,0</xsl:text></xsl:when>
245 <xsl:when test="$colora='maroon'"><xsl:text>.5,0,0</xsl:text></xsl:when>
246 <xsl:when test="$colora='navy'"><xsl:text>0,0,.5</xsl:text></xsl:when>
247 <xsl:when test="$colora='olive'"><xsl:text>.5,.5,0</xsl:text></xsl:when>
248 <xsl:when test="$colora='purple'"><xsl:text>.5,0,.5</xsl:text></xsl:when>
249 <xsl:when test="$colora='red'"><xsl:text>1,0,0</xsl:text></xsl:when>
250 <xsl:when test="$colora='silver'"><xsl:text>.75,.75,.75</xsl:text></xsl:when>
251 <xsl:when test="$colora='teal'"><xsl:text>0,.5,.5</xsl:text></xsl:when>
252 <xsl:when test="$colora='white'"><xsl:text>1,1,1</xsl:text></xsl:when>
253 <xsl:when test="$colora='yellow'"><xsl:text>1,1,0</xsl:text></xsl:when>
254 <xsl:otherwise>
255 <xsl:message>Exception at color template</xsl:message>
256 </xsl:otherwise>
257 </xsl:choose>
258 </xsl:template>
259
260 <xsl:template name="Hex2Decimal">
261 <xsl:param name="arg"/>
262 <xsl:choose>
263 <xsl:when test="$arg='f'">
264 <xsl:value-of select="15"/>
265 </xsl:when>
266 <xsl:when test="$arg='e'">
267 <xsl:value-of select="14"/>
268 </xsl:when>
269 <xsl:when test="$arg='d'">
270 <xsl:value-of select="13"/>
271 </xsl:when>
272 <xsl:when test="$arg='c'">
273 <xsl:value-of select="12"/>
274 </xsl:when>
275 <xsl:when test="$arg='b'">
276 <xsl:value-of select="11"/>
277 </xsl:when>
278 <xsl:when test="$arg='a'">
279 <xsl:value-of select="10"/>
280 </xsl:when>
281 <xsl:when test="translate($arg, '0123456789', '9999999999')='9'"> <!-- if $arg is number -->
282 <xsl:value-of select="$arg"/>
283 </xsl:when>
284 <xsl:otherwise>
285 <xsl:message>Exception at Hex2Decimal template</xsl:message>
286 </xsl:otherwise>
287 </xsl:choose>
288 </xsl:template>
289
290 <xsl:template match="m:*/text()">
291 <xsl:call-template name="replaceEntities">
292 <xsl:with-param name="content" select="normalize-space()"/>
293 </xsl:call-template>
294 </xsl:template>
295
296 </xsl:stylesheet>