
    lj                        d Z ddlmZ dgZddlZddlZddlZddlmZm	Z	 ddl
mZ ddlmZmZ erddlmZ dd	lmZ d
ZdZdZ ed           G d d                      ZddZdS )z)Utilities for processing LaTeX templates.    )annotationsTexTemplateN)	dataclassfield)Path)TYPE_CHECKINGAny)Self)StrPathzE\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amssymb}z\begin{document}z\end{document}T)eqc                  (   e Zd ZU dZ edd          Zded<   	 dZded<   	 dZded	<   	 d
Z	ded<   	 dZ
ded<   	 eZded<   	 dZded<   	 dZded<   	 ed)d            Zej        d*d            Zed+d,d            Zd-d.d!Zd/d"Zd0d$Zd1d&Zd2d'Zd(S )3r   zATeX templates are used to create ``Tex`` and ``MathTex`` objects. F)defaultinitstr_bodylatextex_compilerdescriptionz.dvioutput_formatz#\documentclass[preview]{standalone}documentclasspreambleYourTextHereplaceholder_textpost_doc_commandsreturnc                    | j         pFd                    t          d| j        | j        t
          | j        | j        t          g                    S )zThe entire TeX template.
N)	r   joinfilterr   r   _BEGIN_DOCUMENTr   r   _END_DOCUMENTselfs    J/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/utils/tex.pybodyzTexTemplate.body9   sU     z 
TYY&M#*)!
 

 
 	
    valueNonec                    || _         d S )N)r   )r$   r(   s     r%   r&   zTexTemplate.bodyJ   s    


r'   tex_template.texfiler   kwargsr	   r
   c                f     | di |}t          |                              d          |_        |S )zCreate an instance by reading the content of a file.

        Using the ``add_to_preamble`` and ``add_to_document`` methods on this instance
        will have no effect, as the body is read from the file.
        zutf-8)encoding )r   	read_textr&   )clsr,   r-   instances       r%   	from_filezTexTemplate.from_fileN   s8     3====T

,,g,>>r'   txtprependboolc                    | j         rt          j        dt          d           |r|dz   | j        z   | _        n| xj        d|z   z  c_        | S )a  Adds text 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
            String containing the text to be added, e.g. ``\usepackage{hyperref}``.
        prepend
            Whether the text should be added at the beginning of the preamble, i.e. right after ``\documentclass``.
            Default is to add it at the end of the preamble, i.e. right before ``\begin{document}``.
        zeThis TeX template was created with a fixed body, trying to add text the preamble will have no effect.   
stacklevelr   )r   warningswarnUserWarningr   )r$   r5   r6   s      r%   add_to_preamblezTexTemplate.add_to_preambleY   sg     : 	Mw   
  	($J6DMMMMTCZ'MMr'   c                l    | j         rt          j        dt          d           | xj        |z  c_        | S )zAdds text to the TeX template just after \begin{document}, e.g. ``\boldmath``.

        Parameters
        ----------
        txt
            String containing the text to be added.
        zeThis TeX template was created with a fixed body, trying to add text the document will have no effect.r9   r:   )r   r<   r=   r>   r   )r$   r5   s     r%   add_to_documentzTexTemplate.add_to_documentp   sK     : 	Mw   
 	#%r'   
expressionc                B    | j                             | j        |          S )ak  Inserts expression verbatim into TeX template.

        Parameters
        ----------
        expression
            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
        )r&   replacer   )r$   rB   s     r%   get_texcode_for_expressionz&TexTemplate.get_texcode_for_expression   s     y  !6
CCCr'   environmentc                    t          |          \  }}| j                            | j        d                    |||g                    S )a*  Inserts expression into TeX template wrapped in ``\begin{environment}`` and ``\end{environment}``.

        Parameters
        ----------
        expression
            The string containing the expression to be typeset, e.g. ``$\sqrt{2}$``.
        environment
            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
        r   )_texcode_for_environmentr&   rD   r   r   )r$   rB   rF   beginends        r%   !get_texcode_for_expression_in_envz-TexTemplate.get_texcode_for_expression_in_env   sJ    " .k::
sy  !499eZ-E#F#F
 
 	
r'   c                *    t          j        |           S )z0Create a deep copy of the TeX template instance.)copydeepcopyr#   s    r%   rM   zTexTemplate.copy   s    }T"""r'   N)r   r   )r(   r   r   r)   )r+   )r,   r   r-   r	   r   r
   )F)r5   r   r6   r7   r   r
   )r5   r   r   r
   )rB   r   r   r   )rB   r   rF   r   r   r   )r   r
   )__name__
__module____qualname____doc__r   r   __annotations__r   r   r   r   _DEFAULT_PREAMBLEr   r   r   propertyr&   setterclassmethodr4   r?   rA   rE   rK   rM   r0   r'   r%   r   r      s        KKr...E....0LTK'MR?M????`%H%%%%f*****Vo
 
 
 X
  
[   [     [    .   "D D D D
 
 
 
,# # # # # #r'   rF   r   r   tuple[str, str]c                    |                      d                               d          } d| z   }|                    d          s|dz  }t          j        d| d          }d|d	         z   dz   }||fS )
a>  Processes the tex_environment string to return the correct ``\begin{environment}[extra]{extra}`` and
    ``\end{environment}`` strings.

    Parameters
    ----------
    environment
        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}``
    z\begin{z\begin{)}]r[      )maxsplitz\end{r   )removeprefixendswithresplit)rF   rI   split_at_bracerJ   s       r%   rH   rH      s      **955BB3GGK $E>>*%%  Xc;;;;N
^A&
&
,C#:r'   )rF   r   r   rX   )rR   
__future__r   __all__rM   ra   r<   dataclassesr   r   pathlibr   typingr   r	   r
   manim.typingr   rT   r!   r"   r   rH   r0   r'   r%   <module>rj      s1   / / " " " " " "   				  ( ( ( ( ( ( ( (       % % % % % % % % %$$$$$$  &! dJ# J# J# J# J# J# J# J#Z     r'   