How to set the font of mono in math

I’m trying to set the font that math.mono() uses inside math blocks, i.e. $mono(code)$. I have tried the following to no avail (most error out)

#show math.equation: set text.mono(font: "JetBrainsMono NF") 
#show math.equation.where(mono: true): set text(font: "JetBrainsMono NF") 
#show math.mono: set text(font: "JetBrainsMono NF") 
1 Like

Monospaced math content created with $mono(...)$ actually just uses the default math font, which contains its own monospaced characters. As it seems like you want to use a normal text font, which is not intended to be used for math content, it would probably make more sense to use raw blocks to create monospaced text. As the backtick syntax doesn’t work in math mode, you need to either call #raw explicitly, or temporarily switch to code mode with a #:

$ x + #raw("y") = #`code` $

image

With this, you can then easily change the font via a show-set rule, though you may need to adjust the text size so it matches the surrounding text.

#show raw: set text(font: "JetBrainsMono NF")

If this font should only be used for math, you can also either scope the show-set rule in a show rule for equations, or create a custom mono function. Keep in mind then that raw only accepts strings as arguments, so you always need to wrap your monospaced text in quotation marks.