verb.js (2068B)
1 /* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */ 2 /* vim: set ts=2 et sw=2 tw=80: */ 3 4 /************************************************************* 5 * 6 * MathJax/extensions/TeX/verb.js 7 * 8 * Implements the \verb|...| command for including text verbatim 9 * (with no processing of macros or special characters). 10 * 11 * --------------------------------------------------------------------- 12 * 13 * Copyright (c) 2009-2015 The MathJax Consortium 14 * 15 * Licensed under the Apache License, Version 2.0 (the "License"); 16 * you may not use this file except in compliance with the License. 17 * You may obtain a copy of the License at 18 * 19 * http://www.apache.org/licenses/LICENSE-2.0 20 * 21 * Unless required by applicable law or agreed to in writing, software 22 * distributed under the License is distributed on an "AS IS" BASIS, 23 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 24 * See the License for the specific language governing permissions and 25 * limitations under the License. 26 */ 27 28 MathJax.Extension["TeX/verb"] = { 29 version: "2.6.0" 30 }; 31 32 MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () { 33 34 var MML = MathJax.ElementJax.mml; 35 var TEX = MathJax.InputJax.TeX; 36 var TEXDEF = TEX.Definitions; 37 38 TEXDEF.Add({macros: {verb: 'Verb'}},null,true); 39 40 TEX.Parse.Augment({ 41 42 /* 43 * Implement \verb|...| 44 */ 45 Verb: function (name) { 46 var c = this.GetNext(); var start = ++this.i; 47 if (c == "" ) {TEX.Error(["MissingArgFor","Missing argument for %1",name])} 48 while (this.i < this.string.length && this.string.charAt(this.i) != c) {this.i++} 49 if (this.i == this.string.length) 50 {TEX.Error(["NoClosingDelim","Can't find closing delimiter for %1", name])} 51 var text = this.string.slice(start,this.i).replace(/ /g,"\u00A0"); this.i++; 52 this.Push(MML.mtext(text).With({mathvariant:MML.VARIANT.MONOSPACE})); 53 } 54 55 }); 56 57 MathJax.Hub.Startup.signal.Post("TeX verb Ready"); 58 59 }); 60 61 MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/verb.js");