mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-12 22:48:41 +00:00
Support for top-level \newline and \\ in inline math (#1298)
* Support for top-level \newline and \\ in inline math This was a little tricky because `\\` was defined as an endOfExpression. Instead made `\\` a termination specific to an array environment. Outside an array environment, buildHTML handles the `cr` object, resulting in a `.newline` class. Currently this turns into a `display: block` (with appropriate vertical spacing) only in inline math, matching LaTeX. * Simplify code * Fix Jest errors * NewLine screenshot test * Bug fix: \\ only works at top level of inline * Add \newline and \cr to test * Switch test to pmatrix * Add vertical space test * Add \\ vs. \newline tests * Fix flow errors * Add \cr test * Add documentation for \\ at top level * Comment out newRow * Fix commenting out
This commit is contained in:
@@ -208,10 +208,6 @@ describe("Parser.expect calls:", function() {
|
||||
"Expected 'EOF', got '\\end' at position 2:" +
|
||||
" x\\̲e̲n̲d̲{matrix}");
|
||||
});
|
||||
it("complains about top-level \\\\", function() {
|
||||
expect("1\\\\2").toFailWithParseError(
|
||||
"Expected 'EOF', got '\\\\' at position 2: 1\\̲\\̲2");
|
||||
});
|
||||
it("complains about top-level &", function() {
|
||||
expect("1&2").toFailWithParseError(
|
||||
"Expected 'EOF', got '&' at position 2: 1&̲2");
|
||||
@@ -292,12 +288,12 @@ describe("environments.js:", function() {
|
||||
describe("parseArray", function() {
|
||||
it("rejects missing \\end", function() {
|
||||
expect("\\begin{matrix}1").toFailWithParseError(
|
||||
"Expected & or \\\\ or \\end at end of input:" +
|
||||
"Expected & or \\\\ or \\cr or \\end at end of input:" +
|
||||
" \\begin{matrix}1");
|
||||
});
|
||||
it("rejects incorrectly scoped \\end", function() {
|
||||
expect("{\\begin{matrix}1}\\end{matrix}").toFailWithParseError(
|
||||
"Expected & or \\\\ or \\end at position 17:" +
|
||||
"Expected & or \\\\ or \\cr or \\end at position 17:" +
|
||||
" …\\begin{matrix}1}̲\\end{matrix}");
|
||||
});
|
||||
});
|
||||
|
@@ -3126,6 +3126,18 @@ describe("The \\mathchoice function", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("Newlines via \\\\ and \\newline", function() {
|
||||
it("should build \\\\ and \\newline the same", () => {
|
||||
expect("hello \\\\ world").toBuildLike("hello \\newline world");
|
||||
expect("hello \\\\[1ex] world").toBuildLike(
|
||||
"hello \\newline[1ex] world");
|
||||
});
|
||||
|
||||
it("should not allow \\cr at top level", () => {
|
||||
expect("hello \\cr world").toNotParse();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Symbols", function() {
|
||||
it("should parse \\text{\\i\\j}", () => {
|
||||
expect("\\text{\\i\\j}").toBuild();
|
||||
|
BIN
test/screenshotter/images/NewLine-chrome.png
Normal file
BIN
test/screenshotter/images/NewLine-chrome.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
BIN
test/screenshotter/images/NewLine-firefox.png
Normal file
BIN
test/screenshotter/images/NewLine-firefox.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
@@ -207,6 +207,14 @@ NegativeSpace:
|
||||
NestedFractions: |
|
||||
\dfrac{\frac{a}{b}}{\frac{c}{d}}\dfrac{\dfrac{a}{b}}
|
||||
{\dfrac{c}{d}}\frac{\frac{a}{b}}{\frac{c}{d}}
|
||||
NewLine: |
|
||||
\frac{a^2+b^2}{c^2} \newline
|
||||
\frac{a^2+b^2}{c^2} \\[1ex]
|
||||
\begin{pmatrix}
|
||||
a & b \\
|
||||
c & d \cr
|
||||
\end{pmatrix} \\
|
||||
a+b+c+{d+\\e}+f+g
|
||||
Not: |
|
||||
\begin{array}{l}
|
||||
\not=\not>\not\geq\not\in\not<\not\leq\not{abc} \\
|
||||
|
Reference in New Issue
Block a user