4 * Part of the jsMath package for mathematics on the web.
6 * This file implements a number of HTML-specific extensions to TeX,
7 * including \color, \style, \class, \unicode, etc. It will be loaded
8 * automatically when needed, or can be loaded by
10 * jsMath.Extension.Require('HTML');
12 * ---------------------------------------------------------------------
14 * Copyright 2005-2006 by Davide P. Cervone
16 * Licensed under the Apache License, Version 2.0 (the "License");
17 * you may not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
20 * http://www.apache.org/licenses/LICENSE-2.0
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS,
24 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
29 /********************************************************************/
31 jsMath.Package(jsMath.Parser,{
43 * Show the argument in a particular color
45 Color: function (name) {
46 var color = this.GetArgument(this.cmd+name); if (this.error) return;
47 this.CheckHTML(color,name); if (this.error) return;
48 // check that it looks like a color?
49 this.AddHTML(name,['<span style="color: '+color+'">','</span>']);
53 * Make the argument be a link
55 Href: function (name) {
56 var href = this.GetArgument(this.cmd+name); if (this.error) return;
57 this.CheckHTML(href,name); if (this.error) return;
58 this.AddHTML(name,['<a class="link" href="'+href+'">','</a>']);
62 * Apply a CSS class to the argument
64 Class: function (name) {
65 var clss = this.GetArgument(this.cmd+name); if (this.error) return;
66 this.CheckHTML(clss,name); if (this.error) return;
67 this.AddHTML(name,['<span class="'+clss+'">','</span>']);
71 * Apply a CSS style to the argument
73 Style: function (name) {
74 var style = this.GetArgument(this.cmd+name); if (this.error) return;
75 this.CheckHTML(style,name); if (this.error) return;
76 this.AddHTML(name,['<span style="'+style+'">','</span>']);
80 * Add a CSS element ID to the argument
82 CSSId: function (name) {
83 var id = this.GetArgument(this.cmd+name); if (this.error) return;
84 this.CheckHTML(id,name); if (this.error) return;
85 this.AddHTML(name,['<span id="'+id+'">','</span>']);
89 * Insert some raw HTML around the argument (this will not affect
90 * the spacing or other TeX features)
92 AddHTML: function (name,params) {
93 var data = this.mlist.data;
94 var arg = this.GetArgument(this.cmd+name); if (this.error) return;
95 arg = jsMath.Parse(arg,data.font,data.size,data.style);
96 if (arg.error) {this.Error(arg); return}
97 this.mlist.Add(jsMath.mItem.HTML(params[0]));
98 for (var i = 0; i < arg.mlist.Length(); i++) {this.mlist.Add(arg.mlist.Get(i))}
99 this.mlist.Add(jsMath.mItem.HTML(params[1]));
102 CheckHTML: function (data,name) {
103 if (data.match(/[<>&"]/))
104 {this.Error("Can't include raw HTML in first argument of "+this.cmd+name)}
108 * Insert a unicode reference as an Ord atom. Its argument should
109 * be the unicode code point, e.g. \unicode{8211}, or \unicode{x203F}.
110 * You can also specify the height (offset from the x height) and depth
111 * in ems, together with a CSS class for the character, e.g.,
112 * \unicode{8211,class,.2,-.3}
114 Unicode: function (name) {
115 var arg = this.GetArgument(this.cmd+name); if (this.error) return;
116 this.CheckHTML(arg,name); if (this.error) return;
117 arg = arg.split(','); arg[0] = '&#'+arg[0]+';';
118 if (!arg[1]) {arg[1] = 'normal'}
119 this.mlist.Add(jsMath.mItem.TextAtom('ord',arg[0],arg[1],arg[2],arg[3]));