Hello everyone! When I want to typeset a formula with two-line text in Typst, I can’t find a simple and easy way. I have to use:
$ std.stack(dir: #ttb, spacing: #0.3em, "一定时期内流通中", "所需要的货币量")
= frac(
"商品价值总额",
std.stack(dir: #ttb, spacing: #0.3em, "同一单位货币流通的", "平均速度(次数)")
) $
But this makes the spacing between the fraction line and the denominator text too small. If I abandon the two-line text, the formula becomes too long.
Is there a simpler way to do this in Typst?
And here is the formula with the Chinese terms translated into English:
$ std.stack(dir: #ttb, spacing: #0.3em, "the required quantity of money", "in circulation over a given period")
= frac(
"total commodity value",
std.stack(dir: #ttb, spacing: #0.3em, "the average velocity of circulation", "of the same monetary unit (times)")
) $
this is surprisingly difficult!
I was able to acheive decent results using grid, as the inset there also applies on the outside and not only between the lines.
#let mstack(..args) = std.grid(inset: (top: 0pt, bottom: 3pt), gutter: 0pt, ..args)
$
mstack("同一单位货币流通的同", "平均速度(次数)同")
= frac(
mstack("同一单位货币流通的同", "平均速度(次数)同"),
mstack("同一单位货币流通的同", "平均速度(次数)同")
)
= frac("同", "同")
$
However, the values for top, bottom, gutter are very much dependent on the font you use, the above is with the typst default. If you use a different font, you will have to fiddle with these until it looks right. (Note that the space between lines is top + gutter + bottom, you can also use negative values if neccesary.) (I have used frac("同", "同") to compare the vertical alignment.)
For example,
#show math.equation: set text(font: ("Luciole Math", "Harano Aji Gothic"))
#let mstack(..args) = std.grid(inset: (top: 0pt, bottom: 1pt), gutter: 2pt, ..args)
$ ... $