Without specifying any weight, if I use raw text in math, its weight is medium, and, if I use raw text outside of math, its weight is regular. It can be seen in this example:
#show raw: set text(font: "Fira Sans", size: 11pt)
`text`
$#`text`$
#text(font: "Fira Sans", weight: "regular", [text])
#text(font: "Fira Sans", weight: "medium", [text])
It is because the weight of math is medium by default, so the raw text inherits it. I noticed it when I used code variables in math. That cause makes sense, but it seems like this should not happen, and it frustrated me before I figured it out.
I fixed it by specifying #show math.equation: set text(weight: "regular")
. I could use also #show raw: set text(weight: "regular")
, but I use code names in headings, and they are supposed to inherit boldness there, and this would not work by fixing the weight. It would be impossible to fix it if I needed to have the weight of math something other than regular as far as I know. In that case, I would need to select specifically raw text in math, and I think that selectors do not allow that currently. (It would be possible by redefining math to inject a local specification of weight for raw text into every equation, but that is ugly.)
I wanted to make an issue on Github from this, but I don’t know how it would be supposed to be solved, so I post it here for discussion. I imagine several imperfect solutions.
The first is to remove the weight specification from the default math font setting. That would have a side effect that math weight would be affected by the surrounding text, which some people dislike because it could confuse the reader if notation depended on font weight. But I use math notation intentionally in a way that it does not depend on font choice, so I prefer that math font would adapt to the font of the surrounding text, like bold in headings.
The second is to have the weight of math regular by default like normal text, so text in it would inherit the weight which it already has. But I respect that math have medium weight to stand out a bit more, although it seems negligible with the default font.
The third is to suitably extend selectors in Typst and set that the default weight of math would be medium, but it would not apply to nonmath content inside math. If that is too out of the intended capabilities of selectors, it would help to be able to select elements within elements, raw text inside math in this case. That would not solve the original issue that I would not need to be bothered by that, but it would allow me to have raw text with regular weight inside math with medium weight while having raw text with unspecified weight outside of math. I believe that such extension is going to come in a future version.