How do I remove automatically inserted spaces in Japanese?

I use typst to create Japanese documents, but I have one problem.
It is that line breaks in the typst file are causing unexpected output format changes – spaces are automatically inserted.
This is not a problem when using LaTeX or perhaps when using typst to create documents in many other languages.

#set text(
  lang: "ja",
  font: "Noto Sans CJK JP",
  cjk-latin-spacing: auto,
)

// From the two examples below, we would like to get the same output,
// but the automatically inserted spaces result in different output.
// Example 1:
εΎθΌ©γ―ηŒ«γ§γ‚γ‚‹γ€‚
名前はまだ焑い。

//Example 2:
εΎθΌ©γ―ηŒ«γ§γ‚γ‚‹γ€‚εε‰γ―γΎγ η„‘γ„γ€‚

image

So, my question is this:
Is there a layout setup or scripting method that would allow me to input Example 1 and still get the same output as Example 2? In other words, is there any way to eliminate or prevent the spaces automatically inserted by line breaks?

1 Like
#set text(
  lang: "ja",
  font: "Noto Sans CJK JP",
  cjk-latin-spacing: auto,
)

#show regex(`\s+`.text): ""

// From the two examples below, we would like to get the same output,
// but the automatically inserted spaces result in different output.
// Example 1:
εΎθΌ©γ―ηŒ«γ§γ‚γ‚‹γ€‚
名前はまだ焑い。

//Example 2:
εΎθΌ©γ―ηŒ«γ§γ‚γ‚‹γ€‚εε‰γ―γΎγ η„‘γ„γ€‚

My opinion is that a single line should be written in one line. And a line break in source code should be translated into a soft break, it’s not a bug.

1 Like

Thank you very much! It seems to be working as I expected.

I understand that this implementation is not a bug, and I understand the argument that what I want to output as a single line should be written as a single line in the source code.
However, for example if a paragraph consists of more than 100 sentences, under this implementation it should be written as a single line of source code. That is sometimes very difficult to use.
I wanted to know if there is a way for the user to control the behavior of soft break.

Thank you very much again for your kind instruction!

This makes sense, and it’s the same in Chinese typesetting. I think this is because Typst is designed for western language, in which words are separated by spaces.

Unhopefully, not for now. But I can see the Typst community do trying to benefit CJK users, like this Text Function #cjk-latin-spacing. Maybe text function will have a cjk-soft-break parameter in the future, which can eliminate unnecessary spaces between CJK characters. :smiling_face_with_three_hearts:

Hi @octo8, your issue is - kind of - already reported as a feature request here: Ignore linebreaks between CJK characters in source code Β· Issue #792 Β· typst/typst Β· GitHub (and you could vote on it by adding a :+1: on the issue). I say kind of since the issue already prescribes a particular fix with comments, but I think other solutions are mentioned there too.

The project wants to have a solution for the issue for typst 0.14, so that’s promising.

3 Likes