From cbd3afd738eff4bd803e2995e422c1134e4cef36 Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Mon, 23 Jul 2018 13:01:02 -0400 Subject: [PATCH] Fix \not vertical alignment (#1497) * Fix \not vertical alignment Fix #1491 by changing from `position: absolute` to `position: relative`. * Switch to \rlap implementation of \not * Separate \not the macro from \not the symbol via \@not * Fix test --- src/buildHTML.js | 9 --------- src/macros.js | 6 ++++++ src/symbols.js | 2 +- test/katex-spec.js | 6 +++++- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/buildHTML.js b/src/buildHTML.js index 330866a5..6a7e6ce0 100644 --- a/src/buildHTML.js +++ b/src/buildHTML.js @@ -183,15 +183,6 @@ export const buildExpression = function( } } - // Process \\not commands within the group. - for (let i = 0; i < groups.length; i++) { - const group = groups[i]; - if (group instanceof domTree.symbolNode && group.value === "\u0338") { - // Results in a solidus being overlaid over the following group/atom. - group.style.position = "absolute"; - } - } - return groups; }; diff --git a/src/macros.js b/src/macros.js index 5eb44849..7419e4f0 100644 --- a/src/macros.js +++ b/src/macros.js @@ -357,6 +357,12 @@ defineMacro("\\llap", "\\mathllap{\\textrm{#1}}"); defineMacro("\\rlap", "\\mathrlap{\\textrm{#1}}"); defineMacro("\\clap", "\\mathclap{\\textrm{#1}}"); +// \not is defined by base/fontmath.ltx via +// \DeclareMathSymbol{\not}{\mathrel}{symbols}{"36} +// It's thus treated like a \mathrel, but defined by a symbol that has zero +// width but extends to the right. We use \rlap to get that spacing. +defineMacro("\\not", '\\mathrel{\\mathrlap\\@not}'); + // Negated symbols from base/fontmath.ltx: // \def\neq{\not=} \let\ne=\neq // \DeclareRobustCommand diff --git a/src/symbols.js b/src/symbols.js index d31b6e51..0cdf674c 100644 --- a/src/symbols.js +++ b/src/symbols.js @@ -563,7 +563,7 @@ defineSymbol(math, main, rel, "\u2265", "\\geq", true); defineSymbol(math, main, rel, "\u2190", "\\gets"); defineSymbol(math, main, rel, ">", "\\gt"); defineSymbol(math, main, rel, "\u2208", "\\in", true); -defineSymbol(math, main, rel, "\u0338", "\\not"); +defineSymbol(math, main, rel, "\u0338", "\\@not"); defineSymbol(math, main, rel, "\u2282", "\\subset", true); defineSymbol(math, main, rel, "\u2283", "\\supset", true); defineSymbol(math, main, rel, "\u2286", "\\subseteq", true); diff --git a/test/katex-spec.js b/test/katex-spec.js index 6d9ac0d1..bb0b57fe 100644 --- a/test/katex-spec.js +++ b/test/katex-spec.js @@ -93,7 +93,11 @@ describe("A rel parser", function() { if (group.type === "htmlmathml") { group = group.value.html[0]; } - expect(group.type).toEqual("rel"); + if (group.type === "mclass") { + expect(group.value.mclass).toEqual("mrel"); + } else { + expect(group.type).toEqual("rel"); + } } }); });