Add \bbox macro that allows you to set background colors, padding, and borders for math formulas

This commit is contained in:
Davide P. Cervone 2011-04-26 15:28:37 -04:00
parent 8aa2e2a3f2
commit 18734b5cce
12 changed files with 122 additions and 16 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

16
extensions/TeX/bbox.js Normal file
View File

@ -0,0 +1,16 @@
/*
* /MathJax/extensions/TeX/bbox.js
*
* Copyright (c) 2010 Design Science, Inc.
*
* Part of the MathJax library.
* See http://www.mathjax.org for details.
*
* Licensed under the Apache License, Version 2.0;
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*/
MathJax.Extension["TeX/bbox"]={version:"1.1"};MathJax.Hub.Register.StartupHook("TeX Jax Ready",function(){var b=MathJax.InputJax.TeX,a=MathJax.ElementJax.mml;b.Definitions.macros.bbox="BBox";b.Parse.Augment({BBox:function(e){var n=this.GetBrackets(e),m=this.ParseArg(e);var j=n.split(/,/),g,d,c;for(var k in j){var f=j[k].replace(/^\s+/,"").replace(/\s+$/,"");var l=f.match(/^(\.\d+|\d+(\.\d*)?)(pt|em|ex|mu|px|in|cm|mm)$/);if(l){var h=l[1]+l[3];if(g){b.Error("Padding specified twice in "+e)}g={height:"+"+h,depth:"+"+h,lspace:h,width:"+"+(2*l[1])+l[3]}}else{if(f.match(/^([a-z0-9]+|\#[0-9a-f]{6}|\#[0-9a-f]{3})$/i)){if(d){b.Error("Background specified twice in "+e)}d=f}else{if(f.match(/^[-a-z]+:/i)){if(c){b.Error("Style specified twice in "+e)}c=f}else{if(f!==""){b.Error("'"+f+"' doesn't look like a color, a padding dimension, or a style")}}}}}if(g){m=a.mpadded(m).With(g)}if(d||c){m=a.mstyle(m).With({mathbackground:d,style:c})}this.Push(m)}});MathJax.Hub.Startup.signal.Post("TeX bbox Ready")});MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/bbox.js");

View File

@ -12,5 +12,5 @@
* http://www.apache.org/licenses/LICENSE-2.0
*/
MathJax.InputJax.TeX=MathJax.InputJax({id:"TeX",version:"1.1.1",directory:MathJax.InputJax.directory+"/TeX",extensionDir:MathJax.InputJax.extensionDir+"/TeX",config:{TagSide:"right",TagIndent:"0.8em",MultLineWidth:"85%"}});MathJax.InputJax.TeX.Register("math/tex");MathJax.InputJax.TeX.loadComplete("config.js");
MathJax.InputJax.TeX=MathJax.InputJax({id:"TeX",version:"1.1.2",directory:MathJax.InputJax.directory+"/TeX",extensionDir:MathJax.InputJax.extensionDir+"/TeX",config:{TagSide:"right",TagIndent:"0.8em",MultLineWidth:"85%"}});MathJax.InputJax.TeX.Register("math/tex");MathJax.InputJax.TeX.loadComplete("config.js");

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,90 @@
/*************************************************************
*
* MathJax/extensions/TeX/bbox.js
*
* This file implements the \bbox macro, which creates an box that
* can be styled (for background colors, and so on). You can include
* an optional dimension that tells how much extra padding to include
* around the bounding box for the mathematics, or a color specification
* for the background color to use, or both. E.g.,
*
* \bbox[2pt]{x+y} % an invisible box around x+y with 2pt of extra space
* \bbox[green]{x+y} % a green box around x+y
* \bbox[green,2pt]{x+y} % a green box with 2pt of extra space
*
* You can also specify style attributes, for example
*
* \bbox[red,border:3px solid blue,5px]{x+y}
*
* would give a red background with a 3px solid blue border that has 5px
* of padding between the border and the mathematics. Note that not all
* output formats support the style specifications. In particular, the
* NativeMML output depends on the browser to render the attributes, and
* not all MathML renderers will honor them (e.g., MathPlayer2 doesn't
* render border styles).
*
* This file will be loaded automatically when \bbox is first used.
*
* ---------------------------------------------------------------------
*
* Copyright (c) 2011 Design Science, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
MathJax.Extension["TeX/bbox"] = {
version: "1.1"
};
MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
var TEX = MathJax.InputJax.TeX,
MML = MathJax.ElementJax.mml;
TEX.Definitions.macros.bbox = "BBox";
TEX.Parse.Augment({
BBox: function (name) {
var bbox = this.GetBrackets(name),
math = this.ParseArg(name);
var parts = bbox.split(/,/), def, background, style;
for (var i in parts) {
var part = parts[i].replace(/^\s+/,'').replace(/\s+$/,'');
var match = part.match(/^(\.\d+|\d+(\.\d*)?)(pt|em|ex|mu|px|in|cm|mm)$/);
if (match) {
var pad = match[1]+match[3];
if (def) {TEX.Error("Padding specified twice in "+name)}
def = {height:"+"+pad, depth:"+"+pad, lspace:pad, width:"+"+(2*match[1])+match[3]};
} else if (part.match(/^([a-z0-9]+|\#[0-9a-f]{6}|\#[0-9a-f]{3})$/i)) {
if (background) {TEX.Error("Background specified twice in "+name)}
background = part;
} else if (part.match(/^[-a-z]+:/i)) {
if (style) {TEX.Error("Style specified twice in "+name)}
style = part;
} else if (part !== "") {
TEX.Error("'"+part+"' doesn't look like a color, a padding dimension, or a style");
}
}
if (def) {math = MML.mpadded(math).With(def)}
if (background || style) {
math = MML.mstyle(math).With({mathbackground:background, style:style});
}
this.Push(math);
}
});
MathJax.Hub.Startup.signal.Post("TeX bbox Ready");
});
MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/bbox.js");

View File

@ -24,7 +24,7 @@
MathJax.InputJax.TeX = MathJax.InputJax({
id: "TeX",
version: "1.1.1",
version: "1.1.2",
directory: MathJax.InputJax.directory + "/TeX",
extensionDir: MathJax.InputJax.extensionDir + "/TeX",

View File

@ -857,7 +857,7 @@
'class': ['Extension','HTML'],
style: ['Extension','HTML'],
cssId: ['Extension','HTML'],
// bbox: ['Extension','bbox'],
bbox: ['Extension','bbox'],
require: 'Require'