diff --git a/src/buildHTML.js b/src/buildHTML.js
index a13b28bb..df6d95a1 100644
--- a/src/buildHTML.js
+++ b/src/buildHTML.js
@@ -300,7 +300,9 @@ function buildHTMLUnbreakable(children, options) {
// falls at the depth of the expression.
const strut = makeSpan(["strut"]);
strut.style.height = (body.height + body.depth) + "em";
- strut.style.verticalAlign = -body.depth + "em";
+ if (body.depth) {
+ strut.style.verticalAlign = -body.depth + "em";
+ }
body.children.unshift(strut);
return body;
@@ -394,7 +396,9 @@ export default function buildHTML(tree: AnyParseNode[], options: Options): DomSp
if (tagChild) {
const strut = tagChild.children[0];
strut.style.height = (htmlNode.height + htmlNode.depth) + "em";
- strut.style.verticalAlign = (-htmlNode.depth) + "em";
+ if (htmlNode.depth) {
+ strut.style.verticalAlign = (-htmlNode.depth) + "em";
+ }
}
return htmlNode;
diff --git a/src/environments/array.js b/src/environments/array.js
index 3feb589e..d2d99be9 100644
--- a/src/environments/array.js
+++ b/src/environments/array.js
@@ -381,8 +381,10 @@ const htmlBuilder: HtmlBuilder<"array"> = function(group, options) {
separator.style.borderRightWidth = `${ruleThickness}em`;
separator.style.borderRightStyle = lineType;
separator.style.margin = `0 -${ruleThickness / 2}em`;
- separator.style.verticalAlign =
- -(totalHeight - offset) + "em";
+ const shift = totalHeight - offset;
+ if (shift) {
+ separator.style.verticalAlign = -shift + "em";
+ }
cols.push(separator);
} else {
diff --git a/src/functions/lap.js b/src/functions/lap.js
index cb84c09b..5507df11 100644
--- a/src/functions/lap.js
+++ b/src/functions/lap.js
@@ -47,7 +47,9 @@ defineFunction({
// This code resolved issue #1153
const strut = buildCommon.makeSpan(["strut"]);
strut.style.height = (node.height + node.depth) + "em";
- strut.style.verticalAlign = -node.depth + "em";
+ if (node.depth) {
+ strut.style.verticalAlign = -node.depth + "em";
+ }
node.children.unshift(strut);
// Next, prevent vertical misplacement when next to something tall.
diff --git a/test/__snapshots__/katex-spec.js.snap b/test/__snapshots__/katex-spec.js.snap
index 8cd15a12..5de278b8 100755
--- a/test/__snapshots__/katex-spec.js.snap
+++ b/test/__snapshots__/katex-spec.js.snap
@@ -1089,7 +1089,7 @@ exports[`Extending katex by new fonts and symbols Add new font class to new exte
>
@@ -1170,7 +1170,7 @@ exports[`Newlines via \\\\ and \\newline \\\\ causes newline, even after mrel an
>
@@ -1219,7 +1219,7 @@ exports[`Newlines via \\\\ and \\newline \\\\ causes newline, even after mrel an