Add \smash, laps, spaces, and phantoms#833
Conversation
1. Support `\smash`, including the optional argument from AMS. 2. Change `\llap` and `\rlap` so that they render in text style. Repeat: This *changes* KaTeX behavior. 3. Add `\mathllap` and `\mathrlap`. These will act as they do in `mathtools` and as in previous KaTeX versions of `\llap` and `\rlap`. 4. Add `\mathclap` and `\clap`. 5. Add `\hphantom` and \vphantom`. 6. Add `\thinspace`, `\medspace`, `\thickspace` 7. Add `\hspace`. This work will resolve issue #270 and parts of #50 and #164. A. Perlis has written a [concise description](https://www.math.lsu.edu/~aperlis/publications/mathclap/perlis_mathclap_24Jun2003.pdf) of items 1 thru 5. Except for `\smash`'s optional argument. It's described in the [AMS User's Guide](http://texdoc.net/texmf-dist/doc/latex/amsmath/amsldoc.pdf). Item 6 also comes from the AMS User's Guide.
|
@kohler, I've taken your advice and exploited |
update smash and phantom screenshots for chrome
src/buildCommon.js
Outdated
| "\\thickspace": { | ||
| size: "0.277778em", | ||
| className: "thickspace", | ||
| }, |
There was a problem hiding this comment.
Are these separate commands or would it make sense to use defineMacro to define \thickspace in terms of \;?
There was a problem hiding this comment.
Using defineMacro would work very well. I'll change it.
| .clap > .inner > span { | ||
| margin-left: -50%; | ||
| margin-right: 50%; | ||
| } |
There was a problem hiding this comment.
I feel like there might be an easier way to center things. I'll check out the branch and experiment.
There was a problem hiding this comment.
I never got around to experimenting. This does the trick and anything else would be marginally smaller so I'm going to merge this as is.
test/katex-spec.js
Outdated
| const noBraceTextExpression = "\\text x"; | ||
| const nestedTextExpression = | ||
| "\\text{a {b} \\blue{c} \\textcolor{#fff}{x} \\llap{x}}"; | ||
| "\\text{a {b} \\blue{c} \\textcolor{#fff}{x} \\mathllap{x}}"; |
There was a problem hiding this comment.
Why change all \laps in this file to \mathlaps?
There was a problem hiding this comment.
It seemed to me that \mathllap is a core command. I found \llap to be less interesting. But your point is well taken. This line is supposed to be testing a text parser. I'll change it back.
There was a problem hiding this comment.
Well, now I have a better answer to your question about the test. Since \lap is a test mode function, we should not expect it to work properly when given math mode arguments, such as \left. So the tests really should be revised to test \mathllap and not \lllap.
test/screenshotter/ss_data.yaml
Outdated
| tex: \frac{a\kern{1em}b}{c}a\kern{1em}b\kern{1ex}c\kern{-0.25em}d | ||
| nolatex: LaTeX fails to typeset this, “Missing number, treated as zero.” | ||
| Lap: ab\llap{f}cd\rlap{g}h | ||
| Lap: ab\mathllap{f}cd\mathrlap{g}h |
There was a problem hiding this comment.
We should probably also verify the changed behavior of llap et al.
There was a problem hiding this comment.
I'll add some tests.
src/functions.js
Outdated
| return { | ||
| type: context.funcName.slice(1), | ||
| type: "lap", | ||
| className: context.funcName.slice(5), |
There was a problem hiding this comment.
I'd like to avoid including CSS specifics at this level, maybe this could be called alignment.
| const inner = buildExpression(group.value.value, options); | ||
| const node = new mathMLTree.MathNode("mphantom", inner); | ||
| node.setAttribute("width", "0px"); | ||
| return node; |
There was a problem hiding this comment.
Thanks for your attention to detail with this.
src/buildHTML.js
Outdated
| // ref: amsmath: \renewcommand{\smash}[1][tb]{% | ||
| // def\mb@t{\ht}\def\mb@b{\dp}\def\mb@tb{\ht\z@\z@\dp}% | ||
| smashHeight = /t/.test(group.value.tb); | ||
| smashDepth = /b/.test(group.value.tb); |
There was a problem hiding this comment.
I see, the tb optional param is used to "smash" the top and/or the bottom of the group.
There was a problem hiding this comment.
These tests could be moved into functions.js so that we don't have repeat the here and in buildMathML.js.
src/functions.js
Outdated
| }; | ||
| }); | ||
|
|
||
| // smash, with optional [bt], as in AMS |
There was a problem hiding this comment.
nit: the comment uses bt but everywhere else it's tb
src/functions.js
Outdated
| return { | ||
| type: "smash", | ||
| body: body, | ||
| tb: tb, |
There was a problem hiding this comment.
smashHeight: /t/.test(tbArg),
smashDepth: /b/.test(tbArg),
There was a problem hiding this comment.
Do we care if there are other values in tbArg?
\llap is fundamentally a text-mode function. We should not expect it to work correctly when given math-mode arguments. So test \mathllap instead.
A correction. The previous macro returned an error if given an argument with math-mode content, such as x^2. The corrected macro will not return an error. It will instead return well rendered math, but letters are in `\mathrm` font.
|
@ronkok I've updated the |
update Lap screenshots
k4b7
left a comment
There was a problem hiding this comment.
LGTM. Thanks for making changes.
|
@kevinbarabash, It just occurred to me that there is another breaking change in release 0.9.0-alpha, one that is not yet listed in the release notes. The My current draft of the function support page has been so updated. But I did not emphasize the change as much as I did when |
|
Good call. I can up date the release notes. |
|
I've updated the release notes. |
Support
\smash, including the optional argument from AMS.Change
\llapand\rlapso that they render in text style. Repeat: This changes KaTeX behavior.Add
\mathllapand\mathrlap. These will act as they do inmathtoolsand as in previous KaTeX versions of\llapand\rlap.Add
\mathclapand\clap.Add
\hphantomand\vphantom.Add
\thinspace,\medspace,\thickspaceAdd
\hspace.This work will resolve issue #270 and parts of #50 and #164.
A. Perlis has written a concise description of items 1 thru 5. Except for
\smash's optional argument. It's described in the AMS User's Guide.Item 6 also comes from the AMS User's Guide.