ManimCommunity / manim

A community-maintained Python framework for creating mathematical animations.
https://www.manim.community
MIT License
20.86k stars 1.52k forks source link

Chinese/Japanese text cannot be presented #3256

Closed wangjia184 closed 1 year ago

wangjia184 commented 1 year ago

Description of bug / unexpected behavior

Run the example code of multiple-font and it ended with following screenshot image

Expected behavior

It should be like this one: image

How to reproduce the issue

Manim Community v0.17.3, starting it using docker

docker run -it -p 8888:8888 -v "G:\\projects\\manim:/manim"  manimcommunity/manim jupyter lab --ip=0.0.0.0

Then run the multiple-font example code from https://docs.manim.community/en/stable/reference/manim.mobject.text.text_mobject.Text.html#multiplefonts

%%manim -ql MultipleFonts 

class MultipleFonts(Scene):
    def construct(self):
        morning = Text("வணக்கம்", font="sans-serif")
        japanese = Text(
            "日本へようこそ", t2c={"日本": BLUE}
        )  # works same as ``Text``.
        mess = Text("Multi-Language", weight=BOLD)
        russ = Text("Здравствуйте मस नम म ", font="sans-serif")
        hin = Text("नमस्ते", font="sans-serif")
        arb = Text(
            "صباح الخير \n تشرفت بمقابلتك", font="sans-serif"
        )  # don't mix RTL and LTR languages nothing shows up then ;-)
        chinese = Text("臂猿「黛比」帶著孩子", font="sans-serif")
        self.add(morning, japanese, mess, russ, hin, arb, chinese)
        for i,mobj in enumerate(self.mobjects):
            mobj.shift(DOWN*(i-3))

Others

There is no TEX_USE_CTEX = True in constants.py any more.

This issue from 3b1b says the following config could fix it. But seems that is not available to community edition?

tex:
  executable: xelatex -no-pdf
  intermediate_filetype: xdv
  template_file: ctex_template.tex
  text_to_replace: '[tex_expression]'
uwezi commented 1 year ago

The example you use does use Text() and not Tex() therefore "ctex" has no relevance here.

Text() uses your system's fonts for rendering - and it seems that the font used by default is lacking CJK-characters. Not all system fonts contain a full set of unicode characters. I don't know which fonts are available inside your Docker environment.

In this parallel discussion you can see that neither Text() nor Tex() have a principle problem with CJK-fonts: BraceLabel text can not use chinese #3254

Come over to Discord - there are both Japanese and Chinese communities which will probably be able to help you: Where can I find more resources for learning Manim?

image

On my system without fine tuning the fonts, at least Japanese, Cyrillic, Arabic and Chinese work with the fonts I have installed image

wangjia184 commented 1 year ago

Thanks @uwezi , I solved this problem by installing Chinese font into docker image

FROM manimcommunity/manim:v0.17.3

USER root
RUN apt-get install -y fontconfig fonts-wqy-zenhei
RUN fc-cache -fv

USER manimuser

First installs fontconfig (https://packages.debian.org/sid/fontconfig) and the Chinese Fonts (https://packages.debian.org/sid/fonts/). And then rebuilds the font cache

Three font families can be used now