I am trying to use overbraces for my equation, but a two-line annotation pushes the math content down, out of line from the rest of the equation. Example:
$S &= overbrace(beta (alpha) S I, "one line") - overbrace(mu (N), "two" \ "line")$
The µ(N) term is out of line with the rest of the equation. This does not happen in the reverse direction with underbraces:
$S &= underbrace(beta (alpha) S I, "one line") - underbrace(mu (N), "two" \ "line")$
Is this a bug or is this intentional? How can I avoid pushing annotated math terms out of the line of the equation?
This may be a bug in Typst, but fortunately, in addition to reporting the bug to the developers, we can also manually adjust the equation’s baseline using box to achieve alignment.
Here is a example:
#let ob(content, annotation) = {
let f(x) = move(math.equation(x))
box(
math.overbrace(f(content), f(math.inline(annotation))),
baseline: -0.0912em,
)
}
$
S &= overbrace(beta (alpha) S I, "one line" ) - mu ob(mu (N), alpha) \ \
S &= overbrace(beta (alpha) S I, "one line" ) - mu ob(mu (N), "two" \ "lines") \ \ \
S &= overbrace(beta (alpha) S I, "one line" ) - mu ob(mu (N), "and" \ "three" \ "lines") \ \ \
S &= overbrace(beta (alpha) S I, "one line" ) - mu ob(mu (N), "also" \ "even" \ "four" \ "lines") \
$
Concept:
As I mentioned, I manually align the formula by adjusting the baseline parameter of the box. There might be some additional techniques involved in this process.
About the extra move:
This is a rather magical technique. Someone told me that using move would make external elements respect the alignment of the elements inside the move, and this turns out to be true. After using move, I only need to account for the remaining offset, since the formula’s alignment has already been addressed. I’m not entirely sure why or how it works, but I guess when facing alignment issues, adding a move might, to some extent, help.
Why is the baseline -0.0912em?
I measured it. The value is precise to four decimal places to ensure pixel-perfect alignment. Feel free to modify it if you have a more accurate value.