mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-12 22:48:41 +00:00
Implicit \color, explicitly grouped \textcolor (#619)
This commit is contained in:
committed by
Kevin Barabash
parent
ad0abbd4e9
commit
25dde7f841
@@ -166,18 +166,22 @@ beforeEach(function() {
|
||||
|
||||
toParseLike: function(util, baton) {
|
||||
return {
|
||||
compare: function(actual, expected) {
|
||||
compare: function(actual, expected, settings) {
|
||||
const usedSettings = settings ? settings : defaultSettings;
|
||||
|
||||
const result = {
|
||||
pass: true,
|
||||
message: "Parse trees of '" + actual +
|
||||
"' and '" + expected + "' are equivalent",
|
||||
};
|
||||
|
||||
const actualTree = parseAndSetResult(actual, result);
|
||||
const actualTree = parseAndSetResult(actual, result,
|
||||
usedSettings);
|
||||
if (!actualTree) {
|
||||
return result;
|
||||
}
|
||||
const expectedTree = parseAndSetResult(expected, result);
|
||||
const expectedTree = parseAndSetResult(expected, result,
|
||||
usedSettings);
|
||||
if (!expectedTree) {
|
||||
return result;
|
||||
}
|
||||
@@ -726,7 +730,7 @@ describe("A text parser", function() {
|
||||
const textExpression = "\\text{a b}";
|
||||
const noBraceTextExpression = "\\text x";
|
||||
const nestedTextExpression =
|
||||
"\\text{a {b} \\blue{c} \\color{#fff}{x} \\llap{x}}";
|
||||
"\\text{a {b} \\blue{c} \\textcolor{#fff}{x} \\llap{x}}";
|
||||
const spaceTextExpression = "\\text{ a \\ }";
|
||||
const leadingSpaceTextExpression = "\\text {moo}";
|
||||
const badTextExpression = "\\text{a b%}";
|
||||
@@ -799,8 +803,9 @@ describe("A text parser", function() {
|
||||
describe("A color parser", function() {
|
||||
const colorExpression = "\\blue{x}";
|
||||
const newColorExpression = "\\redA{x}";
|
||||
const customColorExpression = "\\color{#fA6}{x}";
|
||||
const badCustomColorExpression = "\\color{bad-color}{x}";
|
||||
const customColorExpression = "\\textcolor{#fA6}{x}";
|
||||
const badCustomColorExpression = "\\textcolor{bad-color}{x}";
|
||||
const oldColorExpression = "\\color{#fA6}xy";
|
||||
|
||||
it("should not fail", function() {
|
||||
expect(colorExpression).toParse();
|
||||
@@ -833,10 +838,26 @@ describe("A color parser", function() {
|
||||
});
|
||||
|
||||
it("should have correct greediness", function() {
|
||||
expect("\\color{red}a").toParse();
|
||||
expect("\\color{red}{\\text{a}}").toParse();
|
||||
expect("\\color{red}\\text{a}").toNotParse();
|
||||
expect("\\color{red}\\frac12").toNotParse();
|
||||
expect("\\textcolor{red}a").toParse();
|
||||
expect("\\textcolor{red}{\\text{a}}").toParse();
|
||||
expect("\\textcolor{red}\\text{a}").toNotParse();
|
||||
expect("\\textcolor{red}\\frac12").toNotParse();
|
||||
});
|
||||
|
||||
it("should use one-argument \\color by default", function() {
|
||||
expect(oldColorExpression).toParseLike("\\textcolor{#fA6}{xy}");
|
||||
});
|
||||
|
||||
it("should use one-argument \\color if requested", function() {
|
||||
expect(oldColorExpression).toParseLike("\\textcolor{#fA6}{xy}", {
|
||||
colorIsTextColor: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("should use two-argument \\color if requested", function() {
|
||||
expect(oldColorExpression).toParseLike("\\textcolor{#fA6}{x}y", {
|
||||
colorIsTextColor: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1178,7 +1199,7 @@ describe("A TeX-compliant parser", function() {
|
||||
it("should fail if there are not enough arguments", function() {
|
||||
const missingGroups = [
|
||||
"\\frac{x}",
|
||||
"\\color{#fff}",
|
||||
"\\textcolor{#fff}",
|
||||
"\\rule{1em}",
|
||||
"\\llap",
|
||||
"\\bigl",
|
||||
@@ -1396,8 +1417,8 @@ describe("A font parser", function() {
|
||||
expect(bbBody[2].value.type).toEqual("font");
|
||||
});
|
||||
|
||||
it("should work with \\color", function() {
|
||||
const colorMathbbParse = getParsed("\\color{blue}{\\mathbb R}")[0];
|
||||
it("should work with \\textcolor", function() {
|
||||
const colorMathbbParse = getParsed("\\textcolor{blue}{\\mathbb R}")[0];
|
||||
expect(colorMathbbParse.value.type).toEqual("color");
|
||||
expect(colorMathbbParse.value.color).toEqual("blue");
|
||||
const body = colorMathbbParse.value.value;
|
||||
@@ -1485,11 +1506,11 @@ describe("An HTML font tree-builder", function() {
|
||||
});
|
||||
|
||||
it("should render a combination of font and color changes", function() {
|
||||
let markup = katex.renderToString("\\color{blue}{\\mathbb R}");
|
||||
let markup = katex.renderToString("\\textcolor{blue}{\\mathbb R}");
|
||||
let span = "<span class=\"mord mathbb\" style=\"color:blue;\">R</span>";
|
||||
expect(markup).toContain(span);
|
||||
|
||||
markup = katex.renderToString("\\mathbb{\\color{blue}{R}}");
|
||||
markup = katex.renderToString("\\mathbb{\\textcolor{blue}{R}}");
|
||||
span = "<span class=\"mord mathbb\" style=\"color:blue;\">R</span>";
|
||||
expect(markup).toContain(span);
|
||||
});
|
||||
@@ -1649,7 +1670,7 @@ describe("A MathML font tree-builder", function() {
|
||||
});
|
||||
|
||||
it("should render a combination of font and color changes", function() {
|
||||
let tex = "\\color{blue}{\\mathbb R}";
|
||||
let tex = "\\textcolor{blue}{\\mathbb R}";
|
||||
let tree = getParsed(tex);
|
||||
let markup = buildMathML(tree, tex, defaultOptions).toMarkup();
|
||||
let node = "<mstyle mathcolor=\"blue\">" +
|
||||
@@ -1658,7 +1679,7 @@ describe("A MathML font tree-builder", function() {
|
||||
expect(markup).toContain(node);
|
||||
|
||||
// reverse the order of the commands
|
||||
tex = "\\mathbb{\\color{blue}{R}}";
|
||||
tex = "\\mathbb{\\textcolor{blue}{R}}";
|
||||
tree = getParsed(tex);
|
||||
markup = buildMathML(tree, tex, defaultOptions).toMarkup();
|
||||
node = "<mstyle mathcolor=\"blue\">" +
|
||||
|
Reference in New Issue
Block a user