4 * Part of the jsMath package for mathematics on the web.
6 * This file implements the \verb macro. You can activate it
9 * jsMath.Extension.Macro('verb');
11 * which will cause the extension to be loaded only when it is
12 * needed, or you can force it to be loaded via
14 * jsMath.Extension.Require('verb');
16 * once jsMath.js has been loaded, or by adding "extensions/verb.js"
17 * to the loadFiles array in the easy/load.js file.
19 * ---------------------------------------------------------------------
21 * Copyright 2008 by Davide P. Cervone
23 * Licensed under the Apache License, Version 2.0 (the "License");
24 * you may not use this file except in compliance with the License.
25 * You may obtain a copy of the License at
27 * http://www.apache.org/licenses/LICENSE-2.0
29 * Unless required by applicable law or agreed to in writing, software
30 * distributed under the License is distributed on an "AS IS" BASIS,
31 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32 * See the License for the specific language governing permissions and
33 * limitations under the License.
36 /********************************************************************/
38 jsMath.Package(jsMath.Parser,{
40 macros: {verb: 'Verb'},
43 * Implement \verb|...|
45 Verb: function (name) {
46 var c = this.GetNext(); var start = ++this.i;
47 if (c == "" ) {this.Error(this.cmd+name+" requires an argument"); return}
48 while (this.i < this.string.length && this.string.charAt(this.i) != c) {this.i++}
49 if (this.i == this.string.length)
50 {this.Error("Can't find closing delimiter for "+this.cmd+name); return}
51 var text = this.string.slice(start,this.i); this.i++;
52 text = text.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
53 text = '<span style="font-family:monospace">'+text+'</span>';
54 var box = jsMath.Box.Text(text,'normal','T',this.mlist.data.size).Styled();
55 box.h = box.bh+box.bd -jsMath.d; box.d = jsMath.d;
56 this.mlist.Add(jsMath.mItem.Typeset(box));