Line breaks for inline formulas (#1287)
* Line breaks for inline formulas * Basic support for \allowbreak and \nobreak * Fix spacing around \nobreak, and add documentation * Backwards-compatibility _getBuilt to fix tests * Put operator spacing on same line as operator * One approach to ~ * Simplify \allowbreak/\nobreak, make ~/\nobreakspace prevent line breaks * Adapt to #1295 * Prevent wrapping within a .base * Implement \hspace* properly * Fix flow error * Update comment for regularSpace * Update screenshots * Move `width: min-content` from .katex into .base * Fix screenshot * Add min-width rule to .vlist-s * Factor out hasClass method * Cleanup nobreak test * Pull out buildHTMLUnbreakable * Fix \hspace* test (no longer the same as \hspace) * Fix \nobreak handling * Add screenshot test
@@ -53,8 +53,13 @@ const _getBuilt = function(expr, settings) {
|
||||
// grab the root node of the HTML rendering
|
||||
const builtHTML = rootNode.children[1];
|
||||
|
||||
// Remove the outer .katex and .katex-inner layers
|
||||
return builtHTML.children[2].children;
|
||||
// combine the non-strut children of all base spans
|
||||
const children = [];
|
||||
for (let i = 0; i < builtHTML.children.length; i++) {
|
||||
children.push(...builtHTML.children[i].children.filter(
|
||||
(node) => node.classes.indexOf("strut") < 0));
|
||||
}
|
||||
return children;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -2889,9 +2894,9 @@ describe("A macro expander", function() {
|
||||
|
||||
// This may change in the future, if we support the extra features of
|
||||
// \hspace.
|
||||
it("should treat \\hspace, \\hspace*, \\hskip like \\kern", function() {
|
||||
it("should treat \\hspace, \\hskip like \\kern", function() {
|
||||
expect("\\hspace{1em}").toParseLike("\\kern1em");
|
||||
expect("\\hspace*{1em}").toParseLike("\\kern1em");
|
||||
expect("\\hskip{1em}").toParseLike("\\kern1em");
|
||||
});
|
||||
|
||||
it("should expand \\limsup as expected", () => {
|
||||
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 6.5 KiB |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 6.9 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 8.5 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 9.5 KiB After Width: | Height: | Size: 9.5 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 7.0 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
BIN
test/screenshotter/images/LineBreak-chrome.png
Normal file
After Width: | Height: | Size: 33 KiB |
BIN
test/screenshotter/images/LineBreak-firefox.png
Normal file
After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 9.9 KiB After Width: | Height: | Size: 9.9 KiB |
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.3 KiB |
Before Width: | Height: | Size: 7.3 KiB After Width: | Height: | Size: 6.1 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 9.9 KiB |
Before Width: | Height: | Size: 9.9 KiB After Width: | Height: | Size: 9.9 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 6.0 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
@@ -144,6 +144,20 @@ LeftRightStyleSizing: |
|
||||
LimitControls: |
|
||||
\displaystyle\int\limits_2^3 3x^2\,dx + \sum\nolimits^n_{i=1}i +
|
||||
\textstyle\int\limits_x^y z
|
||||
LineBreak: |
|
||||
\frac{x^2}{y^2} + z^2 =
|
||||
z^2 + \frac{x^2}{y^2} =
|
||||
\frac{x^2}{y^2} +\nobreak z^2 =
|
||||
z^2 + \frac{x^2}{y^2} =
|
||||
\frac{x^2}{y^2} + ~ z^2 =
|
||||
z^2 + \frac{x^2}{y^2} =
|
||||
\frac{x^2}{y^2} + \hspace{1em} z^2 =
|
||||
z^2 + \frac{x^2}{y^2} =
|
||||
\frac{x^2}{y^2} + z^2 = \hspace*{1em}
|
||||
z^2 + \frac{x^2}{y^2} =
|
||||
\frac{x^2}{y^2} + z^2 =
|
||||
hi \allowbreak there =
|
||||
hi \allowbreak there
|
||||
LowerAccent: |
|
||||
\begin{matrix}
|
||||
\underleftarrow{AB} \quad \underrightarrow{AB} \quad \underleftrightarrow{AB} \quad \undergroup{AB} \\
|
||||
|