Skip to content

Commit

Permalink
Correct handling of unbraced kerns followed by spaces.
Browse files Browse the repository at this point in the history
Did not realize that `Parser.nextToken.text` can contain spaces
(it can). Handle that.
  • Loading branch information
kohler committed Jun 30, 2017
1 parent b866cd5 commit 07c527e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ Parser.prototype.parseSizeGroup = function(optional) {
let res;
if (!optional && this.nextToken.text !== "{") {
res = this.parseRegexGroup(
/^[-+]? *(?:$|\d+|\d+\.\d*|\.\d*) *[a-z]{0,2}$/, "size");
/^[-+]? *(?:$|\d+|\d+\.\d*|\.\d*) *[a-z]{0,2}\s*$/, "size");
} else {
res = this.parseStringGroup("size", optional);
}
Expand Down
28 changes: 28 additions & 0 deletions test/katex-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1004,17 +1004,20 @@ describe("A kern parser", function() {
const emKern = "\\kern{1em}";
const exKern = "\\kern{1ex}";
const muKern = "\\kern{1mu}";
const abKern = "a\\kern{1em}b";
const badUnitRule = "\\kern{1px}";
const noNumberRule = "\\kern{em}";

it("should list the correct units", function() {
const emParse = getParsed(emKern)[0];
const exParse = getParsed(exKern)[0];
const muParse = getParsed(muKern)[0];
const abParse = getParsed(abKern)[1];

expect(emParse.value.dimension.unit).toEqual("em");
expect(exParse.value.dimension.unit).toEqual("ex");
expect(muParse.value.dimension.unit).toEqual("mu");
expect(abParse.value.dimension.unit).toEqual("em");
});

it("should not parse invalid units", function() {
Expand All @@ -1037,17 +1040,42 @@ describe("A non-braced kern parser", function() {
const emKern = "\\kern1em";
const exKern = "\\kern 1 ex";
const muKern = "\\kern 1mu";
const abKern1 = "a\\mkern1mub";
const abKern2 = "a\\kern-1mub";
const abKern3 = "a\\kern-1mu b";
const badUnitRule = "\\kern1px";
const noNumberRule = "\\kern em";

it("should list the correct units", function() {
const emParse = getParsed(emKern)[0];
const exParse = getParsed(exKern)[0];
const muParse = getParsed(muKern)[0];
const abParse1 = getParsed(abKern1)[1];
const abParse2 = getParsed(abKern2)[1];
const abParse3 = getParsed(abKern3)[1];

expect(emParse.value.dimension.unit).toEqual("em");
expect(exParse.value.dimension.unit).toEqual("ex");
expect(muParse.value.dimension.unit).toEqual("mu");
expect(abParse1.value.dimension.unit).toEqual("mu");
expect(abParse2.value.dimension.unit).toEqual("mu");
expect(abParse3.value.dimension.unit).toEqual("mu");
});

it("should parse elements on either side of a kern", function() {
const abParse1 = getParsed(abKern1);
const abParse2 = getParsed(abKern2);
const abParse3 = getParsed(abKern3);

expect(abParse1.length).toEqual(3);
expect(abParse1[0].value).toEqual("a");
expect(abParse1[2].value).toEqual("b");
expect(abParse2.length).toEqual(3);
expect(abParse2[0].value).toEqual("a");
expect(abParse2[2].value).toEqual("b");
expect(abParse3.length).toEqual(3);
expect(abParse3[0].value).toEqual("a");
expect(abParse3[2].value).toEqual("b");
});

it("should not parse invalid units", function() {
Expand Down

0 comments on commit 07c527e

Please sign in to comment.