bbox.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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/bbox.js
  6. *
  7. * This file implements the \bbox macro, which creates an box that
  8. * can be styled (for background colors, and so on). You can include
  9. * an optional dimension that tells how much extra padding to include
  10. * around the bounding box for the mathematics, or a color specification
  11. * for the background color to use, or both. E.g.,
  12. *
  13. * \bbox[2pt]{x+y} % an invisible box around x+y with 2pt of extra space
  14. * \bbox[green]{x+y} % a green box around x+y
  15. * \bbox[green,2pt]{x+y} % a green box with 2pt of extra space
  16. *
  17. * You can also specify style attributes, for example
  18. *
  19. * \bbox[red,border:3px solid blue,5px]{x+y}
  20. *
  21. * would give a red background with a 3px solid blue border that has 5px
  22. * of padding between the border and the mathematics. Note that not all
  23. * output formats support the style specifications. In particular, the
  24. * NativeMML output depends on the browser to render the attributes, and
  25. * not all MathML renderers will honor them (e.g., MathPlayer2 doesn't
  26. * render border styles).
  27. *
  28. * This file will be loaded automatically when \bbox is first used.
  29. *
  30. * ---------------------------------------------------------------------
  31. *
  32. * Copyright (c) 2011-2013 The MathJax Consortium
  33. *
  34. * Licensed under the Apache License, Version 2.0 (the "License");
  35. * you may not use this file except in compliance with the License.
  36. * You may obtain a copy of the License at
  37. *
  38. * http://www.apache.org/licenses/LICENSE-2.0
  39. *
  40. * Unless required by applicable law or agreed to in writing, software
  41. * distributed under the License is distributed on an "AS IS" BASIS,
  42. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  43. * See the License for the specific language governing permissions and
  44. * limitations under the License.
  45. */MathJax.Extension["TeX/bbox"]={version:"2.2"};MathJax.Hub.Register.StartupHook("TeX Jax Ready",function(){var d=MathJax.InputJax.TeX,l=MathJax.ElementJax.mml;d.Definitions.Add({macros:{bbox:"BBox"}},null,!0);d.Parse.Augment({BBox:function(b){var g=this.GetBrackets(b,""),e=this.ParseArg(b),g=g.split(/,/),a,h,k,m;for(m in g){var c=g[m].replace(/^\s+/,"").replace(/\s+$/,""),f=c.match(/^(\.\d+|\d+(\.\d*)?)(pt|em|ex|mu|px|in|cm|mm)$/);f?(a&&d.Error(["MultipleBBoxProperty","%1 specified twice in %2","Padding",b]),a=f[1]+f[3],a={height:"+"+a,depth:"+"+a,lspace:a,width:"+"+2*f[1]+f[3]}):c.match(/^([a-z0-9]+|\#[0-9a-f]{6}|\#[0-9a-f]{3})$/i)?(h&&d.Error(["MultipleBBoxProperty","%1 specified twice in %2","Background",b]),h=c):c.match(/^[-a-z]+:/i)?(k&&d.Error(["MultipleBBoxProperty","%1 specified twice in %2","Style",b]),k=this.BBoxStyle(c)):""!==c&&d.Error(["InvalidBBoxProperty","'%1' doesn't look like a color, a padding dimension, or a style",c])}a&&(e=l.mpadded(e).With(a));if(h||k)e=l.mstyle(e).With({mathbackground:h,style:k});this.Push(e)},BBoxStyle:function(b){return b}});MathJax.Hub.Startup.signal.Post("TeX bbox Ready")});MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/bbox.js");