"""Utilities for processing LaTeX templates."""

__all__ = [
    "TexTemplate",
    "TexTemplateFromFile",
]

import copy
import re


class TexTemplate:
    """TeX templates are used for creating Tex() and MathTex() objects.

    Parameters
    ----------
    tex_compiler : Optional[:class:`str`], optional
        The TeX compiler to be used, e.g. ``latex``, ``pdflatex`` or ``lualatex``
    output_format : Optional[:class:`str`], optional
        The output format resulting from compilation, e.g. ``.dvi`` or ``.pdf``
    documentclass : Optional[:class:`str`], optional
        The command defining the documentclass, e.g. ``\\documentclass[preview]{standalone}``
    preamble : Optional[:class:`str`], optional
        The document's preamble, i.e. the part between ``\\documentclass`` and ``\\begin{document}``
    placeholder_text : Optional[:class:`str`], optional
        Text in the document that will be replaced by the expression to be rendered
    post_doc_commands : Optional[:class:`str`], optional
        Text (definitions, commands) to be inserted at right after ``\\begin{document}``, e.g. ``\\boldmath``

    Attributes
    ----------
    tex_compiler : :class:`str`
        The TeX compiler to be used, e.g. ``latex``, ``pdflatex`` or ``lualatex``
    output_format : :class:`str`
        The output format resulting from compilation, e.g. ``.dvi`` or ``.pdf``
    documentclass : :class:`str`
        The command defining the documentclass, e.g. ``\\documentclass[preview]{standalone}``
    preamble : :class:`str`
        The document's preample, i.e. the part between ``\\documentclass`` and ``\\begin{document}``
    placeholder_text : :class:`str`
        Text in the document that will be replaced by the expression to be rendered
    post_doc_commands : :class:`str`
        Text (definitions, commands) to be inserted at right after ``\\begin{document}``, e.g. ``\\boldmath``
    """

    default_documentclass = r"\documentclass[preview]{standalone}"
    default_preamble = r"""
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{dsfont}
\usepackage{setspace}
\usepackage{tipa}
\usepackage{relsize}
\usepackage{textcomp}
\usepackage{mathrsfs}
\usepackage{calligra}
\usepackage{wasysym}
\usepackage{ragged2e}
\usepackage{physics}
\usepackage{xcolor}
\usepackage{microtype}
\DisableLigatures{encoding = *, family = * }
\linespread{1}
"""
    default_placeholder_text = "YourTextHere"
    default_tex_compiler = "latex"
    default_output_format = ".dvi"
    default_post_doc_commands = ""

    def __init__(
        self,
        tex_compiler=None,
        output_format=None,
        documentclass=None,
        preamble=None,
        placeholder_text=None,
        post_doc_commands=None,
        **kwargs,
    ):
        self.tex_compiler = (
            tex_compiler
            if tex_compiler is not None
            else TexTemplate.default_tex_compiler
        )
        self.output_format = (
            output_format
            if output_format is not None
            else TexTemplate.default_output_format
        )
        self.documentclass = (
            documentclass
            if documentclass is not None
            else TexTemplate.default_documentclass
        )
        self.preamble = (
            preamble if preamble is not None else TexTemplate.default_preamble
        )
        self.placeholder_text = (
            placeholder_text
            if placeholder_text is not None
            else TexTemplate.default_placeholder_text
        )
        self.post_doc_commands = (
            post_doc_commands
            if post_doc_commands is not None
            else TexTemplate.default_post_doc_commands
        )
        self._rebuild()

    def _rebuild(self):
        """Rebuilds the entire TeX template text from ``\\documentclass`` to ``\\end{document}`` according to all settings and choices."""
        self.body = (
            self.documentclass
            + "\n"
            + self.preamble
            + "\n"
            + r"\begin{document}"
            + "\n"
            + self.post_doc_commands
            + "\n"
            + self.placeholder_text
            + "\n"
            + "\n"
            + r"\end{document}"
            + "\n"
        )

    def add_to_preamble(self, txt, prepend=False):
        """Adds stuff to the TeX template's preamble (e.g. definitions, packages). Text can be inserted at the beginning or at the end of the preamble.

        Parameters
        ----------
        txt : :class:`string`
            String containing the text to be added, e.g. ``\\usepackage{hyperref}``
        prepend : Optional[:class:`bool`], optional
            Whether the text should be added at the beginning of the preample, i.e. right after ``\\documentclass``. Default is to add it at the end of the preample, i.e. right before ``\\begin{document}``
        """
        if prepend:
            self.preamble = txt + "\n" + self.preamble
        else:
            self.preamble += "\n" + txt
        self._rebuild()

    def add_to_document(self, txt):
        """Adds txt to the TeX template just after \\begin{document}, e.g. ``\\boldmath``

        Parameters
        ----------
        txt : :class:`str`
            String containing the text to be added.
        """
        self.post_doc_commands += "\n" + txt + "\n"
        self._rebuild()

    def get_texcode_for_expression(self, expression):
        """Inserts expression verbatim into TeX template.

        Parameters
        ----------
        expression : :class:`str`
            The string containing the expression to be typeset, e.g. ``$\\sqrt{2}$``

        Returns
        -------
        :class:`str`
            LaTeX code based on current template, containing the given ``expression`` and ready for typesetting
        """
        return self.body.replace(self.placeholder_text, expression)

    def _texcode_for_environment(self, environment):
        """Processes the tex_environment string to return the correct ``\\begin{environment}[extra]{extra}`` and
        ``\\end{environment}`` strings

        Parameters
        ----------
        environment : :class:`str`
            The tex_environment as a string. Acceptable formats include:
            ``{align*}``, ``align*``, ``{tabular}[t]{cccl}``, ``tabular}{cccl``, ``\\begin{tabular}[t]{cccl}``.

        Returns
        -------
        Tuple[:class:`str`, :class:`str`]
            A pair of strings representing the opening and closing of the tex environment, e.g.
            ``\\begin{tabular}{cccl}`` and ``\\end{tabular}``
        """

        # If the environment starts with \begin, remove it
        if environment[0:6] == r"\begin":
            environment = environment[6:]

        # If environment begins with { strip it
        if environment[0] == r"{":
            environment = environment[1:]

        # The \begin command takes everything and closes with a brace
        begin = r"\begin{" + environment
        if (
            begin[-1] != r"}" and begin[-1] != r"]"
        ):  # If it doesn't end on } or ], assume missing }
            begin += r"}"

        # While the \end command terminates at the first closing brace
        split_at_brace = re.split(r"}", environment, 1)
        end = r"\end{" + split_at_brace[0] + r"}"

        return begin, end

    def get_texcode_for_expression_in_env(self, expression, environment):
        r"""Inserts expression into TeX template wrapped in \begin{environemnt} and \end{environment}

        Parameters
        ----------
        expression : :class:`str`
            The string containing the expression to be typeset, e.g. ``$\\sqrt{2}$``
        environment : :class:`str`
            The string containing the environment in which the expression should be typeset, e.g. ``align*``

        Returns
        -------
        :class:`str`
            LaTeX code based on template, containing the given expression inside its environment, ready for typesetting
        """
        begin, end = self._texcode_for_environment(environment)
        return self.body.replace(self.placeholder_text, f"{begin}\n{expression}\n{end}")

    def copy(self) -> "TexTemplate":
        return copy.deepcopy(self)


class TexTemplateFromFile(TexTemplate):
    """A TexTemplate object created from a template file (default: tex_template.tex)

    Parameters
    ----------
    tex_compiler : Optional[:class:`str`], optional
        The TeX compiler to be used, e.g. ``latex``, ``pdflatex`` or ``lualatex``
    output_format : Optional[:class:`str`], optional
        The output format resulting from compilation, e.g. ``.dvi`` or ``.pdf``
    documentclass : Optional[:class:`str`], optional
        The command defining the documentclass, e.g. ``\\documentclass[preview]{standalone}``
    preamble : Optional[:class:`str`], optional
        The document's preamble, i.e. the part between ``\\documentclass`` and ``\\begin{document}``
    placeholder_text : Optional[:class:`str`], optional
        Text in the document that will be replaced by the expression to be rendered
    post_doc_commands : Optional[:class:`str`], optional
        Text (definitions, commands) to be inserted at right after ``\\begin{document}``, e.g. ``\\boldmath``
    kwargs : :class:`str`
        The kwargs specified can only be strings.

    Other Parameters
    ----------------
    tex_filename : Optional[:class:`str`], optional
        Path to a valid TeX template file

    Attributes
    ----------
    template_file : :class:`str`
        Path to a valid TeX template file
    body : :class:`str`
        Content of the TeX template file
    tex_compiler : :class:`str`
        The TeX compiler to be used, e.g. ``latex``, ``pdflatex`` or ``lualatex``
    output_format : :class:`str`
        The output format resulting from compilation, e.g. ``.dvi`` or ``.pdf``
    """

    def __init__(self, **kwargs):
        self.template_file = kwargs.pop("tex_filename", "tex_template.tex")
        super().__init__(**kwargs)

    def _rebuild(self):
        with open(self.template_file, "r") as infile:
            self.body = infile.read()

    def file_not_mutable(self):
        raise Exception("Cannot modify TexTemplate when using a template file.")

    def add_to_preamble(self, txt, prepend=False):
        self.file_not_mutable()

    def add_to_document(self, txt):
        self.file_not_mutable()

manim/utils/tex.py
"""Utilities for processing LaTeX templates."""

__all__ = [
    "TexTemplate",
    "TexTemplateFromFile",
]

import copy
import re


class TexTemplate:
    """TeX templates are used for creating Tex() and MathTex() objects.

    Parameters
    ----------
    tex_compiler : Optional[:class:`str`], optional
        The TeX compiler to be used, e.g. ``latex``, ``pdflatex`` or ``lualatex``
    output_format : Optional[:class:`str`], optional
        The output format resulting from compilation, e.g. ``.dvi`` or ``.pdf``
    documentclass : Optional[:class:`str`], optional
        The command defining the documentclass, e.g. ``\\documentclass[preview]{standalone}``
    preamble : Optional[:class:`str`], optional
        The document's preamble, i.e. the part between ``\\documentclass`` and ``\\begin{document}``
    placeholder_text : Optional[:class:`str`], optional
        Text in the document that will be replaced by the expression to be rendered
    post_doc_commands : Optional[:class:`str`], optional
        Text (definitions, commands) to be inserted at right after ``\\begin{document}``, e.g. ``\\boldmath``

    Attributes
    ----------
    tex_compiler : :class:`str`
        The TeX compiler to be used, e.g. ``latex``, ``pdflatex`` or ``lualatex``
    output_format : :class:`str`
        The output format resulting from compilation, e.g. ``.dvi`` or ``.pdf``
    documentclass : :class:`str`
        The command defining the documentclass, e.g. ``\\documentclass[preview]{standalone}``
    preamble : :class:`str`
        The document's preample, i.e. the part between ``\\documentclass`` and ``\\begin{document}``
    placeholder_text : :class:`str`
        Text in the document that will be replaced by the expression to be rendered
    post_doc_commands : :class:`str`
        Text (definitions, commands) to be inserted at right after ``\\begin{document}``, e.g. ``\\boldmath``
    """

    default_documentclass = r"\documentclass[preview]{standalone}"
    default_preamble = r"""
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{dsfont}
\usepackage{setspace}
\usepackage{tipa}
\usepackage{relsize}
\usepackage{textcomp}
\usepackage{mathrsfs}
\usepackage{calligra}
\usepackage{wasysym}
\usepackage{ragged2e}
\usepackage{physics}
\usepackage{xcolor}
\usepackage{microtype}
\DisableLigatures{encoding = *, family = * }
\linespread{1}
"""
    default_placeholder_text = "YourTextHere"
    default_tex_compiler = "latex"
    default_output_format = ".dvi"
    default_post_doc_commands = ""

    def __init__(
        self,
        tex_compiler=None,
        output_format=None,
        documentclass=None,
        preamble=None,
        placeholder_text=None,
        post_doc_commands=None,
        **kwargs,
    ):
        self.tex_compiler = (
            tex_compiler
            if tex_compiler is not None
            else TexTemplate.default_tex_compiler
        )
        self.output_format = (
            output_format
            if output_format is not None
            else TexTemplate.default_output_format
        )
        self.documentclass = (
            documentclass
            if documentclass is not None
            else TexTemplate.default_documentclass
        )
        self.preamble = (
            preamble if preamble is not None else TexTemplate.default_preamble
        )
        self.placeholder_text = (
            placeholder_text
            if placeholder_text is not None
            else TexTemplate.default_placeholder_text
        )
        self.post_doc_commands = (
            post_doc_commands
            if post_doc_commands is not None
            else TexTemplate.default_post_doc_commands
        )
        self._rebuild()

    def _rebuild(self):
        """Rebuilds the entire TeX template text from ``\\documentclass`` to ``\\end{document}`` according to all settings and choices."""
        self.body = (
            self.documentclass
            + "\n"
            + self.preamble
            + "\n"
            + r"\begin{document}"
            + "\n"
            + self.post_doc_commands
            + "\n"
            + self.placeholder_text
            + "\n"
            + "\n"
            + r"\end{document}"
            + "\n"
        )

    def add_to_preamble(self, txt, prepend=False):
        """Adds stuff to the TeX template's preamble (e.g. definitions, packages). Text can be inserted at the beginning or at the end of the preamble.

        Parameters
        ----------
        txt : :class:`string`
            String containing the text to be added, e.g. ``\\usepackage{hyperref}``
        prepend : Optional[:class:`bool`], optional
            Whether the text should be added at the beginning of the preample, i.e. right after ``\\documentclass``. Default is to add it at the end of the preample, i.e. right before ``\\begin{document}``
        """
        if prepend:
            self.preamble = txt + "\n" + self.preamble
        else:
            self.preamble += "\n" + txt
        self._rebuild()

    def add_to_document(self, txt):
        """Adds txt to the TeX template just after \\begin{document}, e.g. ``\\boldmath``

        Parameters
        ----------
        txt : :class:`str`
            String containing the text to be added.
        """
        self.post_doc_commands += "\n" + txt + "\n"
        self._rebuild()

    def get_texcode_for_expression(self, expression):
        """Inserts expression verbatim into TeX template.

        Parameters
        ----------
        expression : :class:`str`
            The string containing the expression to be typeset, e.g. ``$\\sqrt{2}$``

        Returns
        -------
        :class:`str`
            LaTeX code based on current template, containing the given ``expression`` and ready for typesetting
        """
        return self.body.replace(self.placeholder_text, expression)

    def _texcode_for_environment(self, environment):
        """Processes the tex_environment string to return the correct ``\\begin{environment}[extra]{extra}`` and
        ``\\end{environment}`` strings

        Parameters
        ----------
        environment : :class:`str`
            The tex_environment as a string. Acceptable formats include:
            ``{align*}``, ``align*``, ``{tabular}[t]{cccl}``, ``tabular}{cccl``, ``\\begin{tabular}[t]{cccl}``.

        Returns
        -------
        Tuple[:class:`str`, :class:`str`]
            A pair of strings representing the opening and closing of the tex environment, e.g.
            ``\\begin{tabular}{cccl}`` and ``\\end{tabular}``
        """

        # If the environment starts with \begin, remove it
        if environment[0:6] == r"\begin":
            environment = environment[6:]

        # If environment begins with { strip it
        if environment[0] == r"{":
            environment = environment[1:]

        # The \begin command takes everything and closes with a brace
        begin = r"\begin{" + environment
        if (
            begin[-1] != r"}" and begin[-1] != r"]"
        ):  # If it doesn't end on } or ], assume missing }
            begin += r"}"

        # While the \end command terminates at the first closing brace
        split_at_brace = re.split(r"}", environment, 1)
        end = r"\end{" + split_at_brace[0] + r"}"

        return begin, end

    def get_texcode_for_expression_in_env(self, expression, environment):
        r"""Inserts expression into TeX template wrapped in \begin{environemnt} and \end{environment}

        Parameters
        ----------
        expression : :class:`str`
            The string containing the expression to be typeset, e.g. ``$\\sqrt{2}$``
        environment : :class:`str`
            The string containing the environment in which the expression should be typeset, e.g. ``align*``

        Returns
        -------
        :class:`str`
            LaTeX code based on template, containing the given expression inside its environment, ready for typesetting
        """
        begin, end = self._texcode_for_environment(environment)
        return self.body.replace(self.placeholder_text, f"{begin}\n{expression}\n{end}")

    def copy(self) -> "TexTemplate":
        return copy.deepcopy(self)


class TexTemplateFromFile(TexTemplate):
    """A TexTemplate object created from a template file (default: tex_template.tex)

    Parameters
    ----------
    tex_compiler : Optional[:class:`str`], optional
        The TeX compiler to be used, e.g. ``latex``, ``pdflatex`` or ``lualatex``
    output_format : Optional[:class:`str`], optional
        The output format resulting from compilation, e.g. ``.dvi`` or ``.pdf``
    documentclass : Optional[:class:`str`], optional
        The command defining the documentclass, e.g. ``\\documentclass[preview]{standalone}``
    preamble : Optional[:class:`str`], optional
        The document's preamble, i.e. the part between ``\\documentclass`` and ``\\begin{document}``
    placeholder_text : Optional[:class:`str`], optional
        Text in the document that will be replaced by the expression to be rendered
    post_doc_commands : Optional[:class:`str`], optional
        Text (definitions, commands) to be inserted at right after ``\\begin{document}``, e.g. ``\\boldmath``
    kwargs : :class:`str`
        The kwargs specified can only be strings.

    Other Parameters
    ----------------
    tex_filename : Optional[:class:`str`], optional
        Path to a valid TeX template file

    Attributes
    ----------
    template_file : :class:`str`
        Path to a valid TeX template file
    body : :class:`str`
        Content of the TeX template file
    tex_compiler : :class:`str`
        The TeX compiler to be used, e.g. ``latex``, ``pdflatex`` or ``lualatex``
    output_format : :class:`str`
        The output format resulting from compilation, e.g. ``.dvi`` or ``.pdf``
    """

    def __init__(self, **kwargs):
        self.template_file = kwargs.pop("tex_filename", "tex_template.tex")
        super().__init__(**kwargs)

    def _rebuild(self):
        with open(self.template_file, "r") as infile:
            self.body = infile.read()

    def file_not_mutable(self):
        raise Exception("Cannot modify TexTemplate when using a template file.")

    def add_to_preamble(self, txt, prepend=False):
        self.file_not_mutable()

    def add_to_document(self, txt):
        self.file_not_mutable()

manim/utils/tex.py
diff --git a/manim/utils/tex.py b/manim/utils/tex.py
index 8ab08a56a0..532d6af3b3 100644
--- a/manim/utils/tex.py
+++ b/manim/utils/tex.py
@@ -48,6 +48,7 @@ class TexTemplate:
 \usepackage[english]{babel}
 \usepackage[utf8]{inputenc}
 \usepackage[T1]{fontenc}
+\usepackage{lmodern}
 \usepackage{amsmath}
 \usepackage{amssymb}
 \usepackage{dsfont}
diff --git a/tests/control_data/graphical_units_data/coordinate_systems/NumberPlaneTest.npz b/tests/control_data/graphical_units_data/coordinate_systems/NumberPlaneTest.npz
index 98ceac3e9a..949ab720f5 100644
Binary files a/tests/control_data/graphical_units_data/coordinate_systems/NumberPlaneTest.npz and b/tests/control_data/graphical_units_data/coordinate_systems/NumberPlaneTest.npz differ
diff --git a/tests/control_data/graphical_units_data/plot/AxesTest.npz b/tests/control_data/graphical_units_data/plot/AxesTest.npz
index 51d28b7d64..5cbf26cdee 100644
Binary files a/tests/control_data/graphical_units_data/plot/AxesTest.npz and b/tests/control_data/graphical_units_data/plot/AxesTest.npz differ
diff --git a/tests/control_data/graphical_units_data/plot/PlotFunctions.npz b/tests/control_data/graphical_units_data/plot/PlotFunctions.npz
index dfddd05f28..97814c3480 100644
Binary files a/tests/control_data/graphical_units_data/plot/PlotFunctions.npz and b/tests/control_data/graphical_units_data/plot/PlotFunctions.npz differ

Nondeterministic build failures in `Tex('The horse does not eat cucumber salad.')`
## Description of bug / unexpected behavior
<!-- Add a clear and concise description of the problem you encountered. -->

As I've been figuring out the test coverage toolset for Manim, I've done quite a lot of automated builds on a copied (not forked) repository (https://github.com/MrMallIronmaker/manim-cov/). For some reason, occasionally one of the Ubuntu builds fails while I've been playing around with coverage settings. Whether it's 3.7, 3.8, or 3.9 is apparently random.

All of them fail in the Tex doctest.


## Expected behavior
It should pass the test.


## How to reproduce the issue
<!-- Provide a piece of code illustrating the undesired behavior. -->

<details><summary>Code for reproducing the problem</summary>
In theory the problematic code is here:
```py
Tex('The horse does not eat cucumber salad.')
```

However, I've not been able to replicate this issue 

</details>


## Additional media files
<!-- Paste in the files manim produced on rendering the code above. Note that GitHub doesn't allow posting videos, so you may need to convert it to a GIF or use the `-i` rendering option. -->

<details><summary>Build output</summary>

```
Run poetry run pytest --cov-append --doctest-modules manim
  poetry run pytest --cov-append --doctest-modules manim
  shell: /usr/bin/bash -e {0}
  env:
    POETRY_VIRTUALENVS_CREATE: false
    pythonLocation: /opt/hostedtoolcache/Python/3.8.8/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.8.8/x64/lib
Skipping virtualenv creation, as specified in config file.
============================= test session starts ==============================
platform linux -- Python 3.8.8, pytest-6.2.2, py-1.10.0, pluggy-0.13.1
rootdir: /home/runner/work/manim-cov/manim-cov, configfile: pyproject.toml
plugins: cov-2.11.1
collected 30 items

manim/_config/__init__.py .                                              [  3%]
manim/_config/utils.py ..                  
## Logs
<details><summary>Terminal output</summary>
<!-- Add "-v DEBUG" when calling manim to generate more detailed logs -->

```
PASTE HERE OR PROVIDE LINK TO https://pastebin.com/ OR SIMILAR
```

<!-- Insert screenshots here (only when absolutely necessary, we prefer copy/pasted output!) -->

</details>


## System specifications

<details><summary>System Details</summary>

- OS (with version, e.g Windows 10 v2004 or macOS 10.15 (Catalina)):
- RAM:
- Python version (`python/py/python3 --version`):
- Installed modules (provide output from `pip list`):
```
PASTE HERE
```

</details>

<details><summary>LaTeX details</summary>

+ LaTeX distribution (e.g. TeX Live 2020):
+ Installed LaTeX packages:
<!-- output of `tlmgr list --only-installed` for TeX Live or a screenshot of the Packages page for MikTeX -->
</details>

<details><summary>FFMPEG</summary>

Output of `ffmpeg -version`:

```
PASTE HERE
```
</details>

## Additional comments
<!-- Add further context that you think might be relevant for this issue here. -->
                              [ 10%]
manim/animation/animation.py .                                           [ 13%]
manim/mobject/geometry.py .........                                      [ 43%]
manim/mobject/mobject.py ......                                          [ 63%]
manim/mobject/svg/tex_mobject.py ..F                                     [ 73%]
manim/mobject/svg/text_mobject.py ...                                    [ 83%]
manim/mobject/types/vectorized_mobject.py ....                           [ 96%]
manim/utils/color.py .                                                   [100%]

=================================== FAILURES ===================================
_________________ [doctest] manim.mobject.svg.tex_mobject.Tex __________________
491 A string compiled with LaTeX in normal mode.
492 
493     Tests
494     -----
495 
496     Check whether writing a LaTeX string works::
497 
498         >>> Tex('The horse does not eat cucumber salad.')
UNEXPECTED EXCEPTION: IndexError('list index out of range')
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.8.8/x64/lib/python3.8/doctest.py", line 1336, in __run
    exec(compile(example.source, filename, "single",
  File "<doctest manim.mobject.svg.tex_mobject.Tex[0]>", line 1, in <module>
  File "/home/runner/work/manim-cov/manim-cov/manim/mobject/svg/tex_mobject.py", line 506, in __init__
    MathTex.__init__(
  File "/home/runner/work/manim-cov/manim-cov/manim/mobject/svg/tex_mobject.py", line 392, in __init__
    self.break_up_by_substrings()
  File "/home/runner/work/manim-cov/manim-cov/manim/mobject/svg/tex_mobject.py", line 434, in break_up_by_substrings
    sub_tex_mob.move_to(self.submobjects[last_submob_index], RIGHT)
IndexError: list index out of range
/home/runner/work/manim-cov/manim-cov/manim/mobject/svg/tex_mobject.py:498: UnexpectedException
----------------------------- Captured stdout call -----------------------------
                    INFO     Writing "The horse does not  tex_file_writing.py:81
                             eat cucumber salad." to medi                       
                             a/Tex/3ecc83aec1683253.tex                         
------------------------------ Captured log call -------------------------------
INFO     manim:tex_file_writing.py:81 Writing "The horse does not eat cucumber salad." to media/Tex/3ecc83aec1683253.tex
=============================== warnings summary ===============================
manim/mobject/mobject.py::manim.mobject.mobject.Mobject.set
  <doctest manim.mobject.mobject.Mobject.set[1]>:1: DeprecationWarning: This method is not guaranteed to stay around. Please prefer setting the attribute normally or with Mobject.set().

manim/mobject/mobject.py::manim.mobject.mobject.Mobject.set
  <doctest manim.mobject.mobject.Mobject.set[2]>:1: DeprecationWarning: This method is not guaranteed to stay around. Please prefer getting the attribute normally.

manim/mobject/svg/tex_mobject.py::manim.mobject.svg.tex_mobject.Tex
  /home/runner/work/manim-cov/manim-cov/manim/mobject/svg/svg_mobject.py:261: UserWarning: media/Tex/3ecc83aec1683253.svg contains a reference to id #g0-84, which is not recognized
    warnings.warn(warning_text)

manim/mobject/svg/tex_mobject.py::manim.mobject.svg.tex_mobject.Tex
  /home/runner/work/manim-cov/manim-cov/manim/mobject/svg/svg_mobject.py:261: UserWarning: media/Tex/3ecc83aec1683253.svg contains a reference to id #g0-104, which is not recognized
    warnings.warn(warning_text)

manim/mobject/svg/tex_mobject.py::manim.mobject.svg.tex_mobject.Tex
  /home/runner/work/manim-cov/manim-cov/manim/mobject/svg/svg_mobject.py:261: UserWarning: media/Tex/3ecc83aec1683253.svg contains a reference to id #g0-101, which is not recognized
    warnings.warn(warning_text)

manim/mobject/svg/tex_mobject.py::manim.mobject.svg.tex_mobject.Tex
  /home/runner/work/manim-cov/manim-cov/manim/mobject/svg/svg_mobject.py:261: UserWarning: media/Tex/3ecc83aec1683253.svg contains a reference to id #g0-111, which is not recognized
    warnings.warn(warning_text)

manim/mobject/svg/tex_mobject.py::manim.mobject.svg.tex_mobject.Tex
  /home/runner/work/manim-cov/manim-cov/manim/mobject/svg/svg_mobject.py:261: UserWarning: media/Tex/3ecc83aec1683253.svg contains a reference to id #g0-114, which is not recognized
    warnings.warn(warning_text)

manim/mobject/svg/tex_mobject.py::manim.mobject.svg.tex_mobject.Tex
  /home/runner/work/manim-cov/manim-cov/manim/mobject/svg/svg_mobject.py:261: UserWarning: media/Tex/3ecc83aec1683253.svg contains a reference to id #g0-115, which is not recognized
    warnings.warn(warning_text)

manim/mobject/svg/tex_mobject.py::manim.mobject.svg.tex_mobject.Tex
  /home/runner/work/manim-cov/manim-cov/manim/mobject/svg/svg_mobject.py:261: UserWarning: media/Tex/3ecc83aec1683253.svg contains a reference to id #g0-100, which is not recognized
    warnings.warn(warning_text)

manim/mobject/svg/tex_mobject.py::manim.mobject.svg.tex_mobject.Tex
  /home/runner/work/manim-cov/manim-cov/manim/mobject/svg/svg_mobject.py:261: UserWarning: media/Tex/3ecc83aec1683253.svg contains a reference to id #g0-110, which is not recognized
    warnings.warn(warning_text)

manim/mobject/svg/tex_mobject.py::manim.mobject.svg.tex_mobject.Tex
  /home/runner/work/manim-cov/manim-cov/manim/mobject/svg/svg_mobject.py:261: UserWarning: media/Tex/3ecc83aec1683253.svg contains a reference to id #g0-116, which is not recognized
    warnings.warn(warning_text)

manim/mobject/svg/tex_mobject.py::manim.mobject.svg.tex_mobject.Tex
  /home/runner/work/manim-cov/manim-cov/manim/mobject/svg/svg_mobject.py:261: UserWarning: media/Tex/3ecc83aec1683253.svg contains a reference to id #g0-97, which is not recognized
    warnings.warn(warning_text)

manim/mobject/svg/tex_mobject.py::manim.mobject.svg.tex_mobject.Tex
  /home/runner/work/manim-cov/manim-cov/manim/mobject/svg/svg_mobject.py:261: UserWarning: media/Tex/3ecc83aec1683253.svg contains a reference to id #g0-99, which is not recognized
    warnings.warn(warning_text)

manim/mobject/svg/tex_mobject.py::manim.mobject.svg.tex_mobject.Tex
  /home/runner/work/manim-cov/manim-cov/manim/mobject/svg/svg_mobject.py:261: UserWarning: media/Tex/3ecc83aec1683253.svg contains a reference to id #g0-117, which is not recognized
    warnings.warn(warning_text)

manim/mobject/svg/tex_mobject.py::manim.mobject.svg.tex_mobject.Tex
  /home/runner/work/manim-cov/manim-cov/manim/mobject/svg/svg_mobject.py:261: UserWarning: media/Tex/3ecc83aec1683253.svg contains a reference to id #g0-109, which is not recognized
    warnings.warn(warning_text)

manim/mobject/svg/tex_mobject.py::manim.mobject.svg.tex_mobject.Tex
  /home/runner/work/manim-cov/manim-cov/manim/mobject/svg/svg_mobject.py:261: UserWarning: media/Tex/3ecc83aec1683253.svg contains a reference to id #g0-98, which is not recognized
    warnings.warn(warning_text)

manim/mobject/svg/tex_mobject.py::manim.mobject.svg.tex_mobject.Tex
  /home/runner/work/manim-cov/manim-cov/manim/mobject/svg/svg_mobject.py:261: UserWarning: media/Tex/3ecc83aec1683253.svg contains a reference to id #g0-108, which is not recognized
    warnings.warn(warning_text)

manim/mobject/svg/tex_mobject.py::manim.mobject.svg.tex_mobject.Tex
  /home/runner/work/manim-cov/manim-cov/manim/mobject/svg/svg_mobject.py:261: UserWarning: media/Tex/3ecc83aec1683253.svg contains a reference to id #g0-46, which is not recognized
    warnings.warn(warning_text)

-- Docs: https://docs.pytest.org/en/stable/warnings.html

----------- coverage: platform linux, python 3.8.8-final-0 -----------
Coverage XML written to file coverage.xml

=========================== short test summary info ============================
FAILED manim/mobject/svg/tex_mobject.py::manim.mobject.svg.tex_mobject.Tex
================== 1 failed, 29 passed, 18 warnings in 6.56s ===================
Error: Process completed with exit code 1.
```

</details>
