ManimCommunity / manim

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

LaTeX compilation error when breaking up a MathTex string by subscripts #1865

Open dalejbarr opened 3 years ago

dalejbarr commented 3 years ago

Description of bug / unexpected behavior

When using MathTex() with the substrings_to_isolate argument, I get the following error:

ERROR    LaTeX compilation error:    tex_file_writing.py:199
                             Argument of \align* has an                         
                             extra }.

Expected behavior

Expected a MathTex object parsed into substrings.

How to reproduce the issue

Code for reproducing the problem ```py reqeq2 = MathTex(r"Y_{ij} = \mu_i + \gamma_i X_{ij} + e_{ij}", substrings_to_isolate = "i") ``` However, ```py reqeq2 = MathTex(r"Y_{ij} = \mu_i + \gamma_i X_{ij}", substrings_to_isolate = "i") ``` works as expected.

Additional media files

Images/GIFs

System specifications

System Details - OS: Linux Ubuntu 20.04 - Python version 3.8.10 - Installed modules (provide output from `pip list`): ``` Package Version ---------------------- -------------------- apturl 0.5.2 asn1crypto 0.24.0 atomicwrites 1.1.5 attrs 19.3.0 backcall 0.2.0 bcrypt 3.1.7 beautifulsoup4 4.8.2 binwalk 2.2.0 blinker 1.4 Brlapi 0.7.0 certifi 2019.11.28 chardet 3.0.4 click 8.0.1 click-default-group 1.2.2 cloup 0.7.1 colorama 0.4.3 colour 0.1.5 command-not-found 0.3 commonmark 0.9.1 cryptography 2.8 cupshelpers 1.0 cycler 0.10.0 dbus-python 1.2.16 decorator 5.0.9 defer 1.0.6 descartes 1.1.0 distro 1.4.0 distro-info 0.23ubuntu1 duplicity 0.8.12.0 entrypoints 0.3 et-xmlfile 1.0.1 eyeD3 0.8.10 fasteners 0.14.1 future 0.18.2 glcontext 2.3.3 html5lib 1.0.1 httplib2 0.14.0 idna 2.8 importlib-metadata 1.5.0 ipython 7.23.1 ipython-genutils 0.2.0 isc 2.0 jdcal 1.0 jedi 0.18.0 Jinja2 2.10.1 keyring 18.0.1 keyrings.alt 3.4.0 kiwisolver 1.0.1 language-selector 0.1 launchpadlib 1.10.13 lazr.restfulclient 0.14.2 lazr.uri 1.0.3 libvirt-python 6.1.0 lockfile 0.12.2 louis 3.12.0 lxml 4.5.0 macaroonbakery 1.3.1 Mako 1.1.0 manim 0.9.0 ManimPango 0.3.0 mapbox-earcut 0.12.10 MarkupSafe 1.1.0 matplotlib 3.1.2 matplotlib-inline 0.1.2 mizani 0.7.3 moderngl 5.6.4 moderngl-window 2.3.0 monotonic 1.5 more-itertools 4.2.0 mpmath 1.2.1 multipledispatch 0.6.0 netifaces 0.10.4 networkx 2.5.1 numexpr 2.7.1 numpy 1.20.2 oauth 1.0.1 oauthlib 3.1.0 olefile 0.46 openpyxl 3.0.3 packaging 20.3 palettable 3.3.0 pandas 1.2.4 paramiko 2.6.0 parso 0.8.2 patsy 0.5.1 pexpect 4.6.0 pickleshare 0.7.5 Pillow 7.0.0 pip 20.0.2 plotnine 0.8.0 pluggy 0.13.0 ply 3.11 progressbar 2.5 prompt-toolkit 3.0.18 protobuf 3.6.1 proton-client 0.5.1 protonvpn-cli 3.7.2 protonvpn-gui 1.1.0 protonvpn-nm-lib 3.3.2 psutil 5.5.1 py 1.8.1 pybind11 2.4.3 pycairo 1.20.1 pycrypto 2.6.1 pycups 1.9.73 pydbus 0.6.0 pydub 0.25.1 pyglet 1.5.17 Pygments 2.9.0 PyGObject 3.36.0 PyICU 2.4.2 pyinotify 0.9.6 PyJWT 1.7.1 pymacaroons 0.13.0 PyNaCl 1.3.0 PyOpenGL 3.1.0 pyOpenSSL 19.0.0 pyparsing 2.4.6 PyQt5 5.14.1 pyqtgraph 0.11.0rc0 pyRFC3339 1.1 pyrr 0.10.3 pytest 4.6.9 python-apt 2.0.0+ubuntu0.20.4.5 python-dateutil 2.7.3 python-debian 0.1.36ubuntu1 python-gnupg 0.4.5 python-magic 0.4.16 pythondialog 3.4.0 pytz 2019.3 pyxdg 0.26 PyYAML 5.3.1 reportlab 3.5.34 requests 2.22.0 requests-unixsocket 0.2.0 rich 10.6.0 scipy 1.6.2 screeninfo 0.6.7 SecretStorage 2.3.1 setuptools 45.2.0 simplejson 3.16.0 sip 4.19.21 six 1.14.0 soupsieve 1.9.5 ssh-import-id 5.10 statsmodels 0.12.2 sympy 1.8 system-service 0.3 systemd-python 234 tables 3.6.1 tqdm 4.60.0 traitlets 5.0.5 ubuntu-advantage-tools 27.2 ubuntu-drivers-common 0.0.0 ufw 0.36 unattended-upgrades 0.1 urllib3 1.25.8 usb-creator 0.3.7 validators 0.18.2 wadllib 1.3.3 watchdog 2.1.3 wcwidth 0.1.8 webencodings 0.5.1 wheel 0.34.2 xkit 0.0.0 xlrd 1.1.0 xlwt 1.3.0 zipp 1.0.0 zope.interface 4.7.1 ```
LaTeX details + LaTeX distribution: TeX Live 2019/Debian
FFMPEG Output of `ffmpeg -version`: ``` ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers built with gcc 9 (Ubuntu 9.3.0-10ubuntu2) configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared libavutil 56. 31.100 / 56. 31.100 libavcodec 58. 54.100 / 58. 54.100 libavformat 58. 29.100 / 58. 29.100 libavdevice 58. 8.100 / 58. 8.100 libavfilter 7. 57.100 / 7. 57.100 libavresample 4. 0. 0 / 4. 0. 0 libswscale 5. 5.100 / 5. 5.100 libswresample 3. 5.100 / 3. 5.100 libpostproc 55. 5.100 / 55. 5.100 ```

Additional comments

k4pran commented 3 years ago

I found that what is causing the issue is that in the above case or similar it creates a substring like 'j} + e_{'. When there is a closed brace then an open brace it doesn't compile. I am not sure of the solution though, maybe using regex to detect scenarios like this where it won't compile and break the string up a different way?