Added support for \not (#140)

* Added support for \not

* fix grammar in comment
This commit is contained in:
Kevin Barabash
2017-08-23 13:24:17 -04:00
committed by GitHub
parent 201193233e
commit c6647e3303
8 changed files with 51 additions and 0 deletions

View File

@@ -117,6 +117,40 @@ const buildExpression = function(expression, options, isRealGroup) {
}
}
// Process \\not commands within the group.
// TODO(kevinb): Handle multiple \\not commands in a row.
// TODO(kevinb): Handle \\not{abc} correctly. The \\not should appear over
// the 'a' instead of the 'c'.
for (let i = 0; i < groups.length; i++) {
if (groups[i].value === "\u0338" && i + 1 < groups.length) {
const children = groups.slice(i, i + 2);
children[0].classes = ["mainrm"];
// \u0338 is a combining glyph so we could reorder the children so
// that it comes after the other glyph. This works correctly on
// most browsers except for Safari. Instead we absolutely position
// the glyph and set its right side to match that of the other
// glyph which is visually equivalent.
children[0].style.position = "absolute";
children[0].style.right = "0";
// Copy the classes from the second glyph to the new container.
// This is so it behaves the same as though there was no \\not.
const classes = groups[i + 1].classes;
const container = makeSpan(classes, children);
// LaTeX adds a space between ords separated by a \\not.
if (classes.indexOf("mord") !== -1) {
// \glue(\thickmuskip) 2.77771 plus 2.77771
container.style.paddingLeft = "0.277771em";
}
// Ensure that the \u0338 is positioned relative to the container.
container.style.position = "relative";
groups.splice(i, 2, container);
}
}
return groups;
};

View File

@@ -661,6 +661,9 @@ const buildExpression = function(expression, options) {
const group = expression[i];
groups.push(buildGroup(group, options));
}
// TODO(kevinb): combine \\not with mrels and mords
return groups;
};

View File

@@ -504,6 +504,7 @@ defineSymbol(math, main, rel, "\u2190", "\\gets");
defineSymbol(math, main, rel, ">", "\\gt");
defineSymbol(math, main, rel, "\u2208", "\\in");
defineSymbol(math, main, rel, "\u2209", "\\notin");
defineSymbol(math, main, rel, "\u0338", "\\not");
defineSymbol(math, main, rel, "\u2282", "\\subset");
defineSymbol(math, main, rel, "\u2283", "\\supset");
defineSymbol(math, main, rel, "\u2286", "\\subseteq");

View File

@@ -49,6 +49,7 @@
}
.base {
position: relative;
display: inline-block;
}
@@ -107,6 +108,11 @@
font-style: italic;
}
.mainrm {
font-family: KaTeX_Main;
font-style: normal;
}
// This value is also used in fontMetrics.js, if you change it make sure the
// values match.
@ptperem: 10.0;

View File

@@ -240,9 +240,11 @@ describe("A bin parser", function() {
describe("A rel parser", function() {
const expression = "=<>\\leq\\geq\\neq\\nleq\\ngeq\\cong";
const notExpression = "\\not=\\not<\\not>\\not\\leq\\not\\geq\\not\\in";
it("should not fail", function() {
expect(expression).toParse();
expect(notExpression).toParse();
});
it("should build a list of rels", function() {

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -155,6 +155,11 @@ NegativeSpaceBetweenRel: A =\!= B
NestedFractions: |
\dfrac{\frac{a}{b}}{\frac{c}{d}}\dfrac{\dfrac{a}{b}}
{\dfrac{c}{d}}\frac{\frac{a}{b}}{\frac{c}{d}}
Not: |
\begin{array}{l}
\not=\not>\not\geq\not\in\not<\not\leq\not{abc} \\
\not xy + ab \not xy
\end{array}
NullDelimiterInteraction: a \bigl. + 2 \quad \left. + a \right)
OldFont: |
\begin{matrix}