#set page(height: 3cm, width: 4cm)
#show math.equation: math.display
#set box(stroke: red)
#set text(top-edge: "bounds", bottom-edge: "bounds")
if $w x = 100$ so $x = 100/w$, in conclusion.
if $w x = 100$ so #box($x = 100/w$), in conclusion. // baseline shift!
if $w x = 100$ so #box(baseline: 35%, $x = 100/w$), in conclusion. // manually set the baseline.
let $2^y^y^y = 1$, $y^y^y = log_2 (1)$ as well.
let $2^y^y^y = 1$, #box(baseline: 30%, $y^y^y = log_2 (1)$) as well. // different value of baseline needed.
What I want is a way to create display-style inline equations that does not have linebreak in between. What I have tried is using box but it causes baseline of the equation body to be different from the text. This can be alleviated by manually set the baseline shift, but it is painful because different body of the equation cause different size of the box, thus different baseline shift. How do I do?
This is because a multi-line math expression, like a fraction, needs to set its baseline at the math axis height (a constant provided by the font, then scaled by the font size), but a boxed frame probably set its baseline with another value or never set it.
I tried the following snippet and it seems to work:
#let pick = [#none#label("x")]
#let bind(x) = [$#x^#pick$]
#let group(body, baseline: label("x")) = {
let puppet = [#box($a^#[#none#label("current-line")]$ + box(body + $bind(x)$))<puppet>]
show <puppet>: it => box(place(hide(it)))
puppet
context {
let locs = query(selector.or(<current-line>, baseline).before(here()))
let loc-base = locs.filter(it => it.label == baseline).last()
let loc-floor = locs.filter(it => it.label == <current-line>).last()
let base-y = loc-base.location().position().y
let floor-y = loc-floor.location().position().y
box(body, baseline: 0% - base-y + floor-y,)
}
}
So basically I stuff the boxed equation with non-boxed equation tagged with <current-line> label, and attach the normal text tagged with <x> label to the original equation body.
After that I place the equation and hide it, so that I can measure the distance between the shifted baseline, and use that information to set the box’s baseline.
I did some similar but not the same hackery for equation baselines: baselinefix/main.pdf · main · bluss / typst-recipes · GitLab (code exists in same directory) Since I worked with display equations and you inline, our solutions are not interchangeable, at least I don’t think so.
The biggest thing I learned was the sensitivity to floating point accuracy, and I added rounding to avoid the issue.
You have put both the measurement points in supscripts but I think that if you place the probe point as just an appendix to the equation that its location will be on the actual baseline itself? Since you do a relative measurement it doesn’t matter.