mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-05 03:08:40 +00:00
Fix \nobreakspace, refactor "regular space" checking (#1200)
* Fix \nobreakspace, refactor "regular space" checking Fix #1199 by adding \nobreakspace to the list of commands/symbols that behave like a regular space character. Refactor to put that list in one place, and use an object so it checks instantly instead of sequentially. * Copy test from #1201
This commit is contained in:
committed by
Kevin Barabash
parent
017eb7b91d
commit
abfb641d7a
@@ -682,6 +682,16 @@ const spacingFunctions: {[string]: {| size: string, className: string |}} = {
|
||||
},
|
||||
};
|
||||
|
||||
// A lookup table to determine whether a spacing function/symbol should be
|
||||
// treated like a regular space character.
|
||||
const regularSpace: {[string]: boolean} = {
|
||||
" ": true,
|
||||
"\\ ": true,
|
||||
"~": true,
|
||||
"\\space": true,
|
||||
"\\nobreakspace": true,
|
||||
};
|
||||
|
||||
/**
|
||||
* Maps TeX font commands to objects containing:
|
||||
* - variant: string used for "mathvariant" attribute in buildMathML.js
|
||||
@@ -777,4 +787,5 @@ export default {
|
||||
svgData,
|
||||
tryCombineChars,
|
||||
spacingFunctions,
|
||||
regularSpace,
|
||||
};
|
||||
|
@@ -419,8 +419,7 @@ groupTypes.supsub = function(group, options) {
|
||||
};
|
||||
|
||||
groupTypes.spacing = function(group, options) {
|
||||
if (group.value === "\\ " || group.value === "\\space" ||
|
||||
group.value === " " || group.value === "~") {
|
||||
if (buildCommon.regularSpace.hasOwnProperty(group.value)) {
|
||||
// Spaces are generated by adding an actual space. Each of these
|
||||
// things has an entry in the symbols table, so these will be turned
|
||||
// into appropriate outputs.
|
||||
|
@@ -228,8 +228,7 @@ groupTypes.supsub = function(group, options) {
|
||||
groupTypes.spacing = function(group) {
|
||||
let node;
|
||||
|
||||
if (group.value === "\\ " || group.value === "\\space" ||
|
||||
group.value === " " || group.value === "~") {
|
||||
if (buildCommon.regularSpace.hasOwnProperty(group.value)) {
|
||||
node = new mathMLTree.MathNode(
|
||||
"mtext", [new mathMLTree.TextNode("\u00a0")]);
|
||||
} else {
|
||||
|
@@ -875,6 +875,11 @@ describe("A text parser", function() {
|
||||
expect(textWithEmbeddedMath).toParse();
|
||||
});
|
||||
|
||||
it("should parse spacing functions", function() {
|
||||
expect("a b\\, \\; \\! \\: ~ \\thinspace \\medspace \\quad \\ ").toBuild();
|
||||
expect("\\enspace \\thickspace \\qquad \\space \\nobreakspace").toBuild();
|
||||
});
|
||||
|
||||
it("should omit spaces after commands", function() {
|
||||
expect("\\text{\\textellipsis !}")
|
||||
.toParseLike("\\text{\\textellipsis!}");
|
||||
@@ -2999,11 +3004,11 @@ describe("The \\mathchoice function", function() {
|
||||
|
||||
describe("Symbols", function() {
|
||||
it("should parse \\text{\\i\\j}", () => {
|
||||
expect("\\text{\\i\\j}").toParse();
|
||||
expect("\\text{\\i\\j}").toBuild();
|
||||
});
|
||||
|
||||
it("should parse spacing functions in math or text mode", () => {
|
||||
expect("A\\;B\\,C\\nobreakspace \\text{A\\;B\\,C\\nobreakspace}").toParse();
|
||||
expect("A\\;B\\,C\\nobreakspace \\text{A\\;B\\,C\\nobreakspace}").toBuild();
|
||||
});
|
||||
|
||||
it("should render ligature commands like their unicode characters", () => {
|
||||
|
Reference in New Issue
Block a user