ManimCommunity / manim

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

weird baseline issue in multilanguage LaTeX objects #3262

Open uwezi opened 1 year ago

uwezi commented 1 year ago

Description of bug / unexpected behavior

When mixing Chinese script and Western text inside the same Tex() object using the TexTemplateLibrary.ctex or XeLaTeX directly, the baselines of the Chinese script is not adjusted to the rest of the text. Running the same code on Docker with Manim v0.16.0 results in a correct rendering.

Expected behavior

The baseline generated by LaTeX/XeLaTeX should be preserved.

How to reproduce the issue

Code for reproducing the problem ```py class MyScene2(Scene): def construct(self): tex = Tex(r'Hallo 你好 \LaTeX', tex_template=TexTemplateLibrary.ctex).scale_to_fit_width(12) self.add(tex) self.wait() ```

Additional media files

Images/GIFs XeLaTeX output: ![image](https://github.com/ManimCommunity/manim/assets/8582807/5eb01cc9-0b8c-4b84-be78-1819c6c68c5b) Docker ![image](https://github.com/ManimCommunity/manim/assets/8582807/43daff35-59b6-4fb1-9298-da44b2924886) Manim v0.17.3 ![image](https://github.com/ManimCommunity/manim/assets/8582807/a5d96193-f26f-41cf-a3cb-34aed00ef4c5)

System specifications

System Details - OS: Windows 10 - Python version 3.9.8 - XeTeX, Version 3.141592653-2.6-0.999995 (MiKTeX 23.5)

Additional comments

same unwanted behavior is observed on the Manimator on Discord

uwezi commented 1 year ago

Conversion using a xetex-generated .pdf instead of .xdv works:

class MyScene3(Scene):
    def construct(self):
        template = TexTemplateLibrary.ctex
        template.output_format=".pdf"
        tex = Tex(r'Hello  你好  \LaTeX', tex_template=template).scale_to_fit_width(12)
        self.add(tex)
        self.wait() 

image

louisstuart96 commented 1 year ago

Actually this bug is brought by dvisvgm program. dvisvgm involves converting dvi/xdv format generated by LaTeX into SVG picture, the latter being what manim is really operating with. You can check the cache files in media folder and find some LaTeX files and corresponding xdv and SVG files.

I suggest you can collect all these files and report an issue to https://github.com/mgieseki/dvisvgm.

EDIT: MWE.tex for this case:

\documentclass[preview]{standalone}
\usepackage{xeCJK}
\setCJKmainfont{SimSun}
\begin{document}
Hallo 你好 \LaTeX
\end{document}

Commands for generating xdv and SVG file:

xelatex -no-pdf MWE.tex
dvisvgm -n MWE.xdv
MarkHoo commented 1 year ago

Actually this bug is brought by dvisvgm program. dvisvgm involves converting dvi/xdv format generated by LaTeX into SVG picture, the latter being what manim is really operating with. You can check the cache files in media folder and find some LaTeX files and corresponding xdv and SVG files.

I suggest you can collect all these files and report an issue to https://github.com/mgieseki/dvisvgm.

EDIT: MWE.tex for this case:

\documentclass[preview]{standalone}
\usepackage{xeCJK}
\setCJKmainfont{SimSun}
\begin{document}
Hallo 你好 \LaTeX
\end{document}

Commands for generating xdv and SVG file:

xelatex -no-pdf MWE.tex
dvisvgm -n MWE.xdv
MarkHoo commented 1 year ago

Conversion using a xetex-generated .pdf instead of .xdv works:

class MyScene3(Scene):
    def construct(self):
        template = TexTemplateLibrary.ctex
        template.output_format=".pdf"
        tex = Tex(r'Hello  你好  \LaTeX', tex_template=template).scale_to_fit_width(12)
        self.add(tex)
        self.wait() 

image

Two weeks ago dvisvgm released a repaired version, you can download the new version of dvisvgm, and then replace the old version under the LaTeX installation path.

dvisvgm 3.1

MrDiver commented 10 months ago

Is this fixed now ?

louisstuart96 commented 10 months ago

Is this fixed now ?

Up till now, the hotfix of dvisvgm (v3.1+) has not yet been updated in TeX Live 2023. As a workaround, people have to manually download/build a patched dvisvgm executable to replace the buggy one. This hotfix is supposed to take effect in the next year's TeX Live build.

MarkHoo commented 10 months ago

Is this fixed now ?

You can manually download the version of dvisvgm >=3.1 and configure the environment variables after installation. However, it should be noted that its environment variable must be in front of miktex or live.

MarkHoo commented 10 months ago

Is this fixed now ?

https://dvisvgm.de/Downloads/