added math templates
[lambda.git] / jsMath / extensions / verb.js
1 /*
2  *  extensions/verb.js
3  *  
4  *  Part of the jsMath package for mathematics on the web.
5  *
6  *  This file implements the \verb macro.  You can activate it
7  *  by calling
8  *  
9  *    jsMath.Extension.Macro('verb');
10  *  
11  *  which will cause the extension to be loaded only when it is
12  *  needed, or you can force it to be loaded via
13  *  
14  *    jsMath.Extension.Require('verb');
15  *    
16  *  once jsMath.js has been loaded, or by adding "extensions/verb.js"
17  *  to the loadFiles array in the easy/load.js file.
18  *  
19  *  ---------------------------------------------------------------------
20  *
21  *  Copyright 2008 by Davide P. Cervone
22  * 
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
26  * 
27  *      http://www.apache.org/licenses/LICENSE-2.0
28  * 
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.
34  */
35
36 /********************************************************************/
37
38 jsMath.Package(jsMath.Parser,{
39   
40   macros: {verb: 'Verb'},
41   
42   /*
43    *  Implement \verb|...|
44    */
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,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
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));
57   }
58 });