noErrors.js 6.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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/noErrors.js
  6. *
  7. * Prevents the TeX error messages from being displayed and shows the
  8. * original TeX code instead. You can configure whether the dollar signs
  9. * are shown or not for in-line math, and whether to put all the TeX on
  10. * one line or use multiple-lines.
  11. *
  12. * To configure this extension, use
  13. *
  14. * MathJax.Hub.Config({
  15. * TeX: {
  16. * noErrors: {
  17. * inlineDelimiters: ["",""], // or ["$","$"] or ["\\(","\\)"]
  18. * multiLine: true, // false for TeX on all one line
  19. * style: {
  20. * "font-size": "90%",
  21. * "text-align": "left",
  22. * "color": "black",
  23. * "padding": "1px 3px",
  24. * "border": "1px solid"
  25. * // add any additional CSS styles that you want
  26. * // (be sure there is no extra comma at the end of the last item)
  27. * }
  28. * }
  29. * }
  30. * });
  31. *
  32. * Display-style math is always shown in multi-line format, and without
  33. * delimiters, as it will already be set off in its own centered
  34. * paragraph, like standard display mathematics.
  35. *
  36. * The default settings place the invalid TeX in a multi-line box with a
  37. * black border. If you want it to look as though the TeX is just part of
  38. * the paragraph, use
  39. *
  40. * MathJax.Hub.Config({
  41. * TeX: {
  42. * noErrors: {
  43. * inlineDelimiters: ["$","$"], // or ["",""] or ["\\(","\\)"]
  44. * multiLine: false,
  45. * style: {
  46. * "font-size": "normal",
  47. * "border": ""
  48. * }
  49. * }
  50. * }
  51. * });
  52. *
  53. * You may also wish to set the font family, as the default is "serif"
  54. *
  55. * ---------------------------------------------------------------------
  56. *
  57. * Copyright (c) 2009-2013 The MathJax Consortium
  58. *
  59. * Licensed under the Apache License, Version 2.0 (the "License");
  60. * you may not use this file except in compliance with the License.
  61. * You may obtain a copy of the License at
  62. *
  63. * http://www.apache.org/licenses/LICENSE-2.0
  64. *
  65. * Unless required by applicable law or agreed to in writing, software
  66. * distributed under the License is distributed on an "AS IS" BASIS,
  67. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  68. * See the License for the specific language governing permissions and
  69. * limitations under the License.
  70. */(function(c,h){var g=c.CombineConfig("TeX.noErrors",{disabled:!1,multiLine:!0,inlineDelimiters:["",""],style:{"font-size":"90%","text-align":"left",color:"black",padding:"1px 3px",border:"1px solid"}});MathJax.Extension["TeX/noErrors"]={version:"2.2",config:g};c.Register.StartupHook("TeX Jax Ready",function(){var a=MathJax.InputJax.TeX.formatError;MathJax.InputJax.TeX.Augment({formatError:function(l,f,k,b){if(g.disabled)return a.apply(this,arguments);var d=l.message.replace(/\n.*/,"");c.signal.Post(["TeX Jax - parse error",d,f,k,b]);var d=g.inlineDelimiters,e=k||g.multiLine;k||(f=d[0]+f+d[1]);f=e?f.replace(/ /g,"\u00a0"):f.replace(/\n/g," ");return MathJax.ElementJax.mml.merror(f).With({isError:!0,multiLine:e})}})});c.Register.StartupHook("HTML-CSS Jax Config",function(){c.Config({"HTML-CSS":{styles:{".MathJax .noError":c.Insert({"vertical-align":c.Browser.isMSIE&&g.multiLine?"-2px":""},g.style)}}})});c.Register.StartupHook("HTML-CSS Jax Ready",function(){var a=MathJax.ElementJax.mml,c=MathJax.OutputJax["HTML-CSS"],f=a.math.prototype.toHTML,k=a.merror.prototype.toHTML;a.math.Augment({toHTML:function(b,d){var e=this.data[0];e&&e.data[0]&&e.data[0].isError?(b.style.fontSize="",b=this.HTMLcreateSpan(b),b.bbox=e.data[0].toHTML(b).bbox):b=f.call(this,b,d);return b}});a.merror.Augment({toHTML:function(b){if(!this.isError)return k.call(this,b);b=this.HTMLcreateSpan(b);b.className="noError";this.multiLine&&(b.style.display="inline-block");for(var d=this.data[0].data[0].data.join("").split(/\n/),e=0,a=d.length;e<a;e++)c.addText(b,d[e]),e!==a-1&&c.addElement(b,"br",{isMathJax:!0});d=c.getHD(b.parentNode);e=c.getW(b.parentNode);if(1<a){var a=(d.h+d.d)/2,f=c.TeX.x_height/2;b.parentNode.style.verticalAlign=c.Em(d.d+(f-a));d.h=f+a;d.d=a-f}b.bbox={h:d.h,d:d.d,w:e,lw:0,rw:e};return b}})});c.Register.StartupHook("SVG Jax Config",function(){c.Config({SVG:{styles:{".MathJax_SVG .noError":c.Insert({"vertical-align":c.Browser.isMSIE&&g.multiLine?"-2px":""},g.style)}}})});c.Register.StartupHook("SVG Jax Ready",function(){var a=MathJax.ElementJax.mml,c=a.math.prototype.toSVG,f=a.merror.prototype.toSVG;a.math.Augment({toSVG:function(a,b){var d=this.data[0];return a=d&&d.data[0]&&d.data[0].isError?d.data[0].toSVG(a):c.call(this,a,b)}});a.merror.Augment({toSVG:function(a){if(!this.isError||"math"!==this.Parent().type)return f.call(this,a);a=h.addElement(a,"span",{className:"noError",isMathJax:!0});this.multiLine&&(a.style.display="inline-block");for(var b=this.data[0].data[0].data.join("").split(/\n/),d=0,e=b.length;d<e;d++)h.addText(a,b[d]),d!==e-1&&h.addElement(a,"br",{isMathJax:!0});1<e&&(b=a.offsetHeight/2,a.style.verticalAlign=-b+b/e+"px");return a}})});c.Register.StartupHook("NativeMML Jax Ready",function(){var a=MathJax.ElementJax.mml,c=MathJax.Extension["TeX/noErrors"].config,f=a.math.prototype.toNativeMML,g=a.merror.prototype.toNativeMML;a.math.Augment({toNativeMML:function(b){var a=this.data[0];return b=a&&a.data[0]&&a.data[0].isError?a.data[0].toNativeMML(b):f.call(this,b)}});a.merror.Augment({toNativeMML:function(b){if(!this.isError)return g.call(this,b);b=b.appendChild(document.createElement("span"));for(var a=this.data[0].data[0].data.join("").split(/\n/),e=0,f=a.length;e<f;e++)b.appendChild(document.createTextNode(a[e])),e!==f-1&&b.appendChild(document.createElement("br"));this.multiLine&&(b.style.display="inline-block",1<f&&(b.style.verticalAlign="middle"));for(var h in c.style)c.style.hasOwnProperty(h)&&(a=h.replace(/-./g,function(a){return a.charAt(1).toUpperCase()}),b.style[a]=c.style[h]);return b}})});c.Startup.signal.Post("TeX noErrors Ready")})(MathJax.Hub,MathJax.HTML);MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/noErrors.js");