manim icon indicating copy to clipboard operation
manim copied to clipboard

weird baseline issue in multilanguage LaTeX objects

Open uwezi opened this issue 1 year ago • 8 comments

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
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

Docker

image

Manim v0.17.3

image

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 avatar Jun 06 '23 08:06 uwezi

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

uwezi avatar Jun 06 '23 10:06 uwezi

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

louisstuart96 avatar Jun 14 '23 07:06 louisstuart96

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 avatar Jul 20 '23 05:07 MarkHoo

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

MarkHoo avatar Jul 20 '23 05:07 MarkHoo

Is this fixed now ?

MrDiver avatar Dec 10 '23 15:12 MrDiver

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.

louisstuart96 avatar Dec 10 '23 18:12 louisstuart96

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 avatar Dec 11 '23 13:12 MarkHoo

Is this fixed now ?

https://dvisvgm.de/Downloads/

MarkHoo avatar Dec 11 '23 14:12 MarkHoo