Spacing with text in equations with a single CJK charater

The spacing behavior is now that, if the text in an equation consists of multiple characters, then the spacing is added.

This makes sense for English texts, but not for CJK characters - a single CJK character could mean something. For example,

$ A union B = {x : x in A "或" x in B} $

Here should be spacing before and after the “或” character (means “or”).

My current solution is to add a \u200b character (Zero Width Space) to force it to be 2-character long. Is there a more elegant way to do this?

Could you give a screenshot? I can’t reproduce what you’ve described.

#show math.equation: set align(start)
$ A union B = {x : x in A "或" x in B} $
$ A union B = {x : x in A "抑或" x in B} $
$ A union B = {x : x in A #[或] x in B} $
$ A union B = {x : x in A #[抑或] x in B} $


Rendered via Typst-Renderer on discord, and I get the same with my local Typst renderer. Is this because this is solved on a newer version?

Oh, you didn’t put spaces around "…", but your code example put spaces…

#show math.equation: set align(start)

= Without spaces
$ A union B = {x : x in A"或"x in B} $
$ A union B = {x : x in A"抑或"x in B} $
$ A union B = {x : x in A#[或]x in B} $
$ A union B = {x : x in A#[抑或]x in B} $

= With spaces
$ A union B = {x : x in A "或" x in B} $
$ A union B = {x : x in A "抑或" x in B} $
$ A union B = {x : x in A #[或] x in B} $
$ A union B = {x : x in A #[抑或] x in B} $

Do you have any evidence?

In my local project it behaviors as in the body.
image
produces
image
and
image
produces
image

I’m kinda confused - is this some problem with my settings or typst version?

(by the way should I modify this post’s title & tags by this)

Probably. If you want others to help, please provide more context.

Indeed, if you are only showing part of a document, this is highly likely a problem with your settings. Maybe some transformational show rule somewhere.

I can reproduce what @Y.D.X posted in Spacing with text in equations with a single CJK charater - #4 by Y.D.X. If there are spaces in the source, it will be reflected in the output.

My guess is that some math-related package is used that modifies math.equation, like quick-maths – Typst Universe or something.

The guidelines say that you should post minimal code, and so far it renders correctly for at least 2 of 3. How to post in the Questions category

Also, https://sscce.org can be useful in the long run.

Single-letter strings are affected by this 0.14.1 bug fix: Single-letter strings inside math mode are not sensitive to spaces around them · Issue #7270 · typst/typst · GitHub

2 Likes

Moreover, the aforementioned bot is on 0.14.2, and it also handles the example from Spacing with text in equations with a single CJK charater - #4 by Y.D.X correctly.