typst
typst copied to clipboard
Text in math mode should use text font
I became aware of this while trying to understand https://github.com/typst/typst/issues/355
If I change the text font to "Comic Neue" (Only to get a distinctly different font)
Hello world, $"Hello world"$, $#text(font: "Comic Neue")[Hello world]$
will render as
This is not what I expect. In LaTeX, the input
Hello world, $\text{Hello world}$
will indeed render as
,
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.
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:
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...
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.
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.
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.![]()
if necessary, it can now be "fixed" using the zero-width space: \u{200b}
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.if necessary, it can now be "fixed" using the zero-width space: \u{200b}
you can also use upright
function if necessary
Just to chime in-- it looks like this is very related to https://github.com/typst/typst/issues/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.
Any ideas why "A " converts the A to text font but "B " does not?
Any ideas why "A " converts the A to text font but "B " does not?
I think you need to be more specific here. Neither are typeset using the text font by default.
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.
I agree with the proposal, although I have some concerns regarding implementation. I certainly would not want math operators to look different than the other math objects, so if the desired math font offers a corresponding text version, there should probably be a way to tell Typst to use it for operators — for example, Libertine for general text, New CM Math for math, and New CM for operators. (It is probably not a good idea to use the upright style of the math font because, as has already been said, math fonts usually are not built to support long strings of characters, e.g. they don't support even standard ligatures.)
(Note that I'm assuming a distinction of operators/variables and math-embedded text as outlined in #1125.)