diff --git a/src/buildCommon.js b/src/buildCommon.js index 1e05dcd5..3cc07e53 100644 --- a/src/buildCommon.js +++ b/src/buildCommon.js @@ -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[] => { diff --git a/src/buildHTML.js b/src/buildHTML.js index 362197cb..a13b28bb 100644 --- a/src/buildHTML.js +++ b/src/buildHTML.js @@ -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) { diff --git a/src/functions/op.js b/src/functions/op.js index 96f6254e..35f99434 100644 --- a/src/functions/op.js +++ b/src/functions/op.js @@ -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 diff --git a/src/functions/text.js b/src/functions/text.js index a2d7c803..7acf5434 100644 --- a/src/functions/text.js +++ b/src/functions/text.js @@ -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); diff --git a/test/__snapshots__/katex-spec.js.snap b/test/__snapshots__/katex-spec.js.snap index e5626cb5..8cd15a12 100755 --- a/test/__snapshots__/katex-spec.js.snap +++ b/test/__snapshots__/katex-spec.js.snap @@ -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 - ۱ - - - ۱ + ۱۱ diff --git a/test/screenshotter/images/Arrays-chrome.png b/test/screenshotter/images/Arrays-chrome.png index 670bcc88..ffc0416d 100644 Binary files a/test/screenshotter/images/Arrays-chrome.png and b/test/screenshotter/images/Arrays-chrome.png differ diff --git a/test/screenshotter/images/BoldSymbol-chrome.png b/test/screenshotter/images/BoldSymbol-chrome.png index 44e9a444..c7eca59a 100644 Binary files a/test/screenshotter/images/BoldSymbol-chrome.png and b/test/screenshotter/images/BoldSymbol-chrome.png differ diff --git a/test/screenshotter/images/BoldSymbol-firefox.png b/test/screenshotter/images/BoldSymbol-firefox.png index 3e18b13b..8aa0eb5e 100644 Binary files a/test/screenshotter/images/BoldSymbol-firefox.png and b/test/screenshotter/images/BoldSymbol-firefox.png differ diff --git a/test/screenshotter/images/BoldSymbol-safari.png b/test/screenshotter/images/BoldSymbol-safari.png index 83f2bc30..3dae9d26 100644 Binary files a/test/screenshotter/images/BoldSymbol-safari.png and b/test/screenshotter/images/BoldSymbol-safari.png differ diff --git a/test/screenshotter/images/ColorImplicit-chrome.png b/test/screenshotter/images/ColorImplicit-chrome.png index 57bda31d..2aed1ae1 100644 Binary files a/test/screenshotter/images/ColorImplicit-chrome.png and b/test/screenshotter/images/ColorImplicit-chrome.png differ diff --git a/test/screenshotter/images/ColorImplicit-firefox.png b/test/screenshotter/images/ColorImplicit-firefox.png index 39dc6425..e882407e 100644 Binary files a/test/screenshotter/images/ColorImplicit-firefox.png and b/test/screenshotter/images/ColorImplicit-firefox.png differ diff --git a/test/screenshotter/images/ColorImplicit-safari.png b/test/screenshotter/images/ColorImplicit-safari.png index 3cf5bfca..f1f3954c 100644 Binary files a/test/screenshotter/images/ColorImplicit-safari.png and b/test/screenshotter/images/ColorImplicit-safari.png differ diff --git a/test/screenshotter/images/DashesAndQuotes-chrome.png b/test/screenshotter/images/DashesAndQuotes-chrome.png index cffd3fd8..fa1c6198 100644 Binary files a/test/screenshotter/images/DashesAndQuotes-chrome.png and b/test/screenshotter/images/DashesAndQuotes-chrome.png differ diff --git a/test/screenshotter/images/ExtensibleArrows-chrome.png b/test/screenshotter/images/ExtensibleArrows-chrome.png index a40b475e..726581e6 100644 Binary files a/test/screenshotter/images/ExtensibleArrows-chrome.png and b/test/screenshotter/images/ExtensibleArrows-chrome.png differ diff --git a/test/screenshotter/images/ExtensibleArrows-firefox.png b/test/screenshotter/images/ExtensibleArrows-firefox.png index 20b78d42..bd3b89ef 100644 Binary files a/test/screenshotter/images/ExtensibleArrows-firefox.png and b/test/screenshotter/images/ExtensibleArrows-firefox.png differ diff --git a/test/screenshotter/images/ExtensibleArrows-safari.png b/test/screenshotter/images/ExtensibleArrows-safari.png index 74491a6d..d6928498 100644 Binary files a/test/screenshotter/images/ExtensibleArrows-safari.png and b/test/screenshotter/images/ExtensibleArrows-safari.png differ diff --git a/test/screenshotter/images/FractionTest-chrome.png b/test/screenshotter/images/FractionTest-chrome.png index 02e5fda7..2b54f3a7 100644 Binary files a/test/screenshotter/images/FractionTest-chrome.png and b/test/screenshotter/images/FractionTest-chrome.png differ diff --git a/test/screenshotter/images/GreekLetters-chrome.png b/test/screenshotter/images/GreekLetters-chrome.png index a82b6109..c1ce451c 100644 Binary files a/test/screenshotter/images/GreekLetters-chrome.png and b/test/screenshotter/images/GreekLetters-chrome.png differ diff --git a/test/screenshotter/images/GreekLetters-firefox.png b/test/screenshotter/images/GreekLetters-firefox.png index 20cdc03f..e4c059ce 100644 Binary files a/test/screenshotter/images/GreekLetters-firefox.png and b/test/screenshotter/images/GreekLetters-firefox.png differ diff --git a/test/screenshotter/images/GreekLetters-safari.png b/test/screenshotter/images/GreekLetters-safari.png index 194df4eb..6d4c4753 100644 Binary files a/test/screenshotter/images/GreekLetters-safari.png and b/test/screenshotter/images/GreekLetters-safari.png differ diff --git a/test/screenshotter/images/GreekUnicode-chrome.png b/test/screenshotter/images/GreekUnicode-chrome.png index 87aa0e4c..e31bddf3 100644 Binary files a/test/screenshotter/images/GreekUnicode-chrome.png and b/test/screenshotter/images/GreekUnicode-chrome.png differ diff --git a/test/screenshotter/images/GreekUnicode-firefox.png b/test/screenshotter/images/GreekUnicode-firefox.png index 349b6357..2092c47a 100644 Binary files a/test/screenshotter/images/GreekUnicode-firefox.png and b/test/screenshotter/images/GreekUnicode-firefox.png differ diff --git a/test/screenshotter/images/GreekUnicode-safari.png b/test/screenshotter/images/GreekUnicode-safari.png index 4fb5c164..6a1fbf59 100644 Binary files a/test/screenshotter/images/GreekUnicode-safari.png and b/test/screenshotter/images/GreekUnicode-safari.png differ diff --git a/test/screenshotter/images/LineBreak-chrome.png b/test/screenshotter/images/LineBreak-chrome.png index f04fed03..26fcea99 100644 Binary files a/test/screenshotter/images/LineBreak-chrome.png and b/test/screenshotter/images/LineBreak-chrome.png differ diff --git a/test/screenshotter/images/LineBreak-firefox.png b/test/screenshotter/images/LineBreak-firefox.png index 99b91035..92e594b8 100644 Binary files a/test/screenshotter/images/LineBreak-firefox.png and b/test/screenshotter/images/LineBreak-firefox.png differ diff --git a/test/screenshotter/images/LineBreak-safari.png b/test/screenshotter/images/LineBreak-safari.png index 5ed50193..5bf686b0 100644 Binary files a/test/screenshotter/images/LineBreak-safari.png and b/test/screenshotter/images/LineBreak-safari.png differ diff --git a/test/screenshotter/images/MathChoice-chrome.png b/test/screenshotter/images/MathChoice-chrome.png index 65d4793c..6c642afe 100644 Binary files a/test/screenshotter/images/MathChoice-chrome.png and b/test/screenshotter/images/MathChoice-chrome.png differ diff --git a/test/screenshotter/images/MathChoice-firefox.png b/test/screenshotter/images/MathChoice-firefox.png index 4e1df417..8585239f 100644 Binary files a/test/screenshotter/images/MathChoice-firefox.png and b/test/screenshotter/images/MathChoice-firefox.png differ diff --git a/test/screenshotter/images/MathChoice-safari.png b/test/screenshotter/images/MathChoice-safari.png index 9b17b42f..706012ee 100644 Binary files a/test/screenshotter/images/MathChoice-safari.png and b/test/screenshotter/images/MathChoice-safari.png differ diff --git a/test/screenshotter/images/ModSpacing-chrome.png b/test/screenshotter/images/ModSpacing-chrome.png index 0f8999b6..3f018cfc 100644 Binary files a/test/screenshotter/images/ModSpacing-chrome.png and b/test/screenshotter/images/ModSpacing-chrome.png differ diff --git a/test/screenshotter/images/NegativeSpace-chrome.png b/test/screenshotter/images/NegativeSpace-chrome.png index 7e746055..2c76caa7 100644 Binary files a/test/screenshotter/images/NegativeSpace-chrome.png and b/test/screenshotter/images/NegativeSpace-chrome.png differ diff --git a/test/screenshotter/images/OpLimits-chrome.png b/test/screenshotter/images/OpLimits-chrome.png index 0a78f81f..878016c2 100644 Binary files a/test/screenshotter/images/OpLimits-chrome.png and b/test/screenshotter/images/OpLimits-chrome.png differ diff --git a/test/screenshotter/images/OperatorName-chrome.png b/test/screenshotter/images/OperatorName-chrome.png index f61e6f30..950611cd 100644 Binary files a/test/screenshotter/images/OperatorName-chrome.png and b/test/screenshotter/images/OperatorName-chrome.png differ diff --git a/test/screenshotter/images/Phantom-chrome.png b/test/screenshotter/images/Phantom-chrome.png index 77a0a9ee..e5ec08c3 100644 Binary files a/test/screenshotter/images/Phantom-chrome.png and b/test/screenshotter/images/Phantom-chrome.png differ diff --git a/test/screenshotter/images/Phantom-firefox.png b/test/screenshotter/images/Phantom-firefox.png index d82a4b21..51e194ea 100644 Binary files a/test/screenshotter/images/Phantom-firefox.png and b/test/screenshotter/images/Phantom-firefox.png differ diff --git a/test/screenshotter/images/Phantom-safari.png b/test/screenshotter/images/Phantom-safari.png index 20636fa1..bc8f567d 100644 Binary files a/test/screenshotter/images/Phantom-safari.png and b/test/screenshotter/images/Phantom-safari.png differ diff --git a/test/screenshotter/images/StretchyAccent-chrome.png b/test/screenshotter/images/StretchyAccent-chrome.png index 43b0c016..2188f2c6 100644 Binary files a/test/screenshotter/images/StretchyAccent-chrome.png and b/test/screenshotter/images/StretchyAccent-chrome.png differ diff --git a/test/screenshotter/images/StretchyAccent-firefox.png b/test/screenshotter/images/StretchyAccent-firefox.png index f49a4209..f6dbc2b3 100644 Binary files a/test/screenshotter/images/StretchyAccent-firefox.png and b/test/screenshotter/images/StretchyAccent-firefox.png differ diff --git a/test/screenshotter/images/StretchyAccent-safari.png b/test/screenshotter/images/StretchyAccent-safari.png index a10dec9a..7a8be657 100644 Binary files a/test/screenshotter/images/StretchyAccent-safari.png and b/test/screenshotter/images/StretchyAccent-safari.png differ diff --git a/test/screenshotter/images/StrikeThrough-chrome.png b/test/screenshotter/images/StrikeThrough-chrome.png index eb7bafc6..fc77fd72 100644 Binary files a/test/screenshotter/images/StrikeThrough-chrome.png and b/test/screenshotter/images/StrikeThrough-chrome.png differ diff --git a/test/screenshotter/images/StrikeThrough-firefox.png b/test/screenshotter/images/StrikeThrough-firefox.png index 92589b4e..490f9c55 100644 Binary files a/test/screenshotter/images/StrikeThrough-firefox.png and b/test/screenshotter/images/StrikeThrough-firefox.png differ diff --git a/test/screenshotter/images/StrikeThrough-safari.png b/test/screenshotter/images/StrikeThrough-safari.png index c9562b67..8bc86e16 100644 Binary files a/test/screenshotter/images/StrikeThrough-safari.png and b/test/screenshotter/images/StrikeThrough-safari.png differ diff --git a/test/screenshotter/images/StrikeThroughColor-chrome.png b/test/screenshotter/images/StrikeThroughColor-chrome.png index aa39c287..74014b42 100644 Binary files a/test/screenshotter/images/StrikeThroughColor-chrome.png and b/test/screenshotter/images/StrikeThroughColor-chrome.png differ diff --git a/test/screenshotter/images/StrikeThroughColor-firefox.png b/test/screenshotter/images/StrikeThroughColor-firefox.png index a555253c..e22fbb52 100644 Binary files a/test/screenshotter/images/StrikeThroughColor-firefox.png and b/test/screenshotter/images/StrikeThroughColor-firefox.png differ diff --git a/test/screenshotter/images/StrikeThroughColor-safari.png b/test/screenshotter/images/StrikeThroughColor-safari.png index 09caa232..a577ae9d 100644 Binary files a/test/screenshotter/images/StrikeThroughColor-safari.png and b/test/screenshotter/images/StrikeThroughColor-safari.png differ diff --git a/test/screenshotter/images/SupSubLeftAlignReset-chrome.png b/test/screenshotter/images/SupSubLeftAlignReset-chrome.png index 1f022a92..4b73b0e4 100644 Binary files a/test/screenshotter/images/SupSubLeftAlignReset-chrome.png and b/test/screenshotter/images/SupSubLeftAlignReset-chrome.png differ diff --git a/test/screenshotter/images/SurrogatePairs-chrome.png b/test/screenshotter/images/SurrogatePairs-chrome.png index b2132b0b..44931303 100644 Binary files a/test/screenshotter/images/SurrogatePairs-chrome.png and b/test/screenshotter/images/SurrogatePairs-chrome.png differ diff --git a/test/screenshotter/images/TextWithMath-chrome.png b/test/screenshotter/images/TextWithMath-chrome.png index f6072232..2038a9b5 100644 Binary files a/test/screenshotter/images/TextWithMath-chrome.png and b/test/screenshotter/images/TextWithMath-chrome.png differ