ManimCommunity / manim

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

Tex unexpectedly starts new lines for long text, and Text can't control the span between letters with small font size #3143

Open jifbt opened 1 year ago

jifbt commented 1 year ago

Description of bug / unexpected behavior

When inserting a long text, Tex always starts new lines, even if there is enough space.

Also, it seems that Text control the span between letters so badly with small font size that some even overlap with each other.

Expected behavior

There should only be a single line; and span controlling should be better.

How to reproduce the issue

Code for reproducing the problem ```py from manim import * text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." class Intro(Scene): def construct(self): self.add(Text(text, font_size=4).to_corner(UP)) self.add(Tex(text, font_size=4).to_corner(DOWN)) with tempconfig({"quality": "fourk_quality", "save_last_frame": False, "preview": True}): scene = Intro() scene.render() ```

Additional media files

Images/GIFs ![Intro_ManimCE_v0 16 0 post0](https://user-images.githubusercontent.com/55904367/215983119-728cf38c-7fa7-4261-b457-645a9aea1fa4.png)

Logs

Terminal output ``` [02/01/23 16:03:00] INFO Writing Lorem ipsum dolor tex_file_writing.py:87 sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. to media\Tex\a36ba0f1a78a6632. tex [02/01/23 16:03:05] INFO scene_file_writer.py:728 File ready at '[Omitted]\media\images \Intro_ManimCE_v0.16.0.po st0.png' INFO Rendered Intro scene.py:240 Played 0 animations [02/01/23 16:03:06] INFO Previewed File at: file_ops.py:224 '[Omitted]\media\images\Intro_Ma nimCE_v0.16.0.post0.png' ```

System specifications

System Details - OS (with version, e.g., Windows 10 v2004 or macOS 10.15 (Catalina)): Windows 10.0.19043.928 - RAM: 16.0 GB - Python version (`python/py/python3 --version`): Python 3.10.6 - Installed modules (provide output from `pip list`): ``` Package Version ------------------- ------------ certifi 2022.6.15 charset-normalizer 2.1.0 click 8.1.3 click-default-group 1.2.2 cloup 0.13.1 colorama 0.4.5 colorful 0.5.5 colour 0.1.5 commonmark 0.9.1 cyaron 0.4.3 decorator 5.1.1 ffmpeg 1.4 glcontext 2.3.6 idna 3.3 isosurfaces 0.1.0 Jinja2 3.1.2 manim 0.16.0.post0 ManimPango 0.4.1 mapbox-earcut 0.12.11 MarkupSafe 2.1.1 moderngl 5.6.4 moderngl-window 2.4.1 multipledispatch 0.6.0 natsort 8.2.0 networkx 2.8.5 numpy 1.23.1 Pillow 9.2.0 pip 22.3.1 pycairo 1.21.0 pydub 0.25.1 pyglet 1.5.26 Pygments 2.12.0 pyrr 0.10.3 PyYAML 6.0 rarfile 4.0 requests 2.28.1 requests-toolbelt 0.10.1 rich 12.5.1 scipy 1.9.0 screeninfo 0.8 setuptools 63.2.0 six 1.16.0 skia-pathops 0.7.2 srt 3.5.2 tqdm 4.64.0 tuack 0.1.4.12.7 urllib3 1.26.11 watchdog 2.1.9 xeger 0.3.5 ```
LaTeX details + LaTeX distribution (e.g. TeX Live 2020): Tex Live 2022 + Installed LaTeX packages: ``` i 12many: Generalising mathematical index sets i 2up: Macros to print two-up i a0poster: Support for designing posters on large paper i a2ping: Advanced PS, PDF, EPS converter i a2ping.win32: win32 files of a2ping i a4wide: "Wide" a4 layout i a5comb: Support for a5 paper sizes i aaai-named: BibTeX style for AAAI i aalok: LaTeX class file for the Marathi journal 'Aalok' i aastex: Macros for Manuscript Preparation for AAS Journals i abbr: Simple macros supporting abreviations for Plain and LaTeX i abc: Support ABC music notation in LaTeX i abnt: Typesetting academic works according to ABNT rules i abntex2: Typeset technical and scientific Brazilian documents based on ABNT rules i aboensis: A late medieval OpenType cursive font i abraces: Asymmetric over-/underbraces in maths i abstract: Control the typesetting of the abstract environment i abstyles: Adaptable BibTeX styles i academicons: Font containing high quality icons of online academic profiles i accanthis: Accanthis fonts, with LaTeX support i accents: Multiple mathematical accents i accessibility: Create tagged and structured PDF files i accfonts: Utilities to derive new fonts from existing ones i accfonts.win32: win32 files of accfonts i accsupp: Better accessibility support for PDF files i achemso: Support for American Chemical Society journal submissions i acmart: Class for typesetting publications of ACM i acmconf: Class for ACM conference proceedings i acro: Typeset acronyms i acronym: Expand acronyms at least once i acroterm: Manage and index acronyms and terms i active-conf: Class for typesetting ACTIVE conference papers i actuarialangle: Angle symbol denoting a duration in actuarial and financial notation i actuarialsymbol: Actuarial symbols of life contingencies and financial mathematics i addfont: Easier use of fonts without LaTeX support i addliga: Access basic ligatures in legacy TrueType fonts i addlines: A user-friendly wrapper around \enlargethispage i adfathesis: Australian Defence Force Academy thesis format i adforn: OrnementsADF font with TeX/LaTeX support i adfsymbols: SymbolsADF with TeX/LaTeX support i adhocfilelist: '\listfiles' entries from the command line i adigraph: Augmenting directed graphs i adjmulticol: Adjusting margins for multicolumn and single column output i adjustbox: Graphics package-alike macros for "general" boxes i adobemapping: Adobe cmap and pdfmapping files i adrconv: BibTeX styles to implement an address database i adtrees: Macros for drawing adpositional trees i advdate: Print a date relative to "today" i ae: Virtual fonts for T1 encoded CMR-fonts i aeguill: Add several kinds of guillemets to the ae fonts i aesupp: Special support for the ae character i afm2pl: convert AFM to TeX property list (.pl) metrics i afm2pl.win32: win32 files of afm2pl i afparticle: Typesetting articles for Archives of Forensic Psychology i afthesis: Air Force Institute of Technology thesis class i aguplus: Styles for American Geophysical Union i aiaa: Typeset AIAA conference papers i aichej: Bibliography style file for the AIChE Journal i ajl: BibTeX style for AJL i akktex: A collection of packages and classes i akletter: Comprehensive letter support i akshar: Support for syllables in the Devanagari script i albatross: Find fonts that contain a given glyph i albatross.win32: win32 files of albatross i alegreya: Alegreya fonts with LaTeX support i aleph: Extended TeX i aleph.win32: win32 files of aleph i alertmessage: Alert messages for LaTeX i alfaslabone: The Alfa Slab One font face with support for LaTeX and pdfLaTeX i alg: LaTeX environments for typesetting algorithms i algobox: Typeset Algobox programs i algolrevived: A revival of Frutiger's Algol alphabet i algorithm2e: Floating algorithm environment with algorithmic keywords i algorithmicx: The algorithmic style you always wanted i algorithms: A suite of tools for typesetting algorithms in pseudo-code i algpseudocodex: Package for typesetting pseudocode i algxpar: Support multiple lines pseudocode i aligned-overset: Fix alignment at \overset or \underset i alkalami: A font for Arabic-based writing systems in Nigeria and Niger i allrunes: Fonts and LaTeX package for almost all runes i almendra: Almendra fonts with LaTeX support i almfixed: Arabic-Latin Modern Fixed extends TeX-Gyre Latin Modern Mono 10 Regular to full Arabic Unicode support i alnumsec: Alphanumeric section numbering i alpha-persian: Persian version of alpha.bst i alphalph: Convert numbers to letters i alterqcm: Multiple choice questionnaires in two column tables i altfont: Alternative font handling in LaTeX i altsubsup: Subscripts and superscripts with square brackets i amiri: A classical Arabic typeface, Naskh style i amiweb2c-guide: How to install AmiWeb2c i amsaddr: Alter the position of affiliations in amsart i amscdx: Enhanced commutative diagrams i amscls: AMS document classes for LaTeX i amscls-doc: User documentation for AMS document classes i amsfonts: TeX fonts from the American Mathematical Society i amslatex-primer: Getting up and running with AMS-LaTeX i amsldoc-it: Italian translation of amsldoc i amsldoc-vn: Vietnamese translation of AMSLaTeX documentation i amsmath: AMS mathematical facilities for LaTeX i amsmath-it: Italian translations of some old amsmath documents i amsrefs: A LaTeX-based replacement for BibTeX i amstex: American Mathematical Society plain TeX macros i amstex.win32: win32 files of amstex i amsthdoc-it: Italian translation of amsthdoc: Using the amsthm package i andika: andika fonts with support for all LaTeX engines i animate: Create PDF and SVG animations from graphics files and inline graphics i annee-scolaire: Automatically typeset the academic year (French way) i annotate: A bibliography style with annotations i annotate-equations: Easily annotate math equations using TikZ i anonchap: Make chapters be typeset like sections i anonymous-acm: Typeset anonymous versions for ACM articles i anonymouspro: Use AnonymousPro fonts with LaTeX i answers: Setting questions (or exercises) and answers i antanilipsum: Generate sentences in the style of "Amici miei" i antiqua: URW Antiqua condensed font, for use with TeX i antomega: Alternative language support for Omega/Lambda i antt: Antykwa Torunska: a Type 1 family of a Polish traditional type i anufinalexam: LaTeX document shell for ANU final exam i anyfontsize: Select any font size in LaTeX i anysize: A simple package to set up document margins i aobs-tikz: TikZ styles for creating overlaid pictures in beamer i aomart: Typeset articles for the Annals of Mathematics i apa: American Psychological Association format i apa6: Format documents in APA style (6th edition) i apa6e: Format manuscripts to APA 6th edition guidelines i apa7: Format documents in APA style (7th edition) i apacite: Citation style following the rules of the APA i apalike-ejor: A BibTeX style file for the European Journal of Operational Research i apalike-german: A copy of apalike.bst with German localization i apalike2: Bibliography style that approaches APA requirements i apnum: Arbitrary precision numbers implemented by TeX macros i appendix: Extra control of appendices i appendixnumberbeamer: Manage frame numbering in appendixes in beamer i apprendre-a-programmer-en-tex: The book "Apprendre a programmer en TeX" i apprends-latex: Apprends LaTeX! i apptools: Tools for customising appendices i apxproof: Proofs in appendix i arabi: (La)TeX support for Arabic and Farsi, compliant with Babel i arabi-add: Using hyperref and bookmark packages with arabic and farsi languages i arabic-book: An Arabic book class i arabicfront: Frontmatter with arabic page numbers i arabluatex: ArabTeX for LuaLaTeX i arabtex: Macros and fonts for typesetting Arabic i arabxetex: An ArabTeX-like interface for XeLaTeX i aramaic-serto: Fonts and LaTeX for Syriac written in Serto i arara: Automation of LaTeX compilation i arara.win32: win32 files of arara i archaeologie: A citation-style which covers rules of the German Archaeological Institute i archaic: A collection of archaic fonts i archivo: The Archivo font face with support for LaTeX and pdfLaTeX i arcs: Draw arcs over and under text i arev: Fonts and LaTeX support files for Arev Sans i arimo: Arimo sans serif fonts with LaTeX support i armtex: A system for writing Armenian with TeX and LaTeX i around-the-bend: Typeset exercises in TeX, with answers i arphic: Arphic (Chinese) font packages i arphic-ttf: TrueType version of Chinese Arphic fonts i arraycols: New column types for array and tabular environments i arrayjobx: Array data structures for (La)TeX i arraysort: Sort arrays (or portions of them) i arsclassica: A different view of the ClassicThesis package i articleingud: LaTeX class for articles published in INGENIERIA review i arvo: The Arvo font face with support for LaTeX and pdfLaTeX i arydshln: Draw dash-lines in array/tabular i asaetr: Transactions of the ASAE i asana-math: A font to typeset maths in Xe(La)TeX and Lua(La)TeX i asapsym: Using the free ASAP Symbol font with LaTeX and Plain TeX i ascelike: Bibliography style for the ASCE i ascii-chart: An ASCII wall chart i ascii-font: Use the ASCII "font" in LaTeX i asciilist: Environments AsciiList and AsciiDocList for prototyping nested lists in LaTeX i ascmac: Boxes and picture macros with Japanese vertical writing support i askinclude: Interactive use of \includeonly i askmaps: Typeset American style Karnaugh maps i asmeconf: A LaTeX template for ASME conference papers i asmejour: A template for ASME journal papers i aspectratio: Capital A and capital R ligature for Aspect Ratio i assignment: A class file for typesetting homework and lab assignments i assoccnt: Associate counters, making them step when a master steps i association-matrix: LaTeX support for creating association matrices i asternote: Annotation symbols enclosed in square brackets and marked with an asterisk i astro: Astronomical (planetary) symbols i asyfig: Commands for using Asymptote figures i asymptote: 2D and 3D TeX-Aware Vector Graphics Language i asymptote-by-example-zh-cn: Asymptote by example i asymptote-faq-zh-cn: Asymptote FAQ (Chinese translation) i asymptote-manual-zh-cn: A Chinese translation of the asymptote manual i asymptote.win32: win32 files of asymptote i asypictureb: User-friendly integration of Asymptote into LaTeX i atbegshi: Execute stuff at \shipout time i atenddvi: Provides the \AtEndDvi command i atendofenv: Add a custom symbol at the end of an environment i atkinson: Support for the Atkinson Hyperlegible family of fonts i attachfile: Attach arbitrary files to a PDF document i attachfile2: Attach files into PDF i attachfile2.win32: win32 files of attachfile2 i atveryend: Hooks at the very end of a document i aucklandthesis: Memoir-based class for formatting University of Auckland masters' and doctors' theses i augie: Calligraphic font for typesetting handwriting i auncial-new: Artificial Uncial font and LaTeX support macros i aurical: Calligraphic fonts for use with LaTeX in T1 encoding i aurl: Extends the hyperref package with a mechanism for hyperlinked URLs abbreviated with prefixes i authoraftertitle: Make author, etc., available after \maketitle i authorarchive: Adds self-archiving information to scientific papers i authordate: Author/date style citation styles i authorindex: Index citations by author names i authorindex.win32: win32 files of authorindex i auto-pst-pdf: Wrapper for pst-pdf (with some psfrag features) i auto-pst-pdf-lua: Using LuaLaTeX together with PostScript code i autoaligne: Align terms and members in math expressions i autoarea: Automatic computation of bounding boxes with PiCTeX i autobreak: Simple line breaking of long formulae i autofancyhdr: Automatically compute headlength for fancyhdr package i automata: Finite state machines, graphs and trees in MetaPost i autonum: Automatic equation references i autopdf: Conversion of graphics to pdfLaTeX-compatible formats i autopuncitems: Automatically punctuate lists i autosp: A Preprocessor that generates note-spacing commands for MusiXTeX scores i autosp.win32: win32 files of autosp i auxhook: Hooks for auxiliary files i avantgar: URW 'Base 35' font pack for LaTeX i avremu: An 8-Bit Microcontroller Simulator written in LaTeX i awesomebox: Draw admonition blocks in your documents, illustrated with FontAwesome icons i axessibility: Access to formulas in PDF files by assistive technologies i axodraw2: Feynman diagrams in a LaTeX document i axodraw2.win32: win32 files of axodraw2 [Too many; the rest is omitted.] ```
FFMPEG Output of `ffmpeg -version`: ``` ffmpeg version 5.1-essentials_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers built with gcc 12.1.0 (Rev2, 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 --enable-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 --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband libavutil 57. 28.100 / 57. 28.100 libavcodec 59. 37.100 / 59. 37.100 libavformat 59. 27.100 / 59. 27.100 libavdevice 59. 7.100 / 59. 7.100 libavfilter 8. 44.100 / 8. 44.100 libswscale 6. 7.100 / 6. 7.100 libswresample 4. 7.100 / 4. 7.100 libpostproc 56. 6.100 / 56. 6.100```

Additional comments

wildmathing commented 1 year ago

Tex class gives you exactly the same resault as you get using LaTeX, doesn't it? So I think it's not an unexcpected behavior but useful thing for writing a paragraph. And if you don't need hyphenation, just use \mbox like we always do in LaTeX. To be honest I haven't ever seen a 4-size text in text editors yet. Usually there is a limit. Maybe Manim in this case shoud return an error, I don't know. But if you really need this tiny text, you can use scale method

class TinyText(Scene):
    def construct(self):
        text_to_write = (
            "very very very very very very very very very very very very "
            "very very very very very very very very very very very very "
            "long long long long long long long long long long long text"
        )
        tex = Tex("\\mbox{" + text_to_write + "}").scale(0.3)     
        text = Text(text_to_write).shift(UP).scale(0.2)
        self.add(tex, text)
uwezi commented 1 year ago

The standalone document class in LaTeX doesn't support a good control over the text width. But you can typeset your own Tex() in a minipage environment where you can set the width of the rendered text. The width is given in the corresponding length the text would have, if rendered in LaTeX and printed on paper, in the following example for the text width is 6 cm, as given in curly brackets at the beginning of the text itself. When Manim hands over this to LaTeX, the resulting starting line will be \begin{minipage}{6cm} followed by the text itself.

class textTex(Scene):
    def construct(self):
        text=Tex(r"""{6cm}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam et sollicitudin ipsum. Cras magna metus, dictum in est sit amet, vestibulum vehicula lorem. Etiam condimentum lacus nec ex pellentesque lobortis. Proin id dignissim velit. Proin ac justo a ligula rhoncus gravida. Nam sit amet euismod ipsum, sed vehicula ipsum. Curabitur id laoreet purus, venenatis viverra dui. Fusce aliquam eu dolor at sodales. Cras et sem ut leo ultricies interdum ut ac neque. Curabitur pharetra pretium augue, porta hendrerit nulla placerat a. Donec hendrerit, erat a finibus porta, massa lacus pulvinar dolor, eget dictum elit metus quis risus. Pellentesque finibus ac felis vitae faucibus.

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Sed blandit egestas est, eget cursus est interdum non. Cras in quam vitae justo volutpat consectetur. Maecenas lobortis purus id risus lobortis interdum. Ut laoreet mauris in sodales blandit. Ut quis augue consequat, volutpat lorem a, imperdiet est. Vestibulum eleifend augue eget viverra suscipit. Aenean in velit et tellus maximus porttitor. Sed condimentum quis eros pretium bibendum. 
            """,
            tex_environment="minipage",
        ).scale_to_fit_height(7.5)

        self.play(Write(text[0][0:100]))
        self.wait()
        self.play(Write(text[0][199:300]))
        self.wait()
        self.play(Write(text[0][99:200]))
        self.wait()
        self.play(Write(text[0][299:]))
        self.wait()
        self.play(text[0][70:80].animate.set_color(RED))
        self.wait()