From 72a6a670bfd3d07cd3369b41b4c87600a838cce2 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Mon, 18 Aug 2014 11:09:09 -0400 Subject: [PATCH 1/2] Add ability to process units of px in \\[...] (not particularly accurate, however). Issue #890 --- unpacked/jax/input/TeX/jax.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/unpacked/jax/input/TeX/jax.js b/unpacked/jax/input/TeX/jax.js index 2c8166f54..bc1cd5873 100644 --- a/unpacked/jax/input/TeX/jax.js +++ b/unpacked/jax/input/TeX/jax.js @@ -1654,8 +1654,7 @@ var n; if (this.string.charAt(this.i) === "[") { n = this.GetBrackets(name,"").replace(/ /g,""); - if (n && - !n.match(/^((-?(\.\d+|\d+(\.\d*)?))(pt|em|ex|mu|mm|cm|in|pc))$/)) { + if (n && !this.matchDimen(n)) { TEX.Error(["BracketMustBeDimension", "Bracket argument to %1 must be a dimension",name]); } @@ -1676,12 +1675,16 @@ } }, emPerInch: 7.2, + matchDimen: function (dim) { + return dim.match(/^(-?(?:\.\d+|\d+(?:\.\d*)?))(px|pt|em|ex|mu|pc|in|mm|cm)$/); + }, dimen2em: function (dim) { - var match = dim.match(/^(-?(?:\.\d+|\d+(?:\.\d*)?))(pt|em|ex|mu|pc|in|mm|cm)/); + var match = this.matchDimen(dim); var m = parseFloat(match[1]||"1"), unit = match[2]; if (unit === "em") {return m} if (unit === "ex") {return m * .43} if (unit === "pt") {return m / 10} // 10 pt to an em + if (unit === "px") {return m / 12} // assume 12px per em (hack) if (unit === "pc") {return m * 1.2} // 12 pt to a pc if (unit === "in") {return m * this.emPerInch} if (unit === "cm") {return m * this.emPerInch / 2.54} // 2.54 cm to an inch From 4db6b017ee5fc0e1cf3d3864aafb9c9500f914e1 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Mon, 18 Aug 2014 11:29:21 -0400 Subject: [PATCH 2/2] Make px-per-inch configurable and use 72dpi (pt = px in this case) --- unpacked/jax/input/TeX/jax.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/unpacked/jax/input/TeX/jax.js b/unpacked/jax/input/TeX/jax.js index bc1cd5873..20c38b14b 100644 --- a/unpacked/jax/input/TeX/jax.js +++ b/unpacked/jax/input/TeX/jax.js @@ -1675,6 +1675,7 @@ } }, emPerInch: 7.2, + pxPerInch: 72, matchDimen: function (dim) { return dim.match(/^(-?(?:\.\d+|\d+(?:\.\d*)?))(px|pt|em|ex|mu|pc|in|mm|cm)$/); }, @@ -1684,8 +1685,8 @@ if (unit === "em") {return m} if (unit === "ex") {return m * .43} if (unit === "pt") {return m / 10} // 10 pt to an em - if (unit === "px") {return m / 12} // assume 12px per em (hack) if (unit === "pc") {return m * 1.2} // 12 pt to a pc + if (unit === "px") {return m * this.emPerInch / this.pxPerInch} if (unit === "in") {return m * this.emPerInch} if (unit === "cm") {return m * this.emPerInch / 2.54} // 2.54 cm to an inch if (unit === "mm") {return m * this.emPerInch / 25.4} // 10 mm to a cm