commit 3173a6e53eb1da6ad1eab581a95b4e215195afc6
parent 5416b92d5daad8c612ab00df2ea042efada293dd
Author: Emily Eisenberg <emily@khanacademy.org>
Date: Thu, 17 Apr 2014 14:44:30 -0400
Make supsubs work correctly with character boxes
Summary:
In rule 18a. of the TeX book, it says we're supposed to set `u` and `v` to 0 if
the nucleus is a character box. Character boxes are loosely defined, but through
experimentation they are anything that contains a single character, including
ordgroups with a single element in them. This change makes KaTeX follow this
rule, and fixes T2404.
Test Plan:
- Make sure the new huxley screenshot looks good
- Make sure none of the huxley tests have changed
Reviewers: alpert
Reviewed By: alpert
Maniphest Tasks: T2404
Differential Revision: http://phabricator.khanacademy.org/D8275
Diffstat:
4 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/buildTree.js b/buildTree.js
@@ -75,6 +75,24 @@ var getTypeOfGroup = function(group) {
}
};
+var isCharacterBox = function(group) {
+ if (group == null) {
+ return false;
+ } else if (group.type === "mathord" ||
+ group.type === "textord" ||
+ group.type === "bin" ||
+ group.type === "rel" ||
+ group.type === "open" ||
+ group.type === "close" ||
+ group.type === "punct") {
+ return true;
+ } else if (group.type === "ordgroup") {
+ return group.value.length === 1 && isCharacterBox(group.value[0]);
+ } else {
+ return false;
+ }
+};
+
var groupTypes = {
mathord: function(group, options, prev) {
return makeSpan(
@@ -144,8 +162,13 @@ var groupTypes = {
var subwrap = makeSpan(["msub"], [submid]);
}
- var u = base.height - fontMetrics.metrics.supDrop;
- var v = base.depth + fontMetrics.metrics.subDrop;
+ if (isCharacterBox(group.value.base)) {
+ var u = 0;
+ var v = 0;
+ } else {
+ var u = base.height - fontMetrics.metrics.supDrop;
+ var v = base.depth + fontMetrics.metrics.subDrop;
+ }
var p;
if (options.style === Style.DISPLAY) {
diff --git a/test/huxley/Huxleyfile b/test/huxley/Huxleyfile
@@ -42,3 +42,6 @@ url=http://localhost:7936/test/huxley/test.html?m=\KaTeX
[RlapBug]
url=http://localhost:7936/test/huxley/test.html?m=\frac{\rlap{x}}{2}
+
+[SupSubCharacterBox]
+url=http://localhost:7936/test/huxley/test.html?m=a_2f_2{f}_2{aa}_2{af}_2
diff --git a/test/huxley/SupSubCharacterBox.huxley/record.json b/test/huxley/SupSubCharacterBox.huxley/record.json
@@ -0,0 +1 @@
+{"py/object": "huxley.run.Test", "screen_size": {"py/tuple": [1024, 768]}, "steps": [{"py/object": "huxley.steps.ScreenshotTestStep", "index": 0, "offset_time": 0}]}
diff --git a/test/huxley/SupSubCharacterBox.huxley/screenshot0.png b/test/huxley/SupSubCharacterBox.huxley/screenshot0.png
Binary files differ.