You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
correctly using the text font when displaying text in math mode.
Why is this the correct behavior? Because it is common to write something like
And therefore, if $ f(a) > 0 quad "and" quad f'(a) > 0, $ we have
where the text is part of the, well, text. When this is typeset using the math font it looks very awkward.
Obviously this is an extreme example where the text and math fonts are wildly different, but it's still a problem.
Reacted by Andreas Kröpelin, abejlq, Tesla Zhang, Mado, stepney141, Dixon Sean Low Yan Feng, Jacob Stevens-Haas, jaroeichler, Åke Amcoff, Y. Xu and 72 more
Reacted by Tesla Zhang and Winston Tsai
Reacted by Tesla Zhang, Kevin Stephen, Marcin Anforowicz and Winston Tsai
Let's see... if I understood correctly, currently "q" and q is parsed to exactly the same thing in math mode. The option whether or not to use italic font is only determined by the length of the string. #274
You can change math font, but it applies to both math and "text" inside math. #313
Maybe Typst could have an option to set different font for "text" and "math" part inside math mode.
I feel the behavior is intentional? See the section in the tutorial right after
If you want to have a variable that consists of multiple letters, you can enclose it in quotes:
It may be intentional, but a multiple-letter variable is very uncommon, and should be the exception rather than the rule. Math fonts are often not even designed for it to be used for text.
It could maybe be argued that it makes sense for "hello world" to be typeset using the math font, but the explicit text("hello world") definitely shouldn't.
Regardless of what the solution is, it should be easy to use the text font in a math environment without having to manually specify the font.
Reacted by Leedehai, user202729, UndefinedVoidNull, Andreas Kröpelin, Caleb Maclennan, MHellmund, Kye W. Shi, 陳柏瑄, ZC. Fang, Fabian Löschner and 9 more
Just to chime in-- it looks like this is very related to #1125.
Just wanted to add that another way to do text inside math is using the #[] content-block syntax:
X = {1, 2, 3} union {#[multiples of $5$]}
This is an example that most closely mirrors how I would use \text{} in LaTeX-- namely, to insert actual plain English text in math mode, and to be able to nest math expressions within text. Here is LaTeX equivalent:
X = \{1, 2, 3\}\cup\{\text{multiples of \(3\)} \}
In this setting, I very much expect that the text content is actually typeset using text font. Upright math font makes sense for multi-letter math terms and operators, e.g. lim, sin, exp, etc., but in my opinion it absolutely doesn't make sense for rich text content to default to math font.
Reacted by Åke Amcoff, Tesla Zhang, RedPolygon, T. Emil Rivera-Thorsen, Yunzhi Liu, Erni, Robert Bamler, Kevin Stephen, tianyi-smile, nleanba and 8 more
You're right. I wasn't clear. I was trying to do $ ["A"] $ and noticed that the A was italicized. So, I tried the "hack" of doing $ ["A "] $ and it rendered in a non-italicized style. However, replacing A with B was yielding different behavior (it remained italicized). However, I now realize it was likely a conflict due to the chem-par package.
Any progress on the original subject (text in math mode should use text font)?
If you want to see this fixed, please react with a thumbs-up instead of leaving a comment asking for progress. Otherwise, people will unecessarily be pinged. If you want to be more in the loop regarding general development, feel free to join the Discord server.
Reacted by Alberto Corbi, Tim Fischer, Aditya Singh, Kye W. Shi, platypus999, Bill Gan, Steffen Schuldenzucker, Kirill Dimitrenko, Elena Ferro, WinstonMDP and 4 more
AFAIK, there are 3 environments in Typst, code, markup, and math. The same way that there are mechanisms to switch environments from
from markup to code# ...
from code to markup[ ... ]
from markup tu math$ ... $
from code to math [ $ ... $ ] (which I like)
I don't see a clear path
(5) from math to markup" ... " (is it like this?)
Hence
(6) from math to code should be " # ... "? (I'm confused, even highlighting will fail on this)
I highlighted the 4 most important switches. Markup environment should be special, and one should be able to go back a forth from and to markup easily, with a simple construction like 1, 2, 3 and 5. The rest can be chained accesses like 4 and possibly 6.
IMHO, maybe making this type of distinctions in the environments, the behavior will be more expected and consistent, if clearly documented of course. I really like how well documented is the rest, BTW.
UPDATE: Maybe the solution would be to jump to code first. Since we already allow #x to access valuables that live in code, extending this behavior for all functions and for code expressions with #( ... ), then markup from math could be something like #( [ ... ] ).
I can live with the fact that $"..."$ corresponds to $\mathrm{...}$ in LaTeX, and I think having \mathrm{} be the easy-to-use default is probably actually the right thing to do, because I see LaTeX users reaching for \text{} often when \mathrm{} would be more appropriate; e.g., they might write D_\text{test} when D_\mathrm{test} is more correct (D_"test" in typst).
But something like #mtext[], which automatically switches to the current non-math font, should be available for when you write actual prose in a complex equation.
Reacted by nleanba, bluss, Tesla Zhang, Jonas Schulze and Pedro Marinho
#showmath.equation: it=> {
letfunc= $"text"$.body.func()
showfunc: settext(font: font-text)
it
}
does the trick. For instance
And therefore, if $ f(a) > 0 " and " f'(a) > 0, $ we have
$
// "G L"herewouldbeshowninfont-textupright(G L)(n, RR)
=
{M inRR^(n times n) | M "is invertible"}.
$$Delta U_"bath" + Delta U + W = 0 $$ U = U_"micro,pot" + U_"micro,kin"$
Note that /mathrm actually also uses the text font in latex.
Not in classic pdflatex:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tgbonum} % use TEX Gyre Bonum\usepackage{amsmath}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
$\mathrm{Lorem\ ipsum\ dolor\ sit\ amet,\ consectetur\ adipiscing\ elit.}$$\text{Lorem ipsum dolor sit amet, consectetur adipiscing elit.}$\end{document}
output:
Though maybe this is true for LuaLaTeX and unicode-math.
EDIT: yeah, for fontspec and unicode-math, I had to do it like this:
\usepackage{fontspec}
\usepackage{unicode-math}
\setmainfont{Times New Roman}
\setmathfont{New Computer Modern Math}
\setmathrm{New Computer Modern Math} % required for `\mathrm`
I find it a bit strange that (Xe/Lua)LaTeX went that way...
but then, since the above rule deals directly with the text element, it is what ultimately sets the style for all text in equations (which removes the need for
#showmath.text: settext(font: text-font)
). So adding
#showmath.op: it=> {
showtext: settext(font: font-math, size: font-size)
it
}
after has no effect. I haven't found a way to solve this. I'm also worried that this kind of code (in particular the tostr function above) might start to slow down compilation times for larger documents with many equations.
Only VERSION 1 works. If I use VERSION 2, there is no change in the operator font.
That's because you already have this
#showmath.equation: it=> {
showtext: settext(font: font-text, size: font-size)
it
}
and the show text: set text for equations will win over show math.op: set text. The effect of show text: set text(..) and set text(..) is not 100% the same w.r.t precedence, but show text: set text(..) is typically not idiomatic. Here, it can make sense as a workaround, but with #7855 this will become less relevant.
@NeilGirdhar#[] is not as it stands a "text mode" for math. It's parsing typst markup as usual but inserting it as content into an equation. Here's an example of when that goes wrong ($X_1$ is the broken example.)
$
X_1 & #[I am -1 on that idea.] \
X_2 & #[I am #"-1" on that idea.] \
X_3 & "I am -1 on that idea."\$
#[] is not as it stands a "text mode" for math. It's parsing typst markup as usual but inserting it as content into an equation. Here's an example of when that goes wrong (
𝑋
1
is the broken example.)
To me, if you're writing sentences like "I am -1 on that idea", then that is logically content. It's not math. According to any modern style guide, in running text, a minus written inline (like “−1”) should be set with either the true minus sign or an en dash rather than the other options you gave.
X_4 & #[I am −1 on that idea.] \
$X_4$ renders correctly :
The tiny dashes for $X_2, X_3$ are not appropriate to indicate minus in text.
Here's an example of how I would use quoted text in math mode:
Here, it's convenient to make the subscripts clearly not scalar indices, but rather names, which means rendering them as text, but ideally in the math font since they should still match the surrounding math.
Or else, do you have a reference suggesting otherwise?
Activity
user202729 commentedon Mar 27, 2023
Let's see... if I understood correctly, currently
"q"andqis parsed to exactly the same thing in math mode. The option whether or not to use italic font is only determined by the length of the string. #274You can change math font, but it applies to both math and
"text"inside math. #313Maybe Typst could have an option to set different font for "text" and "math" part inside math mode.
I feel the behavior is intentional? See the section in the tutorial right after
https://typst.app/docs/tutorial/writing-in-typst/
On the other hand currently you can do something like
textm("something")to put it in your own font...Enivex commentedon Mar 27, 2023
It may be intentional, but a multiple-letter variable is very uncommon, and should be the exception rather than the rule. Math fonts are often not even designed for it to be used for text.
It could maybe be argued that it makes sense for "hello world" to be typeset using the math font, but the explicit text("hello world") definitely shouldn't.
Regardless of what the solution is, it should be easy to use the text font in a math environment without having to manually specify the font.
Edit: Another example can be found in the reference https://typst.app/docs/reference/math/ . There, "area" and "radius" should arguably be typeset in the math font, but "is natural" should be typeset in the text font.
navh commentedon Aug 21, 2023
I think this is related
If I create a typst document that only contains:
N $N$ $"N"$ $"N."$the result is a wonky N on the last N.NoblFriend commentedon Aug 22, 2023
if necessary, it can now be "fixed" using the zero-width space: \u{200b}
[-]Text in math mode is not using the text font[/-][+]Text in math mode should use text font[/+]memset0 commentedon Dec 25, 2023
you can also use
uprightfunction if necessarykwshi commentedon Feb 5, 2024
Just to chime in-- it looks like this is very related to #1125.
Just wanted to add that another way to do text inside math is using the
#[]content-block syntax:X = {1, 2, 3} union {#[multiples of $5$]}This is an example that most closely mirrors how I would use
\text{}in LaTeX-- namely, to insert actual plain English text in math mode, and to be able to nest math expressions within text. Here is LaTeX equivalent:In this setting, I very much expect that the text content is actually typeset using text font. Upright math font makes sense for multi-letter math terms and operators, e.g.
lim,sin,exp, etc., but in my opinion it absolutely doesn't make sense for rich text content to default to math font.Andrew-S-Rosen commentedon May 27, 2024
Any ideas why "A " converts the A to text font but "B " does not?
Enivex commentedon May 27, 2024
I think you need to be more specific here. Neither are typeset using the text font by default.
Andrew-S-Rosen commentedon May 27, 2024
You're right. I wasn't clear. I was trying to do
$ ["A"] $and noticed that the A was italicized. So, I tried the "hack" of doing$ ["A "] $and it rendered in a non-italicized style. However, replacing A with B was yielding different behavior (it remained italicized). However, I now realize it was likely a conflict due to thechem-parpackage.pammacdotnet commentedon Oct 2, 2024
Any progress on the original subject (text in math mode should use text font)?
laurmaedje commentedon Oct 2, 2024
If you want to see this fixed, please react with a thumbs-up instead of leaving a comment asking for progress. Otherwise, people will unecessarily be pinged. If you want to be more in the loop regarding general development, feel free to join the Discord server.
iagobaapellaniz commentedon Nov 18, 2024
AFAIK, there are 3 environments in Typst, code, markup, and math. The same way that there are mechanisms to switch environments from
# ...[ ... ]$ ... $[ $ ... $ ](which I like)I don't see a clear path
" ... "(is it like this?)Hence
" # ... "? (I'm confused, even highlighting will fail on this)I highlighted the 4 most important switches. Markup environment should be special, and one should be able to go back a forth from and to markup easily, with a simple construction like 1, 2, 3 and 5. The rest can be chained accesses like 4 and possibly 6.
IMHO, maybe making this type of distinctions in the environments, the behavior will be more expected and consistent, if clearly documented of course. I really like how well documented is the rest, BTW.
UPDATE: Maybe the solution would be to jump to code first. Since we already allow
#xto access valuables that live in code, extending this behavior for all functions and for code expressions with#( ... ), then markup from math could be something like#( [ ... ] ).27 remaining items
tmke8 commentedon Dec 29, 2025
I can live with the fact that
$"..."$corresponds to$\mathrm{...}$in LaTeX, and I think having\mathrm{}be the easy-to-use default is probably actually the right thing to do, because I see LaTeX users reaching for\text{}often when\mathrm{}would be more appropriate; e.g., they might writeD_\text{test}whenD_\mathrm{test}is more correct (D_"test"in typst).But something like
#mtext[], which automatically switches to the current non-math font, should be available for when you write actual prose in a complex equation.peedromarinhow commentedon Jan 27, 2026
I think I found a partial solution. It seems like
does the trick. For instance
gets shown as

Here's the full code, adapted from the previous example by @kwshi: https://typst.app/project/rfdOwdkOp4Z5UhXWL4Qgxd
I got this idea after reading this thread: https://forum.typst.app/t/how-to-use-show-set-to-select-non-text-characters-in-math-equation/4782/10.
Edit: I haven't thoroughly tested this. Also, I should mention that operators such as
limare also affected.Andrew15-5 commentedon Jan 27, 2026
funcistext. I recently also usedshow textin a show rule, guess it has at least a few valid use cases.peedromarinhow commentedon Jan 27, 2026
Actually, it seems like just
is already enough.
Enivex commentedon Jan 27, 2026
Note that
/mathrmactually also uses the text font in latex.tmke8 commentedon Jan 27, 2026
Not in classic pdflatex:
output:
Though maybe this is true for LuaLaTeX and
unicode-math.EDIT: yeah, for fontspec and unicode-math, I had to do it like this:
I find it a bit strange that (Xe/Lua)LaTeX went that way...
Enivex commentedon Jan 27, 2026
Okay, i should clarify.
\mathrmuses the roman text font specified for math.winstontsai commentedon Feb 16, 2026
@peedromarinhow I think you can avoid affecting operators such as
limby setting the font formath.opback to the explicit math font.laurmaedje commentedon Feb 16, 2026
The
show math.textisn't really doing anything there. In particular, alsomath.text == text. You'd just writewinstontsai commentedon Feb 16, 2026
@laurmaedje I'm a bit of a noob here but your version doesn't work for me. If I have the following:
Only VERSION 1 works. If I use VERSION 2, there is no change in the operator font.
peedromarinhow commentedon Feb 16, 2026
@winstontsai That indeed works, but after trying it I found yet another issue. It turns out that
(which btw is equivalent to
) also affected the numbers. That can be solved by adding
but then, since the above rule deals directly with the text element, it is what ultimately sets the style for all text in equations (which removes the need for
). So adding
after has no effect. I haven't found a way to solve this. I'm also worried that this kind of code (in particular the
tostrfunction above) might start to slow down compilation times for larger documents with many equations.Btw, I've updated the example I used before to show the code above in action.
laurmaedje commentedon Feb 17, 2026
That's because you already have this
and the
show text: set textfor equations will win overshow math.op: set text. The effect ofshow text: set text(..)andset text(..)is not 100% the same w.r.t precedence, butshow text: set text(..)is typically not idiomatic. Here, it can make sense as a workaround, but with #7855 this will become less relevant.NeilGirdhar commentedon Mar 10, 2026
I don't know if this is the right metaphor. I think a lot of people write (and LLMs generate) math code like this:
So, it seems like double-quoted text should be in the upright math font?
For text in math mode, I think this is more legible
than
Thus, in my opinion, Typst is already doing the right thing?
bluss commentedon Mar 10, 2026
@NeilGirdhar$X_1$ is the broken example.)
#[]is not as it stands a "text mode" for math. It's parsing typst markup as usual but inserting it as content into an equation. Here's an example of when that goes wrong (NeilGirdhar commentedon Mar 13, 2026
To me, if you're writing sentences like "I am -1 on that idea", then that is logically content. It's not math. According to any modern style guide, in running text, a minus written inline (like “−1”) should be set with either the true minus sign or an en dash rather than the other options you gave.
The tiny dashes for$X_2, X_3$ are not appropriate to indicate minus in text.
Here's an example of how I would use quoted text in math mode:
Here, it's convenient to make the subscripts clearly not scalar indices, but rather names, which means rendering them as text, but ideally in the math font since they should still match the surrounding math.
Or else, do you have a reference suggesting otherwise?