fix(builder): combine characters together in all expressions (#2080)
* Combine characters together in all expressions Call `tryCombineChars` in `buildExpression` * update screenshots, exclude 'coverage' from lint * update MathML snapshots * don't combine two 'mbin's or two 'mord's * update screenshots * update screenshots Co-authored-by: ylemkimon <y@ylem.kim> Co-authored-by: Kevin Barabash <kevinb@khanacademy.org>
@@ -243,6 +243,15 @@ const canCombine = (prev: SymbolNode, next: SymbolNode) => {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If prev and next both are just "mbin"s or "mord"s we don't combine them
|
||||
// so that the proper spacing can be preserved.
|
||||
if (prev.classes.length === 1) {
|
||||
const cls = prev.classes[0];
|
||||
if (cls === "mbin" || cls === "mord") {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (const style in prev.style) {
|
||||
if (prev.style.hasOwnProperty(style)
|
||||
&& prev.style[style] !== next.style[style]) {
|
||||
@@ -261,7 +270,7 @@ const canCombine = (prev: SymbolNode, next: SymbolNode) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Combine consequetive domTree.symbolNodes into a single symbolNode.
|
||||
* Combine consecutive domTree.symbolNodes into a single symbolNode.
|
||||
* Note: this function mutates the argument.
|
||||
*/
|
||||
const tryCombineChars = (chars: HtmlDomNode[]): HtmlDomNode[] => {
|
||||
|
@@ -74,6 +74,9 @@ export const buildExpression = function(
|
||||
}
|
||||
}
|
||||
|
||||
// Combine consecutive domTree.symbolNodes into a single symbolNode.
|
||||
buildCommon.tryCombineChars(groups);
|
||||
|
||||
// If `expression` is a partial group, let the parent handle spacings
|
||||
// to avoid processing groups multiple times.
|
||||
if (!isRealGroup) {
|
||||
|
@@ -93,8 +93,7 @@ export const htmlBuilder: HtmlBuilderSupSub<"op"> = (grp, options) => {
|
||||
base = inner[0];
|
||||
base.classes[0] = "mop"; // replace old mclass
|
||||
} else {
|
||||
base = buildCommon.makeSpan(
|
||||
["mop"], buildCommon.tryCombineChars(inner), options);
|
||||
base = buildCommon.makeSpan(["mop"], inner, options);
|
||||
}
|
||||
} else {
|
||||
// Otherwise, this is a text operator. Build the text from the
|
||||
|
@@ -63,8 +63,7 @@ defineFunction({
|
||||
htmlBuilder(group, options) {
|
||||
const newOptions = optionsWithFont(group, options);
|
||||
const inner = html.buildExpression(group.body, newOptions, true);
|
||||
return buildCommon.makeSpan(
|
||||
["mord", "text"], buildCommon.tryCombineChars(inner), newOptions);
|
||||
return buildCommon.makeSpan(["mord", "text"], inner, newOptions);
|
||||
},
|
||||
mathmlBuilder(group, options) {
|
||||
const newOptions = optionsWithFont(group, options);
|
||||
|
@@ -413,22 +413,7 @@ exports[`A font parser \\boldsymbol should inherit mbin/mrel from argument 1`] =
|
||||
"skew": 0,
|
||||
"style": {
|
||||
},
|
||||
"text": "+",
|
||||
"width": 0.89444
|
||||
},
|
||||
{
|
||||
"classes": [
|
||||
"mord",
|
||||
"mathbf"
|
||||
],
|
||||
"depth": 0.13333,
|
||||
"height": 0.63333,
|
||||
"italic": 0,
|
||||
"maxFontSize": 1,
|
||||
"skew": 0,
|
||||
"style": {
|
||||
},
|
||||
"text": "+",
|
||||
"text": "++",
|
||||
"width": 0.89444
|
||||
}
|
||||
],
|
||||
@@ -489,21 +474,6 @@ exports[`A font parser \\boldsymbol should inherit mbin/mrel from argument 1`] =
|
||||
"attributes": {
|
||||
},
|
||||
"children": [
|
||||
{
|
||||
"classes": [
|
||||
"mord",
|
||||
"boldsymbol"
|
||||
],
|
||||
"depth": 0,
|
||||
"height": 0.44444,
|
||||
"italic": 0,
|
||||
"maxFontSize": 1,
|
||||
"skew": 0,
|
||||
"style": {
|
||||
},
|
||||
"text": "x",
|
||||
"width": 0.65903
|
||||
},
|
||||
{
|
||||
"classes": [
|
||||
"mord",
|
||||
@@ -511,28 +481,13 @@ exports[`A font parser \\boldsymbol should inherit mbin/mrel from argument 1`] =
|
||||
],
|
||||
"depth": 0.19444,
|
||||
"height": 0.44444,
|
||||
"italic": 0.03704,
|
||||
"maxFontSize": 1,
|
||||
"skew": 0,
|
||||
"style": {
|
||||
},
|
||||
"text": "y",
|
||||
"width": 0.59028
|
||||
},
|
||||
{
|
||||
"classes": [
|
||||
"mord",
|
||||
"boldsymbol"
|
||||
],
|
||||
"depth": 0,
|
||||
"height": 0.44444,
|
||||
"italic": 0.04213,
|
||||
"maxFontSize": 1,
|
||||
"skew": 0,
|
||||
"style": {
|
||||
},
|
||||
"text": "z",
|
||||
"width": 0.55509
|
||||
"text": "xyz",
|
||||
"width": 0.65903
|
||||
}
|
||||
],
|
||||
"classes": [
|
||||
@@ -1158,10 +1113,7 @@ exports[`Extending katex by new fonts and symbols Add new font class to new exte
|
||||
<span class="sizing reset-size6 size3 mtight">
|
||||
<span class="mord mtight">
|
||||
<span class="mord mockEasternArabicFont-Regular mtight">
|
||||
۱
|
||||
</span>
|
||||
<span class="mord mockEasternArabicFont-Regular mtight">
|
||||
۱
|
||||
۱۱
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 41 KiB |
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 7.0 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 7.1 KiB |
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 6.4 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 9.9 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 41 KiB |
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 41 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 9.9 KiB |
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 24 KiB |