www

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

commit d5cedc55c99e87627e4da311b6f71c07154cd185
parent 3900936f63c2e95a1371759d2c8bc6e5fdaec110
Author: Eddie Kohler <ekohler@gmail.com>
Date:   Thu,  8 Dec 2016 15:00:57 -0500

Support "mu" units for sizes.

18mu is 1em.

And use emPerEx when converting ex to em, rather than xHeight.
(Previously some places used emPerEx and others used xHeight.)

Diffstat:
Msrc/Parser.js | 2+-
Msrc/buildHTML.js | 44+++++++++++++++-----------------------------
Mtest/katex-spec.js | 6++++++
3 files changed, 22 insertions(+), 30 deletions(-)

diff --git a/src/Parser.js b/src/Parser.js @@ -733,7 +733,7 @@ Parser.prototype.parseSizeGroup = function(optional) { number: +(match[1] + match[2]), // sign + magnitude, cast to number unit: match[3], }; - if (data.unit !== "em" && data.unit !== "ex") { + if (data.unit !== "em" && data.unit !== "ex" && data.unit !== "mu") { throw new ParseError("Invalid unit: '" + data.unit + "'", res); } return new ParseFuncOrArgument( diff --git a/src/buildHTML.js b/src/buildHTML.js @@ -543,6 +543,16 @@ groupTypes.genfrac = function(group, options) { options); }; +var calculateSize = function(sizeValue, style) { + var x = sizeValue.number; + if (sizeValue.unit === "ex") { + x *= style.metrics.emPerEx; + } else if (sizeValue.unit === "mu") { + x /= 18; + } + return x; +}; + groupTypes.array = function(group, options) { var r; var c; @@ -589,18 +599,7 @@ groupTypes.array = function(group, options) { var gap = 0; if (group.value.rowGaps[r]) { - gap = group.value.rowGaps[r].value; - switch (gap.unit) { - case "em": - gap = gap.number; - break; - case "ex": - gap = gap.number * style.metrics.emPerEx; - break; - default: - console.error("Can't handle unit " + gap.unit); - gap = 0; - } + gap = calculateSize(group.value.rowGaps[r].value, style); if (gap > 0) { // \@argarraycr gap += arstrutDepth; if (depth < gap) { @@ -1269,21 +1268,11 @@ groupTypes.rule = function(group, options) { // Calculate the shift, width, and height of the rule, and account for units var shift = 0; if (group.value.shift) { - shift = group.value.shift.number; - if (group.value.shift.unit === "ex") { - shift *= style.metrics.xHeight; - } + shift = calculateSize(group.value.shift, style); } - var width = group.value.width.number; - if (group.value.width.unit === "ex") { - width *= style.metrics.xHeight; - } - - var height = group.value.height.number; - if (group.value.height.unit === "ex") { - height *= style.metrics.xHeight; - } + var width = calculateSize(group.value.width, style); + var height = calculateSize(group.value.height, style); // The sizes of rules are absolute, so make it larger if we are in a // smaller style. @@ -1311,10 +1300,7 @@ groupTypes.kern = function(group, options) { var dimension = 0; if (group.value.dimension) { - dimension = group.value.dimension.number; - if (group.value.dimension.unit === "ex") { - dimension *= style.metrics.xHeight; - } + dimension = calculateSize(group.value.dimension, style); } dimension /= style.sizeMultiplier; diff --git a/test/katex-spec.js b/test/katex-spec.js @@ -977,15 +977,18 @@ describe("A rule parser", function() { describe("A kern parser", function() { var emKern = "\\kern{1em}"; var exKern = "\\kern{1ex}"; + var muKern = "\\kern{1mu}"; var badUnitRule = "\\kern{1px}"; var noNumberRule = "\\kern{em}"; it("should list the correct units", function() { var emParse = getParsed(emKern)[0]; var exParse = getParsed(exKern)[0]; + var muParse = getParsed(muKern)[0]; expect(emParse.value.dimension.unit).toEqual("em"); expect(exParse.value.dimension.unit).toEqual("ex"); + expect(muParse.value.dimension.unit).toEqual("mu"); }); it("should not parse invalid units", function() { @@ -1007,15 +1010,18 @@ describe("A kern parser", function() { describe("A non-braced kern parser", function() { var emKern = "\\kern1em"; var exKern = "\\kern 1 ex"; + var muKern = "\\kern 1mu"; var badUnitRule = "\\kern1px"; var noNumberRule = "\\kern em"; it("should list the correct units", function() { var emParse = getParsed(emKern)[0]; var exParse = getParsed(exKern)[0]; + var muParse = getParsed(muKern)[0]; expect(emParse.value.dimension.unit).toEqual("em"); expect(exParse.value.dimension.unit).toEqual("ex"); + expect(muParse.value.dimension.unit).toEqual("mu"); }); it("should not parse invalid units", function() {