Skip to content

Commit

Permalink
Fix KaTeX#136: Size commands generate fragments, not spans.
Browse files Browse the repository at this point in the history
This is so the size commands don't hide the types of their enclosed
atoms. Addresses KaTeX#136.

This slightly changes the vertical position of the Sizing test. Not
sure the vertical position matters, so change the test.
  • Loading branch information
kohler committed Nov 28, 2016
1 parent d3ecb33 commit e9899d8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/buildHTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -1117,18 +1117,28 @@ groupTypes.sizing = function(group, options, prev) {
var inner = buildExpression(group.value.value,
options.withSize(group.value.size), prev);

// Compute the correct maxFontSize.
var style = options.style;
var span = makeSpan(["mord"],
[makeSpan(["sizing", "reset-" + options.size, group.value.size,
style.cls()],
inner)],
options);

// Calculate the correct maxFontSize manually
var fontSize = buildCommon.sizingMultiplier[group.value.size];
span.maxFontSize = fontSize * style.sizeMultiplier;
fontSize = fontSize * style.sizeMultiplier;

// Add size-resetting classes to the inner list and set maxFontSize
// manually. Handle nested size changes.
for (var i = 0; i < inner.length; i++) {
var pos = utils.indexOf(inner[i].classes, "sizing");
if (pos < 0) {
inner[i].classes.push("sizing", "reset-" + options.size,
group.value.size, style.cls());
inner[i].maxFontSize = fontSize;
} else if (inner[i].classes[pos + 1] === "reset-" + group.value.size) {
// This is a nested size change: e.g., inner[i] is the "b" in
// `\Huge a \small b`. Override the old size (the `reset-` class)
// but not the new size.
inner[i].classes[pos + 1] = "reset-" + options.size;
}
}

return span;
return buildCommon.makeFragment(inner);
};

groupTypes.styling = function(group, options, prev) {
Expand Down
Binary file modified test/screenshotter/images/Sizing-chrome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/screenshotter/images/Sizing-firefox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e9899d8

Please sign in to comment.