3b1b / manim

Animation engine for explanatory math videos
MIT License
70.02k stars 6.17k forks source link

Arabic in Manim #1173

Open AyoubRahbawi opened 4 years ago

AyoubRahbawi commented 4 years ago

hello guys i did try this solution here https://github.com/3b1b/manim/issues/342 i added the usepackages of arabic as it said there . but i got random arabic letter instead of english and and also the arabic text i wanted was not written correctly please i need some help here .

TonyCrane commented 4 years ago

Try to use Text instead of Tex(t)Mobject ?

mohamed99akram commented 3 years ago

You can write your text "مرحبا" here and copy the output. then use Text("ﺎﺒﺣﺮﻣ") in your code. it works for me, the text is written correctly. There are 2 things I still need to know though: 1- How to change the font 2- How to write(text) from right to left instead of left to write

yousif-hag-ahmed commented 3 years ago

I got it working please check this ;

image

use this tex file changes

\documentclass[preview]{standalone}

\usepackage[utf8]{inputenc} \usepackage[arabic,english]{babel} \usepackage{arabtex} \usepackage[LAE,LFE]{fontenc}

\usepackage[T1]{fontenc} \usepackage{amsmath} \usepackage{amssymb} \usepackage{dsfont} \usepackage{setspace} \usepackage{tipa} \usepackage{relsize} \usepackage{textcomp} \usepackage{mathrsfs} \usepackage{calligra} \usepackage{wasysym} \usepackage{ragged2e} \usepackage{physics} \usepackage{xcolor} \usepackage{microtype} %\DisableLigatures{encoding = , family = } \usepackage[UTF8]{ctex} \linespread{1}

\begin{document}

\begin{align} \quad \end{align}

\end{document}

and call using TextMobject like this example_text = TextMobject( "هذه بعض المعادلات ", tex_to_color_map={"text": YELLOW} )

hope this helps 👍

please note : after this changes you need to use Text for writing in English

Sameed123 commented 3 years ago

I got it working please check this ;

image

use this tex file changes

\documentclass[preview]{standalone}

\usepackage[utf8]{inputenc} \usepackage[arabic,english]{babel} \usepackage{arabtex} \usepackage[LAE,LFE]{fontenc}

\usepackage[T1]{fontenc} \usepackage{amsmath} \usepackage{amssymb} \usepackage{dsfont} \usepackage{setspace} \usepackage{tipa} \usepackage{relsize} \usepackage{textcomp} \usepackage{mathrsfs} \usepackage{calligra} \usepackage{wasysym} \usepackage{ragged2e} \usepackage{physics} \usepackage{xcolor} \usepackage{microtype} %\DisableLigatures{encoding = , family = } \usepackage[UTF8]{ctex} \linespread{1}

\begin{document}

\begin{align} \quad \end{align}

\end{document}

and call using TextMobject like this example_text = TextMobject( "هذه بعض المعادلات ", tex_to_color_map={"text": YELLOW} )

hope this helps 👍

please note : after this changes you need to use Text for writing in English

Hi Yousif, I tried changing my tex_template.tex file according as you have described.

For some reason I am getting an error. It's saying: "Latex error converting to dvi."

Do you know why this is happening.

Maybe it's some issue with my version of manim.

May I know which version you are using?

Also, I am using a Mac. If you are not using Mac then maybe that's why it is not working for me... (I am mostly a noob at this sort of stuff so excuse me if my questions are too stupid...)

Also, I am running manim on pycharm. Can this possibly be a reason for this error?

Basically I want to know exactly how you are using manim and which version it is so that I can try to do exactly what you are doing.

Any help here would be great.

Thanks a lot.

yousif-hag-ahmed commented 3 years ago

hi I am using Windows actually , can you post your py code so that I can take a look at it and maybe try it here and see . thanks

mahdirezaie336 commented 3 years ago

I got it working please check this ;

image

use this tex file changes

\documentclass[preview]{standalone}

\usepackage[utf8]{inputenc} \usepackage[arabic,english]{babel} \usepackage{arabtex} \usepackage[LAE,LFE]{fontenc}

\usepackage[T1]{fontenc} \usepackage{amsmath} \usepackage{amssymb} \usepackage{dsfont} \usepackage{setspace} \usepackage{tipa} \usepackage{relsize} \usepackage{textcomp} \usepackage{mathrsfs} \usepackage{calligra} \usepackage{wasysym} \usepackage{ragged2e} \usepackage{physics} \usepackage{xcolor} \usepackage{microtype} %\DisableLigatures{encoding = , family = } \usepackage[UTF8]{ctex} \linespread{1}

\begin{document}

\begin{align} \quad \end{align}

\end{document}

and call using TextMobject like this example_text = TextMobject( "هذه بعض المعادلات ", tex_to_color_map={"text": YELLOW} )

hope this helps

please note : after this changes you need to use Text for writing in English

Hi yousif I did exactly what you said but for me it gives this exception:

Traceback (most recent call last): File "/home/mahdi/.local/lib/python3.9/site-packages/manimlib/extract_scene.py", line 155, in main scene = SceneClass(**scene_kwargs) File "/home/mahdi/.local/lib/python3.9/site-packages/manimlib/scene/scene.py", line 75, in init self.construct() File "main.py", line 7, in construct my_text = TextMobject("هذه بعض المعادلات ", tex_to_color_map={"text": YELLOW}) File "/home/mahdi/.local/lib/python3.9/site-packages/manimlib/mobject/svg/tex_mobject.py", line 150, in init self.break_up_by_substrings() File "/home/mahdi/.local/lib/python3.9/site-packages/manimlib/mobject/svg/tex_mobject.py", line 190, in break_up_by_substrings sub_tex_mob.move_to(self.submobjects[last_submob_index], RIGHT) IndexError: list index out of range

Do you have any solutions?

seloumi commented 1 year ago

Here how can you write arabic with mixed math, you need to use lualatex with a recent tex distribution

from manim import *

my_template = TexTemplate(
tex_compiler="lualatex",
preamble=r"""
\usepackage[bidi = basic]{babel}
\babelprovide[main, import]{arabic}
\babelfont{rm}{Amiri}""")

class ArabTex(Tex):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, tex_template=my_template, **kwargs)

class Test(Scene):
    def construct(self):
        arab_text= ArabTex(r'نص عربي طويل مع عبارات رياضية $ax+b$',font_size=50).to_corner(UR)
        self.play(Write(arab_text))
        self.wait()
        tex = MathTex(r'f(x) &= 3 + 2 + 1\\ &= 5 + 1 \\ &= 6', font_size=50)
        tex.next_to(arab_text, DOWN,buff=0.5)
        self.add(tex)
        self.wait()
        circle= Circle()
        circle.next_to(tex, DOWN, buff=0.5) 
        self.play(Create(circle))

https://user-images.githubusercontent.com/8249073/236542312-466a1bcf-5f16-447a-86e3-f7143db234e1.mp4

Xenomorphs commented 1 year ago

Here how can you write arabic with mixed math, you need to use lualatex with a recent tex distribution

from manim import *

my_template = TexTemplate(
tex_compiler="lualatex",
preamble=r"""
\usepackage[bidi = basic]{babel}
\babelprovide[main, import]{arabic}
\babelfont{rm}{Amiri}""")

class ArabTex(Tex):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, tex_template=my_template, **kwargs)

class Test(Scene):
    def construct(self):
        arab_text= ArabTex(r'نص عربي طويل مع عبارات رياضية $ax+b$',font_size=50).to_corner(UR)
        self.play(Write(arab_text))
        self.wait()
        tex = MathTex(r'f(x) &= 3 + 2 + 1\\ &= 5 + 1 \\ &= 6', font_size=50)
        tex.next_to(arab_text, DOWN,buff=0.5)
        self.add(tex)
        self.wait()
        circle= Circle()
        circle.next_to(tex, DOWN, buff=0.5) 
        self.play(Create(circle))

Test.mp4

I'm getting this error, do you know why?:

[06/16/23 22:32:30] INFO     Writing نص عربي طويل مع عبارات رياضية    tex_file_writing.py:97                             $ax+b$ to media\Tex\96664e1c55cbdbda.tex
[06/16/23 22:32:37] ERROR    LaTeX compilation error: LaTeX Error:   tex_file_writing.py:285                             File 'luatex85.sty' not found.

ERROR    LaTeX compilation error: Emergency  stop.    tex_file_writing.py:285                             

ERROR    LaTeX compilation error:  ==> Fatal error occured, bad output DVI file produced!  tex_file_writing.py:285             
Xenomorphs commented 1 year ago

I got it working please check this ; image use this tex file changes \documentclass[preview]{standalone} \usepackage[utf8]{inputenc} \usepackage[arabic,english]{babel} \usepackage{arabtex} \usepackage[LAE,LFE]{fontenc} \usepackage[T1]{fontenc} \usepackage{amsmath} \usepackage{amssymb} \usepackage{dsfont} \usepackage{setspace} \usepackage{tipa} \usepackage{relsize} \usepackage{textcomp} \usepackage{mathrsfs} \usepackage{calligra} \usepackage{wasysym} \usepackage{ragged2e} \usepackage{physics} \usepackage{xcolor} \usepackage{microtype} %\DisableLigatures{encoding = , family = } \usepackage[UTF8]{ctex} \linespread{1} \begin{document} \begin{align} \quad \end{align} \end{document} and call using TextMobject like this example_text = TextMobject( "هذه بعض المعادلات ", tex_to_color_map={"text": YELLOW} ) hope this helps 👍 please note : after this changes you need to use Text for writing in English

Hi Yousif, I tried changing my tex_template.tex file according as you have described.

For some reason I am getting an error. It's saying: "Latex error converting to dvi."

Do you know why this is happening.

Maybe it's some issue with my version of manim.

May I know which version you are using?

Also, I am using a Mac. If you are not using Mac then maybe that's why it is not working for me... (I am mostly a noob at this sort of stuff so excuse me if my questions are too stupid...)

Also, I am running manim on pycharm. Can this possibly be a reason for this error?

Basically I want to know exactly how you are using manim and which version it is so that I can try to do exactly what you are doing.

Any help here would be great.

Thanks a lot.

Getting the same error on Windows. Did you find a way to write Arabic?

Xenomorphs commented 1 year ago

Here how can you write arabic with mixed math, you need to use lualatex with a recent tex distribution

from manim import *

my_template = TexTemplate(
tex_compiler="lualatex",
preamble=r"""
\usepackage[bidi = basic]{babel}
\babelprovide[main, import]{arabic}
\babelfont{rm}{Amiri}""")

class ArabTex(Tex):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, tex_template=my_template, **kwargs)

class Test(Scene):
    def construct(self):
        arab_text= ArabTex(r'نص عربي طويل مع عبارات رياضية $ax+b$',font_size=50).to_corner(UR)
        self.play(Write(arab_text))
        self.wait()
        tex = MathTex(r'f(x) &= 3 + 2 + 1\\ &= 5 + 1 \\ &= 6', font_size=50)
        tex.next_to(arab_text, DOWN,buff=0.5)
        self.add(tex)
        self.wait()
        circle= Circle()
        circle.next_to(tex, DOWN, buff=0.5) 
        self.play(Create(circle))

Test.mp4

Can you also please tell me how you've set everything up for it to work? Please give as much detail as possible, thanks.

seloumi commented 11 months ago

@Xenomorphs what tex distribution you have on your system?

halakilm commented 2 months ago
from manim import *
from manim import config

# Configurer Manim pour produire des vidéos en qualité 2160p à 60fps
config.pixel_height = 2160
config.pixel_width = 3840
config.frame_rate = 60
class HelloWorld(Scene):
    def construct(self):
        # انشاء النص مع حجم خط أكبر
        النص_بالعربية = Text(
            " .{وَلَا تَحْسَبَنَّ الَّذِينَ قُتِلُوا فِي سَبِيلِ اللَّهِ أَمْوَاتًا بَلْ أَحْيَاءٌ عِنْدَ رَبِّهِمْ يُرْزَقُونَ}.",
            font="Times New Roman", color=WHITE, font_size=25).scale(1.5)[::-1]

        # عرض النص
        self.play(Write(النص_بالعربية))
        self.wait(2)
halakilm commented 2 months ago

https://github.com/user-attachments/assets/1343d282-0817-4ac8-b0c1-b940f5fe34bb