How to get rid of unintentional space between text in Math Mode?

Why does this render to create space between the delta and ACD in math mode?

$n_("Vibrio" Delta upright("ACD"))=5$

I was able to get the desired result of no space by adding #h(-1em) between Delta and ACD but shouldn’t the math mode automatically remove spaces between text (coming from latex this was the expected behavior for me)?

1 Like

Please format your code using triple back-ticks (```) as described here:

Also, the title of your post should be a question. From the same page linked above:

The title of your question should make clear what your post is about. Good titles are questions you would ask your friend about Typst.


I don’t know what the “correct” spacing is, but you can remove the existing spacing by adding a zero width space symbol sym.zws:

$n_("Vibrio" Delta upright("ACD"))=5$\
$n_("Vibrio"#sym.zws;Delta#sym.zws;upright("ACD"))=5$

image
# enters code mode and ; exits it. Normally you don’t need a ; but here it’s important not to introduce another (unwanted) space to exit code mode.

Using the horizontal spacing function h() with its weak parameter set to true would be the same as using sym.zws. Usin it doesn’t even require a ; since the closing parenthesis ()) is there:

$n_("Vibrio"#h(0em, weak: true)Delta#h(0em, weak: true)upright("ACD"))=5$\
4 Likes

thanks for the improvement suggestions, quick response and offering a couple of different solutions. I have added more details in the question, mainly shouldn’t text in math mode automatically remove spaces. similar code in latex just squished the delta and ACD together which is what I’ve come to expect.

1 Like

In math mode, normally you use "..." to add text, and it is typically desired to have spaces around the text:

$  2 "if" x > 0 $

image

You can avoid the spaces by omitting the spaces in the source code:

$ 2"if"x > 0 $

image

Similarly in your example you can write the following (I think the upright is useless here anyway since the argument is not math but text):

$ n_("Vibrio"Delta"ACD")=5 $

image

But probably the “ABC” should be math, not text (i.e. it should use the math font). So I guess the right solution is:

$ n_("Vibrio"Delta upright(A C D))=5 $

image

5 Likes

This worked perfectly and the desired output!

$ n_("Vibrio"Delta"ACD")=5 $

By eye, I can’t tell the difference between this and ‘ACD’ in math mode, anyways I want both of them ‘vibrio’ and ‘ACD’ in text.

Depends on the semantical meaning. I believe this will change the output in HTML too, and how it’s read by the AT.