ManimCommunity / manim

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

Tex() object with multi string initialization, indexing affects wrong characters when arg_separator is different from white space #1568

Closed SamuilYu closed 3 years ago

SamuilYu commented 3 years ago

Description of bug / unexpected behavior

When creating a Tex() object with multiple strings and setting an arg_separator to a comma, the object doesn't display fully. And attributes of indexed sub-objects don't modify correctly.

Expected behavior

When running an example specified below, I expected a full text to render on the screen and and the words "world, It is" to get colored. Instead, I got an attached image. tex_object_bug

How to reproduce the issue

Initialize a Tex() object with multiple strings and set arg_separator to something different from whitespace (e.g. arg_separator=','). Try modifying some attributes of sub-objects indexed at different indexes, or of slices (e.g. color). Write out or add the Tex() object to the scene.

Code for reproducing the problem Example: ```python3 class MultiLineExample(Scene): def construct(self): tex = Tex('Hello', 'world', 'It is', 'me!', arg_separator=",") tex[1:3].set_color(YELLOW) self.add(tex) ```

Additional media files

Images/GIFs ![tex_object_bug](https://user-images.githubusercontent.com/52719019/119356435-16a2d180-bcaf-11eb-8b93-cfa44a6983e6.png)

System specifications

System Details - OS: Windows 10 v20H2 - RAM: 12 GB - Python version: Python 3.9 - Installed modules (provide output from `pip list`): ``` Package Version ----------------------------- ------------ alabaster 0.7.12 appdirs 1.4.4 astroid 2.5.6 atomicwrites 1.4.0 attrs 21.2.0 Babel 2.9.1 beautifulsoup4 4.9.3 black 20.8b1 certifi 2020.12.5 cffi 1.14.5 cfgv 3.2.0 chardet 4.0.0 click 7.1.2 click-default-group 1.2.2 cloup 0.7.1 colorama 0.4.4 colour 0.1.5 commonmark 0.9.1 coverage 5.5 cycler 0.10.0 decorator 5.0.7 Deprecated 1.2.12 distlib 0.3.1 docutils 0.17.1 filelock 3.0.12 flake8 3.9.2 furo 2021.4.11b34 gitdb 4.0.7 GitPython 3.1.15 glcontext 2.3.3 identify 2.2.4 idna 2.10 imagesize 1.2.0 iniconfig 1.1.1 isort 5.8.0 Jinja2 2.11.3 kiwisolver 1.3.1 lazy-object-proxy 1.6.0 manim 0.6.0 ManimPango 0.2.6 mapbox-earcut 0.12.10 MarkupSafe 1.1.1 matplotlib 3.4.2 mccabe 0.6.1 moderngl 5.6.4 moderngl-window 2.3.0 multipledispatch 0.6.0 mypy-extensions 0.4.3 networkx 2.5 nodeenv 1.6.0 numpy 1.20.3 packaging 20.9 pathspec 0.8.1 Pillow 8.2.0 pip 21.0.1 pluggy 0.13.1 pre-commit 2.12.1 py 1.10.0 pycairo 1.20.0 pycodestyle 2.7.0 pycparser 2.20 pydub 0.25.1 pyflakes 2.3.1 PyGithub 1.55 pyglet 1.5.16 Pygments 2.9.0 PyJWT 2.1.0 pylint 2.8.2 PyNaCl 1.4.0 pyparsing 2.4.7 pyrr 0.10.3 pytest 6.2.4 pytest-cov 2.11.1 python-dateutil 2.8.1 pytz 2021.1 PyYAML 5.4.1 recommonmark 0.7.1 regex 2021.4.4 requests 2.25.1 rich 6.2.0 scipy 1.6.1 setuptools 54.1.2 six 1.16.0 smmap 4.0.0 snowballstemmer 2.1.0 soupsieve 2.2.1 Sphinx 3.5.3 sphinx-copybutton 0.3.1 sphinxcontrib-applehelp 1.0.2 sphinxcontrib-devhelp 1.0.2 sphinxcontrib-htmlhelp 1.0.3 sphinxcontrib-jsmath 1.0.1 sphinxcontrib-qthelp 1.0.3 sphinxcontrib-serializinghtml 1.1.4 sphinxext-opengraph 0.4.1 toml 0.10.2 tqdm 4.60.0 typed-ast 1.4.3 typing-extensions 3.10.0.0 urllib3 1.26.4 virtualenv 20.4.6 watchdog 2.1.1 wheel 0.36.2 wrapt 1.12.1 ```
LaTeX details + LaTeX distribution: pdfTeX 3.141592653-2.6-1.40.22 (TeX Live 2021/W32TeX) kpathsea version 6.3.3 + Installed LaTeX packages: i amsfonts: TeX fonts from the American Mathematical Society i amsmath: AMS mathematical facilities for LaTeX i atbegshi: Execute stuff at \shipout time i atveryend: Hooks at the very end of a document i auxhook: Hooks for auxiliary files i babel: Multilingual support for Plain TeX or LaTeX i babel-english: Babel support for English i bibtex: Process bibliographies for LaTeX, etc i bibtex.win32: win32 files of bibtex i bigintcalc: Integer calculations on very large numbers i bitset: Handle bit-vector datatype i booktabs: Publication quality tables in LaTeX i cbfonts-fd: LaTeX font description files for the CB Greek fonts i cm: Computer Modern fonts i cm-super: CM-Super family of fonts i dehyph: German hyphenation patterns for traditional orthography i doublestroke: Typeset mathematical double stroke symbols i dvipdfmx: An extended version of dvipdfm i dvipdfmx.win32: win32 files of dvipdfmx i dvips: A DVI to PostScript driver i dvips.win32: win32 files of dvips i dvisvgm: Convert DVI, EPS, and PDF files to Scalable Vector Graphics format (SVG) i dvisvgm.win32: win32 files of dvisvgm i ec: Computer modern fonts in T1 and TS1 encodings i epstopdf-pkg: Call epstopdf "on the fly" i etex: An extended version of TeX, from the NTS project i etexcmds: Avoid name clashes with e-TeX commands i etoolbox: e-TeX tools for LaTeX i euenc: Unicode font encoding definitions for XeTeX i everysel: Provides hooks into \selectfont i everyshi: Take action at every \shipout i fancyvrb: Sophisticated verbatim text i filehook: Hooks for input files i firstaid: First aid for external LaTeX files and packages that need updating i float: Improved interface for floating objects i fontspec: Advanced font selection in XeLaTeX and LuaLaTeX i framed: Framed or shaded regions that can break across pages i fundus-calligra: Support for the calligra font in LaTeX documents i geometry: Flexible and complete interface to document dimensions i gettitlestring: Clean up title references i glyphlist: Adobe Glyph List and TeX extensions i gnu-freefont: A Unicode font, with rather wide coverage i graphics: The LaTeX standard graphics bundle i graphics-cfg: Sample configuration files for LaTeX color and graphics i graphics-def: Colour and graphics option files i grffile: Extended file name support for graphics (legacy package) i helvetic: URW "Base 35" font pack for LaTeX i hycolor: Implements colour for packages hyperref and bookmark i hyperref: Extensive support for hypertext in LaTeX i hyph-utf8: Hyphenation patterns expressed in UTF-8 i hyphen-base: core hyphenation support files i iftex: Am I running under pdfTeX, XeTeX or LuaTeX? i inconsolata: A monospaced font, with support files for use with TeX i infwarerr: Complete set of information/warning/error message macros i intcalc: Expandable arithmetic operations with integers i jknapltx: Miscellaneous packages by Joerg Knappen i knuth-lib: Core TeX and Metafont sources from Knuth i kpathsea: Path searching library for TeX-related files i kpathsea.win32: win32 files of kpathsea i kvdefinekeys: Define keys for use in the kvsetkeys package i kvoptions: Key value format for package options i kvsetkeys: Key value parser with default handler support i l3backend: LaTeX3 backend drivers i l3kernel: LaTeX3 programming conventions i l3packages: High-level LaTeX3 concepts i latex: A TeX macro package that defines LaTeX i latex-amsmath-dev: Development pre-release of the LaTeX amsmath bundle i latex-bin: LaTeX executables and man pages i latex-bin.win32: win32 files of latex-bin i latex-fonts: A collection of fonts used in LaTeX distributions i latex-tools-dev: Development pre-release of the LaTeX tools bundle i latexconfig: configuration files for LaTeX-related formats i latexmk: Fully automated LaTeX document generation i latexmk.win32: win32 files of latexmk i letltxmacro: Let assignment for LaTeX macros i lm: Latin modern fonts in outline formats i lm-math: OpenType maths fonts for Latin Modern i ltxcmds: Some LaTeX kernel commands for general use i lua-alt-getopt: Process application arguments the same way as getopt_long i luahbtex: LuaTeX with HarfBuzz library for glyph shaping i luahbtex.win32: win32 files of luahbtex i lualatex-math: Fixes for mathematics-related LuaLaTeX issues i lualibs: Additional Lua functions for LuaTeX macro programmers i luaotfload: OpenType 'loader' for Plain TeX and LaTeX i luaotfload.win32: win32 files of luaotfload i luatex: The LuaTeX engine i luatex.win32: win32 files of luatex i mathastext: Use the text font in maths mode i mdwtools: Miscellaneous tools by Mark Wooding i metafont: A system for specifying fonts i metafont.win32: win32 files of metafont i mfware: Supporting tools for use with Metafont i mfware.win32: win32 files of mfware i microtype: Subliminal refinements towards typographical perfection i modes: A collection of Metafont mode_def's i ms: Various LaTeX packages by Martin Schroder i natbib: Flexible bibliography support i pdfescape: Implements pdfTeX's escape features using TeX or e-TeX i pdftex: A TeX extension for direct creation of PDF i pdftex.win32: win32 files of pdftex i pdftexcmds: LuaTeX support for pdfTeX utility functions i physics: Macros supporting the Mathematics of Physics i plain: The Plain TeX format i preview: Extract bits of a LaTeX source for output i psnfss: Font support for common PostScript fonts i ragged2e: Alternative versions of "ragged"-type commands i refcount: Counter operations with label references i relsize: Set the font size relative to the current font size i rerunfilecheck: Checksum based rerun checks on auxiliary files i rsfs: Ralph Smith's Formal Script font i scheme-infraonly: infrastructure-only scheme (no TeX at all) i setspace: Set space between lines i standalone: Compile TeX pictures stand-alone or as part of a document i stringenc: Converting a string between different encodings i symbol: URW "Base 35" font pack for LaTeX i tex: A sophisticated typesetting engine i tex-ini-files: Model TeX format creation files i tex.win32: win32 files of tex i texlive-scripts: TeX Live infrastructure programs i texlive-scripts.win32: win32 files of texlive-scripts i texlive.infra: basic TeX Live infrastructure i texlive.infra.win32: win32 files of texlive.infra i times: URW "Base 35" font pack for LaTeX i tipa: Fonts and macros for IPA phonetics characters i tlgs.win32: Freely available PostScript interpreter i tlperl.win32: internal Perl for Windows i tools: The LaTeX standard tools bundle i unicode-data: Unicode data and loaders for TeX i unicode-math: Unicode mathematics support for XeTeX and LuaTeX i uniquecounter: Provides unlimited unique counter i url: Verbatim with URL-sensitive line breaks i wasy: The wasy fonts (Waldi symbol fonts) i wasysym: LaTeX support for the wasy fonts i xcolor: Driver-independent color extensions for LaTeX and pdfLaTeX i xetex: An extended variant of TeX for use with Unicode sources i xetex.win32: win32 files of xetex i xetexconfig: crop.cfg for XeLaTeX i xkeyval: Extension of the keyval package i xunicode: Generate Unicode characters from accented glyphs i zapfding: URW "Base 35" font pack for LaTeX
FFMPEG Output of `ffmpeg -version`: ``` ffmpeg version 4.4-essentials_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers built with gcc 10.2.0 (Rev6, Built by MSYS2 project) configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enabl e-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda- llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --en able-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband libavutil 56. 70.100 / 56. 70.100 libavcodec 58.134.100 / 58.134.100 libavformat 58. 76.100 / 58. 76.100 libavdevice 58. 13.100 / 58. 13.100 libavfilter 7.110.100 / 7.110.100 libswscale 5. 9.100 / 5. 9.100 libswresample 3. 9.100 / 3. 9.100 libpostproc 55. 9.100 / 55. 9.100 ```
k4pran commented 3 years ago

I created a PR fixing this issue #1596. The issue was that in the method break_up_by_substrings(self) for a MathTex object it wasn't counting the index of the separator. It works fine for whitespace because they don't seem to be counted as a TexSymbol, but other arg_separator's need counted or they get cut from the end.