3b1b / manim

Animation engine for explanatory math videos
MIT License
62.01k stars 5.77k forks source link

How to use Russian rendering texts in manim library ? #1293

Open malkowski18 opened 3 years ago

malkowski18 commented 3 years ago

Dear manim users,

I use windows 10 and PyCharm. I run manim scripts on a console. I would like to render some texts in Russian for my lessons and I do not know how to change the settings to add this functionality. please could you help me? I suppose I must add something to the latex preamble file.

Thank you

NeoPlato commented 3 years ago

I was curious and did a bit of digging on this. You may add the extra stuff to your preamble, but as a non-Russian speaker I can't know if this is legit or not.

\documentclass{article}

\usepackage[english, russian]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T2A, 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 = * }
\linespread{1}

\begin{document}

Text in English

\begin{otherlanguage*}{russian}

    В начале июля, в чрезвычайно жаркое время, под вечер, один молодой человек вышел из своей каморки, 
    которую нанимал от жильцов в С — м переулке, на улицу и медленно, как бы в нерешимости, отправился к К — ну мосту

\end{otherlanguage*}

A word and another \foreignlanguage{russian}{слово}

\end{document}

Crime and Punishment. Fitting test case, I guess

image

image

malkowski18 commented 3 years ago

I was curious and did a bit of digging on this. You may add the extra stuff to your preamble, but as a non-Russian speaker I can't know if this is legit or not.

\documentclass{article}

\usepackage[english, russian]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T2A, 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 = * }
\linespread{1}

\begin{document}

Text in English

\begin{otherlanguage*}{russian}

    В начале июля, в чрезвычайно жаркое время, под вечер, один молодой человек вышел из своей каморки, 
    которую нанимал от жильцов в С — м переулке, на улицу и медленно, как бы в нерешимости, отправился к К — ну мосту

\end{otherlanguage*}

A word and another \foreignlanguage{russian}{слово}

\end{document}

Crime and Punishment. Fitting test case, I guess

image

image

Thank you a lot! It works and the text is correct. For anyone meeting the same issue : find your manim catalogue. Go to catalogue manimlib -> textamplate.tex and edit this file as it is shown in the comment above.

arman-sydikov commented 7 months ago

I had to change one line to make it work, as of version 0.18.0 manim was installed to /usr/local/lib/python3.11/site-packages/manim on my mac

$ pip3 show manim
Name: manim
Version: 0.18.0
Location: /usr/local/lib/python3.11/site-packages

So I had to fix tex.py by including russian to usepackage[english]{babel} in TexTemplate class /usr/local/lib/python3.11/site-packages/manim/utils/tex.py

Before

default_preamble = r"""
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
"""

After

default_preamble = r"""
\usepackage[english, russian]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
"""