user13436711
user13436711

Reputation: 31

Bengali words printing out all wrong in manim

I had been trying to animate bengali characters using Manim. I used this method to use pc fonts in Manim. Everything seemed to be working well until i saw the output. For instance, if i write বাংলা লেখা i get the output as (look closely at the output) বাংলা লখো. Most of the times it spits out absolutely meaningless words.

The code used was:

class test_3(Scene):
    def construct(self):
        text1 = Text('বাংলা লেখা', font='Akaash')       
        text2 = Text('english text', font='Arial').move_to(DOWN)
        self.play(Write(text1), Write(text2))
        self.wait()

Upvotes: 3

Views: 845

Answers (3)

raf
raf

Reputation: 255

Bangla texts can be displayed properly just by specifying a Bangla font in Text() or MarkupText().

For example, if I like to display the Bangla text আইনস্টাইনের সমীকরণ in Kalpurush font, it can be done by:

from manim import *

class bangla(Scene):
    def construct(self):
        text = Text("আইনস্টাইনের সমীকরণ", font="Kalpurush")
        self.play(Write(text))

Here, the font is locally installed. Many fonts can be used directly from online via the python package manim-fonts.


If you want to nicely show Bangla texts/sentences that contain inline-maths, you can use the LaTeX package latexbangla.

Here's an example code:

from manim import *

class bangla(Scene):
    def construct(self):
        myTemplate = TexTemplate(tex_compiler="xelatex", output_format=".pdf", preamble=r"\usepackage[banglamainfont=Kalpurush, banglattfont=Kalpurush]{latexbangla}")
        tex = Tex(r"আইনস্টাইনের সমীকরণ, $E^2=(mc^2)^2+(pc)^2$", tex_template=myTemplate)
        self.play(Write(tex))

The output: bangla_ManimCE_v0 14 0

N.B. The issue was also discussed on the Github repositories: ManimCommunity/manim and 3b1b/maim.

Upvotes: 2

Md Ashraful Islam
Md Ashraful Islam

Reputation: 138

Try to use ANSI Bangla fonts like "SutonnyMJ". If you are using Avro keyboard you can use Output as ANSI option like this, Avro Keyboard Output as ANSI

Then if you have chosen font for example "SutonnyMJ", your code should look like this,

class test_3(Scene):
    def construct(self):
        text1 = Text('evsjv †jKAv', font='SutonnyMJ')       
        text2 = Text('english text', font='Arial').move_to(DOWN)
        self.play(Write(text1), Write(text2))
        self.wait()

Here I've replaced বাংলা লেখা with evsjv †jKAv (just ANSI form of the same Unicode text) which will render বাংলা লেখা as the font is now ANSI. I hope that Manim will support unicode fonts soon.


EDIT


I've found Bengali Unicode fonts to be working on Manim now. (24 March, 2021). I did this with Kalpurush font.

The code is

class FirstScene(Scene):
    def construct(self):
        text = Text("বাংলা অক্ষরে লেখা", font="Kalpurush")
        text2 = Text("Another text")
        self.play(Write(text), run_time=1)
        self.wait(3)
        self.remove(text)
        self.play(Write(text2))

See the screenshot below, Screenshot

Upvotes: 1

Navpreet Devpuri
Navpreet Devpuri

Reputation: 573

This is because of font type.
You should use bangli font. Try any font from here

Upvotes: 0

Related Questions