www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

bbox.js (3998B)


      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/bbox.js
      7  *  
      8  *  This file implements the \bbox macro, which creates an box that
      9  *  can be styled (for background colors, and so on).  You can include
     10  *  an optional dimension that tells how much extra padding to include
     11  *  around the bounding box for the mathematics, or a color specification 
     12  *  for the background color to use, or both.  E.g.,
     13  *  
     14  *    \bbox[2pt]{x+y}        %  an invisible box around x+y with 2pt of extra space
     15  *    \bbox[green]{x+y}      %  a green box around x+y
     16  *    \bbox[green,2pt]{x+y}  %  a green box with 2pt of extra space
     17  *
     18  *  You can also specify style attributes, for example
     19  *  
     20  *    \bbox[red,border:3px solid blue,5px]{x+y}
     21  *  
     22  *  would give a red background with a 3px solid blue border that has 5px
     23  *  of padding between the border and the mathematics.  Note that not all
     24  *  output formats support the style specifications.  In particular, the
     25  *  NativeMML output depends on the browser to render the attributes, and
     26  *  not all MathML renderers will honor them (e.g., MathPlayer2 doesn't
     27  *  render border styles).
     28  *  
     29  *  This file will be loaded automatically when \bbox is first used.
     30  *
     31  *  ---------------------------------------------------------------------
     32  *  
     33  *  Copyright (c) 2011-2015 The MathJax Consortium
     34  * 
     35  *  Licensed under the Apache License, Version 2.0 (the "License");
     36  *  you may not use this file except in compliance with the License.
     37  *  You may obtain a copy of the License at
     38  * 
     39  *      http://www.apache.org/licenses/LICENSE-2.0
     40  * 
     41  *  Unless required by applicable law or agreed to in writing, software
     42  *  distributed under the License is distributed on an "AS IS" BASIS,
     43  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     44  *  See the License for the specific language governing permissions and
     45  *  limitations under the License.
     46  */
     47 
     48 MathJax.Extension["TeX/bbox"] = {
     49   version: "2.6.0"
     50 };
     51 
     52 MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
     53 
     54   var TEX = MathJax.InputJax.TeX,
     55       MML = MathJax.ElementJax.mml;
     56 
     57   TEX.Definitions.Add({macros: {bbox: "BBox"}},null,true);
     58   
     59   TEX.Parse.Augment({
     60     BBox: function (name) {
     61       var bbox = this.GetBrackets(name,""),
     62           math = this.ParseArg(name);
     63       var parts = bbox.split(/,/), def, background, style;
     64       for (var i = 0, m = parts.length; i < m; i++) {
     65         var part = parts[i].replace(/^\s+/,'').replace(/\s+$/,'');
     66         var match = part.match(/^(\.\d+|\d+(\.\d*)?)(pt|em|ex|mu|px|in|cm|mm)$/);
     67         if (match) {
     68           if (def)
     69             {TEX.Error(["MultipleBBoxProperty","%1 specified twice in %2","Padding",name])}
     70           var pad = match[1]+match[3];
     71           def = {height:"+"+pad, depth:"+"+pad, lspace:pad, width:"+"+(2*match[1])+match[3]};
     72         } else if (part.match(/^([a-z0-9]+|\#[0-9a-f]{6}|\#[0-9a-f]{3})$/i)) {
     73           if (background)
     74             {TEX.Error(["MultipleBBoxProperty","%1 specified twice in %2","Background",name])}
     75           background = part;
     76         } else if (part.match(/^[-a-z]+:/i)) {
     77           if (style)
     78             {TEX.Error(["MultipleBBoxProperty","%1 specified twice in %2", "Style",name])}
     79           style = this.BBoxStyle(part);
     80         } else if (part !== "") {
     81           TEX.Error(
     82             ["InvalidBBoxProperty",
     83             "'%1' doesn't look like a color, a padding dimension, or a style",
     84             part]
     85           );
     86         }
     87       }
     88       if (def) {math = MML.mpadded(math).With(def)}
     89       if (background || style) {
     90         math = MML.mstyle(math).With({mathbackground:background, style:style});
     91       }
     92       this.Push(math);
     93     },
     94     BBoxStyle: function (styles) {return styles}
     95   });
     96 
     97   MathJax.Hub.Startup.signal.Post("TeX bbox Ready");
     98 
     99 });
    100 
    101 MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/bbox.js");