Text in math scope can't be italic

$
  text(#[_statiblity_])
$

compiler version: typst 0.14.0 (dd1e6e94)

It seems pretty weird that above text is not italic.

The default font in math is New Computer Modern Math (NCMM). For italic text to work you’d have to have a font NCMM italic installed, but I don’t think it exists - there is no such italic font in the NCMM release what I can see.

The way to do it here would be to define a function to be used for text inside math and use a text font (not math font), a font which has an italic variant, and then it will work well.

#let mtext(body) = {
  set text(font: "Libertinus Serif")
  body
}
$
s + t quad #mtext[_statiblity_]
$

bild

1 Like

Another way is to use covers.

#show math.equation: set text(font: (
  (name: "Libertinus Serif", covers: regex("\p{Latin}")),
  "New Computer Modern Math",
))
$ s + t quad #[_statiblity_] $

2 Likes

That’s nice to know, and I think typst should move towards an official solution to this problem[1]. It’s already gotten a lot better with Typst 0.14, to be sure.

I wish it was as easy as using covers, but the drawback I’d point out is this case:

#let mtext(body) = {
  set text(font: "Libertinus Serif")
  body
}
$ s + t quad #mtext[_this_ & more] $

With the covers solution the ampersand would still use the math font. Is there a way without a function like mtext - I think - to have symbols correctly using math vs text font in their respective contexts?


  1. Text in math mode should use text font #366 ↩︎

2 Likes

I believe the answer is no. covers does not even distinguish between { in texts and cases.

Looking closer at issue #366, I’m not sure why box has not been mentioned in the workarounds there. Box resolves the problem of nested equations (but some problems remain):

#let mtext(body) = box({
  set text(font: "Libertinus Serif")
  body
})
$ X = {1, 2, 3} union {#mtext[multiples of $3 + p$ where $p$ is a prime]} $
$ Y = T^#mtext[index $script(pi)$] $   // no automatic script size here

1 Like

I’m glad to see a workaround while a official solution would be better.

But it seems a tricky problem to choose which font in edge cases.