Debian Codegraph @

xsl/mathml2/tokens.xsl

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