Conversation
src/buildHTML.js
Outdated
| const span = groupTypes.text(group, options); | ||
| if (group.value.dy) { | ||
| const dy = group.value.dy.value; | ||
| span.style.top = "" + (-dy.number) + dy.unit; |
There was a problem hiding this comment.
this should handle mu units right?
There was a problem hiding this comment.
Good point -- indeed, it currently does not, but would be easy to tweak to. (A bigger issue is that calculateSize only supports mu and em.)
There was a problem hiding this comment.
It looks like calculateSize supports ex.
const calculateSize = function(sizeValue, style) {
let x = sizeValue.number;
if (sizeValue.unit === "ex") {
x *= style.metrics.emPerEx;
} else if (sizeValue.unit === "mu") {
x /= 18;
}
return x;
};
src/buildHTML.js
Outdated
| span.height += calculateSize(dy.number, options.style); | ||
| } else { | ||
| span.depth -= calculateSize(dy.number, options.style); | ||
| } |
There was a problem hiding this comment.
shouldn't height and depth both be updated regardless of the sign of dy.number?
There was a problem hiding this comment.
The idea is that the height increases if the box is moved up, and the depth increases if the box is moved down. At least, my mental model is that height is the extent above the baseline (y-max) while depth is the extent below the baseline (y-min) -- please correct me if I'm wrong. However, this code doesn't seem to be working, and I'm not really sure how height and depth end up getting used (or not).
There was a problem hiding this comment.
At least, my mental model is that height is the extent above the baseline (y-max) while depth is the extent below the baseline (y-min) -- please correct me if I'm wrong.
That's right, but if a glyph is shifted vertically, the the extent below the baseline will be different.
What happens if you put the test expression inside a \sqrt or a \frac? It may be that just our wrapper container isn't doing the right thing with the height and depth you're setting on the span.
There was a problem hiding this comment.
Inside a \frac or \sqrt, the bounding box looks good:
This screenshot, by the way, was done with code that was slightly tweaked:
groupTypes.transform = function(group, options) {
const span = groupTypes.text(group, options);
const dy = calculateSize(group.value.dy.value, options.style);
if (dy > 0) {
span.height += dy;
} else if (dy < 0) {
span.depth -= dy;
}
span.style.top = -dy + "em";
span.style.position = "relative";
return span;
};
There was a problem hiding this comment.
@ronkok did your tweaks have any effect on the top level bounding box?
There was a problem hiding this comment.
Now that you ask me, yes they did. Odd. I was only trying to clean it up, not change how it worked. Here's a screenshot from the original code:
Now that I need to take this more seriously, here’s a version that restores the outer if statement.
groupTypes.transform = function(group, options) {
const span = groupTypes.text(group, options);
if (group.value.dy) {
const dy = calculateSize(group.value.dy.value, options.style);
if (dy > 0) {
span.height += dy;
} else if (dy < 0) {
span.depth -= dy;
}
span.style.top = -dy + "em";
span.style.position = "relative";
}
return span;
};
That code gives me the good results.
|
Awesome, thanks @kevinbarabash and @ronkok for finding the solution here! Looks like it was close indeed, and switching to Here is what my original example It's better, though the top margin is still a lot smaller (zero or even slightly less) than a straight |
|
You mentioned a smaller margin that a straight |
|
Hey, I got it! I was looking at the definition of the bottom strut in |
Neither did I. Cool! |
|
@edemaine now that everything's working correctly, can you add a screenshot test? |
|
In adding a screenshot test similar to @ronkok's, I realize that we're not quite there yet: It seems that the positive |
|
I don't think the problem is yours. If I understand matters correctly, KaTeX does not change the radical height in a continuous manner. It's a step function. You happened to land on a bad height. |
|
@ronkok Here's what it looks like, switching back to The only difference is the vertical shift in the I believe the issue is Movement Of the Line Box’s Baseline (quirks of vertical-align). Still grokking... |
|
Upon further investigation, I think the So I've reverted to that version, and added a screenshot test. I think we're back to good-to-go. |
|
@edemaine you may want to use the texcmp docker to compare the output against LaTeX's output. |
|
One more question: I currently call the parse node "transform", with the thought that it could be used for rotatebox and such in the future. But I wonder if just calling it "raisebox" and keeping it simple would be better. Let me know your opinion. |
|
Good question. I think having separate |
|
In principle I fixed the switch-to-normalsize issue, but I've run into a bug: #709 |
|
I rebased. The switch to I get the sense that this is the result of some other changes... and presumably #746? |
* Use calculateSize to support all currently supported units (ex, em, mu). * Shift height and depth in all cases.
|
I got another chance to look this over and revise substantially. I believe this is now working almost perfectly. I use I also slightly cleaned up the parse tree: Probably best to look at this as a complete diff but if you prefer you can look at just the last commit for the changes relative to previous versions. |
k4b7
left a comment
There was a problem hiding this comment.
LGTM. I'm going to rename textFunctionStyles to fontFunctionStyles before merging.
|
|
||
| groupTypes.text = function(group, options) { | ||
| const newOptions = options.withFont(group.value.style); | ||
| const newOptions = options.withFont(group.value.font); |
There was a problem hiding this comment.
Calling withFont with a font makes more sense.
|
|
||
| // Transforms (translation/rotation) don't seem to have a representation | ||
| // in MathML, so just treat them like \text{...} | ||
| groupTypes.raisebox = groupTypes.text; |
src/functions.js
Outdated
| type: "text", | ||
| body: ordargument(body), | ||
| style: textFunctionStyles[context.funcName], | ||
| font: textFunctionStyles[context.funcName], |
There was a problem hiding this comment.
Since we're calling these fonts now, should probably rename this to textFunctionFonts.
|
@edemaine thanks for picking this one up again and finishing it off. The results look great! |
|
Thanks @kevinbarabash for all the reviews today!! |









I started working on
\raiseboxsupport which will help for #657 and #224. Currently\raisebox{...ex}{...text...}"works", except that the bounding box of the resulting typeset text isn't set correctly, so raised/lowered objects cut into the lines before/after. I guess I'm still not fully up to speed on how HTML generation works here -- based on other code inbuildHTML.js, I tried manually updating.heightor.depthaccording to whether the box moved up or down, but that didn't work. If anyone has a chance to look at this, I'd appreciate help fixing it.Here's a sample render with the test server:
Here's the same example rendered in TeX, so seems good except for the bounding box issue:
Also fixed a typo where parsed sizes are accidentally labeled as "color" nodes instead of "size" nodes.