ó
    ‰*£h£ ã                   ó°  • S r SSKJrJr  SSKrSSKrSSKrSSKrSSKrSSK	J
r
  SSK	Jr  \R                  R                  S:”  a  S r\rS rS	 rO\rS
 rS r\R(                  " \5      rS r " S S\5      r " S S\5      r " S S\5      rS rS r\R<                  " S S9r  " S S\ 5      r! " S S\ 5      r" " S S\"5      r# " S S\"5      r$ " S S \"5      r% " S! S"\"5      r& " S# S$\"5      r' " S% S&\"5      r( " S' S(\"5      r) " S) S*\ 5      r* " S+ S,\ 5      r+ " S- S.\ 5      r,S9S/ jr-S0 r.S1 r/S:S2 jr0S;S3 jr1  S<S4 jr2S5 r3S6 r4S=S7 jr5S>S8 jr6g)?aË  
The ``latexwalker`` module provides a simple API for parsing LaTeX snippets,
and representing the contents using a data structure based on node classes.

LatexWalker will understand the syntax of most common macros.  However,
``latexwalker`` is NOT a replacement for a full LaTeX engine.  (Originally,
``latexwalker`` was designed to extract useful text for indexing for text
database searches of LaTeX content.)

Simple example usage::

    >>> from pylatexenc.latexwalker import LatexWalker, LatexEnvironmentNode
    >>> w = LatexWalker(r"""
    ... \textbf{Hi there!} Here is \emph{a list}:
    ... \begin{enumerate}[label=(i)]
    ... \item One
    ... \item Two
    ... \end{enumerate}
    ... and $x$ is a variable.
    ... """)
    >>> (nodelist, pos, len_) = w.get_latex_nodes(pos=0)
    >>> nodelist[0]
    LatexCharsNode(pos=0, len=1, chars='\n')
    >>> nodelist[1]
    LatexMacroNode(pos=1, len=18, macroname='textbf',
    nodeargd=ParsedMacroArgs(argnlist=[LatexGroupNode(pos=8, len=11,
    nodelist=[LatexCharsNode(pos=9, len=9, chars='Hi there!')],
    delimiters=('{', '}'))], argspec='{'), macro_post_space='')
    >>> nodelist[5].isNodeType(LatexEnvironmentNode)
    True
    >>> nodelist[5].environmentname
    'enumerate'
    >>> nodelist[5].nodeargd.argspec
    '['
    >>> nodelist[5].nodeargd.argnlist
    [LatexGroupNode(pos=60, len=11, nodelist=[LatexCharsNode(pos=61, len=9,
    chars='label=(i)')], delimiters=('[', ']'))]
    >>> nodelist[7].latex_verbatim()
    '$x$'

You can also use `latexwalker` directly in command-line, producing JSON or a
human-readable node tree::

    $ echo '\textit{italic} text' | latexwalker --output-format=json
    {
      "nodelist": [
        {
          "nodetype": "LatexMacroNode",
          "pos": 0,
          "len": 15,
          "macroname": "textit",
    [...]

    $ latexwalker --help
    [...]

The parser can be influenced by specifying a collection of known macros and
environments (the "latex context") that are specified using
:py:class:`pylatexenc.macrospec.MacroSpec` and
:py:class:`pylatexenc.macrospec.EnvironmentSpec` objects in a
:py:class:`pylatexenc.macrospec.LatexContextDb` object.  See the doc of the
module :py:mod:`pylatexenc.macrospec` for more information.
é    )Úprint_functionÚunicode_literalsNé   )Ú	macrospec)Ú_utilc                 ó   • U $ ©N© )Ústrings    Ú\/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pylatexenc/latexwalker/__init__.pyÚunicoder   g   s   €  ˜ó    c                 ó   • U $ r	   r
   ©Úxs    r   Ú<lambda>r   i   ó   € ¡!r   c                 ó   • U $ r	   r
   r   s    r   r   r   j   r   r   c                 ó6   • [        U 5      R                  S5      $ ©Nzutf-8)r   Úencoder   s    r   r   r   n   s   € ¤'¨!£*×"3Ñ"3°GÔ"<r   c                 ó$   • U R                  S5      $ r   )Údecoder   s    r   r   r   o   s   €  !§(¡(¨7Ô"3r   c                  ó   • [        U 5      $ r	   )Útuple)Úargss    r   Ú
_maketupler   t   s   € ô �‹;Ðr   c                   ó   • \ rS rSrSrSrg)ÚLatexWalkerErroréz   z0
Generic exception class raised by this module.
r
   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__static_attributes__r
   r   r   r   r   z   s   † ñò 	r   r   c                   óB   ^ • \ rS rSrSrSU 4S jjrS rS rS rSr	U =r
$ )	ÚLatexWalkerParseErroré€   a  
Represents an error while parsing LaTeX code.

The following attributes are available if they were provided to the class
constructor:

.. py:attribute:: msg

   The error message

.. py:attribute:: s

   The string that was currently being parsed

.. py:attribute:: pos

   The index in the string where the error occurred, starting at zero.

.. py:attribute:: lineno

   The line number where the error occurred, starting at 1.

.. py:attribute:: colno

   The column number where the error occurred in the line `lineno`, starting
   at 1.
c                 ó    >• S U l         Xl        X l        X0l        X@l        XPl        / U l        [        [        U ]'  U R                  5       5        g r	   )Úinput_sourceÚmsgÚsÚposÚlinenoÚcolnoÚopen_contextsÚsuperr(   Ú__init__Ú_dispstr)Úselfr,   r-   r.   r/   r0   Ú	__class__s         €r   r3   ÚLatexWalkerParseError.__init__œ   sB   ø€ Ø ˆÔØŒØŒØŒØŒØŒ
ØˆÔäÔ# TÑ3°D·M±M³OÕDr   c           
      ó   • U R                   nU R                  (       a  USR                  U R                  5      -  nUSU R                  U R                  U R
                  U R                  5      -  -   nU R                  (       aJ  US-  n[        U R                  5       H,  nUu  pEpgUSR                  SU R                  XVU5      US9-  nM.     U$ )Nz  in {}z %sz
Open LaTeX blocks:
z{empty:8}{loc:>10}  {what}
Ú )ÚemptyÚlocÚwhat)	r,   r+   ÚformatÚ_fmt_posr.   r/   r0   r1   Úreversed)r5   r,   ÚdispÚcontextr<   r.   r/   r0   s           r   r4   ÚLatexWalkerParseError._dispstr§   sÄ   € Ø�h‰hˆØ××Ø�9×#Ñ# D×$5Ñ$5Ó6Ñ6ˆCØ�U˜DŸM™M¨$¯(©(°D·K±KÀÇÁÓLÑMÑMˆØ××ØÐ,Ñ,ˆDÜ# D×$6Ñ$6Ö7�Ø+2Ñ(�˜6ØÐ6×=Ñ=ÀBØ<@¿M¹MÈ#ÐUZÓ<[Ø=Að >ð Cñ C’ñ 8ð
 ˆr   c                 ó.   • Ub  Ub  SX#4-  $ SU-  $ SU-  $ )Nz@(%d,%d)z@%dz	@ char %dr
   )r5   r.   r/   r0   s       r   r>   ÚLatexWalkerParseError._fmt_posµ   s0   € ØÑØÑ Ø! 6 /Ñ1Ð1Ø˜&‘>Ð!Ø˜CÑ Ð r   c                 ó"   • U R                  5       $ r	   )r4   ©r5   s    r   Ú__str__ÚLatexWalkerParseError.__str__¼   ó   € Ø�}‰}‹Ðr   )r0   r+   r/   r,   r1   r.   r-   ©NNNN)r!   r"   r#   r$   r%   r3   r4   r>   rG   r&   Ú__classcell__©r6   s   @r   r(   r(   €   s"   ø† ñ÷6	Eòò!÷ð r   r(   c                   ó0   ^ • \ rS rSrSrSU 4S jjrSrU =r$ )ÚLatexWalkerEndOfStreaméÂ   z2
Reached end of input stream (e.g., end of file).
c                 ó6   >• [         [        U ]  5         Xl        g r	   )r2   rN   r3   Úfinal_space)r5   rQ   r6   s     €r   r3   ÚLatexWalkerEndOfStream.__init__Æ   s   ø€ ÜÔ$ dÑ4Ô6Ø&Õr   ©rQ   ©r9   )r!   r"   r#   r$   r%   r3   r&   rK   rL   s   @r   rN   rN   Â   s   ø† ñ÷'õ 'r   rN   c                  óˆ   • [         R                  " 5       n SSKJn  U H   u  p#U R	                  UUS   US   US   S9  M"     U $ )aJ  
Return a :py:class:`pylatexenc.macrospec.LatexContextDb` instance
initialized with a collection of known macros and environments.

TODO: 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)rX   rY   rZ   )r   ÚLatexContextDbÚ_defaultspecsrW   Úadd_context_category)ÚdbrW   ÚcatÚcatspecss       r   Úget_default_latex_context_dbra   Ï   sU   € ô, 
×	!Ò	!Ó	#€Bå$ã‰ˆØ
×Ñ Ø'/°Ñ'9Ø-5°nÑ-EØ)1°*Ñ)=ð 	 ó 	?ñ ð €Ir   c                 ó¼   • [         R                  " S5        [        R                  " XU5      nUR                  Ul        Xl        X#l        SUR                  l	        U$ )aV  
.. deprecated:: 2.0

   Use :py:func:`pylatexenc.macrospec.std_macro` instead which does the same
   thing, or invoke the :py:class:`~pylatexenc.macrospec.MacroSpec` class
   directly (or a subclass).

   In `pylatexenc 1.x`, `MacrosDef` was a class.  Since `pylatexenc 2.0`,
   `MacrosDef` is a function which returns a
   :py:class:`~pylatexenc.macrospec.MacroSpec` instance.  In this way the
   earlier idiom ``MacrosDef(...)`` still works in `pylatexenc 2`.  The
   field names of the constructed object might have changed since
   `pylatexenc 1.x`, so you might have to adapt existing code if you were
   accessing individual fields of `MacrosDef` objects.

   In the object returned by `MacrosDef()`, we provide the legacy attributes
   `macname`, `optarg`, and `numargs`, so that existing code accessing those
   properties can continue to work.
z�`pylatexenc.latexwalker.MacrosDef` is now obsolete. It should still work in most use cases, but new code should use `pylatexenc.macrospec.MacroSpec` instead.T)
r   Úpylatexenc_deprecated_2r   Ú	std_macroÚ	macronameÚmacnameÚoptargÚnumargsÚargs_parserÚ&_like_pylatexenc1x_ignore_leading_star)rf   rg   rh   Úms       r   Ú	MacrosDefrl   ÷   sT   € ô( 
×!Ò!ð	4ôô 	×Ò˜G¨WÓ5€Aà—‘€A„IØ„HØ„Ið <@€A‡M�MÔ8Ø€Hr   c                  óˆ   • [        [        5       R                  5        V s/ s H  n U R                  U 4PM     sn 5      $ s  sn f r	   )Údictra   Úiter_macro_specsre   )rk   s    r   r   r     s>   € œTä-Ó/×@Ñ@ÔBó#âBˆAð 
�‰�aÓÙBñ#ô ùò #s    ?)Úgenerate_dict_fnc                   óR   ^ • \ rS rSrSrSU 4S jjrS rS rS rS r	S r
S	rS
rU =r$ )Ú
LatexTokeni:  a=  
Represents a token read from the LaTeX input.

This is used internally by :py:class:`LatexWalker`'s methods.  You probably
don't need to worry about individual tokens.  Rather, you should use the
high-level functions provided by :py:class:`LatexWalker` (e.g.,
:py:meth:`~LatexWalker.get_latex_nodes()`).  So most likely, you can ignore
this class entirely.

Instances of this class are what the method
:py:meth:`LatexWalker.get_token()` returns.  See the doc of that function
for more information on how tokens are parsed.

This is not the same thing as a LaTeX token, it's just a part of the input
which we treat in the same way (e.g. a bunch of content characters, a
comment, a macro, etc.)

Information about the object is stored into the fields `tok` and `arg`. The
`tok` field is a string which identifies the type of the token. The `arg`
depends on what `tok` is, and describes the actual input.

Additionally, this class stores information about the position of the token
in the input stream in the field `pos`.  This `pos` is an integer which
corresponds to the index in the input string.  The field `len` stores the
length of the token in the input string.  This means that this token spans
in the input string from `pos` to `pos+len`.

Leading whitespace before the token is not returned as a separate
'char'-type token, but it is given in the `pre_space` field of the token
which follows.  Pre-space may contain a newline, but not two consecutive
newlines.

The `post_space` is only used for 'macro' and 'comment' tokens, and it
stores any spaces encountered after a macro, or the newline with any
following spaces that terminates a LaTeX comment.  When we encounter two
consecutive newlines these are not included in `post_space`.

The `tok` field may be one of:

  - 'char': raw character(s) which have no special LaTeX meaning and which
    are part of the text content.
    
    The `arg` field contains the characters themselves.

  - 'macro': a macro invocation, but not ``\begin`` or ``\end``
    
    The `arg` field contains the name of the macro, without the leading
    backslash.

  - 'begin_environment': an invocation of ``\begin{environment}``.
    
    The `arg` field contains the name of the environment inside the braces.

  - 'end_environment': an invocation of ``\end{environment}``.
    
    The `arg` field contains the name of the environment inside the braces.

  - 'comment': a LaTeX comment delimited by a percent sign up to the end of
    the line.
    
    The `arg` field contains the text in the comment line, not including the
    percent sign nor the newline.

  - 'brace_open': an opening brace.  This is usually a curly brace, and
    sometimes also a square bracket.  What is parsed as a brace depends on
    the arguments to :py:meth:`~LatexWalker.get_token()`.
    
    The `arg` is a string which contains the relevant brace character.
    
  - 'brace_close': a closing brace.  This is usually a curly brace, and
    sometimes also a square bracket.  What is parsed as a brace depends on
    the arguments to :py:meth:`~LatexWalker.get_token()`.
    
    The `arg` is a string which contains the relevant brace character.

  - 'mathmode_inline': a delimiter which starts/ends inline math.  This is
    (e.g.) a single '$' character which is not part of a double '$$'
    display environment delimiter.

    The `arg` is the string value of the delimiter in question ('$')

  - 'mathmode_display': a delimiter which starts/ends display math, e.g.,
    ``\[``.

    The `arg` is the string value of the delimiter in question (e.g.,
    ``\[`` or ``$$``)

  - 'specials': a character or character sequence that has a special
    meaning in LaTeX.  E.g., '~', '&', etc.

    The `arg` field is then the corresponding
    :py:class:`~pylatexenc.macrospec.SpecialsSpec` instance.  [The rationale
    for setting `arg` to a `SpecialsSpec` instance, in contrast to the
    behavior for macros and envrionments, is that macros and environments
    are delimited directly by LaTeX syntax and are determined unambiguously
    without any lookup in the latex context database.  This is not the case
    for specials.]
c                 óÚ   >• Xl         X l        X0l        X@l        XPl        X`l        / SQU l        U R                   S;   a  U R                  R                  S5        [        [        U ]+  5         g )N©ÚtokÚargr.   ÚlenÚ	pre_space)ÚmacroÚcommentÚ
post_space)ru   rv   r.   rw   rx   r{   Ú_fieldsÚappendr2   rr   r3   )r5   ru   rv   r.   rw   rx   r{   r6   s          €r   r3   ÚLatexToken.__init__�  sT   ø€ ØŒØŒØŒØŒØ"ŒØ$ŒÚ@ˆŒØ�8‰8Ð+Ó+Ø�L‰L×Ñ Ô-ÜŒj˜$Ñ(Õ*r   c                 ó4   • [        U R                  5       5      $ r	   ©Ú_unicode_from_strrG   rF   s    r   Ú__unicode__ÚLatexToken.__unicode__ª  ó   € Ü  §¡£Ó0Ð0r   c                 ó�   • SSR                  U R                   Vs/ s H  nU< S[        X5      < 3PM     sn5      -   S-   $ s  snf )NzLatexToken(ú, Ú=Ú))Újoinr|   Úgetattr©r5   Úks     r   Ú__repr__ÚLatexToken.__repr__­  sR   € àØ�I‰IØ!%§¢ó0Ú!-˜Aó "#¤7¨4¥?Ó3Ù!-ñ0ó 1ñ1ð ñð	ùò0s   ›A
c                 ó"   • U R                  5       $ r	   ©r�   rF   s    r   rG   ÚLatexToken.__str__µ  rI   r   c                 óF   ^ ^• [        UU 4S jT R                   5       5      $ )Nc              3   óV   >#   • U  H  n[        TU5      [        TU5      :H  v •  M      g 7fr	   ©rŠ   ©Ú.0ÚfÚotherr5   s     €€r   Ú	<genexpr>Ú$LatexToken.__eq__.<locals>.<genexpr>¹  s$   øé € ÐTÂlÀ”g˜d AÓ&¬'°%¸Ó*;Ö;Âlùó   ƒ&))Úallr|   ©r5   r˜   s   ``r   Ú__eq__ÚLatexToken.__eq__¸  s   ù€ ÜÕTÀdÇlÂlÓTÓVÐVr   c                 ó   • [         $ r	   ©ÚNotImplementedr�   s     r   Ú__ne__ÚLatexToken.__ne__¼  ó   € ¤NÐ2r   N)r|   rv   rw   r.   r{   rx   ru   rT   )r!   r"   r#   r$   r%   r3   r‚   r�   rG   rž   r£   Ú__hash__r&   rK   rL   s   @r   rr   rr   :  s.   ø† ña÷D
+ò1òòòWò 3à†Hr   rr   c                   óh   ^ • \ rS rSrSr  SU 4S jjrS rS rS rS r	S	 r
SrS
 rS rS rSrU =r$ )Ú	LatexNodeiÉ  a÷  
Represents an abstract 'node' of the latex document.

Use :py:meth:`nodeType()` to figure out what type of node this is, and
:py:meth:`isNodeType()` to test whether it is of a given type.

You should use :py:meth:`LatexWalker.make_node()` to create nodes, so that
the latex walker has the opportunity to do some additional setting up.

All nodes have the following attributes:

.. py:attribute:: parsing_state

   The parsing state at the time this node was created.  This object stores
   additional context information for this node, such as whether or not this
   node was parsed in a math mode block of LaTeX code.

   See also the :py:meth:`LatexWalker.make_parsing_state()` and the
   `parsing_state` argument of :py:meth:`LatexWalker.get_latex_nodes()`.

.. py:attribute:: pos

   The position in the parsed string that this node represents.  The parsed
   string can be recovered as `parsing_state.s`, see
   :py:attr:`ParsingState.s`.

.. py:attribute:: len

   How many characters in the parsed string this node represents, starting
   at position `pos`.  The parsed string can be recovered as
   `parsing_state.s`, see :py:attr:`ParsingState.s`.

.. versionadded:: 2.0
   
   The attributes `parsing_state`, `pos` and `len` were added in
   `pylatexenc 2.0`.
Nc                 ó  >• [         [        U ]
  " S0 UD6  X0l        X@l        XPl        [        SS/[        U5      -   5      U l        Ub0  [        [        U R                  5      [        U5      -   5      U l	        g U R                  U l	        g )Nr.   rw   r
   )
r2   r¨   r3   Úparsing_stater.   rw   r   Úlistr|   Ú_redundant_fields)r5   r|   r¬   rª   r.   rw   Úkwargsr6   s          €r   r3   ÚLatexNode.__init__ï  ss   ø€ ô 	Œi˜Ò'Ñ1¨&Ò1à*ÔØŒØŒä˜e U˜^¬d°7«mÑ;Ó<ˆŒØÑ(Ü%*¬4°·±Ó+=ÄÐEVÓ@WÑ+WÓ%XˆDÕ"à%)§\¡\ˆDÕ"r   c                 ó   • [         $ )zÛ
Returns the class which corresponds to the type of this node.  This is a
Python class object, that is one of
:py:class:`~pylatexenc.latexwalker.LatexCharsNode`,
:py:class:`~pylatexenc.latexwalker.LatexGroupNode`, etc.
)r¨   rF   s    r   ÚnodeTypeÚLatexNode.nodeType  s
   € ô Ðr   c                 ó   • [        X5      $ )z¥
Returns `True` if the current node is of the given type.  The argument `t`
must be a Python class such as,
e.g. :py:class:`~pylatexenc.latexwalker.LatexGroupNode`.
)Ú
isinstance)r5   Úts     r   Ú
isNodeTypeÚLatexNode.isNodeType  s   € ô ˜$Ó"Ð"r   c                 ó¦   • U R                   c  [        S5      eU R                   R                  U R                  U R                  U R                  -    $ )zŠ
Return the chunk of LaTeX code that this node represents.

This is a shorthand for ``node.parsing_state.s[node.pos:node.pos+node.len]``.
zNCan't use latex_verbatim() on node because we don't have any parsing_state set)rª   Ú	TypeErrorr-   r.   rw   rF   s    r   Úlatex_verbatimÚLatexNode.latex_verbatim  sL   € ð ×ÑÑ%Üð 9ó :ð :à×!Ñ!×#Ñ# D§H¡H¨t¯x©x¸¿¹Ñ/@ÐAÐAr   c                 ój  ^ ^• TS L=(       a§    T R                  5       TR                  5       :H  =(       a    TR                  T R                  L =(       a`    TR                  T R                  :H  =(       a@    TR                  T R                  :H  =(       a     [	        UU 4S jT R
                   5       5      $ )Nc              3   óV   >#   • U  H  n[        TU5      [        TU5      :H  v •  M      g 7fr	   r”   r•   s     €€r   r™   Ú#LatexNode.__eq__.<locals>.<genexpr>%  s$   øé € ÐPÂ,¸Q”'˜$ Ó"¤g¨e°QÓ&7Ö7Â,ùr›   )r°   rª   r.   rw   rœ   r|   r�   s   ``r   rž   ÚLatexNode.__eq__  sŒ   ù€ Ø˜DÐ ÷ Ø�M‰M‹O˜uŸ~™~Ó/Ñ/÷à×Ñ 4×#5Ñ#5Ð5÷ð �I‰I˜Ÿ™Ñ!÷ð �I‰I˜Ÿ™Ñ!÷	ô
 ÝPÀ$Ç,Â,ÓPóð	r   c                 ó   • [         $ r	   r¡   r�   s     r   r£   ÚLatexNode.__ne__)  r¥   r   c                 ó4   • [        U R                  5       5      $ r	   r€   rF   s    r   r‚   ÚLatexNode.__unicode__-  r„   r   c                 ó"   • U R                  5       $ r	   r�   rF   s    r   rG   ÚLatexNode.__str__/  rI   r   c                 ó  • U R                  5       R                  S-   SR                  [        U R                  5      5      -   SR                  U R                   Vs/ s H  o< S[        X5      < 3PM     sn5      -   S-   $ s  snf )NÚ(z"parsing_state=<parsing state {}>, r†   r‡   rˆ   )r°   r!   r=   Úidrª   r‰   r|   rŠ   r‹   s     r   r�   ÚLatexNode.__repr__1  sx   € à�M‰M‹O×$Ñ$ sÑ*Ø0×7Ñ7¼¸4×;MÑ;MÓ8NÓOñPà�I‰I¸d¿lºlÓLºl¸¢¤7¨4¥?Ó3¹lÑLÓMñNð ñð	ùò Ms   ÁB
)r|   r¬   rw   rª   r.   rJ   )r!   r"   r#   r$   r%   r3   r°   rµ   r¹   rž   r£   r¦   r‚   rG   r�   r&   rK   rL   s   @r   r¨   r¨   É  sI   ø† ñ$ðJ 37Ø37÷2ò&ò#ò	Bòò 3à€Hò1ò÷ð r   r¨   c                   ó2   ^ • \ rS rSrSrU 4S jrS rSrU =r$ )ÚLatexCharsNodei:  zŸ
A string of characters in the LaTeX document, without any special LaTeX
code.

.. py:attribute:: chars

   The string of characters represented by this node.
c                 ó>   >• [         [        U ]
  " SSS0UD6  Xl        g )Nr|   ©Úcharsr
   )r2   rÊ   r3   rÍ   )r5   rÍ   r­   r6   s      €r   r3   ÚLatexCharsNode.__init__C  s)   ø€ ÜŒn˜dÒ,ñ 	
Ø ð	
àò	
ð �
r   c                 ó   • [         $ r	   )rÊ   rF   s    r   r°   ÚLatexCharsNode.nodeTypeJ  ó   € ÜÐr   rÌ   ©	r!   r"   r#   r$   r%   r3   r°   r&   rK   rL   s   @r   rÊ   rÊ   :  s   ø† ñõ÷ð r   rÊ   c                   ó2   ^ • \ rS rSrSrU 4S jrS rSrU =r$ )ÚLatexGroupNodeiM  a   
A LaTeX group delimited by braces, ``{like this}``.

Note: in the case of an optional macro or environment argument, this node is
also used to represents a group delimited by square braces instead of curly
braces.

.. py:attribute:: nodelist

   A list of nodes describing the contents of the LaTeX braced group.  Each
   item of the list is a :py:class:`LatexNode`.

.. py:attribute:: delimiters

   A 2-item tuple that stores the delimiters for this group node.  Usually
   this is `('{', '}')`, except for optional macro arguments where this
   might be for instance `('[', ']')`.

   .. versionadded:: 2.0

      The `delimiters` field was added in `pylatexenc 2.0`.
c                 ón   >• UR                  SS5      n[        [        U ]  " SSS0UD6  Xl        X0l        g )NÚ
delimiters©Ú{Ú}r|   )ÚnodelistrÖ   r
   )Úpopr2   rÔ   r3   rÚ   rÖ   )r5   rÚ   r­   rÖ   r6   s       €r   r3   ÚLatexGroupNode.__init__d  s>   ø€ Ø—Z‘Z ¨jÓ9ˆ
ÜŒn˜dÒ,ñ 	
Ø.ð	
àò	
ð !ŒØ$�r   c                 ó   • [         $ r	   )rÔ   rF   s    r   r°   ÚLatexGroupNode.nodeTypem  rÑ   r   )rÖ   rÚ   rÒ   rL   s   @r   rÔ   rÔ   M  s   ø† ñõ,%÷ð r   rÔ   c                   ó2   ^ • \ rS rSrSrU 4S jrS rSrU =r$ )ÚLatexCommentNodeip  aK  
A LaTeX comment, delimited by a percent sign until the end of line.

.. py:attribute:: comment

   The comment string, not including the '%' sign nor the following newline

.. py:attribute:: comment_post_space

   The newline that terminated the comment possibly followed by spaces
   (e.g., indentation spaces of the next line)

c                 ón   >• UR                  SS5      n[        [        U ]  " SSS0UD6  Xl        X0l        g )NÚcomment_post_spacer9   r|   ©rz   râ   r
   )rÛ   r2   rà   r3   rz   râ   )r5   rz   r­   râ   r6   s       €r   r3   ÚLatexCommentNode.__init__~  sB   ø€ Ø#ŸZ™ZÐ(<¸bÓAÐäÔ Ò.ñ 	
Ø9ð	
àò	
ð
 ŒØ"4Õr   c                 ó   • [         $ r	   )rà   rF   s    r   r°   ÚLatexCommentNode.nodeType‰  s   € ÜÐr   rã   rÒ   rL   s   @r   rà   rà   p  s   ø† ñõ	5÷ ð  r   rà   c                   ó2   ^ • \ rS rSrSrU 4S jrS rSrU =r$ )ÚLatexMacroNodeiŒ  a  
Represents a macro type node, e.g. ``\textbf``

.. py:attribute:: macroname

   The name of the macro (string), *without* the leading backslash.

.. py:attribute:: nodeargd

   The :py:class:`pylatexenc.macrospec.ParsedMacroArgs` object that
   represents the macro arguments.

   For macros that do not accept any argument, this is an empty
   :py:class:`~pylatexenc.macrospec.ParsedMacroArgs` instance.  The
   attribute `nodeargd` can be `None` even for macros that accept arguments,
   in the situation where :py:meth:`LatexWalker.get_latex_expression()`
   encounters the macro when reading a single expression.

   Arguments must be declared in the latex context passed to the
   :py:class:`LatexWalker` constructor, using a suitable
   :py:class:`pylatexenc.macrospec.MacroSpec` object.  Some known macros are
   already declared in the default latex context.

   .. versionadded:: 2.0

      The `nodeargd` attribute was introduced in `pylatexenc 2`.

.. py:attribute:: macro_post_space

   Any spaces that were encountered immediately after the macro.

The following attributes are obsolete since `pylatexenc 2.0`.

.. py:attribute:: nodeoptarg

   .. deprecated:: 2.0

      Macro arguments are stored in `nodeargd` in `pylatexenc 2`.  Accessing
      the argument `nodeoptarg` will still give a first optional argument
      for standard latex macros, for backwards compatibility.

   If non-`None`, this corresponds to the optional argument of the macro.

.. py:attribute:: nodeargs

   .. deprecated:: 2.0

      Macro arguments are stored in `nodeargd` in pylatexenc 2.  Accessing
      the argument `nodeargs` will still provide a list of argument nodes
      for standard latex macros, for backwards compatibility.

   A list of arguments to the macro. Each item in the list is a
   :py:class:`LatexNode`.
c                 ó&  >• UR                  S[        R                  " 5       5      nUR                  SS5      nUR                  SS 5      nUR                  S/ 5      n[        [        U ]  " S	SSS.UD6  Xl        X0l        X@l        XPl	        X`l
        g )
NÚnodeargdÚmacro_post_spacer9   Ú
nodeoptargÚnodeargs)re   rê   rë   )rì   rí   ©r|   r¬   r
   )rÛ   r   ÚParsedMacroArgsr2   rè   r3   re   rê   rë   rì   rí   )r5   re   r­   rê   rë   rì   rí   r6   s          €r   r3   ÚLatexMacroNode.__init__Ã  sŽ   ø€ Ø—‘˜J¬	×(AÒ(AÓ(CÓDˆØŸ™Ð$6¸Ó;Ðà—:‘:˜l¨DÓ1ˆ
Ø—‘˜J¨Ó+ˆäŒn˜dÒ,ð 	ØAØ 9ñ	ð ò	ð
 #ŒØ ŒØ 0Ôà$ŒØ �r   c                 ó   • [         $ r	   )rè   rF   s    r   r°   ÚLatexMacroNode.nodeTypeÖ  rÑ   r   )rë   re   rê   rí   rì   rÒ   rL   s   @r   rè   rè   Œ  s   ø† ñ5õl!÷&ð r   rè   c                   ó2   ^ • \ rS rSrSrU 4S jrS rSrU =r$ )ÚLatexEnvironmentNodeiÛ  aó  
A LaTeX Environment Node, i.e. ``\begin{something} ... \end{something}``.

.. py:attribute:: environmentname

   The name of the environment ('itemize', 'equation', ...)

.. py:attribute:: nodelist

   A list of :py:class:`LatexNode`'s that represent all the contents between
   the ``\begin{...}`` instruction and the ``\end{...}`` instruction.

.. py:attribute:: nodeargd

   The :py:class:`pylatexenc.macrospec.ParsedMacroArgs` object that
   represents the arguments passed to the environment.  These are arguments
   that are present after the ``\begin{xxxxxx}`` command, as in
   ``\begin{tabular}{ccc}`` or ``\begin{figure}[H]``.  Arguments must be
   declared in the latex context passed to the :py:class:`LatexWalker`
   constructor, using a suitable
   :py:class:`pylatexenc.macrospec.EnvironmentSpec` object.  Some known
   environments are already declared in the default latex context.

   .. versionadded:: 2.0

      The `nodeargd` attribute was introduced in `pylatexenc 2`.

The following attributes are available, but they are obsolete since
`pylatexenc 2.0`.

.. py:attribute:: envname

   .. deprecated:: 2.0

      This attribute was renamed `environmentname` for consistency with the
      rest of the package.

.. py:attribute:: optargs

   .. deprecated:: 2.0

      Macro arguments are stored in `nodeargd` in `pylatexenc 2`.  Accessing
      the argument `optargs` will still give a list of initial optional
      arguments for standard latex macros, for backwards compatibility.

.. py:attribute:: args

   .. deprecated:: 2.0

      Macro arguments are stored in `nodeargd` in `pylatexenc 2`.  Accessing
      the argument `args` will still give a list of curly-brace-delimited
      arguments for standard latex macros, for backwards compatibility.
c                 ó  >• UR                  S[        R                  " 5       5      nUR                  S/ 5      nUR                  S/ 5      n[        [        U ]  " SSSS.UD6  Xl        X l        X@l        Xl	        XPl
        X`l        g )Nrê   Úoptargsr   )ÚenvironmentnamerÚ   rê   )Úenvnamerö   r   rî   r
   )rÛ   r   rï   r2   rô   r3   r÷   rÚ   rê   rø   rö   r   )r5   r÷   rÚ   r­   rê   rö   r   r6   s          €r   r3   ÚLatexEnvironmentNode.__init__  s‚   ø€ Ø—:‘:˜j¬)×*CÒ*CÓ*EÓFˆà—*‘*˜Y¨Ó+ˆØ�z‰z˜& "Ó%ˆäÔ" DÒ2ð 	Ø@Ø >ñ	ð ò	ð
  /ÔØ ŒØ Œà&ŒØŒØ�	r   c                 ó   • [         $ r	   )rô   rF   s    r   r°   ÚLatexEnvironmentNode.nodeType%  s   € Ü#Ð#r   )r   r÷   rø   rê   rÚ   rö   rÒ   rL   s   @r   rô   rô   Û  s   ø† ñ4õl÷&$ð $r   rô   c                   ó2   ^ • \ rS rSrSrU 4S jrS rSrU =r$ )ÚLatexSpecialsNodei(  a.  
Represents a specials type node, e.g. ``&`` or ``~``

.. py:attribute:: specials_chars

   The name of the specials (string), *without* the leading backslash.

.. py:attribute:: nodeargd

   If the specials spec (cf. :py:class:`~pylatexenc.macrospec.SpecialsSpec`)
   has `args_parser=None` then the attribute `nodeargd` is set to `None`.
   If `args_parser` is specified in the spec, then the attribute `nodeargd`
   is a :py:class:`pylatexenc.macrospec.ParsedMacroArgs` instance that 
   represents the arguments to the specials.

   The `nodeargd` attribute can also be `None` even if the specials expects
   arguments, in the special situation where
   :py:meth:`LatexWalker.get_latex_expression()` encounters this specials.

   Arguments must be declared in the latex context passed to the
   :py:class:`LatexWalker` constructor, using a suitable
   :py:class:`pylatexenc.macrospec.SpecialsSpec` object.  Some known latex
   specials are already declared in the default latex context.

.. versionadded:: 2.0

   Latex specials were introduced in `pylatexenc 2.0`.
c                 ón   >• UR                  SS 5      n[        [        U ]  " SSS0UD6  Xl        X0l        g )Nrê   r|   )Úspecials_charsrê   r
   )rÛ   r2   rý   r3   rÿ   rê   )r5   rÿ   r­   rê   r6   s       €r   r3   ÚLatexSpecialsNode.__init__E  s@   ø€ Ø—‘˜J¨Ó-ˆäÔ Ò/ñ 	Ø3ð	àò	ð -ÔØ �r   c                 ó   • [         $ r	   )rý   rF   s    r   r°   ÚLatexSpecialsNode.nodeTypeO  s   € Ü Ð r   )rê   rÿ   rÒ   rL   s   @r   rý   rý   (  s   ø† ñõ8!÷!ð !r   rý   c                   ó8   ^ • \ rS rSrSr/ 4U 4S jjrS rSrU =r$ )ÚLatexMathNodeiU  aØ  
A Math node type.

Note that currently only 'inline' math environments are detected.

.. py:attribute:: displaytype

   Either 'inline' or 'display', to indicate an inline math block or a
   display math block. (Note that math environments such as
   ``\begin{equation}...\end{equation}``, are reported as
   :py:class:`LatexEnvironmentNode`'s, and not as
   :py:class:`LatexMathNode`'s.)

.. py:attribute:: delimiters

   A 2-item tuple containing the begin and end delimiters used to delimit
   this math mode section.

   .. versionadded:: 2.0

      The `delimiters` attribute was introduced in `pylatexenc 2`.

.. py:attribute:: nodelist

   The contents of the environment, given as a list of
   :py:class:`LatexNode`'s.
c                 óz   >• UR                  SS5      n[        [        U ]  " SSS0UD6  Xl        X l        X@l        g )NrÖ   ©NNr|   )ÚdisplaytyperÚ   rÖ   r
   )rÛ   r2   r  r3   r  rÚ   rÖ   )r5   r  rÚ   r­   rÖ   r6   s        €r   r3   ÚLatexMathNode.__init__q  sD   ø€ Ø—Z‘Z ¨lÓ;ˆ
äŒm˜TÒ+ñ 	
Ø=ð	
àò	
ð
 'ÔØ ŒØ$�r   c                 ó   • [         $ r	   )r  rF   s    r   r°   ÚLatexMathNode.nodeType}  s   € ÜÐr   )rÖ   r  rÚ   rÒ   rL   s   @r   r  r  U  s   ø† ñð6 .0÷ 
%÷ð r   r  c                   ó4   ^ • \ rS rSrU 4S jrS rS rSrU =r$ )Ú_PushPropOverridei„  c                 óN   >• [         [        U ]  5         Xl        X l        X0l        g r	   )r2   r  r3   ÚobjÚpropnameÚ	new_value)r5   r  r  r  r6   s       €r   r3   Ú_PushPropOverride.__init__…  s    ø€ ÜÔ Ñ/Ô1ØŒØ ŒØ"�r   c                 óÀ   • U R                   bP  [        U R                  U R                  5      U l        [        U R                  U R                  U R                   5        U $ r	   )r  rŠ   r  r  ÚinitvalÚsetattrrF   s    r   Ú	__enter__Ú_PushPropOverride.__enter__‹  s?   € Ø�>‰>Ñ%Ü" 4§8¡8¨T¯]©]Ó;ˆDŒLÜ�D—H‘H˜dŸm™m¨T¯^©^Ô<Øˆr   c                 óv   • U R                   b,  [        U R                  U R                  U R                  5        g g r	   )r  r  r  r  r  )r5   ÚtypeÚvalueÚ	tracebacks       r   Ú__exit__Ú_PushPropOverride.__exit__‘  s)   € à�>‰>Ñ%Ü�D—H‘H˜dŸm™m¨T¯\©\Õ:ð &r   )r  r  r  r  )	r!   r"   r#   r$   r3   r  r  r&   rK   rL   s   @r   r  r  „  s   ø† õ#ò÷;ð ;r   r  c                   óH   ^ • \ rS rSrSrU 4S jrS rS rS	S jrS r	Sr
U =r$ )
ÚParsingStatei—  a£	  
Stores some information about the current parsing state, such as whether we
are currently in a math mode block.

One of the ideas of `pylatexenc` is to make the parsing of LaTeX code mostly
state-independent mark-up parsing (in contrast to a full TeX engine, whose
state constantly changes and whose parsing behavior is altered dynamically
while parsing).  However a minimal state of the context might come in handy
sometimes.  Perhaps some macros or specials should behave differently in
math mode than in text mode.

This class also stores some essential information that is associated with
:py:class:`LatexNode`\ 's and which provides a context to better understand
the node structure.  For instance, we store the original parsed string, and
each node refers to which part of the string they represent.

.. py:attribute:: s

   The string that is parsed by the :py:class:`LatexWalker`

.. py:attribute:: latex_context

   The latex context (with macros/environments specifications) that was used
   when parsing the string `s`.  This is a
   :py:class:`pylatexenc.macrospec.LatexContextDb` object.

.. py:attribute:: in_math_mode

   Whether or not we are in a math mode chunk of LaTeX (True or False).
   This can be inline or display, and can be caused by an equation
   environment.

.. py:attribute:: math_mode_delimiter

   Information about the kind of math mode we are currently in, if
   `in_math_mode` is `True`.  This is a string which can be set to aid the
   parser.  The parser sets this field to the math mode delimiter that
   initiated the math mode (one of ``'$'``, ``'$$'``, ``r'\('``, ``r'\)'``).
   For user-initiated math modes (e.g. by a custom environment definition),
   you can set this string to any custom value EXCEPT any of the core math
   mode delimiters listed above.

   .. note:: The tokenizer/parser relies on the value of the
             `math_mode_delimiter` attribute to disambiguate two consecutive
             dollar signs ``...$$...`` into either a display math mode
             delimiter or two inline math mode delimiters (as in
             ``$a$$b$``).  You should only set `math_mode_delimiter='$'` if
             you know what you're doing.

.. versionadded:: 2.0

   This class was introduced in version 2.0.

.. versionadded:: 2.7

   The attribute `math_mode_delimiter` was introduced in version 2.7.

.. versionchanged:: 2.7

   All arguments must now be specified as keyword arguments as of version
   2.7.
c                 ó²   >• [         [        U ]  5         S U l        S U l        SU l        S U l        SU l        UR                  SS5      nU R                  XS9  g )NF)r-   Úlatex_contextÚin_math_modeÚmath_mode_delimiterÚ_do_sanitizeT)Údo_sanitize)
r2   r  r3   r-   r   r!  r"  r|   rÛ   Ú_set_fields)r5   r­   r$  r6   s      €r   r3   ÚParsingState.__init__Ö  sW   ø€ ÜŒl˜DÑ*Ô,ØˆŒØ!ˆÔØ!ˆÔØ#'ˆÔ ØVˆŒà—j‘j °Ó6ˆà×Ñ˜ÐÒ9r   c                 ól   • U R                   " SSS0U R                  5       D6nUR                  U5        U$ )aà  
Return a new :py:class:`ParsingState` instance that is a copy of the current
parsing state, but where the given properties keys have been set to the
corresponding values (given as keyword arguments).

This makes it easy to create a sub-context in a given parser.  For
instance, if we enter math mode, we might write::

   parsing_state_inner = parsing_state.sub_context(in_math_mode=True)

If no arguments are provided, this returns a copy of the present parsing
context object.
r#  Fr
   )r6   Ú
get_fieldsr%  )r5   r­   Úps      r   Úsub_contextÚParsingState.sub_contextâ  s2   € ð �NŠNÑC¨ÐC°·±Ó1BÑCˆà	�‰�fÔàˆr   c           
      ól   • [        U R                   Vs/ s H  o[        X5      4PM     sn5      $ s  snf )zT
Returns the fields and values associated with this `ParsingState` as a
dictionary.
)rn   r|   rŠ   )r5   r—   s     r   r(  ÚParsingState.get_fieldsö  s-   € ô
 °D·L²LÓA²L¨qœ Ó)Ó*±LÑAÓBÐBùÒAs   ”1c                 óÎ   • UR                  5        H:  u  p4X0R                  ;  a  [        SR                  X45      5      e[	        XU5        M<     U(       a  U R                  US9  g g )Nz'Invalid field for ParsingState: {}={!r})Úgiven_fields)Úitemsr|   Ú
ValueErrorr=   r  Ú	_sanitize)r5   r­   r$  rŒ   Úvs        r   r%  ÚParsingState._set_fieldsþ  sZ   € à—L‘L–N‰DˆAØŸ™Ó$Ü Ð!J×!QÑ!QÐRSÓ!WÓXÐXÜ�D˜QÖñ #ö
 ð �N‰N¨ˆNÒ/ð r   c                 ó¨   • U R                   (       dA  U R                  (       a/  SU l        SU;   a!  [        R                  SU R                  5        gggg)a  
Sanitize the parsing state.  E.g., clear any `math_mode_delimiter` if
`in_math_mode` is `False`.

The argument `given_fields` is what fields the user required to set;
this is used to generate warnings if incompatible field configurations
were explicitly required to be set.
Nr"  zFParsingState: You set math_mode_delimiter=%r but in_math_mode is False)r!  r"  ÚloggerÚwarning)r5   r/  s     r   r2  ÚParsingState._sanitize
  sL   € ð × ×  T×%=×%=Ø'+ˆDÔ$Ø$¨Ó4Ü—‘ð,Ø-1×-EÑ-Eõð 5ð &>Ð r   )r|   r!  r   r"  r-   ©T)r!   r"   r#   r$   r%   r3   r*  r(  r%  r2  r&   rK   rL   s   @r   r  r  —  s(   ø† ñ=õ|
:òò(Cô
0÷ð r   r  c                   ó¦   ^ • \ rS rSrSrSU 4S jjrS rS rS r  SS jr	S r
S	 rSS
 jrSS jrSS jrSS jrSS jrS r    SS jrSrU =r$ )ÚLatexWalkeri"  aZ  
A parser which walks through an input stream, parsing it as LaTeX markup.

Arguments:

  - `s`: the string to parse as LaTeX code

  - `latex_context`: a :py:class:`pylatexenc.macrospec.LatexContextDb`
    object that provides macro and environment specifications with
    instructions on how to parse arguments, etc.  If you don't specify this
    argument, or if you specify `None`, then the default database is used.
    The default database is obtained with
    :py:func:`get_default_latex_context_db()`.

    .. versionadded:: 2.0

       This `latex_context` argument was introduced in version 2.0.

Additional keyword arguments are flags which influence the parsing.
Accepted flags are:

  - `tolerant_parsing=True|False` If set to `True`, then the parser
    generally ignores syntax errors rather than raising an exception.

  - `strict_braces=True|False` This option refers specifically to reading a
    encountering a closing brace when an expression is needed.  You
    generally won't need to specify this flag, use `tolerant_parsing`
    instead.

The methods provided in this class perform various parsing of the given
string `s`.  These methods typically accept a `pos` parameter, which must be
an integer, which defines the position in the string `s` to start parsing.

These methods, unless otherwise documented, return a tuple `(node, pos,
len)`, where node is a :py:class:`LatexNode` describing the parsed content,
`pos` is the position at which the LaTeX element of iterest was encountered,
and `len` is the length of the string that is considered to be part of the
`node`.  That is, the position in the string that is immediately after the
node is `pos+len`.

The following obsolete flag is accepted by the constructor for backwards
compatibility with `pylatexenc 1.x`:

  - `macro_dict`: This argument is kept for compatibility with `pylatexenc
    1.x`.  This is a dictionary of known LaTeX macro specifications.  If
    specified, this should be a dictionary where the keys are macro names
    and values are :py:class:`pylatexenc.macrospec.MacroSpec` instances, as
    returned for instance by the `pylatexenc 1.x`-emulating function
    :py:func:`MacrosDef`.  If you specify this argument, you cannot provide
    a custom `latex_context`.  This argument is superseded by the
    `latex_context` argument.  Furthermore, if you specify this argument, no
    specials are parsed so that the behavior closer to `pylatexenc 1.x`.

    .. deprecated:: 2.0

       The `macro_dict` argument has been replaced by the much more powerful
       `latex_context` argument which allows you to further provide
       environment specifications, etc.

  - `keep_inline_math=True|False`: Obsolete option.  In `pylatexenc 1.x`,
    this option triggered a weird behavior especially since there is a
    similarly named option in
    :py:class:`pylatexenc.latex2text.LatexNodes2Text` with a different
    meaning.  [See `Issue #14
    <https://github.com/phfaist/pylatexenc/issues/14>`_.]  You should now
    only use the option `math_mode=` in
    :py:class:`pylatexenc.latex2text.LatexNodes2Text`.

    .. deprecated:: 2.0

       This option is ignored starting from `pylatexenc 2`.  Instead, you
       should set the option `math_mode=` accordingly in
       :py:class:`pylatexenc.latex2text.LatexNodes2Text`.


.. py:attribute:: s

   The string that is being parsed.

   Do NOT modify this attribute.
c                 ó¢  >• Xl         S U l        SU l        Ucƒ  SU;   ar  [        R                  " S5        UR                  SS 5      n[        5       nUR                  S/S9nUR                  SUR                  5       UR                  5       5        O[        5       nOSU;   a  [        S5      e[        U R                   US9U l        UR                  S	S
5      U l        UR                  SS5      U l        SU;   a  [        R                  " S5        US	 U(       a$  [         R#                  SUR%                  5       5        [&        [(        U ]W  5         g )NFÚ
macro_dictz°The `macro_dict=...` option in LatexWalker() is obsolete since pylatexenc 2.  It'll still work, but please consider using instead the more versatile option `latex_context=...`.rY   )Ú
keep_whichÚcustomz@Cannot specify both `latex_context=` and `macro_dict=` arguments)r-   r   Útolerant_parsingTÚstrict_bracesÚkeep_inline_mathz¬The keep_inline_math=... option in LatexWalker() has no effect in pylatexenc 2.  Please consider using the more versatile option math_mode=... in LatexNodes2Text() instead.z.LatexWalker(): Unknown flag(s) encountered: %r)r-   Ú_line_no_calcÚdebug_nodesr   rc   rÛ   ra   Úfilter_contextr]   ÚvaluesÚiter_environment_specsr¸   r  Údefault_parsing_stater@  rA  r6  r7  Úkeysr2   r;  r3   )r5   r-   r   r­   r=  Údefault_latex_contextr6   s         €r   r3   ÚLatexWalker.__init__u  sO  ø€ àŒð "ˆÔà ˆÔàÑ Ø˜vÓ%ä×-Ò-ðEôð $ŸZ™Z¨°dÓ;�
ä(DÓ(FÐ%à 5× DÑ DØ .Ð/ð !Eð !�ð ×2Ñ2ØØ×%Ñ%Ó'Ø)×@Ñ@ÓBõô !=Ó >‘ð ˜vÓ%ÜØVóð ô &2Ø�f‰fØ'ñ&
ˆÔ"ð !'§
¡
Ð+=¸tÓ DˆÔØ#ŸZ™Z¨¸Ó?ˆÔà Ó'Ü×)Ò)ð>ôð
 Ð)Ð*æä�N‰NÐKÈVÏ[É[Ë]Ô[äŒk˜4Ñ)Õ+r   c                 ó:   • U R                   R                  " S0 UD6$ )a  
Return a new parsing state object that corresponds to the current string
that we are parsing (`s` provided to the constructor) and the current
latex context (`latex_context` provided to the constructor).

If no arguments are provided, this returns the default parsing state.

If keyword arguments are provided, then they can override fields from
the default parsing state.  For instance, if we enter math mode, you
might use::

  parsing_state_mathmode = \
      my_latex_walker.make_parsing_state(in_math_mode=True)
r
   )rH  r*  )r5   r­   s     r   Úmake_parsing_stateÚLatexWalker.make_parsing_state¾  s   € ð ×)Ñ)×5Ò5Ñ?¸Ñ?Ð?r   c                 ó6   • U R                   U R                  SS.$ )a'  
The parse flags currently set on this object.  Returns a dictionary with
keys 'keep_inline_math', 'tolerant_parsing' and 'strict_braces'.

.. deprecated:: 2.0

   The 'keep_inline_math' key is always set to `None` starting in
   `pylatexenc 2` and might be removed entirely in future versions.
N)r@  rA  rB  )r@  rA  rF   s    r   Úparse_flagsÚLatexWalker.parse_flagsÏ  s#   € ð !%× 5Ñ 5Ø!×/Ñ/à $ñ	
ð 	
r   c                 ó0   • [         R                  SU5        g )Nz0Ignoring parse error (tolerant parsing mode): %s)r6  Úinfo)r5   Úexcs     r   Ú_report_ignore_parse_errorÚ&LatexWalker._report_ignore_parse_errorà  s   € Ü�‰ÐFÈÕLr   c           	      óÌ	  ^ ^^^• Uc  T R                  5       nS/nU(       a  Xr-  nSU;   a  UR                  S5      (       d  US/-  nT R                  mSmUUU U4S jnT[        T5      :  aw  TT   R	                  5       (       a_  TTT   -  mTS-  mTR                  S5      (       a  [        S	STS
-
  S
TSS S9$ T[        T5      :  a  TT   R	                  5       (       a  M_  T[        T5      :¼  a	  [        TS9eTT   S:X  Ga	  TS-   [        T5      :¼  a
  [        5       eTTS-      n	Sn
S
nTTS-      R                  5       (       an  Sn
TU-   [        T5      :  aZ  TTU-      R                  5       (       a?  U	TTU-      -  n	US-  nTU-   [        T5      :  a  TTU-      R                  5       (       a  M?  U	S;   a  [        SSU	-   TUTS9$ U	S;   a  [        SSU	-   TUTS9$ U(       a�  U	S;   a{  [        R                  " STTU-   S 5      nUc'  U" SR                  U	5      USU	-   S9u  pÞU(       a  UeU$ [        U	S:X  a  SOSUR                  S5      TX¼R                  5       -   TS9$ SnU
(       a�  TU-   [        T5      :  a{  TTU-      R	                  5       (       a`  UTTU-      -  nUS-  nUR                  S5      (       a  USS nUS
-  nO/TU-   [        T5      :  a  TTU-      R	                  5       (       a  M`  [        SU	TUTUS9$ TT   S:X  aÙ  [        R                  " S5      R                  TT5      nSnUb…  UR                  S5      R!                  S 5      (       a)  UR#                  5       T-
  nUR#                  5       T-
  nSnOIUR#                  5       T-
  nUR                  5       T-
  nUR                  5       nO[        T5      T-
  nUnSn[        S!TTS-   TU-    TUTUS9$ [%        U6 u  nnTT   U;   a  [        S"TT   TSTS9$ TT   U;   a  [        S#TT   TSTS9$ TR!                  S$T5      (       a.  UR&                  (       a  UR(                  S%:X  d  [        SS$TS
TS9$ TR!                  S%T5      (       a  [        SS%TSTS9$ UR*                  R-                  TTUS&9nUb   [        S'UT[        UR.                  5      TS9$ [        S	TT   TSTS9$ )(a  
Parses the latex content given to the constructor (and stored in `self.s`),
starting at position `pos`, to parse a single "token", as defined by
:py:class:`LatexToken`.

Parse the token in the stream pointed to at position `pos`.

For tokens of type 'char', usually a single character is returned.  The
only exception is at paragraph boundaries, where a single 'char'-type
token has argument '\\n\\n'.

Returns a :py:class:`LatexToken`. Raises
:py:exc:`LatexWalkerEndOfStream` if end of stream reached.

The argument `include_brace_chars=` allows to specify additional pairs
of single characters which should be considered as braces (i.e., of
'brace_open' and 'brace_close' token types).  It should be a list of
2-item tuples, for instance ``[('[', ']'), ('<', '>')]``.  The pair
`('{', '}')` is always considered as braces.  The delimiters may not
have more than one character each.

If `environments=False`, then ``\begin`` and ``\end`` tokens count as
regular 'macro' tokens (see :py:class:`LatexToken`); otherwise (the
default) they are considered as the token types 'begin_environment' and
'end_environment'.

The parsing of the tokens might be influcenced by the `parsing_state` (a
:py:class:`ParsingState` instance).  Currently, the only influence this
has is that some latex specials are parsed differently if in math mode.
See doc for :py:class:`ParsingState`.  If `parsing_state` is `None`, the
default parsing state returned by :py:meth:`make_parsing_state()` is
used.

.. deprecated:: 2.0

   The flag `keep_inline_math` is only accepted for compatibiltiy with
   earlier versions of `pylatexenc`, but it has no effect starting in
   `pylatexenc 2`.  See the :py:class:`LatexWalker` class doc.

.. deprecated:: 2.0

   If `brackets_are_chars=False`, then square bracket characters count
   as 'brace_open' and 'brace_close' token types (see
   :py:class:`LatexToken`); otherwise (the default) they are considered
   just like other normal characters.

.. versionadded:: 2.0

   The `parsing_state` argument was introduced in version 2.0.
Nr×   Úbrackets_are_chars©Ú[Ú]r9   c           	      ó¨   >• [        STTU S.TR                  TSS9D6nTR                  (       a   TR                  U5        S [	        SUTUTS94$ US 4$ )N©r-   r.   r,   T©Úas_dictÚcharrt   r
   )r(   Úpos_to_lineno_colnor@  rU  rr   )r,   rw   ÚplaceholderÚer.   r-   r5   Úspaces       €€€€r   Ú_token_parse_errorÚ1LatexWalker.get_token.<locals>._token_parse_error8  s|   ø€ Ü%ð ØØØñð ×*Ñ*¨3¸Ð*Ð=ñ	ˆAð ×$×$Ø×/Ñ/°Ô2ØœZØØ#ØØØ#ñð ð ð �d�7ˆNr   rV   z

r`  r   éþÿÿÿrt   rS   Ú\FTÚmathmode_display)rÆ   rˆ   Úmathmode_inline)ÚbeginÚendz^\s*\{([\w* ._-]+)\}z+Bad \{} macro: expected {{environmentname}})r,   rw   rb  rk  Úbegin_environmentÚend_environmentry   )ru   rv   r.   rw   rx   r{   Ú%z(\n|\r|\n\r)(?P<extraspace>\s*)Ú
extraspace)Ú
Úz
rz   Ú
brace_openÚbrace_closeú$$Ú$©rª   rZ   )rM  rÛ   r-   rw   ÚisspaceÚendswithrr   rN   ÚisalphaÚreÚmatchr=   Úgrouprl  ÚcompileÚsearchÚ
startswithÚstartÚzipr!  r"  r   Útest_for_specialsrÿ   )r5   r.   Úinclude_brace_charsrY   rB  rª   r­   Úbrace_charsre  ry   ÚisalphamacroÚiÚenvmatchrc  r´   r{   rk   ÚmlenÚarglenÚmspaceÚopenbracecharsÚclosebracecharsÚsspecr-   rd  s   ``                     @@r   Ú	get_tokenÚLatexWalker.get_tokenã  sp  û€ ðj Ñ Ø ×3Ñ3Ó5ˆMà!�lˆæØÑ.ˆKà 6Ó)Ø—:‘:Ð2×3Ñ3Ø 
˜|Ñ+�à�F‰Fˆàˆ÷$	ð 	ð$ ”C˜“F‹l˜q ™vŸ~™~×/Ñ/Ø�Q�s‘V‰OˆEØ�1‰HˆCØ�~‰~˜f×%Ñ%Ü! f°&¸cÀ!¹eÈØ,1°#°2¨Jñ8ð 8ð	 ”C˜“F‹l˜q ™vŸ~™~×/Ó/ð ”#�a“&‹=Ü(°UÑ;Ð;àˆS‰6�TŒ>à�1‰uœ˜A›‹Ü,Ó.Ð.Ø�c˜!‘e‘HˆEà ˆLØˆAØ��Q‘‰x×Ñ×!Ñ!Ø#�Ø˜!‘eœC ›F“l q¨¨Q©¡x×'7Ñ'7×'9Ñ'9Ø˜Q˜s 1™u™XÑ%�EØ˜‘F�Að ˜!‘eœC ›F“l q¨¨Q©¡x×'7Ñ'7×'9Ó'9ð ˜
Ó"Ü!Ð&8¸dÀ5¹jØ&)¨q¸EñCð Cà˜
Ó"Ü!Ð&7¸TÀ%¹ZØ&)¨q¸EñCð Cö  Ð)9Ó 9äŸ8š8Ð$;¸Q¸sÀ1¹u¸v¸YÓG�ØÑ#Ù-ØJ×QÑQÐRWÓXØØ$(¨¡Jñ‘D�Aö
 Ø˜Ø�Hä!Ø05¸Ó0@Ñ,ÐFWØ Ÿ™ qÓ)ØØŸ,™,›.Ñ(Ø#ñð ð ˆJÞà˜!‘eœC ›F“l q¨¨Q©¡x×'7Ñ'7×'9Ñ'9Ø ! C¨¡E¡(Ñ*�JØ˜‘F�AØ!×*Ñ*¨6×2Ñ2ð &0°° _˜
Ø˜Q™˜Øð ˜!‘eœC ›F“l q¨¨Q©¡x×'7Ñ'7×'9Ó'9ô  '¨u¸#À1Ø(-¸*ñFð Fð ˆS‰6�S‹=ä—
’
Ð=Ó>×EÑEÀaÈÓMˆAØˆDØ‰}Ø—7‘7˜<Ó(×3Ñ3Ð5J×LÑLð ŸW™W›Y s™]�FØŸ7™7›9 S™=�DØ‘FàŸW™W›Y s™]�FØŸ5™5›7 3™;�DØŸW™W›Y‘Fä˜Q› ™�Ø�Ø�Ü )°°3°q±5¸¸V¹Ð1DÈ#ÐSWØ(-¸&ñBð Bô +.¨{Ð*;Ñ'ˆ˜àˆS‰6�^Ó#Ü ,°A°c±FÀÈÐV[Ñ\Ð\àˆS‰6�_Ó$Ü -°Q°s±VÀÈ!ÐW\Ñ]Ð]ð �<‰<˜˜c×"Ñ"ð "×.×.°=×3TÑ3TÐX[Ó3[Ü!Ð&8¸dØ&)¨q¸EñCð Cà�<‰<˜˜S×!Ñ!ÜÐ"3¸À#È1ÐX]Ñ^Ð^à×+Ñ+×=Ñ=Øˆs -ð >ð 
ˆð ÑÜ *°%Ø"%¬3¨u×/CÑ/CÓ+DÐPUñWð Wô
 ˜f¨!¨C©&°c¸qÈEÑRÐRr   c                 óÎ   • UR                  S5      UR                  S5      UR                  S5      pTnU" SX4US.UD6nU R                  (       a  [        R                  SU5        U$ )a!  
Create and return a node of type `node_class` which holds a representation
of the latex code at position `pos` and of length `len` in the parsed
string.

The node class should be a :py:class:`LatexNode` subclass.  Keyword
arguments are supplied directly to the constructor of the node class.

Mandatory keyword-only arguments are 'pos', 'len', and 'parsing_state'.

All nodes produced by :py:meth:`get_latex_nodes()` and friends use this
method to create node classes.

.. versionadded:: 2.0

   This method was introduced in `pylatexenc 2.0`.
r.   rw   rª   )r.   rw   rª   zNew node: %rr
   )rÛ   rD  r6  Údebug)r5   Ú
node_classr­   r.   rw   rª   Únodes          r   Ú	make_nodeÚLatexWalker.make_nodeÉ  s_   € ð( �J‰J�uÓ˜vŸz™z¨%Ó0°&·*±*¸_Ó2Mð  ˆñ ÐR˜c¸-ÑRÈ6ÑRˆØ××Ü�L‰L˜¨Ô.Øˆr   c                 ó4   • U R                   " U4X#US.UD6UU4$ )N)rª   r.   rw   )r•  )r5   Únclassrª   r.   rw   r­   s         r   Ú_mknodeposlenÚLatexWalker._mknodeposlenä  s+   € à�NŠN˜6Ð[°ÈSÑ[ÐTZÑ[ØØð
ð 	
r   c                 ó˜   • U R                   c%  [        R                  " U R                  5      U l         U R                   R	                  XS9$ )a%  
Return the line and column number corresponding to the given `pos` in our
string `self.s`.

The first time this function is called, line numbers are calculated for
the entire string.  These are cached for future calls which are then
fast.

Return a tuple `(lineno, colno)` giving line number and column number.
Line numbers start at 1 and column numbers start at zero, i.e., the
beginning of the document (`pos=0`) has line and column number `(1,0)`.
If `as_dict=True`, then a dictionary with keys 'lineno', 'colno' is
returned instead of a tuple.
r^  )rC  r   ÚLineNumbersCalculatorr-   ra  )r5   r.   r_  s      r   ra  ÚLatexWalker.pos_to_lineno_colnoì  sA   € ð  ×ÑÑ%Ü!&×!<Ò!<¸T¿V¹VÓ!DˆDÔà×!Ñ!×5Ñ5°cÐ5ÐKÐKr   c                 ó|  • Uc  U R                  5       n[        U SU5         U R                  USUS9nUR                  S:X  a½  UR                  S:X  aa  U R
                  (       d&  [        SU R                  U40 U R                  USS	9D6eU R                  [        US
UR                  SS9sSSS5        $ U R                  [        UUR                  SUR                  SSUR                  UR                  S9	sSSS5        $ UR                  S:X  aI  U R                  [        UUR                  R                   SUR                  UR                  S9sSSS5        $ UR                  S:X  a0  U R#                  UR                  UR                  -   US9sSSS5        $ UR                  S:X  a#  U R%                  UR                  US9sSSS5        $ UR                  S:X  a‹  U R&                  (       aP  U R
                  (       d?  [        SR)                  UR                  5      U R                  U40 U R                  USS	9D6eU R                  [        US
UR                  SS9sSSS5        $ UR                  S:X  a>  U R                  [        UUR                  UR                  UR                  S9sSSS5        $ UR                  S;   a©  UR                  R+                  S5      (       aK  U R                  [        UUR                  SSUR                  UR                  UR                  S9sSSS5        $ U R                  [        UUR                  UR                  UR                  S9sSSS5        $ [        SR)                  UR                  5      U R                  U40 U R                  USS	9D6e! , (       d  f       g= f)aá  
Parses the latex content given to the constructor (and stored in `self.s`),
starting at position `pos`, to parse a single LaTeX expression.

Reads a latex expression, e.g. macro argument. This may be a single char, an escape
sequence, or a expression placed in braces.  This is what TeX calls a "token" (and
not what we call a token... anyway).

Parsing might be influenced by the `parsing_state`.  See doc for
:py:class:`ParsingState`.  If `parsing_state` is `None`, then the
default parsing state is used.

Returns a tuple `(node, pos, len)`, where `pos` is the position of the
first char of the expression and `len` the length of the expression.

.. versionadded:: 2.0

   The `parsing_state` argument was introduced in version 2.0.
NrA  F)rY   rª   ry   rl  zExpected expression, got \endTr^  r9   r   ©rª   rÍ   r.   rw   ©rª   re   rê   rë   rì   rí   r.   rw   rZ   ©rª   rÿ   rê   r.   rw   rz   rw  rs  rt  z+Expected expression, got closing brace '{}'r`  ©rj  ri  rh  )rª   re   rì   rí   rë   r.   rw   zUnknown token type: {})rM  r  r�  ru   rv   r@  r(   r-   ra  r™  rÊ   r.   rè   r{   rw   rý   rÿ   Úget_latex_expressionÚget_latex_braced_grouprA  r=   r€  )r5   r.   rA  rª   ru   s        r   r£  Ú LatexWalker.get_latex_expression  s†  € ð* Ñ Ø ×3Ñ3Ó5ˆMä˜t _°mÕDà—.‘. °5È�.ÐVˆCà�w‰w˜'Ó!Ø—7‘7˜eÓ#Ø×0×0ä3Ø<Ø ŸF™F CñKð #×6Ñ6°sÀDÐ6ÐIñKð Kð
  $×1Ñ1´.Ø@MØ8:Ø69·g±gØ67ð	  2ð  9÷ EÑDð$ ×)Ñ)¬.Ø8EØ47·G±GØ37Ø;>¿>¹>Ø59ÀDØ.1¯g©g¸3¿7¹7ð *ð D÷% EÑDð2 �w‰w˜*Ó$Ø×)Ñ)Ô*;Ø8EØ9<¿¹×9OÑ9OØ37Ø.1¯g©g¸3¿7¹7ð	 *ð D÷5 EÑDð> �w‰w˜)Ó#Ø×0Ñ0°·±¸¿¹±ÐP]Ð0Ð^÷A EÑDðB �w‰w˜,Ó&Ø×2Ñ2°3·7±7È-Ð2ÐX÷E EÑDðF �w‰w˜-Ó'ð
 ×%×%¨d×.C×.CÜ/ØE×LÑLÈSÏWÉWÓUØŸ™ ñð ×2Ñ2°3ÀÐ2ÐEñð ð
 ×)Ñ)¬.Ø8EØ02Ø.1¯g©g¸1ð *ð >÷] EÑDðd �w‰w˜&Ó Ø×)Ñ)¬.Ø8EØ03·±Ø.1¯g©gØ.1¯g©gð	 *ð 7÷g EÑDðp �w‰wÐAÓAà—7‘7×%Ñ% d×+Ñ+Ø×-Ñ-¬nØ<IØ8;¿¹Ø9=Ø7;Ø?B¿~¹~Ø25·'±'Ø25·'±'ð .ð ;÷w EÑDðH  ×-Ñ-¬nØ<IØ47·G±GØ25·'±'Ø25·'±'ð	 .ð ;÷I EÑDôT (Ø(×/Ñ/°·±Ó8¸$¿&¹&À#ñ?à×*Ñ*¨3¸Ð*Ð=ñ?ð ?÷U EÕDúsG   ¡B	N-Â4AN-Ä AN-Å6N-Æ)N-ÇBN-É'AN-Ê5A1N-Ì04N-Í.?N-Î-
N;c                 óÔ   • Uc  U R                  5       n U R                  US/SUS9nUR                  S:X  a!  UR                  S:X  a  U R                  USUS9$ g! [         a     gf = f)aK  
Parses the latex content given to the constructor (and stored in `self.s`),
starting at position `pos`, to attempt to parse an optional argument.

Parsing might be influenced by the `parsing_state`. See doc for
:py:class:`ParsingState`.  If `parsing_state` is `None`, the default
parsing state is used.

Attempts to parse an optional argument. If this is successful, we return
a tuple `(node, pos, len)` if success where `node` is a
:py:class:`LatexGroupNode`.  Otherwise, this method returns None.

.. versionadded:: 2.0

   The `parsing_state` argument was introduced in version 2.0.
NrY  F)r„  rY   rª   rs  rZ  ©Ú
brace_typerª   )rM  r�  rN   ru   rv   r¤  )r5   r.   rª   ru   s       r   Úget_latex_maybe_optional_argÚ(LatexWalker.get_latex_maybe_optional_argi  s�   € ð$ Ñ Ø ×3Ñ3Ó5ˆMð	Ø—.‘. ¸:¸,ÐUZØ/<ð !ð >ˆCð �7‰7�lÓ" s§w¡w°#£~Ø×.Ñ.¨s¸sØ=Jð /ð Lð Lð øô &ó 	ñ ð		ús   •A Á
A'Á&A'c           	      óh  • Uc  U R                  5       nSnUS:X  a  SnO=US:X  a  SnO4US:X  a  SnO+US:X  a  S	nO"[        U5      S
:X  a  Uu  p$O[        SU-  5      eSnU(       a
  US:w  a  X$4/nU R                  XUS9nUR                  S:w  d  UR
                  U:w  a7  [        SU R                  USU R                  U   -  S.U R                  USS9D6eU R                  UR                  UR                  -   X$4US9u  pxn	U R                  [        UUX$4UR                  X‰-   UR                  -
  S9$ )a  
Parses the latex content given to the constructor (and stored in `self.s`),
starting at position `pos`, to read a latex group delimited by braces.

Reads a latex expression enclosed in braces ``{ ... }``. The first token of
`s[pos:]` must be an opening brace.

Parsing might be influenced by the `parsing_state`.  See doc for
:py:class:`ParsingState`.  If `parsing_state` is `None`, the default
parsing state is used.

Returns a tuple `(node, pos, len)`, where `node` is a
:py:class:`LatexGroupNode` instance, `pos` is the position of the first
char of the expression (which has to be an opening brace), and `len` is
the length of the group, including the closing brace (relative to the
starting position).

The group must be delimited by the given `brace_type`.  `brace_type` may
be one of ``{``, ``[``, ``(`` or ``<``, or a 2-item tuple of two
distinct single characters providing the opening and closing brace
chars (e.g., ``("<", ">")``).

.. versionadded:: 2.0

   The `parsing_state` argument was introduced in version 2.0.
NrØ   rÙ   rZ  r[  rÆ   rˆ   Ú<Ú>r   z3Invalid brace type for get_latex_braced_group(): %s©r„  rª   rs  z8get_latex_braced_group: not an opening brace/bracket: %sr]  Tr^  )Ústop_upon_closing_bracerª   )rÚ   rª   rÖ   r.   rw   r
   )rM  rw   r1  r�  ru   rv   r(   r-   ra  Úget_latex_nodesr.   r™  rÔ   )
r5   r.   r¨  rª   Úclosing_bracer„  ÚfirsttokrÚ   ÚnposÚnlens
             r   r¤  Ú"LatexWalker.get_latex_braced_groupŽ  s‚  € ð8 Ñ Ø ×3Ñ3Ó5ˆMàˆØ˜ÓØ‰MØ˜3ÓØ‰MØ˜3ÓØ‰MØ˜3ÓØ‰MÜ�‹_ Ó!Ø(2Ñ%ˆJ˜äÐRÐU_Ñ`ÓaÐaà"ÐÞ˜*¨Ó+Ø$.Ð#>Ð"?Ðà—>‘> #Ø0=ð "ð ?ˆà�<‰<˜<Ó'¨X¯\©\¸ZÓ-GÜ'ð Ø—&‘&ØØNÐQU×QWÑQWÐX[ÑQ\Ñ]ñð ×*Ñ*¨3¸Ð*Ð=ñ	ð ð "&×!5Ñ!5Ø�L‰L˜8Ÿ<™<Ñ'Ø%/Ð$?Ø'ð "6ð "
Ñˆ˜ð ×!Ñ!¤.¸8Ø0=Ø.8Ð-HØ(0¯©Ø(,©°h·l±lÑ(Bð	 "ð Dð 	Dr   c                 ó  • Uc  U R                  5       nUnU R                  XS9nUR                  S:w  d  UbN  UR                  U:w  a>  [	        SU R
                  USUb  UOS< SUR                  < 3S.U R                  USS	9D6eUc  UR                  nUR                  UR                  -   nUR                  R                  U5      nUc  [        R                  " S
5      n UR                  XUS9n[        U5      S:X  a  Uu  pšp¼OUu  pšn0 nX«-   nUR#                  SU5      nUR$                  (       a  UR'                  SSU-   S-   S9nU R)                  UUUS9u  pïnU	b0  U	R*                  (       a  U	R*                  S   nU	R*                  S   nOS/ nnU R-                  [.        UUUU	U/UUUU-   U-
  S9	$ ! [        [        4 a8  nU R                  UUSR!                  U5      5      nUb  UeSUS0 4n SnAGN	SnAff = f)a  
Parses the latex content given to the constructor (and stored in `self.s`),
starting at position `pos`, to read a latex environment.

Reads a latex expression enclosed in a
``\begin{environment}...\end{environment}``.  The first token in the
stream must be the ``\begin{environment}``.

If `environmentname` is given and nonempty, then additionally a
:py:exc:`LatexWalkerParseError` is raised if the environment in the
input stream does not match the provided environment name.

Arguments to the begin environment command are parsed according to the
corresponding specification in the given latex context `latex_context`
provided to the constructor.  The environment name is looked up as a
"macro name" in the macro spec.

Parsing might be influenced by the `parsing_state`.  See doc for
:py:class:`ParsingState`.  If `parsing_state` is `None`, the default
parsing state is used.

Returns a tuple (node, pos, len) where node is a
:py:class:`LatexEnvironmentNode`.

.. versionadded:: 2.0

   The `parsing_state` argument was introduced in version 2.0.
Nrw  rm  z'get_latex_environment: expected \begin{z<environment name>z}: r]  Tr^  r9   ©Úwr.   rª   z'arguments of environment "\begin{{{}}}"r   é   Úinner_parsing_staterØ   rÙ   ©r!  r"  )Ústop_upon_end_environmentrª   rV   )rª   r÷   rÚ   rê   rö   r   r.   rw   r
   )rM  r�  ru   rv   r(   r-   ra  r.   rw   r   Úget_environment_specr   ÚEnvironmentSpecÚ
parse_argsrN   Ú_exchandle_parse_subexpressionr=   ÚgetÚis_math_moder*  r°  Úlegacy_nodeoptarg_nodeargsr™  rô   )r5   r.   r÷   rª   Ústartposr²  Úenv_specÚ
argsresultrc  ÚargdÚaposÚalenÚadicÚparsing_state_innerrÚ   r³  r´  ÚlegnodeoptargÚlegnodeargss                      r   Úget_latex_environmentÚ!LatexWalker.get_latex_environmentÖ  sg  € ð< Ñ Ø ×3Ñ3Ó5ˆMàˆà—>‘> #�>ÐCˆØ�<‰<Ð.Ó.ØÑ'¨H¯L©L¸OÓ,KÜ'ð Ø—&‘&Ùà'6Ñ'B‘OÐH\Ò\Ø—L“Lðñð ×*Ñ*¨3¸Ð*Ð=ñð ð Ñ#Ø&Ÿl™lˆOà�l‰l˜XŸ\™\Ñ)ˆà ×.Ñ.×CÑCÀOÓTˆØÑÜ ×0Ò0°Ó4ˆHð		,Ø!×,Ñ,¨tÈMÐ,ÐZˆJô ˆz‹?˜aÓØ'1Ñ$ˆT˜˜tà!+ÑˆT˜ØˆDà‰kˆà"Ÿh™hÐ'<¸mÓLÐà× × Ø"/×";Ñ";Ø!Ø$'¨Ñ$7¸Ñ$;ð #<ð #Ðð
 "&×!5Ñ!5°cØP_ØDWð "6ð "YÑˆ˜ð Ñ × ?× ?Ø ×;Ñ;¸AÑ>ˆMØ×9Ñ9¸!Ñ<‰Kà)-¨r˜;ˆMà×!Ñ!Ô"6Ø0=Ø2AØ+3Ø+/à+8¨/Ø'2Ø&.Ø&*¨4¡i°Ñ&8ð "ð 	:ð 		:øôG 'Ô(=Ð>ó 	,Ø×3Ñ3ØØØ<×CÑCÀOÓTóˆAð
 ‰} A˜gØ  Q¨Ð+ŽJûð	,ús   Ã#F9 Æ9HÇ	-G<Ç<Hc           	      óZ  • [        U[        5      (       aJ  [        SU R                  UR                  SR                  U5      S.U R                  UR                  SS9D6n[        USS5      bB  UR                  c5  UR                  c(  U R                  UR                  5      u  Ul        Ul	        UR                  R                  [        SR                  U5      UR                  /U R                  UR                  5      Q76 5        U R                  (       a  U R                  U5        gU$ )	aI  
(INTERNAL.) Handle an exception raised by a method that you called to parse
a macro arguments or another "sub-expression".  Use as::

    except (LatexWalkerEndOfStream, LatexWalkerParseError) as e:
        e = self._exchandle_parse_subexpression(e, <tok>, "what this is about")
        if e is not None: raise e
        ... # do sth to recover from parse error in tolerant mode

Use in an exception handler that captures both `LatexWalkerEndOfStream`
and `LatexWalkerParseError`.  Returns what exception you should raise if
you got one of these while parsing, e.g., macro arguments.
zEnd of input while parsing {}r]  Tr^  r.   Nz{}r
   )r³   rN   r(   r-   r.   r=   ra  rŠ   r/   r0   r1   r}   r   r@  rU  )r5   rc  ru   r<   s       r   rÀ  Ú*LatexWalker._exchandle_parse_subexpression@  sý   € ô �aÔ/×0Ñ0Ü%ð Ø—&‘&Ø—G‘GØ3×:Ñ:¸4Ó@ñð ×*Ñ*¨3¯7©7¸DÐ*ÐAñ	ˆAô �1�e˜TÓ"Ñ.°1·8±8Ñ3CÈÏÉÉØ $× 8Ñ 8¸¿¹Ó ?ÑˆAŒH�a”gà	�‰×ÑÜ�t—{‘{ 4Ó(¨#¯'©'ð ;Ø×0Ñ0°·±Ó9ò;ô	
ð
 × × Ø×+Ñ+¨AÔ.ØØˆr   c           
      ó†  ^ ^^^^^• Uc  T R                  5       n/ nSmSnT(       aC  TS:X  a  SnO/TS:X  a  SnO&TS:X  a  SnOTS:X  a  S	nO[        T5      S
:X  a  Tu  nmTS:w  a  UT4/mTb@  UR                  (       d/  [        R	                  SR                  TUR                  5      5        Un	 " S S5      n
U
" XS9nUUU UUU4S jn  U" X{5      nU(       aÑ  [        U[        5      (       aL  UR                  UR                  UR                  S9  U=R                  [        UR                  5      -  sl	        UR                   (       aN  UR#                  5       u  nnT R%                  [&        UR(                  UU[        U5      S9nUR+                  U5        XyUR                  U	-
  4$ Mã  ! [         aÐ  nT(       d  T(       d  T(       a®  T(       a	  ST-   S-   nOT(       a	  ST-   S-   nOT(       a  ST-   S-   n[        ST R                  UR                  SR                  W5      S.T R                  [        T R                  5      SS9D6nT R                  (       a  T R                  U5        Sn SnAGN¥UeUn SnAGN¯SnAf[         a0  nT R                  (       a  T R                  U5        Sn SnAGNæe SnAff = f)a'  
Parses the latex content given to the constructor (and stored in `self.s`)
into a list of nodes.

Returns a tuple `(nodelist, pos, len)` where:

  - `nodelist` is a list of :py:class:`LatexNode`\ 's representing the
    parsed LaTeX code.

  - `pos` is the same as the `pos` given as argument; if there is
    leading whitespace it is reported in `nodelist` using a
    :py:class:`LatexCharsNode`.

  - `len` is the length of the parsed expression.  If one of the
    `stop_upon_...=` arguments are provided (cf below), then the `len`
    includes the length of the token/expression that stopped the
    parsing.

If `stop_upon_closing_brace` is given and set to a character, then
parsing stops once the given closing brace is encountered (but not
inside a subgroup).  The brace is given as a character, ']', '}', ')',
or '>'.  Alternatively you may specify a 2-item tuple of two single
distinct characters representing the opening and closing brace chars.
The returned `len` includes the closing brace, but the closing brace is
not included in any of the nodes in the `nodelist`.

If `stop_upon_end_environment` is provided, then parsing stops once the
given environment was closed.  If there is an environment mismatch, then
a `LatexWalkerParseError` is raised except in tolerant parsing mode (see
:py:meth:`parse_flags()`).  Again, the closing environment is included
in the length count but not the nodes.

If `stop_upon_closing_mathmode` is specified, then the parsing stops
once the corresponding math mode (assumed already open) is closed.  This
argument may take the values `None` (no particular request to stop at
any math mode token), or one of ``$``, ``$$``, ``\)`` or ``\]``
indicating a closing math mode delimiter that we are expecting and at
which point parsing should stop.

If the token '$' (respectively '$$') is encountered, it is interpreted
as the *beginning* of a new math mode chunk *unless* the argument
`stop_upon_closing_mathmode=...` has been set to '$' (respectively
'$$').

If `read_max_nodes` is non-`None`, then it should be set to an integer
specifying the maximum number of top-level nodes to read before
returning.  (Top-level nodes means that macro arguments, environment or
group contents, etc., do not count towards `read_max_nodes`.)  If
`None`, the entire input string will be parsed.

.. note::

   There are a few important differences between
   ``get_latex_nodes(read_max_nodes=1)`` and ``get_latex_expression()``:
   The former reads a logical node of the LaTeX document, which can be a
   sequence of characters, a macro invocation with arguments, or an
   entire environment, but the latter reads a single LaTeX "token" in
   a similar way to how LaTeX parses macro arguments.

   For instance, if a macro is encountered, then
   ``get_latex_nodes(read_max_nodes=1)`` will read and parse its
   arguments, and include it in the corresponding
   :py:class:`LatexMacroNode`, whereas ``get_latex_expression()`` will
   return a minimal :py:class:`LatexMacroNode` with no arguments
   regardless of the macro's argument specification.  The same holds for
   latex specials.  For environments,
   ``get_latex_nodes(read_max_nodes=1)`` will return the entire parsed
   environment into a :py:class:`LatexEnvironmentNode`, whereas
   ``get_latex_expression()`` will return a :py:class:`LatexMacroNode`
   named 'begin' with no arguments.

Parsing might be influenced by the `parsing_state`.  See doc for
:py:class:`ParsingState`.  If `parsing_state` is `None`, the default
parsing state is used.

.. versionadded:: 2.0

   The `parsing_state` argument was introduced in version 2.0.
NrÙ   rØ   r[  rZ  rˆ   rÆ   r­  r¬  r   zlCall to LatexWalker.get_latex_nodes(stop_upon_closing_mathmode={!r}) but parsing state has in_math_mode={!r}c                   ó*   • \ rS rSrSS jrS rS rSrg)Ú/LatexWalker.get_latex_nodes.<locals>.PosPointeriã  Nc                 ó4   • Xl         X l        X0l        X@l        g r	   )r.   rª   Ú	lastcharsÚlastchars_pos)r5   r.   rª   rÖ  r×  s        r   r3   Ú8LatexWalker.get_latex_nodes.<locals>.PosPointer.__init__ä  s   € Ø”Ø%2Ô"Ø!*”Ø%2Õ"r   c                 óV   • U =R                   U-  sl         U R                  c  Xl        g g r	   )rÖ  r×  )r5   r.   rÍ   s      r   Úpush_lastcharsÚ>LatexWalker.get_latex_nodes.<locals>.PosPointer.push_lastcharsê  s'   € Ø—’ %Ñ'•Ø×%Ñ%Ñ-Ø),Õ&ð .r   c                 óR   • U R                   U R                  4nSU l        S U l         U$ )Nr9   )r×  rÖ  )r5   Úress     r   Úflush_lastcharsÚ?LatexWalker.get_latex_nodes.<locals>.PosPointer.flush_lastcharsï  s*   € Ø×(Ñ(¨$¯.©.Ð8�Ø!#�”Ø%)�Ô"Ø�
r   )rÖ  r×  rª   r.   )r9   N)r!   r"   r#   r$   r3   rÚ  rÞ  r&   r
   r   r   Ú
PosPointerrÔ  ã  s   † ô3ò-õ
r   rà  )r.   rª   c                 ó�  >•  T$R                  UR                  T"UR                  S9nUR                  UR                  -   Ul        UR                  S:X  aH  UR                  UR                  [        UR                  5      -
  UR                  UR                  -   S9  g[        UR                  5      (       a…  UR                  5       u  pET$R                  [        UR                  XRR                  -   XBR                  U-
  S9nU R                  U5        T#(       a!  [        U 5      T#:¼  a  UR                  Ul        gO±[        UR                  5      (       a—  T$R                  [        UR                  UR                  UR                  [        UR                  5      -
  [        UR                  5      S9nU R                  U5        T#(       a!  [        U 5      T#:¼  a  UR                  Ul        gUR                  S:X  aY  UR                  T%:w  aH  [        S3T$R                   UR                  S	UR                  -  S
.T$R#                  UR                  SS9D6egUR                  S:X  aÁ  T'(       dT  [        S3T$R                   UR                  SR%                  UR                  5      S
.T$R#                  UR                  SS9D6eUR                  T':w  aU  [        S3T$R                   UR                  SR%                  UR                  T'5      S
.T$R#                  UR                  SS9D6egUR                  S;   Gaè  T&b‰  UR                  T&:X  a  gUR                  S;   aU  [        S3T$R                   UR                  SR%                  UR                  T&5      S
.T$R#                  UR                  SS9D6eUR                  S;   d   eOdUR                  S;   aT  [        S3T$R                   UR                  SR%                  UR                  5      S
.T$R#                  UR                  SS9D6eSSS.R'                  UR                  UR                  5      nUR                  S;   a  SOSn	UR                  R)                  SUR                  S9n
 T$R+                  UR                  UU
S9u  p¼nXÍ-   Ul        U R                  T$R                  [0        UR                  U	UUR                  U4UR                  XÍ-   UR                  -
  S95        T#(       a  [        U 5      T#:¼  a  ggUR                  S:X  as  T$R                  [2        UR                  UR                  UR4                  UR                  UR                  S9nU R                  U5        T#(       a  [        U 5      T#:¼  a  ggUR                  S :X  ag   T$R7                  UR                  UR                  UR                  S!9u  nnnUU-   Ul        U R                  U5        T#(       a  [        U 5      T#:¼  a  ggUR                  S#:X  ag   T$R9                  UR                  UR                  UR                  S$9u  nnnUU-   Ul        U R                  U5        T#(       a  [        U 5      T#:¼  a  ggUR                  S&:X  Gap  UR                  nUR                  R:                  R=                  U5      nUc  [>        R@                  " S'5      n URC                  T$UR                  UR                  -   UR                  S(9n[        U5      S+:X  a  Uu  nnnnOUu  nnn0 nUU-   Ul        Ub0  URF                  (       a  URF                  S*   nURF                  S,   nOS/ nnT$R                  [H        UR                  UR                  UUR4                  UUUR                  UR                  UR                  -
  S-9	nU R                  U5        S.U;   a
  US.   Ul        T#(       a  [        U 5      T#:¼  a  ggUR                  S/:X  Ga  UR                  nUR                  UR                  -   Ul        Sn URC                  T$UR                  UR                  S(9n U b*  [        U 5      S+:X  a  U u  nnnn!OU u  nnn0 n!UU-   Ul        O0 n!T$R                  [L        UR                  URJ                  UUR                  UR                  UR                  -
  S19nU R                  U5        S.U!;   a
  U!S.   Ul        T#(       a  [        U 5      T#:¼  a  gg[        S3T$R                   UR                  S2R%                  U5      S
.T$R#                  UR                  SS9D6e! [         a  nT$R                  (       a  Us SnA$ e SnAf[
         a  nT$R                  (       a   ee SnAff = f! [
         ah  nUR,                  R                  [/        SR%                  UR                  5      UR                  /T$R#                  UR                  5      Q76 5        e SnAff = f! [
         aO  nUR,                  R                  [/        S"UR                  /T$R#                  UR                  5      Q76 5        e SnAff = f! [
         ah  nUR,                  R                  [/        S%R%                  UR                  5      UR                  /T$R#                  UR                  5      Q76 5        e SnAff = f! [        [
        4 aO  nT$RE                  UUS)R%                  U5      5      nUb  UeSUR                  UR                  -   S*0 4n SnAGNASnAff = f! [        [
        4 aL  nT$RE                  UUS0R%                  URJ                  5      5      nUb  UeSUR                  S*0 4n  SnAGNJSnAff = f)4aM  
Read a single token and process it, recursing into brace blocks and
environments etc if needed, and appending stuff to nodelist.

Return True whenever we should stop trying to read more. (e.g. upon
reaching the a matched stop_upon_end_environment etc.)  Can return
an exception instance to give more information than simply `True`.
r®  Nr`  ©r.   rÍ   FrŸ  Trt  z*Unexpected mismatching closing brace: '%s'r]  r^  rn  z$Unexpected closing environment: '{}'zDUnexpected mismatching closing environment: '{}', was expecting '{}'r¢  )ú\)ú\]z2Mismatching closing math mode: '{}', expected '{}')rv  ru  ú\(ú\[z"Unexpected closing math mode: '{}'rã  rä  )rå  ræ  )rå  rv  ÚinlineÚdisplayr»  )Ústop_upon_closing_mathmoderª   zmath mode "{}")rª   r  rÚ   rÖ   r.   rw   rz   )rª   rz   râ   r.   rw   rs  r§  z
open bracerm  )r÷   rª   zbegin environment "{}"ry   r9   r·  zarguments of macro "{}"r   r¹  rV   r   Únew_parsing_staterZ   zarguments of specials "{}"r¡  zUnknown token: {!r}r
   )'r�  r.   rª   rN   r@  r(   rw   ru   rÚ  rx   rv   rÖ  rÞ  r•  rÊ   r}   r-   ra  r=   rÁ  r*  r°  r1   r   r  rà   r{   r¤  rÎ  r   Úget_macro_specr   Ú	MacroSpecr¿  rÀ  rÃ  rè   rÿ   rý   )(rÚ   r)  ru   rc  ÚcharsposrÍ   ÚstrnodeÚspacestrnodeÚcorresponding_closing_mathmoder  rË  Úmathinline_nodelistÚmposr‰  ÚcommentnodeÚ	groupnodeÚbposÚblenÚenvnodeÚeposÚelenre   ÚmspecÚmargsresultrê   ÚmaposÚmalenÚmdicrì   rí   r”  rŽ  rÝ  Úspdicr„  Úread_max_nodesr5   r¯  ré  r¼  s(                                     €€€€€€r   Údo_readÚ,LatexWalker.get_latex_nodes.<locals>.do_read÷  sÖ
  ø€ ðØ—n‘n Q§U¡UÐ@SØ34·?±?ð %ð D�ð —G‘G˜cŸg™gÑ%ˆAŒEð �w‰w˜&Ó Ø× Ñ  c§g¡g´°C·M±MÓ0BÑ&BØ(+¯©¸¿¹Ñ(?ð !ñ Bàô �1—;‘;×ÑØ"#×"3Ñ"3Ó"5‘�ØŸ.™.¬Ø78·±Ø/4·]±]Ñ/BØ-5¿7¹7ÀXÑ;Mð )ð O�ð —‘ Ô(Þ!¤c¨(£m°~Ó&EàŸG™G�A”EØøÜ�S—]‘]×#Ñ#ð  $Ÿ~™~¬nØ<=¿O¹OØ47·M±MØ25·'±'¼#¸c¿m¹mÓ:LÑ2LÜ25°c·m±mÓ2Dð	  .ð  F�ð
 —‘ Ô-Þ!¤c¨(£m°~Ó&EàŸG™G�A”EØð �w‰w˜-Ó'à—7‘7Ð5Ó5ä/ð ØŸ&™&ØŸG™GØHÈ#Ï'É'ÑRñð ×2Ñ2°3·7±7ÀDÐ2ÐIñ	ð ð à�w‰wÐ+Ó+æ0ä/ð ØŸ&™&ØŸG™GØC×JÑJÈ3Ï7É7ÓSñð ×2Ñ2°3·7±7ÀDÐ2ÐIñ	ð ð —W‘WÐ 9Ó9ä/ð ØŸ&™&ØŸG™Gð2ß28±&¸¿¹ÐB[Ó2\ñ	ð
 ×2Ñ2°3·7±7ÀDÐ2ÐIñð ð à�w‰wÐAÔAà-Ñ9Ø—w‘wÐ"<Ó<à#Ø—w‘w .Ó0ô 4ð Ø"Ÿf™fØ #§¡Ø T× [Ñ [Ø #§¡Ð)Có!ñð #×6Ñ6°s·w±wÈÐ6ÐMñð ð Ÿ7™7Ð&?Ó?Ð?Ñ?Ø—W‘W Ó.ô
 0ð ØŸ&™&ØŸG™GØ@×GÑGÈÏÉÓPñð ×2Ñ2°3·7±7ÀDÐ2ÐIñ	ð ð "¨%Ñ0×4Ñ4°S·W±W¸c¿g¹gÓFð /à*-¯'©'°\Ó*A™hÀy�à&'§o¡o×&AÑ&AØ!%Ø(+¯©ð 'Bð 'Ð#ð
	Ø8<×8LÑ8LØŸ™Ø3QØ&9ð 9Mð 9Ñ5Ð(°ð ™�”à—‘ §¡Ü!Ø"#§/¡/Ø +Ø0Ø #§¡Ð)GÐHØŸ™ T¡Y¨s¯w©wÑ%6ð !/ð !ô ö "¤c¨(£m°~Ó&EØØà�w‰w˜)Ó#Ø"Ÿn™nÔ-=Ø;<¿?¹?Ø58·W±WØ@CÇÁØ14·±¸c¿g¹gð	 -ð G�ð
 —‘ Ô,Þ!¤c¨(£m°~Ó&EØØà�w‰w˜,Ó&ðØ.2×.IÑ.IØŸ™Ø#&§7¡7Ø&'§o¡oð /Jð /Ñ+�Y  dð ˜t™�”Ø—‘ 	Ô*Þ!¤c¨(£m°~Ó&EØØà�w‰wÐ-Ó-ðØ,0×,FÑ,FØŸ™Ø(+¯©Ø&'§o¡oð -Gð -Ñ)�W˜d Dð ˜t™�”à—‘ Ô(Þ!¤c¨(£m°~Ó&EØØà�w‰w˜'Ô!àŸG™G�	ØŸ™×5Ñ5×DÑDÀYÓO�Ø‘=Ü%×/Ò/°Ó3�EðCà×(Ñ(¨4°S·W±W¸s¿w¹wÑ5FØ78·±ð )ð Hð  ô �{Ó# qÓ(Ø5@Ñ2�X˜u e©Tà/:Ñ,�X˜u eØ�Dà ™�”àÑ'¨H×,O×,OØ!)×!DÑ!DÀQÑ!G�JØ'×BÑBÀ1ÑE‘Hà+/° �JØ—~‘~¤nØ45·O±OØ03·±Ø/7Ø7:·~±~à1;Ø/7Ø*-¯'©'Ø*+¯%©%°·±©-ð &ð 	9�ð —‘ Ô%à&¨$Ó.à&*Ð+>Ñ&?�A”Oæ!¤c¨(£m°~Ó&EØØà�w‰w˜*Ô$àŸ™�àŸ™ #§'¡'Ñ)�”Ø�ð	/Ø×*Ñ*¨T°q·u±uÈAÏOÉOÐ*Ð\�Cð ‘?ä˜3“x 1“}Ø:=Ñ7˜ 5¨%±à36Ñ0˜ 5¨%Ø "˜à! E™M�A•Eð �Eà—~‘~Ô&7Ø45·O±OØ5:×5IÑ5IØ/7Ø*-¯'©'Ø*+¯%©%°·±©-ð &ð 9�ð —‘ Ô%à&¨%Ó/à&+Ð,?Ñ&@�A”Oæ!¤c¨(£m°~Ó&EØØô (ð Ø—&‘&Ø—E‘EØ)×0Ñ0°Ó5ñð ×*Ñ*¨1¯5©5¸$Ð*Ð?ñ	ð øôq	 *ó Ø×(×(Ø•HØûÜ(ó ð  ×0×0Ð1Ð0Øûð	ûôP -ó Ø—O‘O×*Ñ*¬JÐ7G×7NÑ7NÈsÏwÉwÓ7WÐY\×Y`ÑY`ð -[Ø8<×8PÑ8PÐQT×QXÑQXÓ8Yò-[ô ]àûðûôN -ó Ø—O‘O×*Ñ*¬J°|ÀSÇWÁWð -[Ø8<×8PÑ8PÐQT×QXÑQXÓ8Yò-[ô ]àûðûô& -ó Ø—O‘O×*Ñ*Ü"Ð#;×#BÑ#BÀ3Ç7Á7Ó#KÈSÏWÉWð GØ$(×$<Ñ$<¸S¿W¹WÓ$EòGôð ûðûô0 /Ô0EÐFó CØ×;Ñ;ØØØ3×:Ñ:¸9ÓEó�Að
 ‘}¨A gØ#'¨¯©°3·7±7Ñ):¸A¸rÐ"B–KûðCûôf /Ô0EÐFó /Ø×;Ñ;ØØØ6×=Ñ=¸e×>RÑ>RÓSó�Að
 ‘}¨A gØ §¡¨¨2Ð.–Cûð/ús¬   ƒ%e5 Òg Ö53h6 Ø,3j Û.2l á%m) å5
f>å?fæf>æfæf>æ%f9æ9f>ç
h3çA#h.è.h3è6
jé A
j
ê
jê
lêA#k?ë?lìm&ìAm!í!m&í)oí9Ao ï oTÚ'z\end{z*Unexpected end of stream, was expecting {}r]  r^  Frâ  rŸ  r
   )rM  rw   r!  r6  r7  r=   rN   r(   r-   r.   ra  r@  rU  r³   rÚ  rQ   rÖ  rÞ  r•  rÊ   rª   r}   )r5   r.   r¯  r¼  ré  r   rª   rÚ   Ú)opening_brace_for_stop_upon_closing_braceÚorigposrà  r)  r  Úr_endnowrc  Ú	expectingrí  rÍ   rî  r„  s   ` ````             @r   r°  ÚLatexWalker.get_latex_nodese  s¾  ý€ ðh Ñ Ø ×3Ñ3Ó5ˆMàˆà"ÐØ48Ð1Þ"Ø&¨#Ó-Ø<?Ñ9Ø(¨CÓ/Ø<?Ñ9Ø(¨CÓ/Ø<?Ñ9Ø(¨CÓ/Ø<?Ñ9ÜÐ,Ó-°Ó2à+ñ SÐ9Ð;Rð '¨#Ó-à>Ð@WÐXð'Ð#ð
 &Ñ1¸-×:T×:TÜ�N‰Nð;ß<B¹FØ/Ø"×/Ñ/ó=ôð ˆ÷	ñ 	ñ$ ˜3Ñ<ˆ÷J	ò J	ð\
 ð á" 8Ó/�ö@ ô ˜hÔ(>×?Ñ?Ø×$Ñ$¨¯©Ø+3×+?Ñ+?ð %ñ Aà—E’EœS ×!5Ñ!5Ó6Ñ6•Eà—;—;Ø&'×&7Ñ&7Ó&9‘O�H˜eØ"Ÿn™n¬^Ø;<¿?¹?Ø38Ø19¼sÀ5»zð -ð K�Gð —O‘O GÔ,Ø ¨1¯5©5°7©?Ð;Ð;ñe øô *ó !Þ*Ö.GÞ0æ.Ø$'Ð(?Ñ$?ÀÑ$C™	Þ2Ø$,Ð-FÑ$FÀsÑ$J™	Þ3Ø$'Ð(BÑ$BÀ3Ñ$F˜	Ü-ð ØŸ&™&ØŸE™EØHß#™V IÓ.ñ	ð
 ×2Ñ2´3°t·v±v³;ÈÐ2ÐMñ�Að ×,×,Ø×7Ñ7¸Ô:Ø#'žà˜à –HûÜ(ó Ø×(×(Ø×3Ñ3°AÔ6Ø$–Hàûðús1   ÃF. Æ.
K Æ8B;JÉ9JÊK Ê$J;Ê:J;Ê;K )rC  rD  rH  r-   rA  r@  r	   )NTNN)Fr  )rØ   N)r   NNNNN)r!   r"   r#   r$   r%   r3   rM  rP  rU  r�  r•  r™  ra  r£  r©  r¤  rÎ  rÀ  r°  r&   rK   rL   s   @r   r;  r;  "  s�   ø† ñP÷dF,òR@ò"
ò"Mð EIØ7;ôcSòLò6
ôLô,d?ôN"ôJEDôPg:òT"ðJ >BØ26ØHLØ&*÷R<ò R<r   r;  c                 ó8   • [        U 40 UD6R                  UUUS9$ )zÇ
Parse the next token in the stream.

Returns a `LatexToken`. Raises `LatexWalkerEndOfStream` if end of stream reached.

.. deprecated:: 1.0
   Please use :py:meth:`LatexWalker.get_token()` instead.
)r.   rX  rY   )r;  r�  )r-   r.   rX  rY   rP  s        r   r�  r�  Ÿ	  s0   € ô �qÑ(˜KÑ(×2Ñ2°sØFXØ@Lð 3ð Nð Nr   c                 ó4   • [        U 40 UD6R                  US9$ )aT  
Reads a latex expression, e.g. macro argument. This may be a single char, an escape
sequence, or a expression placed in braces.

Returns a tuple `(<LatexNode instance>, pos, len)`. `pos` is the first char of the
expression, and `len` is its length.

.. deprecated:: 1.0
   Please use :py:meth:`LatexWalker.get_latex_expression()` instead.
©r.   )r;  r£  ©r-   r.   rP  s      r   r£  r£  ­	  s"   € ô �qÑ(˜KÑ(×=Ñ=À#Ð=ÐFÐFr   c                 ó4   • [        U 40 UD6R                  US9$ )z×
Attempts to parse an optional argument. Returns a tuple `(groupnode, pos, len)` if
success, otherwise returns None.

.. deprecated:: 1.0
   Please use :py:meth:`LatexWalker.get_latex_maybe_optional_arg()` instead.
r  )r;  r©  r  s      r   r©  r©  ¼	  s"   € ô �qÑ(˜KÑ(×EÑEÈ#ÐEÐNÐNr   c                 ó4   • [        U 40 UD6R                  XS9$ )ap  
Reads a latex expression enclosed in braces {...}. The first token of `s[pos:]` must
be an opening brace.

Returns a tuple `(node, pos, len)`. `pos` is the first char of the
expression (which has to be an opening brace), and `len` is its length,
including the closing brace.

.. deprecated:: 1.0
   Please use :py:meth:`LatexWalker.get_latex_braced_group()` instead.
)r.   r¨  )r;  r¤  )r-   r.   r¨  rP  s       r   r¤  r¤  È	  s"   € ô �qÑ(˜KÑ(×?Ñ?ÀCÐ?Ð_Ð_r   c                 ó6   • [        U 40 UD6R                  UUS9$ )aA  
Reads a latex expression enclosed in a \begin{environment}...\end{environment}. The first
token in the stream must be the \begin{environment}.

Returns a tuple (node, pos, len) with node being a :py:class:`LatexEnvironmentNode`.

.. deprecated:: 1.0
   Please use :py:meth:`LatexWalker.get_latex_environment()` instead.
)r.   r÷   )r;  rÎ  )r-   r.   r÷   rP  s       r   rÎ  rÎ  Ø	  s-   € ô �qÑ(˜KÑ(×>Ñ>À3ØO^ð ?ð `ð `r   c                 ó8   • [        U 40 UD6R                  UUUS9$ )a`  
Parses latex content `s`.

Returns a tuple `(nodelist, pos, len)` where nodelist is a list of `LatexNode` 's.

If `stop_upon_closing_brace` is given, then `len` includes the closing brace, but the
closing brace is not included in any of the nodes in the `nodelist`.

.. deprecated:: 1.0
   Please use :py:meth:`LatexWalker.get_latex_nodes()` instead.
)r¯  r¼  ré  )r;  r°  )r-   r.   r¯  r¼  ré  rP  s         r   r°  r°  æ	  s/   € ô �qÑ(˜KÑ(×8Ñ8Ø 7Ø";Ø#=ð 9ð ð r   c                 ó„  • S nSnU  GH3  nUc  M	  UR                  [        5      (       a  X#R                  -  nM3  UR                  [        5      (       a5  USUR                  < UR
                  < U" UR                  5      < 3-  nM‚  UR                  [        5      (       a&  X#R                  < U" UR                  5      < 3-  nMÂ  UR                  [        5      (       a!  USUR                  -   UR                  -   -  nMý  UR                  [        5      (       a:  X#R                  S   [        UR                  5      -   UR                  S   -   -  nGMQ  UR                  [         5      (       aT  USUR"                  < SU" UR                  5      < 3-  nU[        UR                  5      -  nUS	UR"                  -  -  nGM¿  UR                  [$        5      (       a:  X#R                  S   [        UR                  5      -   UR                  S   -   -  nGM  US
UR'                  5       R(                  -  -  nGM6     U$ )Nc                 óf  • U b  U R                   b  U R                  c  gSn[        U R                   U R                  5       Hl  u  p#US:X  a  Ub  U[        U/5      -  nM  M!  US:X  a  Ub  U[        U/5      -  nM;  M=  US:X  a  U[        U/5      -  nMT  [	        SR                  U5      5      e   U$ )Nr9   Ú*rZ  rØ   zUnknown argument type: {!r})ÚargspecÚargnlistr‚  Únodelist_to_latexr1  r=   )rê   Ú	argslatexÚargtÚargns       r   Úadd_argsÚ#nodelist_to_latex.<locals>.add_args
  sÈ   € ØÑ˜x×/Ñ/Ñ7¸8×;LÑ;LÑ;TØØˆ	Ü˜h×.Ñ.°×0AÑ0AÖB‰JˆDØ�s‹{ØÑ#ØÔ!2°D°6Ó!:Ñ:’Iñ $à˜“ØÑ#àÔ!2°D°6Ó!:Ñ:’Iñ $ð ˜“àÔ.°¨vÓ6Ñ6’	ä Ð!>×!EÑ!EÀdÓ!KÓLÐLñ Cð Ðr   r9   rh  ro  r   rV   z\begin{rÙ   z\end{%s}z<[UNKNOWN LATEX NODE: '%s']>)rµ   rÊ   rÍ   rè   re   rë   rê   rý   rÿ   rà   rz   râ   rÔ   rÖ   r  rÚ   rô   rø   r  r°   r!   )rÚ   r  ÚlatexÚns       r   r  r  

  sÌ  € òð& €EÜˆØ‰9ÙØ�<‰<œ×'Ñ'Ø—W‘WÑˆEÙà�<‰<œ×'Ñ'Ù !§+£+¨q×/AÓ/AÁ8ÈAÏJÉJÕCWÐXÑXˆEÙà�<‰<Ô)×*Ñ*Ø×/Ó/±¸!¿*¹*Õ1EÐFÑFˆEÙà�<‰<Ô(×)Ñ)Ø�S˜Ÿ™‘] 1×#7Ñ#7Ñ7Ñ7ˆEÙà�<‰<œ×'Ñ'Ø—\‘\ !‘_Ô'8¸¿¹Ó'DÑDÀqÇ|Á|ÐTUÁÑVÑVˆEÚà�<‰<Ô,×-Ñ-Ù q§y¤y±(¸1¿:¹:Õ2FÐGÑGˆEØÔ& q§z¡zÓ2Ñ2ˆEØ�[ 1§9¡9Ñ-Ñ-ˆEÚà�<‰<œ×&Ñ&Ø—\‘\ !‘_Ô'8¸¿¹Ó'DÑDÀqÇ|Á|ÐTUÁÑVÑVˆEÚàÐ1°1·:±:³<×3HÑ3HÑIÑI‹ñC ðF €Lr   c                 óh   • U S:X  a  SU-  $ U S:X  a  SU-  $ U S:X  a  SU-  $ U S:X  a  SU-  $ X-   U -   $ )	NrØ   z{%s}rZ  z[%s]rÆ   z(%s)r¬  z<%s>r
   )Ú
brace_charÚ	thestrings     r   Úput_in_bracesr!  P
  s\   € à�cÓØ˜	Ñ"Ð"Ø�cÓØ˜	Ñ"Ð"Ø�cÓØ˜	Ñ"Ð"Ø�cÓØ˜	Ñ"Ð"àÑ! JÑ.Ð.r   c           	      ó  ^ ^
• SnSn/ m
U
U 4S jnT c  SnGOT R                  [        5      (       a  [        T R                  5      nGOÚT R                  [        5      (       a  ST R
                  -   nU" 5         GO¨T R                  [        5      (       a  T R                  S-   nU" 5         GOvT R                  [        5      (       a  ST R                  R                  5       -   nGO=T R                  [        5      (       aF  U(       a  T R                   H  n[        XqUS9  M     g SnT
R                  S	T R                  S
45        OÝT R                  [         5      (       a5  ST R"                  -  nU" 5         T
R                  S	T R                  S
45        OŽT R                  [$        5      (       aN  T R&                  S   T R(                  -   S-   T R&                  S   -   nT
R                  S	T R                  S
45        O&[+        ST R-                  5       R.                  -  5        [+        SU-  U-   U-   S-   U-   5        T
 HJ  u  p(n	[1        U[2        5      (       a  [+        SUS-   -  U-   U-   5        M4  U H  n[        XqS-   X)S9  M     ML     g )Nr9   c                  ó~  >• TR                   c  g TR                   R                  b  TR                   R                  c  TR                  S5        g [	        TR                   R                  TR                   R                  5       H6  u  pU S:X  a  SnOU S:X  a  SnOU S:X  a  SnOSnTR                  X!/S	45        M8     g )
N)z<args> z<cannot be displayed>NrZ  z[.]: rØ   z{.}: r  z<*>:   z<unknown>: F)rê   r  r  r}   r‚  )r  r  r´   Úiterchildrenr  s      €€r   r  Údisp_node.<locals>.add_argse
  s§   ø€ Ø�:‰:ÑàØ�Z‰Z×ÑÑ'¨1¯:©:×+>Ñ+>Ñ+FØ×ÑÐ JÔKØÜ˜aŸj™j×0Ñ0°!·*±*×2EÑ2EÖF‰JˆDØ�s‹{Ø‘Ø˜“Ø‘Ø˜“Ø‘à!�Ø×Ñ  F¨EÐ 2Ö3ò Gr   z<None>rh  z (specials)ro  )ÚindentrA   zGroup: ú* Fz
\begin{%s}r   z mathrV   zUNKNOWN NODE TYPE: %sÚ z  r¹  )r&  rA   Ú
skip_group)rµ   rÊ   ÚreprrÍ   rè   re   rý   rÿ   rà   rz   ÚstriprÔ   rv   Ú	disp_noder}   rÚ   rô   r÷   r  rÖ   r  Úprintr°   r!   r³   Ú_basestring)r  r&  rA   r)  Útitlerz   r  ÚnnrÚ   Úskipr$  s   `         @r   r,  r,  _
  s  ù€ à€EØ€GØ€Lö4ð$ 	�yØŠØ	
�‰”n×	%Ñ	%Ü�Q—W‘W“ŠØ	
�‰”n×	%Ñ	%Ø�Q—[‘[Ñ ˆÙŽ
Ø	
�‰Ô'×	(Ñ	(Ø× Ñ  =Ñ0ˆÙŽ
Ø	
�‰Ô&×	'Ñ	'Ø�a—i‘i—o‘oÓ'Ñ'ŠØ	
�‰”n×	%Ñ	%ÞØ—e”e�Ü˜"°WÔ=ñ àØˆØ×Ñ˜T 1§:¡:¨uÐ5Õ6Ø	
�‰Ô*×	+Ñ	+Ø × 1Ñ 1Ñ2ˆÙŒ
Ø×Ñ˜T 1§:¡:¨uÐ5Õ6Ø	
�‰”m×	$Ñ	$Ø—‘˜Q‘ §¡Ñ-¨gÑ5°a·l±lÀ1±oÑEˆØ×Ñ˜T 1§:¡:¨uÐ5Õ6äÐ% q§z¡z£|×'<Ñ'<Ñ=Ô>ä	ˆ#ˆf‰*�wÑ
 Ñ
&¨Ñ
-¨gÑ
5Ô6ã#/Ñˆ˜4Ü�h¤×,Ñ,Ü�#�v˜a‘x‘. 7Ñ*¨XÑ5Ô6ÙÛˆBÜ�b¨¡°7ÔLó ò	 $0r   c                 óD   ^ ^•  " UU 4S jS[         R                  5      mT$ )Nc                   ó@   >^ • \ rS rSrSrUU 4S jrUU U4S jrSrU =r$ )Ú0make_json_encoder.<locals>.LatexNodesJSONEncoderi¢
  z`
A :py:class:`json.JSONEncoder` that can encode :py:class:`LatexNode` objects
(and subclasses).
c                 ó&   >• [         TU ]  " U0 UD6  g r	   )r2   r3   )r5   r   r­   ÚLatexNodesJSONEncoderr6   s      €€r   r3   Ú9make_json_encoder.<locals>.LatexNodesJSONEncoder.__init__©
  s   ø€ ÜÐ'¨Ò7¸ÐHÀÓHr   c                 ó|  >• [        U[        5      (       ai  UnSUR                  R                  0nUR                   H  nUR
                  U   X4'   M     UR                  TR                  UR                  SS95        U$ [        U[        R                  5      (       a  UR                  5       $ [        TU ]7  U5      $ )NÚnodetypeTr^  )r³   r¨   r6   r!   r|   Ú__dict__Úupdatera  r.   r   rï   Úto_json_objectr2   Údefault)r5   r  r  ÚdÚfldr6  r6   Úlatexwalkers        €€€r   r=  Ú8make_json_encoder.<locals>.LatexNodesJSONEncoder.default¬
  s¦   ø€ Ü˜#œy×)Ñ)à�à §¡× 4Ñ 4ð�ð Ÿ9œ9�CØŸZ™Z¨™_�A“Fñ %à—‘˜×8Ñ8¸¿¹ÈÐ8ÐMÔNØ�ä˜#œy×8Ñ8×9Ñ9Ø×)Ñ)Ó+Ð+ô Ð.°Ñ=¸cÓBÐBr   r
   )	r!   r"   r#   r$   r%   r3   r=  r&   rK   )r6   r6  r@  s   @€€r   r6  r4  ¢
  s   ù† ñ	ö
	I÷	Cõ 	Cr   r6  )ÚjsonÚJSONEncoder)r@  Úuse_line_numbersr6  s   ` @r   Úmake_json_encoderrE   
  s%   ù€ ÷Cð C¤× 0Ñ 0ô Cð< !Ð r   )TT)rØ   r	   )r   NNN)r   r'  Fr9  )7r%   Ú
__future__r   r   r{  ÚsysÚloggingrB  Ú
pylatexencr9   r   r   Úversion_infoÚmajorr   Ústrr.  Ú_str_from_unicoder�   Ú
basestringÚ	getLoggerr!   r6  r   Ú	Exceptionr   r(   rN   ra   rl   ÚLazyDictÚdefault_macro_dictÚobjectrr   r¨   rÊ   rÔ   rà   rè   rô   rý   r  r  r  r;  r�  r£  r©  r¤  rÎ  r°  r  r!  r,  rE  r
   r   r   Ú<module>rT     s®  ðñ4>÷@ 8ã 	Û 
Û Û ã Ý Ý à×Ñ×Ñ˜AÓâ&Ø€KÙ#ÐÙ#Ñð €KÙ<ÐÙ3Ðà	×	Ò	˜8Ó	$€òô	�yô 	ô=Ð,ô =ôD'Ð-ô 'ò òP"ðJ —^’^ññÐ ðô0D�ô Dô^n�ô nôb�Yô ô&!�Yô !ôF �yô  ô8K�Yô Kô^K$˜9ô K$ôZ(!˜	ô (!ôZ)�Iô )ô^;˜ô ;ô&B�6ô BôVU<�&ô U<ôz+NòGò	Oô`ô `ð W[Ø/3ôòHAòL/ô<MõB !r   