
    Ki*                        d Z ddlmZmZ ddlZddlZddlZddlZddlZddl	Z	ej
        j        dk    rd ZeZej        Zn	ej        ZeZddlZddlmZ ddlmZ dd	lmZ  ej        e          Z G d
 de          Z G d de          Z G d de          ZdhdZdidZ d Z!d Z"djdZ#djdZ$d Z%d Z&ddddddd d!d"d#d$d%d&d'Z' e(d(           ed)          i e(d*           ed+           e(d,           ed-           e(d.           ed/           e(d0           ed1           e(d2           ed3           e(d4           ed5           e(d6           ed7           e(d8           ed9           e(d:           ed;           e(d<           ed=           e(d>           ed?          i e(d@           edA           e(d0           edB           e(d2           edC           e(d8           edD           e(dE           edF          i e(d@           edG           e(d0           edH           e(dI           edJ           e(dK           edL           e(dM           edN           e(d8           edO           e(dE           edP          idQZ) e(dR           e(dE           e(dS           e(dT          f\  Z*Z+Z,Z-dU Z.ej/        dVk     rdW Z.dX Z0dY Z1 ej2        dZ [          Z3	  ej2        d\ [          Z4	 d]Z5	 ddddd^dddd_d^dddd_d^d`Z6da Z7 G db dce          Z8 G dd deej9                  Z:	 	 dkdfZ;dldgZ<dS )mu  
A simplistic, heuristic LaTeX code parser allowing to returns a text-only
approximation.  Suitable, e.g. for indexing tex code in a database for full text
searching.

The main class is :py:class:`LatexNodes2Text`.  For a quick start, try::

    from pylatexenc.latex2text import LatexNodes2Text

    latex = "... LaTeX code ..."
    text = LatexNodes2Text().latex_to_text(latex)

You may also use the command-line version of `latex2text`::

    $ echo '\textit{italic} \`acc\^ented text' | latex2text
    italic àccênted text

    )print_functionunicode_literalsN   c                     | S N )strings    v/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/pylatexenc/latex2text/__init__.pyunicoder   7   s           )latexwalker)	macrospec)_utilc                   $     e Zd ZdZd fd	Z xZS )MacroTextSpecaB  
    A specification of how to obtain a textual representation of a macro.

    .. py:attribute:: macroname

       The name of the macro (no backslash)

    .. py:attribute:: simplify_repl

       The replacement text of the macro invocation.  This is either a string or
       a callable:

         - If `simplify_repl` is a string, this string is used as the text
           representation of this macro node.

           The string may contain a single '%s' replacement placeholder which
           will be replaced by the concatenated textual representation of all
           macro arguments.  Alternatively, the string may contain '%(<n>)s'
           (where `<n>` is an integer) to refer to the n-th argument (starting
           at '%(1)s').  You cannot mix the two %-formatting styles.

         - If `simplify_repl` is a callable, it should accept the corresponding
           :py:class:`pylatexenc.latexwalker.LatexMacroNode` as an argument.

           The callable will be inspected to see what other arguments it
           accepts.  If it accepts an argument named `l2tobj`, the
           :py:class:`LatexNodes2Text` instance is provided to that argument.
           If it accepts an argument named `macroname`, the name of the macro is
           provided to that argument.

    .. py:attribute:: discard

       If set to `True`, then the macro call is discarded, i.e., it is converted
       to an empty string.


    .. versionadded:: 2.0

       The class :py:class:`MacroTextSpec` was introduced in `pylatexenc
       2.0` to succeed to the previously named `MacroDef` class.
    Nc                     t          t          |                                            || _        |dn|| _        || _        d S NT)superr   __init__	macronamediscardsimplify_repl)selfr   r   r   	__class__s       r
   r   zMacroTextSpec.__init__q   sC    mT""++---" 'ttg*r   NN__name__
__module____qualname____doc__r   __classcell__r   s   @r
   r   r   G   sH        ( (R+ + + + + + + + + +r   r   c                   $     e Zd ZdZd fd	Z xZS )EnvironmentTextSpeca  
    A specification of how to obtain a textual representation of an environment.

    .. py:attribute:: environmentname

       The name of the environment

    .. py:attribute:: simplify_repl

       The replacement text of the environment.  This is either a string or a
       callable:

         - If `simplify_repl` is a string, this string is used as the text
           representation of this environment node.

           The string may contain a single '%s' replacement placeholder, in
           which the (processed) environment body will be substituted.

           Alternatively, the `simplify_repl` string may contain '%(<n>)s'
           (where `<n>` is an integer) to refer to the n-th argument after
           ``egin{environment}`` (starting at '%(1)s').  The body of the
           environment has to be referred to with `%(body)s`.

           You cannot mix the two %-formatting styles.

         - If `simplify_repl` is a callable, it should accept the corresponding
           :py:class:`pylatexenc.latexwalker.LatexEnvironmentNode` as an
           argument.

           The callable will be inspected to see what other arguments it
           accepts.  If it accepts an argument named `l2tobj`, the
           :py:class:`LatexNodes2Text` instance is provided to that argument.
           If it accepts an argument named `environmentname`, the name of the
           environment is provided to that argument.

    .. py:attribute:: discard

       If set to `True`, then the full environment is discarded, i.e., it is
       converted to an empty string.


    .. versionadded:: 2.0

       The class :py:class:`EnvironmentTextSpec` was introduced in `pylatexenc
       2.0` to succeed to the previously named `EnvDef` class.
    NFc                     t          t          |                                            || _        || _        || _        d S r   )r   r%   r   environmentnamer   r   )r   r'   r   r   r   s       r
   r   zEnvironmentTextSpec.__init__   s;    !4((11333.*r   NFr   r#   s   @r
   r%   r%   x   sH        - -\         r   r%   c                   $     e Zd ZdZd fd	Z xZS )SpecialsTextSpeca  
    A specification of how to obtain a textual representation of latex specials.

    .. py:attribute:: specials_chars

       The sequence of special LaTeX characters

    .. py:attribute:: simplify_repl

       The replacement text for the given latex specials.  This is either a
       string or a callable:

         - If `simplify_repl` is a string, this string is used as the text
           representation of this specials node.

           The string may contain a single '%s' replacement placeholder which
           will be replaced by the concatenated textual representation of all
           macro arguments.

           Alternatively, the string may contain '%(<n>)s' (where `<n>` is an
           integer) to refer to the n-th argument (starting at '%(1)s').  You
           cannot mix the two %-formatting styles.

         - If `simplify_repl` is a callable, it should accept the corresponding
           :py:class:`pylatexenc.latexwalker.LatexSpecialsNode` as an argument.

           The callable will be inspected to see what other arguments it
           accepts.  If it accepts an argument named `l2tobj`, the
           :py:class:`LatexNodes2Text` instance is provided to that argument.
           If it accepts an argument named `specials_chars`, the characters that
           were parsed this "latex specials" node are provided to that argument.

    .. versionadded:: 2.0

       Latex specials were introduced in `pylatexenc 2.0`.
    Nc                 r    t          t          |                                            || _        || _        d S r   )r   r*   r   specials_charsr   )r   r,   r   r   s      r
   r   zSpecialsTextSpec.__init__   s6    %%..000,*r   r   r   r#   s   @r
   r*   r*      sH        # #H+ + + + + + + + + +r   r*   Fc                 B    t          | ||          }|j        |_        |S )a?  
    .. deprecated:: 2.0

       Instantiate a :py:class:`EnvironmentTextSpec` instead.

       Since `pylatexenc 2.0`, `EnvDef` is a function which returns a
       :py:class:`~pylatexenc.macrospec.EnvironmentTextSpec` instance.  In this
       way the earlier idiom ``EnvDef(...)`` still works in `pylatexenc 2`.
    )r'   r   r   )r%   r'   envname)r.   r   r   es       r
   EnvDefr0      s.     	G=$+	- 	- 	-A!AIHr   c                 B    t          | ||          }|j        |_        |S )a7  
    .. deprecated:: 2.0

       Instantiate a :py:class:`MacroTextSpec` instead.

       Since `pylatexenc 2.0`, `MacroDef` is a function which returns a
       :py:class:`~pylatexenc.macrospec.MacroTextSpec` instance.  In this way
       the earlier idiom ``MacroDef(...)`` still works in `pylatexenc 2`.
    )r   r   r   )r   r   macname)r2   r   r   ms       r
   MacroDefr4      s&     	}gVVVAAIHr   c                 ,    |                     |           S )z
    Can be used as callback for display equation environments.

    .. versionadded:: 2.0

       This function was introduced in `pylatexenc 2.0`.
    )math_node_to_text)envnodel2tobjs     r
   fmt_equation_environmentr9     s     ##G,,,r   c                 ,    |                     |           S )a-  
    This function can be used as callback in :py:class:`MacroTextSpec` for
    ``\input`` or ``\include`` macros.  The `macronode` must be a macro node
    with a single argument.  If :py:meth:`set_tex_input_directory()` was called
    with a nonempty input directory in the :py:class:`LatexNodes2Text` object,
    then this method reads the contents of the file name in the macro argument
    according to the provided settings.  Otherwise, returns an empty string.

    .. versionadded:: 2.0

       This function was introduced in `pylatexenc 2.0`.
    )_input_node_simplify_repl)	macronoder8   s     r
   fmt_input_macror=     s     ++I666r   Tc                     | ffd	S )a/  
    This function returns a callable that can be used in
    :py:class:`MacroTextSpec`, :py:class:`EnvironmentTextSpec`, or
    :py:class:`SpecialsTextSpec` for latex nodes that do not have a good textual
    representation, providing as text replacement the simple placeholder text
    ``'< P L A C E H O L D E R   T E X T >'``.

    If `block=True` (the default), the placeholder text is typeset in an
    indented block on its own.  Otherwise, it is typeset inline.

    .. versionadded:: 2.0

       This function was introduced in `pylatexenc 2.0`.
    c                 (    t          ||          S )N)block)_do_fmt_placeholder_node)nr8   phtr@   s      r
   <lambda>z,placeholder_node_formatter.<locals>.<lambda>-  s     fE::: r   r   )placeholdertextr@   s    `r
   placeholder_node_formatterrF     s&     #2 ; ; ; ; ; ;r   c                 z    dd                     |           z   dz   }|r|                    |d          S d|z   dz   S )Nz<  z >    indent)join_fmt_indented_block)rE   r8   r@   txts       r
   rA   rA   0  sN     /**
*T
1C >))#f)===9s?r   c                 t    dD ]$}t          | |          rt          | |          } n%d}t          ||          S )a  
    This function can be used as callable in :py:class:`MacroTextSpec`,
    :py:class:`EnvironmentTextSpec`, or :py:class:`SpecialsTextSpec` for latex
    nodes that do not have a good textual representation.  The text replacement
    is the placeholder text
    ``'< N A M E   O F   T H E   M A C R O   O R   E N V I R O N M E N T >'``.

    .. versionadded:: 2.0

       This function was introduced in `pylatexenc 2.0`.
    )r   r'   r,   z	<unknown>)hasattrgetattrrA   )noder8   attnames       r
   fmt_placeholder_noderU   8  sV     B  4 	4%%DE	 #D&111r   c                 2    G fdd          } |            }| j         D ]}|                    t          j                  r |j        dk    r|                                 A|                    t          j                  r |j        dk    r|                                 |	                    |           |                                 t          d |j        D                       d                    fd|j        D                       }d|z   d	z   S )
a  
    This function can be used as a callable in :py:class:`EnvironmentTextSpec`
    for matrix-like environments like ``\begin{bmatrix}...\end{bmatrix}``.

    The contents is parsed by separating columns with ``&``'s and rows with
    ``\\``'s, and is rendered in the form ``[  a11  a12  ;  a21  a22  ]``.

    .. versionadded:: 2.8

       This function was introduced in `pylatexenc 2.8`.
    c                   ,    e Zd Zd Zd Z fdZd ZdS ).fmt_matrix_environment_node.<locals>.StateTypec                 0    g | _         g | _        g | _        d S r   )matrix_rowsbuffer_this_columnbuffer_nodesr   s    r
   r   z7fmt_matrix_environment_node.<locals>.StateType.__init__]  s     !D&(D# "Dr   c                 :    | j                             |           d S r   )r\   appendr   rR   s     r
   add_contentz:fmt_matrix_environment_node.<locals>.StateType.add_contentb  s    $$T*****r   c                     | j         rD| j                                                | j                                                              g | _         d S r   )r\   r[   r_   nodelist_to_textstrip)r   r8   s    r
   
new_columnz9fmt_matrix_environment_node.<locals>.StateType.new_columne  sY      '..++D,=>>EEGG   !#Dr   c                 z    |                                   | j                            | j                   g | _        d S r   )re   rZ   r_   r[   r]   s    r
   new_rowz6fmt_matrix_environment_node.<locals>.StateType.new_rowl  s:    OO##T%<>>>&(D###r   N)r   r   r    r   ra   re   rg   )r8   s   r
   	StateTyperX   \  s[        	# 	# 	#
	+ 	+ 	+	# 	# 	# 	# 	#	) 	) 	) 	) 	)r   rh   &\c              3   >   K   | ]}|D ]}t          |          V  d S r   )len).0rowxs      r
   	<genexpr>z.fmt_matrix_environment_node.<locals>.<genexpr>  s5      PP3PPaCFFPPPPPPPr   z; c              3   Z   K   | ]%}d                      fd|D                       V  &dS )rH   c              3   D   K   | ]}|                     d           V  dS )rH   N)rjust)rm   ro   max_char_widths     r
   rp   z8fmt_matrix_environment_node.<locals>.<genexpr>.<genexpr>  sE       
 
 GGNC((
 
 
 
 
 
r   NrL   )rm   rn   rt   s     r
   rp   z.fmt_matrix_environment_node.<locals>.<genexpr>  sm       " "
 	 	 
 
 
 

 
 
 	 	" " " " " "r   z[ z ])nodelist
isNodeTyper   LatexSpecialsNoder,   re   LatexMacroNoder   rg   ra   maxrZ   rL   )rR   r8   rh   staterB   matrix_contentsrt   s    `    @r
   fmt_matrix_environment_noder}   O  sW   ) ) ) ) ) ) ) ) ) )* IKKE ] 	 	<<566 	1;Ks;R;R<<233 	t8K8KMMOOO!	MMOOO PPu/@PPPRRNii " " " "
 $" " "  O /!D((r   )i  i )i4 iN )ih i )i i )i i )i i )i8 iR )il i )i i )i i )i i" )i< iV )ip i )bolditaliczbold-italicscriptzbold-scriptfrakturdoublestruckzbold-fraktursansz	sans-boldzsans-italiczsans-bold-italic	monospacehi!  Bi,!  Ei0!  Fi1!  Hi!  Ii!  Li!  Mi3!  Ri!  r/   i/!  gi
!  oi4!  Ci-!  i!  i!  i!  Zi(!  i!  i!  Ni!  Pi!  Qi!  i!  i$!  )r   r   r   r   Aazc                    t          |           }t                              |i                               |d           }||S t                              |t          t
          f          \  }}|t          k    r%|t          k    rt          ||z   t          z
            S |t
          k    r%|t          k    rt          ||z   t
          z
            S | S r   )	ord_fmt_math_style_exceptionsget_fmt_math_style_offsets_oA_oa_oZchr_oz)cstyleocr   	offset_up	offset_los         r
   _fmt_math_style_charr     s    	QB"&&ub1155b$??A}266usCkJJIy	SyyR3YY9r>C'(((	SyyR3YY9r>C'((( Hr   i c                     | S r   r   )r   r   s     r
   rD   rD     s    A r   c                 F    d                     fd| D                       S )a  
    Return the text with letters replaced by unicode characters so that the
    style `style` is applied.  (We use the unicode math alphanumeric symbols,
    see `https://unicode.org/charts/PDF/U1D400.pdf`_.)

    The `style` must be one of 'bold', 'italic', 'bold-italic', 'script',
    'bold-script', 'fraktur', 'doublestruck', 'bold-fraktur', 'sans',
    'sans-bold', 'sans-italic', 'sans-bold-italic', or 'monospace'.

    The character `c` is essentially expected to be an ascii letter, and any
    other character will be returned unchanged.  (Possible exceptions might be
    implemented in the future, for instance to implement the double-struck
    one/identity operator ``\mathbbm{1}``.)
     c              3   :   K   | ]}t          |           V  dS ))r   N)r   )rm   r   r   s     r
   rp   z&fmt_math_text_style.<locals>.<genexpr>  s1      HHa)!5999HHHHHHr   ru   )textr   s    `r
   fmt_math_text_styler     s,     77HHHH4HHHJJJr   c                      t          j                    } ddlm} |D ]0\  }}|                     ||d         |d         |d                    1| S )a  
    Return a :py:class:`pylatexenc.macrospec.LatexContextDb` instance
    initialized with a collection of text replacements for known macros and
    environments.

    TODO: clean up and document categories.

    If you want to add your own definitions, you should use the
    :py:meth:`pylatexenc.macrospec.LatexContextDb.add_context_category()`
    method.  If you would like to override some definitions, use that method
    with the argument `prepend=True`.  See docs for
    :py:meth:`pylatexenc.macrospec.LatexContextDb.add_context_category()`.

    If there are too many macro/environment definitions, or if there are some
    irrelevant ones, you can always filter the returned database using
    :py:meth:`pylatexenc.macrospec.LatexContextDb.filter_context()`.

    .. versionadded:: 2.0

       The :py:class:`pylatexenc.macrospec.LatexContextDb` class as well as this
       method, were all introduced in `pylatexenc 2.0`.
       )specsmacrosenvironmentsspecialsr   r   r   )r   LatexContextDb_defaultspecsr   add_context_category)dbr   catcatspecss       r
   get_default_latex_context_dbr     sz    . 
	!	#	#B$$$$$$ ? ?X
'/'9-5n-E)1*)= 	  	? 	? 	? 	?
 Ir   c                  p    t          d t                                                      D                       S )Nc                      g | ]}|j         |fS r   )r   rm   r3   s     r
   
<listcomp>z<lambda>.<locals>.<listcomp>  s/     # # # 
a# # #r   )dictr   iter_macro_specsr   r   r
   rD   rD     s>    T # #-//@@BB# # #   r   )generate_dict_fnc                  p    t          d t                                                      D                       S )Nc                      g | ]}|j         |fS r   )r'   r   s     r
   r   z<lambda>.<locals>.<listcomp>2  s0     # # # 
	A# # #r   )r   r   iter_environment_specsr   r   r
   rD   rD   2  s>    T # #-//FFHH# # #   r   r   between-macro-and-charsbetween-latex-constructsafter-commentin-equationsbased-on-source)r   r   zexcept-in-equationsc                 ^   dddd d}| |S | du rt           d         S | du r+t          d |                                D                       S t          | t                    r|                    |            |S t          | t
                    r| dk    rt          d          S | dk    rt          d          S | t           vr"t          d                    |                     | d	k    rt          j
        d
d           d} t           |          S t          d                    |                     )NFr   r   Tc                     g | ]}|d fS Tr   )rm   ks     r
   r   z3_parse_strict_latex_spaces_dict.<locals>.<listcomp>{  s    1111aY111r   onoffz0invalid value for strict_latex_spaces preset: {}defaulta  The value 'default' for `strict_latex_spaces=` in LatexNodes2Text() is deprecated. The actual default changed to 'macros', and for backwards compatibility the obsolete value 'default' still refers to the earlier default which is now called 'based-on-source'.   )
stacklevelr   z+Invalid value for strict_latex_spaces: {!r})_strict_latex_spaces_predefr   keys
isinstanceupdate
basestring_parse_strict_latex_spaces_dict
ValueErrorformatr   pylatexenc_deprecated_2)strict_latex_spacesds     r
   r   r   n  su   #($)		 	A "		%	%*844		$	$11111222	'	.	. 7	$%%%	'	4	4 7$&&24888%''25999&AAAO$f%899; ; ; )++)M     #4*+>??F &!4557 7 	7r   c                        e Zd ZdZd fd	Z	 	 ddZd Zd Zd Zd	 Z	ddZ
ddZd Zd Zd Zd Zd Zd ZddZd ZddZd Zd Zd Zd Z xZS ) LatexNodes2Textu/  
    Simplistic Latex-To-Text Converter.

    This class parses a nodes structure generated by the :py:mod:`latexwalker` module,
    and creates a text representation of the structure.

    It is capable of parsing ``\input`` directives safely, see
    :py:meth:`set_tex_input_directory()` and :py:meth:`read_input_file()`.  By default,
    ``\input`` and ``\include`` directives are ignored.

    Arguments to the constructor:

    - `latex_context_db` is a :py:class:`pylatexenc.macrospec.LatexContextDb`
      class storing a collection of rules for converting macros, environments,
      and other latex specials to text.  The `LatexContextDb` should contain
      specifications via :py:class:`MacroTextSpec`,
      :py:class:`EnvironmentTextSpec`, and :py:class:`SpecialsTextSpec` objects.

      The default latex context database can be obtained using
      :py:func:`get_default_latex_context_db()`.

    Additional keyword arguments are flags which may influence the behavior:

    - `math_mode='text'|'with-delimiters'|'verbatim'|'remove'`: Specify how to
      treat chunks of LaTeX code that correspond to math modes.  If 'text' (the
      default), then the math mode contents is incorporated as normal text.  If
      'with-delimiters', the content is incorporated as normal text but it is
      still included in the original math-mode delimiters, such as '$...$'.  If
      'verbatim', then the math mode chunk is kept verbatim, including the
      delimiters.  The value 'remove' means to remove the math mode sections
      entirely and not to produce any replacement text.

    - `keep_comments=True|False`: If set to `True`, then LaTeX comments are kept
      (including the percent-sign); otherwise they are discarded.  (By default
      this is `False`)

    - `fill_text`: If set to `True` or to a positive integer, then the
      whitespace of LaTeX char blocks is re-layed out to fill at the given
      number of characters or 80 by default.  The fill is by far not perfect,
      but the resulting text might be slightly more readable.

    - `strict_latex_spaces=True|False`: If set to `True`, then we follow closely
      LaTeX's handling of whitespace.  For instance, whitespace following a bare
      macro (i.e. without any delimiting characters like '{') is
      consumed/removed.  If set to `False` (the default), then some liberties
      are taken with respect to whitespace [hopefully making the result slightly
      more aesthetic, but this behavior is mostly there for historical reasons].

      You may also use one of the presets
      `strict_latex_spaces='based-on-source'|'macros'|'except-in-equations'`,
      which allow for finer control of how whitespace is handled:

        - The value 'based-on-source' is the option that is furthest from
          latex's behavior with spaces, and takes liberties in incuding spaces
          that are present in the source file in several situations where LaTeX
          would remove them, including after macros.  This is meant to be
          hopefully slightly more aesthetic.  However, this option might
          inadvertently break up words: For instance::

              Sk\l odowska

          would be replaced by::

             Skł odowska

        - The value 'macros' is the same as specifying
          `strict_latex_spaces=False`, and it is the default.  It will make
          macros and other sequences of LaTeX constructions obey LaTeX space
          rules, but will keep indentations after comments and keep more liberal
          whitespace rules in equations for a hopefully more aesthetic result.

        - The 'except-in-equations' preset goes as you would expect, setting
          strict latex spacing only outside of equation contexts.

      Finally, the argument `strict_latex_spaces` may also be set to a
      dictionary with keys 'between-macro-and-chars', 'after-comment',
      'between-latex-constructs', and 'in-equations', with individual values
      either `True` or `False`, dictating whitespace behavior in specific cases
      (`True` indicates strict latex behavior).  The value for 'in-equations'
      may even be another dictionary with the same keys to override values in
      equations.  A value of `False` for 'in-equation' has the same meaning as
      'macros'.

      .. versionchanged:: 2.0

         Since `pylatexenc 2.0`, the default value of `strict_latex_spaces` is
         'macros', and no longer 'based-on-source'.

      .. deprecated:: 2.0

         The value 'default' is also accepted, but it is no longer the default!
         It is an alias for 'based-on-source'

      .. versionchanged:: 2.6

         In `pylatexenc` versions 2.0–2.5, contrary to the documentation, the
         default value of `strict_latex_spaces` was actually still
         'based-on-source'.  This bug was fixed in version 2.6, so that now, the
         default setting is actually 'macros'.

    - `keep_braced_groups=True|False`: If set to `True`, then braces delimiting
      a TeX group ``{Like this}`` will be kept in the output, with the contents
      of the group converted to text as usual.  (By default this is `False`)

    - `keep_braced_groups_minlen=<int>`: If `keep_braced_groups` is set to
      `True`, then we keep braced groups only if their contents length (after
      conversion to text) is longer than the given value.  E.g., if
      `keep_braced_groups_minlen=2`, then ``{\'e}tonnant`` still goes to
      ``étonnant`` but ``{\'etonnant}``
      becomes ``{étonnant}``.

    .. versionadded: 1.4

       Added the `strict_latex_spaces`, `keep_braced_groups`, and
       `keep_braced_groups_minlen` flags

    .. versionadded: 2.0

       Added the `math_mode=` flag to replace the poorly designed
       `keep_inline_math=` flag;

       Added the `fill_text=` flag.

    Additionally, the following arguments are accepted for backwards compatibility:

    - `keep_inline_math=True|False`: Obsolete since `pylatexenc 2`.  If set to
      `True`, then this is the same as `math_mode='verbatim'`, and if set to
      `False`, this is the same as `math_mode='text'`.

      .. deprecated:: 2.0

         The `keep_inline_math=` option is deprecated because it had a weird
         behavior and was poorly implemented, especially given that a similarly
         named option in :py:class:`LatexWalker` had a different effect.  See
         issue :issue:`14`.

    - `text_replacements` this argument is ignored starting from `pylatexenc 2`.

      .. deprecated:: 2.0

         Text replacements are no longer made at the end of the text conversion.
         This feature is replaced by the concept of LaTeX specials---see, e.g.,
         :py:class:`pylatexenc.latexwalker.LatexSpecialsNode`.

         To keep existing code working, add a call to
         :py:meth:`apply_text_replacements()` immediately after
         :py:meth:`nodelist_to_text()` to achieve the same effect as in
         `pylatexenc 1.x`.  See :py:meth:`apply_text_replacements()`.

    - `env_dict`, `macro_dict`: Obsolete since `pylatexenc 2`.  If set, they are
      dictionaries of known environment and macro definitions.  They default to
      :py:data:`default_env_dict` and :py:data:`default_macro_dict`,
      respectively.

      .. deprecated:: 2.0

         You should now use the more powerful option `latex_context_db=`.  You
         cannot specify both `macro_list` (or `env_list`) and
         `latex_context_db`.
    Nc                    t          t          |                                            |d|v sd|v rt          j        d           |                    dg           }|                    dg           }t          j                    }|                    d|	                                |	                                g            nt                      }|| _        d | _        d| _        d|v rFd|v rt          d	          t          j        d
           |                    d          rdnd| _        n|                    dd          | _        | j        dvrt!          d          |                    dd          | _        |                    dd          }t%          |          | _        |                    dd          | _        |                    dd          | _        |                    dd           | _        | j        sd | _        | j        du rd| _        d|v r|d= t          j        d           |r<t.                              dt3          |                                                     d S d S )N
macro_dictenv_dictzThe `macro_dict=...` and `env_dict=...` options in LatexNodes2Text() are obsolete since pylatexenc 2.  They will still work, but please consider using instead the more versatile option `latex_context=...`.customr   Tkeep_inline_math	math_modezJCannot specify both math_mode= and keep_inline_math= for LatexNodes2Text()zcThe keep_inline_math=... option in LatexNodes2Text() has been replaced by the math_mode=... option.verbatimr   )r   with-delimitersr   removezPmath_mode= option must be one of 'text', 'with-delimiters', 'verbatim', 'remove'keep_commentsFr   keep_braced_groupskeep_braced_groups_minlenr   	fill_textP   text_replacementszThe text_replacements= argument is ignored since pylatexenc 2. To keep existing code working, add a call to `LatexNodes2Text.apply_text_replacements()`. New code should use "latex specials" instead.z2LatexNodes2Text(): Unknown flag(s) encountered: %r)r   r   r   r   r   popr   r   r   valuesr   latex_contexttex_input_directorystrict_input	TypeErrorr   r   r   r   r   r   r   r   loggerwarninglistr   )r   r   flagsr   r   r   r   s         r
   r   zLatexNodes2Text.__init__:  s   ot$$--/// u$$
e(;(;-S   #YY|R88
 99Z44 ) 8 : :228:D:K:K:M:M@H@Q@Q<> 3 @ @ @ @ != > >*#'  &&e## !8 9 9 9),   ,1995G+H+HTZZfDNN"YY{F;;DN>!RRR 4 5 5 5 #YY>>#ii(=uEE#BCV#W#W "')),@%"H"H).3NPQ)R)R&;55~ 	"!DN>T!!DN%'')*)B    	/NNO

--/ / / / /	/ 	/r   Tc                 8    || _         |r|ni | _        || _        dS )a[  
        Set where to look for input files when encountering the ``\input`` or
        ``\include`` macro.

        Alternatively, you may also override :py:meth:`read_input_file()` to
        implement a custom file lookup mechanism.

        The argument `tex_input_directory` is the directory relative to which to
        search for input files.

        If `strict_input` is set to `True`, then we always check that the
        referenced file lies within the subtree of `tex_input_directory`,
        prohibiting for instance hacks with '..' in filenames or using symbolic
        links to refer to files out of the directory tree.

        The argument `latex_walker_init_args` allows you to specify the parse
        flags passed to the constructor of
        :py:class:`pylatexenc.latexwalker.LatexWalker` when parsing the input
        file.
        N)r   latex_walker_init_argsr   )r   r   r   r   s       r
   set_tex_input_directoryz'LatexNodes2Text.set_tex_input_directory  s.    , $7 @V&^&<&<\^#(r   c                    | j         dS t          j                            t          j                            | j         |                    }| j        rVt          j                            | j                   }|                    |          st                              d|           dS t          j        	                    |          s't          j        	                    |dz             r|dz   }t          j        	                    |          s't          j        	                    |dz             r|dz   }t          j        
                    |          st                              d|           dS t                              d|           	 t          |          5 }|                                cddd           S # 1 swxY w Y   dS # t          $ r'}t                              d||           Y d}~dS d}~ww xY w)	a  
        This method may be overridden to implement a custom lookup mechanism when
        encountering ``\input`` or ``\include`` directives.

        The default implementation looks for a file of the given name relative
        to the directory set by :py:meth:`set_tex_input_directory()`.  If
        `strict_input=True` was set, we ensure strictly that the file resides in
        a subtree of the reference input directory (after canonicalizing the
        paths and resolving all symlinks).

        If `set_tex_input_directory()` was not called, or if it was called with
        a value of `None`, then no file system access is attempted an an empty
        string is returned.

        You may override this method to obtain the input data in however way you
        see fit.  In that case, a call to `set_tex_input_directory()` may not be
        needed as that function simply sets properties which are used by the
        default implementation of `read_input_file()`.

        This function accepts the referred filename as argument (the argument to
        the ``\input`` macro), and should return a string with the file
        contents (or generate a warning or raise an error).
        Nr   zPCan't access path '%s' leading outside of mandated directory [strict input mode]z.texz.latexzError, file doesn't exist: '%s'zReading input file %rzError, can't access '%s': %s)r   ospathrealpathrL   r   
startswithr   r   existsisfiledebugopenreadIOError)r   fnfnfulldirfullfr/   s         r
   read_input_filezLatexNodes2Text.read_input_file  s   2 #+2!!"',,t/G"L"LMM 
	 g&&t'?@@G$$W-- *  
 rw~~f%% 	%"'..&*I*I 	%f_Fw~~f%% 	'"'..(9J*K*K 	'h&Fw~~f%% 	NN=rBBB2,f555	f  vvxx                                    	 	 	NN:BBBB22222	s<   G
 F=0G
 =GG
 GG
 

G;G66G;c                    t          |j                  dk    r t                              d|j                   |                     |                     |j        d         g                                                    }|sdS |                     t          j        |fi | j	        
                                d                   S )Nr   z5Expected exactly one argument for '\input' ! Got = %rr   r   )rl   nodeargsr   r   r  rc   rd   r   LatexWalkerr   get_latex_nodes)r   rB   inputtexs      r
   r;   z)LatexNodes2Text._input_node_simplify_repl  s    
 qz??aNNT:' ' ' ''(=(=qz!}o(N(N(T(T(V(VWW 	2$$#HLL0KLL_q"
 
 	
r   c                 |    |                      t          j        |fi |                                d                   S )a  
        Parses the given `latex` code and returns its textual representation.

        This is equivalent to constructing a
        :py:class:`pylatexenc.latexwalker.LatexWalker` with the given `latex`
        string, calling its method
        :py:meth:`~pylatexenc.latexwalker.LatexWalker.get_latex_nodes()`, and
        providing the outcome to :py:meth:`nodelist_to_text()`.

        The `parse_flags` are keyword arguments to provide to the
        :py:class:`pylatexenc.latexwalker.LatexWalker` constructor.
        r   )rc   r   r  r  )r   latexparse_flagss      r
   latex_to_textzLatexNodes2Text.latex_to_text  sC     $$#E99[99IIKKAN
 
 	
r   c                 f   d}d}|D ]}|                      |          r6|                    t          j                  r| j        d         s
||j        z  }|                    d          }|dk    rt          |          |z
  dz
  }nt          |          }||                     ||          z  }|}|S )a  
        Extracts text from a node list. `nodelist` is a list of `latexwalker` nodes,
        typically returned by
        :py:meth:`pylatexenc.latexwalker.LatexWalker.get_latex_nodes()`.

        This function basically applies `node_to_text()` to each node and
        concatenates the results into one string.  (This is not quite actually
        the case, since we take some care as to where we add whitespace
        according to the class options.)
        r   Nr   
r   textcol)	_is_bare_macro_noderw   r   LatexCharsNoder   macro_post_spacerfindrl   node_to_text)r   rv   s	prev_noderR   last_nl_posr  s          r
   rc   z LatexNodes2Text.nodelist_to_text  s     	 	 	D''	22 4{9::4 /0IJ 4 33A''$--Kb  a&&,Q.a&&""4"999AIIr   r   c                     |dS |                     t          j                  r|                     ||          S |                     t          j                  r|                     |          S |                     t          j                  r|                     |          S |                     t          j                  r| 	                    |          S |                     t          j
                  r|                     |          S |                     t          j                  r|                     |          S |                     t          j                  r|                     |          S t                               d|           dS )a  
        Return the textual representation of the given `node`.

        If `prev_node_hint` is specified, then the current node is formatted
        suitably as following the node given in `prev_node_hint`.  This might
        affect how much space we keep/discard, etc.
        Nr   r  z0LatexNodes2Text.node_to_text(): Unknown node: %r)rw   r   r  chars_node_to_textLatexCommentNodecomment_node_to_textLatexGroupNodegroup_node_to_textry   macro_node_to_textLatexEnvironmentNodeenvironment_node_to_textrx   specials_node_to_textLatexMathNoder6   r   r   )r   rR   prev_node_hintr  s       r
   r   zLatexNodes2Text.node_to_text*  s_    <2
 ??;566 	B**4*AAA??;788 	3,,T222??;566 	1**4000??;566 	1**4000??;;<< 	700666??;899 	4--d333??;455 	0))$///I4PPP rr   c                     |j         }| j        r|                     ||          }| j        d         s't	          |                                          dk    rdS |S )z
        Return the textual representation of the given `node` representing a block
        of simple latex text with no special characters or macros.  The `node`
        is :py:class:`~pylatexenc.latexwalker.LatexCharsNode`.
        r  r   r   r   )charsr   do_fill_textr   rl   rd   )r   rR   r  contents       r
   r%  z"LatexNodes2Text.chars_node_to_textR  sd     *> 	B'''AAG'(BC 	7==??##q((2r   c                     | j         r;| j        d         rd}|j        dk    rd}d|j        z   |z   S d|j        z   |j        z   S | j        d         rdS |j        S )z
        Return the textual representation of the given `node` representing a latex
        comment.  The `node` is
        :py:class:`~pylatexenc.latexwalker.LatexCommentNode`.
        r   r  r   %)r   r   comment_post_spacecomment)r   rR   nls      r
   r'  z$LatexNodes2Text.comment_node_to_texte  s      	/'8 D*b00 BT\)B.. T\)D,CCC'8 /r
 ..r   c                     |                      |          }| j        r6t          |          | j        k    r|j        d         |z   |j        d         z   S |S )z
        Return the textual representation of the given `node` representing a latex
        group.  The `node` is
        :py:class:`~pylatexenc.latexwalker.LatexGroupNode`.
        r   r   )_groupnodecontents_to_textr   rl   r   
delimiters)r   rR   contentss      r
   r)  z"LatexNodes2Text.group_node_to_text  sY     22488" 	Fs8}}8V'V'V?1%04?13EEEr   c                      |j         } j                            |          }|t          dd          } fd} ||||          }|S )z
        Return the textual representation of the given `node` representing a latex
        macro invocation.  The `node` is
        :py:class:`~pylatexenc.latexwalker.LatexMacroNode`.
        Nr   Tr   c                     |j         r                     | |j         d|z            S |j        rdS g }| j        r| j        j        r| j        j        }d                    fd|D                       S )Nzmacro '\%s'whatr   c                 :    g | ]}                     |          S r   r:  rm   rB   r   s     r
   r   zRLatexNodes2Text.macro_node_to_text.<locals>.get_macro_str_repl.<locals>.<listcomp>  '    JJJ1D;;A>>JJJr   r   apply_simplify_replr   nodeargdargnlistrL   )rR   r   macr   r   s       r
   get_macro_str_replz>LatexNodes2Text.macro_node_to_text.<locals>.get_macro_str_repl  s      Q//c6G5CY5O 0 Q Q Q{ rA} +!7 +M*77JJJJJJJKKKr   )r   r   get_macro_specr   )r   rR   r   rJ  rK  macrostrs   `     r
   r*  z"LatexNodes2Text.macro_node_to_text  sr     N	 //	::;D111C		L 		L 		L 		L 		L &%dIs;;r   c                     |j         }| j                            |          }|t          dd          }|j        r |                     ||j        d|z            S |j        rdS |                     |j                  S )z
        Return the textual representation of the given `node` representing a full
        latex environment.  The `node` is
        :py:class:`~pylatexenc.latexwalker.LatexEnvironmentNode`.
        Nr   Fr>  zenvironment '%s'r@  )	r'   r   get_environment_specr%   r   rG  r   rc   rv   )r   rR   r'   envdefs       r
   r,  z(LatexNodes2Text.environment_node_to_text  s     .#88II>(U;;;F 	W++D&2F1C_1U , W W W> 	2$$T]333r   c                 v     |j         } j                            |          }||S  fd} ||||          }|S )z
        Return the textual representation of the given `node` representing special a
        latex character (or characters).  The `node` is
        :py:class:`~pylatexenc.latexwalker.LatexSpecialsNode`.
        Nc                     |j         r                     | |j         d|z            S |j        rdS | j        r| j        j        r| j        j        }d                    fd|D                       S )Nzspecials '%s'r@  r   c                 :    g | ]}                     |          S r   rC  rD  s     r
   r   zXLatexNodes2Text.specials_node_to_text.<locals>.get_specials_str_repl.<locals>.<listcomp>  rE  r   rF  )rR   r,   specr   r   s       r
   get_specials_str_replzDLatexNodes2Text.specials_node_to_text.<locals>.get_specials_str_repl  s    ! W//d6H5Dn5U 0 W W W| r} +!7 +M*77JJJJJJJKKKr   )r,   r   get_specials_spec)r   rR   r,   sspecrU  r!  s   `     r
   r-  z%LatexNodes2Text.specials_node_to_text  sg     ,"44^DD=!!	L 	L 	L 	L 	L "!$>>r   c                    | j         dk    rg|                    t          j                  s|j        dk    r)|                     |                                d          S |                                S | j         dk    rdS | j         dk    rt          |           5  |                     |j	                  
                                }ddd           n# 1 swxY w Y   |                    t          j                  r|j        }nd|j        z  d	|j        z  f}|                    t          j                  s|j        dk    r)|d
         |                     |d          z   |d         z   S |d
         |z   |d         z   S | j         dk    rt          |           5  |                     |j	                  
                                }ddd           n# 1 swxY w Y   |                    t          j                  s|j        dk    r|                     |          S |S t          d                    | j                             )a  
        Return the textual representation of the given `node` representing a block
        of math mode latex.  The `node` is either a
        :py:class:`~pylatexenc.latexwalker.LatexMathNode` or a
        :py:class:`~pylatexenc.latexwalker.LatexEnvironmentNode`.

        This method is responsible for honoring the `math_mode=...` option
        provided to the constructor.
        r   displayr   rJ   r   r   Nz
\begin{%s}z\end{%s}r   r   r   zunknown math_mode={} !)r   rw   r   r+  displaytyperM   latex_verbatim_PushEquationContextrc   rv   rd   r.  r;  r'   RuntimeErrorr   )r   rR   r3  delimss       r
   r6   z!LatexNodes2Text.math_node_to_text  s    >Z''{?@@ -"i////0C0C0E0Eb/QQQ**,,,^x''2^000%d++ G G//>>DDFFG G G G G G G G G G G G G G G{899 ?')=>%t';<?{?@@ 7"i//ay4#;#;GB#;#O#OORXYZR[[[ay7*VAY66^v%%%d++ G G//>>DDFFG G G G G G G G G G G G G G G{?@@ "i////888 7>>t~NNOOOs$   -CCC-GGGc                    	 t          j        d|                                          }d|v rdnd}t          j        d|                                          }d|v rdnd}|                                } fd	t          j        d                              |          }d 	fdt          |          D             D             }|d	k    r|r|sd
ndz   d                    |          z   |r|sd
ndz   |z   S )Nz^\s*z

r   z\s*$c                     d\  }}|                                  } |j        dz
  k    r dt          j        | j                  z   |z   S |t          j        | j        d|z            |d          z   |z   S )N)r   r   r   r  X)initial_indent)rd   r   textwrapfill)ro   r  head_wstrail_wsr   s       r
   
fill_chunkz0LatexNodes2Text.do_fill_text.<locals>.fill_chunk  s     !'GX		A$.***hmAt~>>>IIM!T^CKPPPQXQYQYZ[ r   z\n{2,}c                 @    g | ]\  }}|                                 |S r   )rd   )rm   jthechunks      r
   r   z0LatexNodes2Text.do_fill_text.<locals>.<listcomp>   s>     
 
 
H ~~

 
 
r   c              3   J   K   | ]\  }}| ||d k    rnd           fV  dS )r   Nr   )rm   ri  ro   rg  r  s      r
   rp   z/LatexNodes2Text.do_fill_text.<locals>.<genexpr>"  sX       " "1 A!Q$$wwA>>@" " " " " "r   r   rH   )researchgrouprd   compilesplit	enumeraterL   )
r   r   r  re  head_parrf  	trail_par	rawchunkschunksrg  s
   ` `      @r
   r2  zLatexNodes2Text.do_fill_text  sQ    )GT**0022$//66b9Wd++1133%11FF	zz||
	 
	 
	 
	 
	 Jy))//55	
 
" " " " " )) 4 4" " "
 
 
 '!))))33bQKK 6Y6SSB8:CD 	Dr   c                     t          |          ri }t          |          d         }d|v r |d<   |                    t          j                  rd|v r
|j        |d<   |                    t          j                  rd|v r
|j        |d<   |                    t          j                  rd|v r
|j	        |d<    ||fi |}|r|S dS d|v rt          |          dk    rpg }|j        r|j        j        r|j        j        }t          j        d	|          }|                    t          j                  r|r                     |j                  f}	nt#          d
 t%           fd|D                       D                       }	|	                                         |j                             nP|rt)           fd|D                       }	n2t#          d t%           fd|D                       D                       }		 ||	z  S # t*          t,          f$ r2 t.                              d                    |                     |cY S w xY w|S )z
        Utility to get the replacement text associated with a `node` for which we
        have a `simplify_repl` object (given by e.g. a MacroTextSpec or
        similar).

        The argument `what` is used in error messages.
        r   r8   r'   r   r,   r   r5  r   z(^|[^%])(%%)*%sc              3   D   K   | ]\  }}t          d |z             |fV  dS r   Nstrrm   ri  vals      r
   rp   z6LatexNodes2Text.apply_simplify_repl.<locals>.<genexpr>Z  sE        +11cQqS#     r   c              3   B   K   | ]}                     |          V  d S r   rC  rm   nnr   s     r
   rp   z6LatexNodes2Text.apply_simplify_repl.<locals>.<genexpr>[  sB       ? ?DFD;;B??? ? ? ? ? ?r   )bodyc                 :    g | ]}                     |          S r   rC  r~  s     r
   r   z7LatexNodes2Text.apply_simplify_repl.<locals>.<listcomp>a  s7     / / /!  ::2>> / / /r   c              3   D   K   | ]\  }}t          d |z             |fV  dS rx  ry  r{  s      r
   rp   z6LatexNodes2Text.apply_simplify_repl.<locals>.<genexpr>d  sE        '-q#S1XXcN     r   c              3   B   K   | ]}                     |          V  d S r   rC  r~  s     r
   rp   z6LatexNodes2Text.apply_simplify_repl.<locals>.<genexpr>e  sB       ; ;@B77;;; ; ; ; ; ;r   z<WARNING: Error in configuration: {} failed its substitution!)callablegetfullargspecrw   r   r+  r'   ry   r   rx   r,   rl   rH  rI  rl  rm  rc   rv   r   rq  r   tupler   r   r   r   r   )
r   rR   r   rA  kwargsfn_argsrr  has_percent_sro   s
   `         r
   rG  z#LatexNodes2Text.apply_simplify_repl-  s    M"" 	F$]33A6G7""#'x {?@@ A G++,0,@(){9:: 5g%%&*n{#{<== ?7**+/+>'(d--f--A 2-C$6$6!$;$; H} 2!7 2=1I&7GGM{?@@   H..t}==@AA  5> ? ? ? ?JR? ? ? 6 6    A
 HH$"7"7"F"FHGGGG  / / / /%-/ / / 0 0   1: ; ; ; ;FN; ; ; 2 2    %$q((z* % % %RVD\\   %$$$% s   H
 
A IIrI   c                 h    d|z   |                     dd|z             z   dz   }| j        rd|z   dz   }|S )Nr  )replacer   )r   r<  rK   r@   s       r
   rM   z#LatexNodes2Text._fmt_indented_blockt  sE    fx//d6kBBBTI> 	$JtOEr   c                     |d uo?|                     t          j                  o |j        d u ot	          |j                  dk    S Nr   )rw   r   ry   
nodeoptargrl   r  r`   s     r
   r  z#LatexNodes2Text._is_bare_macro_node|  sN    D  ( :;;(4'( DM""a'	)r   c                     |dS |                     t          j                  s|                     |          S |                     |j                  S )Nr   )rw   r   r(  r   rc   rv   )r   	groupnodes     r
   r:  z*LatexNodes2Text._groupnodecontents_to_text  sQ    2##K$>?? 	0$$Y///$$Y%7888r   c                 v    |j         r1|j         j        r%|                     |j         j        |                   S dS )z
        Return the textual representation of the `k`\ -th argument of the given
        `node`.  This might be useful for substitution lambdas in macro and
        environment specs.
        r   )rH  rI  r:  )r   rR   r   s      r
   node_arg_to_textz LatexNodes2Text.node_arg_to_text  s?     = 	NT]3 	N224=3I!3LMMMrr   c                     |D ]B\  }}t          |d          r|                    ||          },|                    ||          }C|S )a  
        Convenience function for code that used `text_replacements=` in `pylatexenc
        1.x`.

        If you used custom `text_replacements=` in `pylatexenc 1.x` then you
        will have to change::

          # pylatexenc 1.x with text_replacements
          text_replacements = ...
          l2t = LatexNodes2Text(..., text_replacements=text_replacements)
          text = l2t.nodelist_to_text(...)

        to::

          # pylatexenc 2 text_replacements compatibility code
          text_replacements = ...
          l2t = LatexNodes2Text(...)
          temp = l2t.nodelist_to_text(...)
          text = l2t.apply_text_replacements(temp, text_replacements)

        as a quick fix.  It is recommended however to treat text replacements
        instead as "latex specials".  (Otherwise the brutal text replacements
        might act on text generated from macros and environments and give
        unwanted results.)  See :py:class:`pylatexenc.macrospec.SpecialsSpec`
        and :py:class:`SpecialsTextSpec`.

        .. deprecated:: 2.0

           The `apply_text_replacements()` method was introduced in `pylatexenc
           2.0` as a deprecated method.  You can use it as a quick fix to make
           existing code run as it did in `pylatexenc 1.x`.  Its use is however
           not recommended for new code.  You should use "latex specials"
           instead for characters that have special LaTeX meaning.
        sub)rP   r  r  )r   r!  r   patternreplacements        r
   apply_text_replacementsz'LatexNodes2Text.apply_text_replacements  sZ    J %6 	4 	4 G[w&& 4KKQ//IIg{33r   r   r   r  )r   )rI   )r   r   r    r!   r   r   r  r;   r  rc   r   r%  r'  r)  r*  r,  r-  r6   r2  rG  rM   r  r:  r  r  r"   r#   s   @r
   r   r     s       _ _@H/ H/ H/ H/ H/ H/V SW-1) ) ) )88 8 8v
 
 
(
 
 
$& & &P& & & &P   &/ / /:	 	 	  64 4 4*  4-P -P -P`$D $D $D $DLE E EN   ) ) )9 9 9  + + + + + + +r   r   c                        e Zd Z fdZ xZS )r\  c                     d }|j         d         t          |j         d                   }t          t          |                               |d|           d S )Nr   r   )r   r   r   r\  r   )r   l2tnew_strict_latex_spacesr   s      r
   r   z_PushEquationContext.__init__  sn    "&">2>&E'7' '# 	"D))2238M3J	L 	L 	L 	L 	Lr   )r   r   r    r   r"   r#   s   @r
   r\  r\    sA        	L 	L 	L 	L 	L 	L 	L 	L 	Lr   r\  c                     t          j        dd           t          j        | ||          \  }}}t	          |||          S )z
    Heuristic conversion of LaTeX content `content` to unicode text.

    .. deprecated:: 1.0
       Please use :py:class:`LatexNodes2Text` instead.
    1.0zThe module-level function `pylatexenc.latex2text.latex2text()` is deprecated in favor of the `pylatexenc.latex2text.LatexNodes2Text` class.)r   tolerant_parsingr   r   )r   pylatexenc_deprecated_verr   r  latexnodes2text)r3  r  r   r   rv   tpostlens          r
   
latex2textr    sl     
#	I   )8))+ + +XtT
 8,<)68 8 8 8r   c                 t    t          j        dd           t          ||                              |           S )z
    Extracts text from a node list. `nodelist` is a list of nodes as returned by
    :py:func:`pylatexenc.latexwalker.get_latex_nodes()`.

    .. deprecated:: 1.0
       Please use :py:class:`LatexNodes2Text` instead.
    r  zThe module-level function `pylatexenc.latex2text.latexnodes2text()` is deprecated in favor of the `pylatexenc.latex2text.LatexNodes2Text` class.r  )r   r  r   rc   )rv   r   r   s      r
   r  r    sQ     
#	T   )#   x  !r   r(   r   r   )FFF)FF)=r!   
__future__r   r   r   rl  loggingsysinspectrc  version_infomajorr   rz  r   r  
getargspecunichrr   
pylatexencr   r   r   r   	getLoggerr   r   objectr   r%   r*   r0   r4   r9   r=   rF   rA   rU   r}   r   r   r   r   r   r   r   r   
maxunicoder   r   LazyDictdefault_macro_dictdefault_env_dictdefault_text_replacementsr   r   r   _PushPropOverrider\  r  r  r   r   r
   <module>r     s;  4 & 8 7 7 7 7 7 7 7 				 				  



  Q&&&J+NN'N
C                      		8	$	$.+ .+ .+ .+ .+F .+ .+ .+b3 3 3 3 3& 3 3 3l(+ (+ (+ (+ (+v (+ (+ (+X      2	- 	- 	-7 7 7 ; ; ; ;$   2 2 2.;) ;) ;)D  % %!&&#%*#  & 	C##f++ 	C##f++C##f++C##f++C##f++C##f++C##f++C##f++C##f++C##f++C##f++C##f++ 	C##f++C##f++C##f++C##f++C##f++ 	C##f++C##f++C##f++C##f++C##f++C##f++C##f++1! ! F SXXss3xxS33s88; S#s    >H--K K K,! ! !L $U^    & "5>    (    $)$)	  $($()	  $($()	   ,(7 (7 (7Ve e e e ef e e eV
L 
L 
L 
L 
L;8 
L 
L 
L. BG"8 8 8 82! ! ! ! ! !r   