verb.js 2.0 KB

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