Repository navigation
Description
Description
I use ruby package to add furigana on top of the Japanese words in lualatex:
\documentclass[a4paper]{article}
\usepackage[margin=1cm]{geometry}
\pagestyle{empty}
\usepackage{fontspec}
\setmainfont{Noto Sans CJK JP}
\usepackage{ruby}
\usepackage{fontsize}
\changefontsize[21]{14}
\let\fu\ruby
\begin{document}
\begin{center}
\textbf{柊マグネタイト「マーシャル・マキシマイザー」歌詞}
\end{center}
\begin{center}
\fu{唖}{あ}\fu{々}{あ}、\fu{臨界実験}{りんかいじっけん}に\fu{付}{つ}き\fu{合}{あ}う\fu{朝}{あさ}
\end{center}
\end{document}I just tried a few things with Typst and I can already tell with 99% of confidence that I can do everything I do with lualatex except adding furigana, which is a crucial part of some Japanese documents (depends on type of document and other things). I was thinking about making some kind of table/math-like vertically nested text, but I'm not a package creator, so I don't know how it is (properly) implemented in ruby package, and therefore I don't know how to implement this in Typst. By this, I mean some easy and concise way to add a Typst alternative of \ruby{}{} (without making a separate feature or template or something).
Use Case
It is not the feature everyone will want, but it should probably be included in the compiler (as a Japanese language "exclusive" feature). As furigana is a way to tell the reader how to pronounce words, this feature would be useful for creating content for Japanese beginners or children such as text books, comics (a.k.a. manga) and much more (or lyrics as per my example).
P.S. It could imply that the "vertical" "right to left" layout must be implemented in the Typst as well (for traditional Japanese style text flow).

Activity
Andrew15-5 commentedon Jun 13, 2023
I can think of the most compact and kind of intuitive way of writing it in Typst:
This way you can easily change where the furigana will be placed. And in the simple case, as with the
五^ごyou don't even need to use parenthesis.This looks very clean and makes a lot of sense of you are writing documents with furigana.
bluebear94 commentedon Jun 14, 2023
Note that this feature is complicated to implement properly – see “Requirements for Japanese Text Layout” for more info.
Andrew15-5 commentedon Jun 14, 2023
If you are referring to grouping methods of the ruby and/or base text, then it is purely manual thing. The author chooses which ruby should go next to which base text (see my examples above). The line spacing, as I checked, is only affected by the presence of ruby between the title and the first line of lyrics. All other lines stay the same (1.5 distance) and the ruby goes right in the empty space between the lines. Which means that ruby in most cases doesn't alter line spacing.
In conclusion, it is the author who must make sure that there is enough room for ruby to fit in nicely and be readable and not the typesetting program. The program only needs to make sure that selected ruby is centered right next to selected base text (on top or to the right of the base text). Selection is made of
{}in LaTeX (or()as in my previous comment).P.S. I didn't mention the font size of the ruby. The
rubypackage has the\rubysizemacro that stores font size ratio compared to\normalsizeand by default is equal to0.4(whereas1is equal to\normalsize).[-]Add support for furigana (Japanese)[/-][+]Add support for ruby/furigana (Japanese)[/+]Andrew15-5 commentedon Jun 14, 2023
I don't know if Typst output must be the exact same as LaTeX (probably not), but I was able to completely rewrite my document in Typst (with a lot of small size offsets as compared to LaTeX) using
ruby-typlibrary:The most noticeable things (that are also relative to the issue) are:
Here are LaTeX and Typst examples, respectively:
LaTeX — green, Typst — red:
Overall, both have some positive and negative points, but
ruby-typis not included anywhere (whereasrubyis included in TeX Live and is on CTAN) and has a major issue of not checking for ruby collisions with page margin boundaries and text itself.Andrew15-5 commentedon Jun 14, 2023
Oh, sorry. It can prevent ruby overlapping by manually putting "delimeter" character between adjacent base text and ruby:
Which resolves only half of the problem (it still goes out of the defined page bounds), but also now I have to manually check if there is any overlapping and change the Typst code accordingly. This type of stuff should be automated by the library (or compiler) to eliminate human error (maybe someone didn't check properly and some overlapping is still present in the document).
Andrew15-5 commentedon Jun 28, 2023
I added
[][]format for the library: https://gist.github.com/Andrew15-5/725f1b036fdb376363bd96d8f814aaf7.Now I can use
#ruby[ふりがな][振り仮名]which removes additional""and changes first()to[]. Delimiter also works.This format of the function looks very production ready (not the code itself). Either
#r[][]/#ruby[][]or something like()^()looks pretty good (if it would be the official Typst syntax/feature).Update: Added
auto_spacing: truetoget_ruby()which results in automatic addition of space if ruby is wider than base text (by adding missing delimiter around everycontent/string). This way there won't be any ruby overlapping (when 2 or more rubies are next to each other) and there will be always enough space around base text (if ruby is wider than base text, but there is no adjacent rubies).Andrew15-5 commentedon Jun 30, 2023
I have good news. I've tried adding delimiter around the text (which is something I never thought of even trying), and the problem with ruby going out of page boundaries is resolved. The last problem left is not related to the ruby, so I made a separate discussion.
P.S. I created a repository with improved syntax, which is also a candidate for the public package.
Update:
The package is now merged in Typst
@previewnamespace and can be used like this:[-]Add support for ruby/furigana (Japanese)[/-][+]Add support for ruby/furigana (CJK, e.g., Japanese)[/+][-]Add support for ruby/furigana (CJK, e.g., Japanese)[/-][+]Add support for ruby (CJK, e.g., furigana for Japanese)[/+]minamotorin commentedon Apr 25, 2024
Referencing ruby package of LaTeX, a part of CJK package, is not a good idea. It does not follow Requirements for Japanese Text Layout and it outputs bad typesetting.
In LaTeX, I recommend to refer to pxrubrica package or luatexja-ruby package, a part of luatexja package.
For general information on Japanese typesetting with LaTeX, I reccomend
texdoc japanese.Andrew15-5 commentedon Apr 25, 2024
Interesting, I will try reading it when I got time.
I was using this package only because it looked like the most popular one. I don't remember seeing any other ruby package mentioned before.
OverflowCat commentedon Feb 21, 2025
So, yeah, ruby is involved with linebreaks. The userland implementation can't achieve this effect.
Andrew15-5 commentedon Feb 23, 2025
What does this mean? You mean packages can't fully implement this and only native implementation can truly work? Since ruby is glued to the base text, I don't think it changes anything. It would just depend on/follow how the base text is typeset.
OverflowCat commentedon Feb 23, 2025
Take this example,
#ruby[プルミエール、ダンス][第一位舞踏者]is a single unit, which is different from those that can separated like#ruby[とう|きょう|こう|ぎょう|だい|がく][東|京|工|業|大|学]. We don't know if or where this text will break lines. If it breaks at 第一位舞踏|者, we need to measure the linebreak, that is, calculate the lengths of 第一位舞踏 and 者, and divide プルミエール、ダンス into a 5:1 length ratio. (Both the ruby base and the ruby itself might not be monospace, so counting characters do not work.)Andrew15-5 commentedon Feb 23, 2025
OK, I think I understand. But I still don't know of the text line breaking rules in Japanese. I guess it is indeed would be much easier to do this perfectly in the native code.