ó
    ‰*£h#y  ã                   óî   • S r SSKr\R                  R                  S:”  a  S r\rS rS rO\	rS rS rS	S
K
JrJrJrJr   " S S\5      r " S S\5      r " S S\5      rS rS rS r " S S\5      rg)a"  
Provides classes and helper functions to describe a LaTeX context of known
macros and environments, specifying how they should be parsed by
:py:mod:`pylatexenc.latexwalker`.

.. versionadded:: 2.0

   The entire module :py:mod:`pylatexenc.macrospec` was introduced in
   `pylatexenc 2.0`.
é    Né   c                 ó   • U $ ©N© )Úss    ÚZ/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pylatexenc/macrospec/__init__.pyÚunicoder	   +   s   € ˜1�Hó    c                 ó   • U $ r   r   ©Úxs    r   Ú<lambda>r   -   ó   € ¡!r
   c                 ó   • U $ r   r   r   s    r   r   r   .   r   r
   c                 ó6   • [        U 5      R                  S5      $ ©Nzutf-8)r	   Úencoder   s    r   r   r   2   s   € ¤'¨!£*×"3Ñ"3°GÔ"<r
   c                 ó$   • U R                  S5      $ r   )Údecoder   s    r   r   r   3   s   €  !§(¡(¨7Ô"3r
   é   )ÚParsedMacroArgsÚMacroStandardArgsParserÚParsedVerbatimArgsÚVerbatimArgsParserc                   óH   ^ • \ rS rSrSr\" 5       4U 4S jjrS rS rSr	U =r
$ )Ú	MacroSpecé=   aM  
Stores the specification of a macro.

This stores the macro name and instructions on how to parse the macro
arguments.

.. py:attribute:: macroname

   The name of the macro, without the leading backslash.

.. py:attribute:: args_parser

   The parser instance that can understand this macro's arguments.  For
   standard LaTeX macros this is usually a
   :py:class:`MacroStandardArgsParser` instance.

   If you specify a string, then for convenience this is interpreted as an
   argspec argument for :py:class:`MacroStandardArgsParser` and such an
   instance is automatically created.
c                 ó’   >• [         [        U ]
  " S0 UD6  Xl        [	        U[
        5      (       a  [        U5      U l        g X l        g ©Nr   )Úsuperr   Ú__init__Ú	macronameÚ
isinstanceÚ_basestringr   Úargs_parser)Úselfr"   r%   ÚkwargsÚ	__class__s       €r   r!   ÚMacroSpec.__init__R   s:   ø€ ÜŒi˜Ò'Ñ1¨&Ò1Ø"ŒÜ�k¤;×/Ñ/Ü6°{ÓCˆDÕà*Õr
   c                 ó:   • U R                   R                  " U0 UD6$ ©zv
Shorthand for calling the :py:attr:`args_parser`\ 's `parse_args()` method.
See :py:class:`MacroStandardArgsParser`.
©r%   Ú
parse_args©r&   Úargsr'   s      r   r-   ÚMacroSpec.parse_argsZ   ó    € ð
 ×Ñ×*Ò*¨DÐ;°FÑ;Ð;r
   c                 ó@   • SU R                   < SU R                  < S3$ )NzMacroSpec(macroname=ú, args_parser=Ú))r"   r%   ©r&   s    r   Ú__repr__ÚMacroSpec.__repr__a   s   � Ø:>¿.¼.È$×JZÔJZÐ[Ð[r
   )r%   r"   ©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r!   r-   r6   Ú__static_attributes__Ú__classcell__©r(   s   @r   r   r   =   s'   ø† ññ( /FÓ.G÷ +ò<÷\ð \r
   r   c                   óJ   ^ • \ rS rSrSr\" 5       S4U 4S jjrS rS rSr	U =r
$ )ÚEnvironmentSpecéf   aà  
Stores the specification of a LaTeX environment.

This stores the environment name and instructions on how to parse any
arguments provided after ``\begin{environment}<args>``.

.. py:attribute:: environmentname

   The name of the environment, i.e., the argument of ``\begin{...}`` and
   ``\end{...}``.

.. py:attribute:: args_parser

   The parser instance that can understand this environment's arguments.
   For standard LaTeX environment this is usually a
   :py:class:`MacroStandardArgsParser` instance.

   If you specify a string, then for convenience this is interpreted as an
   argspec argument for :py:class:`MacroStandardArgsParser` and such an
   instance is automatically created.

.. py:attribute:: is_math_mode

   A boolean that indicates whether or not the contents is to be interpreted
   in Math Mode.  This would be True for environments like
   ``\begin{equation}``, ``\begin{align}``, etc., but False for
   ``\begin{figure}``, etc.

.. note::

   Starred variants of environments (as in ``\begin{equation*}``) must not
   be specified using an argspec as for macros (e.g., `argspec='*'`).
   Rather, we need to define a separate environment spec for the starred
   variant with the star in the name itself (``EnvironmentSpec('equation*',
   None)``) because the star really is part of the environment name.  If you
   happened to use ``EnvironmentSpec('equation', '*')``, then the parser
   would recognize the expression ``\begin{equation}*`` but not
   ``\begin{equation*}``.
Fc                 óž   >• [         [        U ]
  " S0 UD6  Xl        [	        U[
        5      (       a  [        U5      U l        OX l        X0l        g r   )	r    rB   r!   Úenvironmentnamer#   r$   r   r%   Úis_math_mode)r&   rE   r%   rF   r'   r(   s        €r   r!   ÚEnvironmentSpec.__init__Ž   sA   ø€ äŒo˜tÒ-Ñ7°Ò7Ø.ÔÜ�k¤;×/Ñ/Ü6°{ÓCˆDÕà*ÔØ(Õr
   c                 ó:   • U R                   R                  " U0 UD6$ r+   r,   r.   s      r   r-   ÚEnvironmentSpec.parse_args˜   r1   r
   c                 ó\   • SU R                   < SU R                  < SU R                  < S3$ )Nz EnvironmentSpec(environmentname=r3   z, is_math_mode=r4   )rE   r%   rF   r5   s    r   r6   ÚEnvironmentSpec.__repr__Ÿ   s%   � à× Ô  $×"2Ô"2°D×4EÔ4Eð
ð 	
r
   )r%   rE   rF   r8   r@   s   @r   rB   rB   f   s)   ø† ñ&ñN 5LÓ4MØ#÷)ò<÷
ð 
r
   rB   c                   ó>   ^ • \ rS rSrSr SU 4S jjrS rS rSrU =r	$ )ÚSpecialsSpecé¦   a?  
Specification of a LaTeX "special char sequence": an active char, a
ligature, or some other non-macro char sequence that has a special meaning.

For instance, '&', '~', and '``' are considered as "specials".

.. py:attribute:: specials_chars

   The string (one or several characters) that has a special meaning. E.g.,
   '&', '~', '``', etc.

.. py:attribute:: args_parser

   A parser (e.g. :py:class:`MacroStandardArgsParser`) that is invoked when
   the specials is encountered.  Can/should be set to `None` if the specials
   should not parse any arguments (e.g. '~').
c                 óF   >• [         [        U ]
  " S0 UD6  Xl        X l        g r   )r    rM   r!   Úspecials_charsr%   )r&   rP   r%   r'   r(   s       €r   r!   ÚSpecialsSpec.__init__¸   s#   ø€ ô 	Œl˜DÒ*Ñ4¨VÒ4Ø,ÔØ&Õr
   c                 óV   • U R                   c  gU R                   R                  " U0 UD6$ )zß
Basically a shorthand for calling the :py:attr:`args_parser`\ 's
`parse_args()` method.  See :py:class:`MacroStandardArgsParser`.

If however the py:attr:`args_parser` attribute is `None`, then this
method returns `None`.
Nr,   r.   s      r   r-   ÚSpecialsSpec.parse_args¿   s/   € ð ×ÑÑ#ØØ×Ñ×*Ò*¨DÐ;°FÑ;Ð;r
   c                 ó@   • SU R                   < SU R                  < S3$ )NzSpecialsSpec(specials_chars=r3   r4   )rP   r%   r5   s    r   r6   ÚSpecialsSpec.__repr__Ë   s   � à×Ô ×!1Ô!1ð
ð 	
r
   )r%   rP   r   )
r9   r:   r;   r<   r=   r!   r-   r6   r>   r?   r@   s   @r   rM   rM   ¦   s!   ø† ñð$ "÷'ò
<÷
ð 
r
   rM   c                 óä  • [        U [        5      (       a-  [        U5      S:w  a  [        S5      e[        U SS 5      nU S   n [        U [        5      (       a  [        U5      S:w  a  [        S5      eU $ [        U [
        5      (       a  [        U5      S:w  a  [        S5      eU $ [        U5      S:X  a  US   nOj[        U5      S:w  a  [        SR                  X5      5      eUS   (       d  [        US   [        5      (       a  US   nOS	nUS   (       a  S
nUSUS   -  -  nUR                  SS5      (       a$  [        U [        U5      UR                  SS5      S9$ [	        U [        U5      S9$ )aæ  
Return a macro specification for the given macro.  Syntax::

  spec = std_macro(macname, argspec)
  #  or
  spec = std_macro(macname, optarg, numargs)
  #  or
  spec = std_macro( (macname, argspec), )
  #  or
  spec = std_macro( (macname, optarg, numargs), )
  #  or
  spec = std_macro( spec ) # spec is already a `MacroSpec` -- no-op

- `macname` is the name of the macro, without the leading backslash.

- `argspec` is a string either characters "\*", "{" or "[", in which star
  indicates an optional asterisk character (e.g. starred macro variants),
  each curly brace specifies a mandatory argument and each square bracket
  specifies an optional argument in square brackets.  For example, "{{\*[{"
  expects two mandatory arguments, then an optional star, an optional
  argument in square brackets, and then another mandatory argument.

  `argspec` may also be `None`, which is the same as ``argspec=''``.

- `optarg` may be one of `True`, `False`, or `None`, corresponding to these
  possibilities:

  + if `True`, the macro expects as first argument an optional argument in
    square brackets. Then, `numargs` specifies the number of additional
    mandatory arguments to the command, given in usual curly braces (or
    simply as one TeX token like a single macro)

  + if `False`, the macro only expects a number of mandatory arguments given
    by `numargs`. The mandatory arguments are given in usual curly braces
    (or simply as one TeX token like a single macro)

  + if `None`, then `numargs` is a string like `argspec` above.  I.e.,
    ``std_macro(macname, None, argspec)`` is the same as
    ``std_macro(macname, argspec)``.

- `numargs`: depends on `optarg`, see above.

To make environment specifications (:py:class:`EnvironmentSpec`) instead of
a macro specification, use the function :py:func:`std_environment()`
instead.

The helper function :py:func:`std_environment()` is a shorthand for calling
this function with additional keyword arguments.  An optional keyword
argument `make_environment_spec=True` to the present function may be
specified to return an `EnvironmentSpec` instead of a `MacroSpec`.  In this
case, you can further specify the `environment_is_math_mode=True|False` to
specify whether of not the environment represents a math mode.
r   z=No positional arguments expected if first argument is a tupler   NzANo positional arguments expected if first argument is a MacroSpeczGNo positional arguments expected if first argument is a EnvironmentSpecr   z@Wrong number of arguments for std_macro, macname={!r}, args={!r}Ú Ú[Ú{Úmake_environment_specFÚenvironment_is_math_mode)r%   rF   ©r%   )
r#   ÚtupleÚlenÚ	TypeErrorr   rB   Úformatr$   Úgetr   )Úmacnamer/   r'   Úargspecs       r   Ú	std_macrord   Ô   sd  € ôn �'œ5×!Ñ!Üˆt‹9˜‹>ÜÐ[Ó\Ð\Ü�W˜Q˜R�[Ó!ˆØ˜!‘*ˆä�'œ9×%Ñ%Üˆt‹9˜‹>ÜÐ_Ó`Ð`Øˆä�'œ?×+Ñ+Üˆt‹9˜‹>ÜÐeÓfÐfØˆä
ˆ4ƒy�Aƒ~à�q‘'‰Ü	ˆT‹�a‹ÜØN×UÑUØóóð 	ð �!�Wœ D¨¡G¬[×9Ñ9à�q‘'‰àˆØ��7ØˆGØ�3�t˜A‘w‘;Ñˆà‡z�zÐ)¨5×1Ñ1Ü˜wÔ4KÈGÓ4TØ,2¯J©JÐ7QÐSXÓ,Yñ[ð 	[ä�WÔ*AÀ'Ó*JÑKÐKr
   c                 óz   • UR                  SS5      n[        U5      nUR                  SUS9  [        U /UQ70 UD6$ )aß	  
Return an environment specification for the given environment.  Syntax::

  spec = std_environment(envname, argspec, is_math_mode=True|False)
  #  or
  spec = std_environment(envname, optarg, numargs, is_math_mode=True|False)
  #  or
  spec = std_environment( (envname, argspec), is_math_mode=True|False)
  #  or
  spec = std_environment( (envname, optarg, numargs), is_math_mode=True|False)
  #  or
  spec = std_environment( spec ) # spec is already a `EnvironmentSpec` -- no-op

- `envname` is the name of the environment, i.e., the argument to
  ``\begin{...}``.

- `argspec` is a string either characters "\*", "{" or "[", in which star
  indicates an optional asterisk character (e.g. starred environment
  variants), each curly brace specifies a mandatory argument and each square
  bracket specifies an optional argument in square brackets.  For example,
  "{{\*[{" expects two mandatory arguments, then an optional star, an
  optional argument in square brackets, and then another mandatory argument.

  `argspec` may also be `None`, which is the same as ``argspec=''``.

.. note::

   See :py:class:`EnvironmentSpec` for an important remark about starred
   variants for environments.  TL;DR: a starred verison of an environment is
   defined as a separate `EnvironmentSpec` with the star in the name and
   *not* using an ``argspec='*'``.

- `optarg` may be one of `True`, `False`, or `None`, corresponding to these
  possibilities:

  + if `True`, the environment expects as first argument an optional argument in
    square brackets. Then, `numargs` specifies the number of additional
    mandatory arguments to the command, given in usual curly braces (or
    simply as one TeX token like a single environment)

  + if `False`, the environment only expects a number of mandatory arguments given
    by `numargs`. The mandatory arguments are given in usual curly braces
    (or simply as one TeX token like a single environment)

  + if `None`, then `numargs` is a string like `argspec` above.  I.e.,
    ``std_environment(envname, None, argspec)`` is the same as
    ``std_environment(envname, argspec)``.

- `numargs`: depends on `optarg`, see above.

- `is_math_mode`: if set to True, then the environment represents a math
  mode environment (e.g., 'equation', 'align', 'gather', etc.), i.e., whose
  contents should be parsed in an appropriate math mode.  Note that
  `is_math_mode` *must* be given as a keyword argument, in contrast to all
  other arguments which must be positional (non-keyword) arguments.
rF   FT)rZ   r[   )ÚpopÚdictÚupdaterd   )Úenvnamer/   r'   rF   Úkwargs2s        r   Ústd_environmentrk   2  sI   € ðr —:‘:˜n¨eÓ4€LÜ�6‹l€GØ‡N�N¨Ø,8ð ñ :ä�WÐ/˜tÒ/ wÑ/Ð/r
   c                 ó   • [        U SS9$ )a¥  
Return a latex specials specification for the given character sequence.  Syntax::

  spec = std_specials(specials_chars)

where `specials_chars` is the sequence of characters that has a special
LaTeX meaning, e.g. ``&`` or ``''``.

This helper function only allows to create specs for simple specials without
any argument parsing.  For more complicated specials, you can instantiate a
:py:class:`SpecialsSpec` directly.
Nr\   )rM   ©rP   s    r   Ústd_specialsrn   r  s   € ô ˜°DÑ9Ð9r
   c                   ó¤   ^ • \ rS rSrSrU 4S jr/ / / SSS4S jrS rS rS	 r	S
 r
S rS rS rSS jrSS jrSS jrSS jr/ / / 4S jrSrU =r$ )ÚLatexContextDbi‰  ap  
Store a database of specifications of known macros, environments, and other
latex specials.  This might be, e.g., how many arguments a macro accepts, or
how to determine the text representation of a macro or environment.

When used with :py:class:`pylatexenc.latexwalker.LatexWalker`, the
specifications describe mostly rules for parsing arguments of macros and
environments, and which sequences of characters to consider as "latex
specials".  Specifications for macros, environments, and other specials are
stored as :py:class:`MacroSpec`, :py:class:`EnvironmentSpec`, and
:py:class:`SpecialsSpec` instances, respectively.
When used with :py:class:`pylatexenc.latex2text.LatexNodes2Text`, the
specifications for macros, environments, and other specials are stored as
:py:class:`pylatexenc.latex2text.MacroTextSpec` ,
:py:class:`pylatexenc.latex2text.EnvironmentTextSpec`, and
:py:class:`pylatexenc.latex2text.SpecialsTextSpec` instances, respectively.

In fact, the objects stored in this database may be of any type, except that
macro specifications must have an attribute `macroname`, environment
specifications must have an attribute `environmentname`, and specials
specification must have an attribute `specials_chars`.

The `LatexContextDb` instance is meant to be (pseudo-)immutable.  Once
constructed and all the definitions added with
:py:meth:`add_context_category()`, one should refrain from modifying it
directly after providing it to, e.g., a
:py:class:`~pylatexenc.latexwalker.LatexWalker` object.  The reason is that
the latex walker keeps track of what the latex context was when parsing
nodes, and modifying the context will modify that stored information, too.
Instead of being tempted to modify the object, create a new one with
:py:meth:`filter_context()`.

See :py:func:`pylatexenc.latexwalker.get_default_latex_context_db()` for the
default latex context for `latexwalker` with a default collection of known
latex macros and environments.
See :py:func:`pylatexenc.latex2text.get_default_latex_context_db()` for the
default latex context for `latex2text` with a set of text replacements for a
collection of known macros and environments.
c                 ót   >• [         [        U ]
  " S0 UD6  / U l        0 U l        S U l        S U l        S U l        g r   )r    rp   r!   Úcategory_listÚdÚunknown_macro_specÚunknown_environment_specÚunknown_specials_spec)r&   r'   r(   s     €r   r!   ÚLatexContextDb.__init__±  s<   ø€ ÜŒn˜dÒ,Ñ6¨vÒ6àˆÔØˆŒà"&ˆÔØ(,ˆÔ%Ø%)ˆÕ"r
   FNc                 ó:  • XR                   ;   a  [        SR                  U5      5      e[        XVU4 Vs/ s H  oˆ(       d  M  UPM     sn5      S:”  a  [	        S5      eU(       a  U R                   R                  SU5        OÑU(       aI  X`R                   ;   a  U R                   R                  U5      n	OSn	U R                   R                  X‘5        O�U(       a_  XpR                   ;   a  U R                   R                  U5      S-   n	O[        U R                   5      n	U R                   R                  X‘5        OU R                   R                  U5        [        S U 5       5      [        S U 5       5      [        S U 5       5      S.U R                  U'   g	s  snf )
a÷  
Register a category of macro and environment specifications in the context
database.

The category name `category` must not already exist in the database.

The argument `macros` is an iterable (e.g., a list) of macro
specification objects.  The argument `environments` is an iterable
(e.g., a list) of environment spec objects.  Similarly, the `specials`
argument is an iterable of latex specials spec instances.

If you specify `prepend=True`, then macro and environment lookups will
prioritize this category over other categories.  Categories are normally
searched for in the order they are registered to the database; if you
specify `prepend=True`, then the new category is prepended to the
existing list so that it is searched first.

If `insert_before` is not `None`, then it must be a string; the
definitions are inserted in the category list immediately before the
given category name, or at the beginning of the list if the given
category doesn't exist.  If `insert_after` is not `None`, then it must
be a string; the definitions are inserted in the category list
immediately after the given category name, or at the end of the list if
the given category doesn't exist.

You may only specify one of `prepend=True`, `insert_before='...'` or
`insert_after='...'`.
z9Category {} is already registered in the context databaser   zgadd_context_category(): You may only specify one of prepend=True, insert_before=... or insert_after=...r   c              3   ó<   #   • U  H  oR                   U4v •  M     g 7fr   )r"   )Ú.0Úms     r   Ú	<genexpr>Ú6LatexContextDb.add_context_category.<locals>.<genexpr>ö  s   é € Ð>²f°Ÿ[™[¨!Õ,²fùó   ‚c              3   ó<   #   • U  H  oR                   U4v •  M     g 7fr   )rE   )rz   Úes     r   r|   r}   ÷  s   é € Ð PÂ,¸Q×#4Ñ#4°aÕ"8Â,ùr~   c              3   ó<   #   • U  H  oR                   U4v •  M     g 7fr   rm   )rz   r   s     r   r|   r}   ø  s   é € ÐGºX¸×/Ñ/°Õ3ºXùr~   ©ÚmacrosÚenvironmentsÚspecialsN)
rr   Ú
ValueErrorr`   r^   r_   ÚinsertÚindexÚappendrg   rs   )
r&   Úcategoryrƒ   r„   r…   ÚprependÚinsert_beforeÚinsert_afterr   Úis
             r   Úadd_context_categoryÚ#LatexContextDb.add_context_category¼  sc  € ð> ×)Ñ)Ó)ÜÐXß$™f XÓ.ó0ð 0ô ˜W°\ÑBÓIÒB�qÃa—ÑBÑIÓJÈQÓNÜð Ró Sð Sö Ø×Ñ×%Ñ% a¨Õ2ÞØ× 2Ñ 2Ó2Ø×&Ñ&×,Ñ,¨]Ó;‘à�Ø×Ñ×%Ñ% aÕ2ÞØ×1Ñ1Ó1Ø×&Ñ&×,Ñ,¨\Ó:¸QÑ>‘ä˜×*Ñ*Ó+�Ø×Ñ×%Ñ% aÕ2à×Ñ×%Ñ% hÔ/ô Ñ>±fÓ>Ó>Ü Ñ PÁ,Ó PÓPÜÑG¹XÓGÓGñ
ˆ�‰ˆxÒùò+ Js   µ
FÁFc                 ó   • Xl         g)zR
Set the macro spec to use when encountering a macro that is not in the
database.
N)rt   )r&   Ú	macrospecs     r   Úset_unknown_macro_specÚ%LatexContextDb.set_unknown_macro_specû  s
   € ð
 #,Õr
   c                 ó   • Xl         g)zd
Set the environment spec to use when encountering a LaTeX environment that
is not in the database.
N)ru   )r&   Úenvironmentspecs     r   Úset_unknown_environment_specÚ+LatexContextDb.set_unknown_environment_spec  s
   € ð
 )8Õ%r
   c                 ó   • Xl         g)zg
Set the latex specials spec to use when encountering a LaTeX environment
that is not in the database.
N)rv   )r&   Úspecialsspecs     r   Úset_unknown_specials_specÚ(LatexContextDb.set_unknown_specials_spec	  s
   € ð
 &2Õ"r
   c                 ó,   • [        U R                  5      $ )z\
Return a list of valid category names that are registered in the current
database context.
)Úlistrr   r5   s    r   Ú
categoriesÚLatexContextDb.categories  s   € ô
 �D×&Ñ&Ó'Ð'r
   c                 ó˜   • U R                    H/  nXR                  U   S   ;   d  M  U R                  U   S   U   s  $    U R                  $ )ai  
Look up a macro specification by macro name.  The macro name is searched for
in all categories one by one and the first match is returned.

Returns a macro spec instance that matches the given `macroname`.  If
the macro name was not found, we return the default macro specification
set by :py:meth:`set_unknown_macro_spec()` or `None` if no such spec was
set.
rƒ   )rr   rs   rt   )r&   r"   Úcats      r   Úget_macro_specÚLatexContextDb.get_macro_spec  sM   € ð ×%Ô%ˆCàŸF™F 3™K¨Ñ1Õ1Ø—v‘v˜c‘{ 8Ñ,¨YÑ7Ò7ñ &ð ×&Ñ&Ð&r
   c                 ó˜   • U R                    H/  nXR                  U   S   ;   d  M  U R                  U   S   U   s  $    U R                  $ )aj  
Look up an environment specification by environment name.  The environment
name is searched for in all categories one by one and the first match is
returned.

Returns the environment spec.  If the environment name was not found, we
return the default environment specification set by
:py:meth:`set_unknown_environment_spec()` or `None` if no such spec was
set.
r„   )rr   rs   ru   )r&   rE   r¢   s      r   Úget_environment_specÚ#LatexContextDb.get_environment_spec'  sM   € ð ×%Ô%ˆCà§&¡&¨¡+¨nÑ"=Õ=Ø—v‘v˜c‘{ >Ñ2°?ÑCÒCñ &ð ×,Ñ,Ð,r
   c                 ó˜   • U R                    H/  nXR                  U   S   ;   d  M  U R                  U   S   U   s  $    U R                  $ )a(  
Look up a "latex specials" specification by character sequence.  The
sequence name is searched for in all categories one by one and the first
match is returned.

If you are parsing a chunk of LaTeX code, you should use
:py:meth:`test_for_specials()` instead.  Unlike
:py:meth:`test_for_specials()`, :py:meth:`get_specials_spec()` returns
the first match regardless of matched length.  [Rationale: we only need
to worry about matching the longest specials sequence when parsing LaTeX
code.  Calling `get_specials_spec()` means one has already parsed the
sequence and one is looking up additional specs on it.]

Returns the specials spec.  If the latex specials was not found, we
return the default latex specials specification set by
:py:meth:`set_unknown_specials_spec()` or `None` if no such spec was
set.
r…   )rr   rs   rv   )r&   rP   r¢   s      r   Úget_specials_specÚ LatexContextDb.get_specials_spec8  sM   € ð& ×%Ô%ˆCà§¡¨¡¨ZÑ!8Õ8Ø—v‘v˜c‘{ :Ñ.¨~Ñ>Ò>ñ &ð ×)Ñ)Ð)r
   c                 ó  • SnSnU R                    Hs  nU R                  U   S   R                  5        HL  n[        U5      U:”  d  M  UR	                  Xr5      (       d  M,  U R                  U   S   U   n[        U5      nMN     Mu     U$ )aÁ  
Test the given position in the string for any LaTeX specials.  The lookup
proceeds by searching for in all categories one by one and the first
match is returned, except that the longest match accross all categories
is returned.  For instance, a match of '``' in a later category will
take precedence over a match of '`' in a earlier-searched category.

Returns a specials spec instance, or `None` if no specials are detected
at the position `pos`.
r   Nr…   )rr   rs   Úkeysr^   Ú
startswith)r&   r   ÚposÚparsing_stateÚbest_match_lenÚbest_match_sr¢   rP   s           r   Útest_for_specialsÚ LatexContextDb.test_for_specialsQ  sƒ   € ð ˆØˆØ×%Ô%ˆCà"&§&¡&¨¡+¨jÑ"9×">Ñ">Ö"@�Ü�~Ó&¨Õ7¸A¿L¹LÈ×<]Ó<]Ø#'§6¡6¨#¡;¨zÑ#:¸>Ñ#J�LÜ%(¨Ó%8’Nó #Añ &ð Ðr
   c              #   óø   #   • Uc  U R                   nU Ha  nX R                   ;  a$  [        SR                  X R                   5      5      eU R                  U   S   R	                  5        H  nUv •  M	     Mc     g7f)aº  
Yield the macro specs corresponding to all macros in the given categories.

If `categories` is `None`, then the known macro specs from all
categories are provided in one long iterable sequence.  Otherwise,
`categories` should be a list or iterable of category names (e.g.,
'latex-base') of macro specs to return.

The macro specs from the different categories specified are concatenated
into one long sequence which is yielded spec by spec.
NzAInvalid latex macro spec db category: {!r} (Expected one of {!r})rƒ   ©rr   r†   r`   rs   Úvalues©r&   rŸ   ÚcÚspecs       r   Úiter_macro_specsÚLatexContextDb.iter_macro_specsg  su   é € ð ÑØ×+Ñ+ˆJãˆAØ×*Ñ*Ó*Ü Ð!dß"(¡&¨×,>Ñ,>Ó"?óAð AàŸ™˜q™	 (Ñ+×2Ñ2Ö4�Ø”
ó 5ò	 ùó   ‚A8A:c              #   óø   #   • Uc  U R                   nU Ha  nX R                   ;  a$  [        SR                  X R                   5      5      eU R                  U   S   R	                  5        H  nUv •  M	     Mc     g7f)aØ  
Yield the environment specs corresponding to all environments in the given
categories.

If `categories` is `None`, then the known environment specs from all
categories are provided in one long iterable sequence.  Otherwise,
`categories` should be a list or iterable of category names (e.g.,
'latex-base') of environment specs to return.

The environment specs from the different categories specified are
concatenated into one long sequence which is yielded spec by spec.
NúGInvalid latex environment spec db category: {!r} (Expected one of {!r})r„   rµ   r·   s       r   Úiter_environment_specsÚ%LatexContextDb.iter_environment_specs~  su   é € ð ÑØ×+Ñ+ˆJãˆAØ×*Ñ*Ó*Ü Ø]ß‘V˜A×1Ñ1Ó2óð ð Ÿ™˜q™	 .Ñ1×8Ñ8Ö:�Ø”
ó ;ò ùr¼   c              #   óø   #   • Uc  U R                   nU Ha  nX R                   ;  a$  [        SR                  X R                   5      5      eU R                  U   S   R	                  5        H  nUv •  M	     Mc     g7f)aÌ  
Yield the specials specs corresponding to all environments in the given
categories.

If `categories` is `None`, then the known specials specs from all
categories are provided in one long iterable sequence.  Otherwise,
`categories` should be a list or iterable of category names (e.g.,
'latex-base') of specials specs to return.

The specials specs from the different categories specified are
concatenated into one long sequence which is yielded spec by spec.
Nr¾   r…   rµ   r·   s       r   Úiter_specials_specsÚ"LatexContextDb.iter_specials_specs˜  su   é € ð ÑØ×+Ñ+ˆJãˆAØ×*Ñ*Ó*Ü Ð!jß"(¡&¨×,>Ñ,>Ó"?óAð AàŸ™˜q™	 *Ñ-×4Ñ4Ö6�Ø”
ó 7ò	 ùr¼   c                 ó^  • [        5       nU R                  Ul        U R                  Ul        U R                  Ul        U(       + =(       d    SU;   nU(       + =(       d    SU;   nU(       + =(       d    SU;   nU R                   H¦  nU(       a  X�;  a  M  U(       a  X‚;   a  M  UR                  UU(       a   U R                  U   S   R                  5       O/ U(       a   U R                  U   S   R                  5       O/ U(       a   U R                  U   S   R                  5       O/ S9  M¨     U$ )a  
Return a new :py:class:`LatexContextDb` instance where we only keep
certain categories of macro and environment specifications.

If `keep_categories` is set to a nonempty list, then the returned
context will not contain any definitions that do not correspond to the
specified categories.

If `exclude_categories` is set to a nonempty list, then the returned
context will not contain any definitions that correspond to the
specified categories.

It is explicitly fine to have category names in `keep_categories` and
`exclude_categories` that don't exist in the present object
(cf. :py:meth:`categories()`).

The argument `keep_which`, if non-empty, specifies which definitions to
keep.  It should be a subset of the list ['macros', 'environments',
'specials'].

The returned context will make a copy of the dictionaries that store the
macro and environment specifications, but the specification classes (and
corresponding argument parsers) might correspond to the same instances.
I.e., the returned context is not a full deep copy.
rƒ   r„   r…   r‚   )rp   rt   ru   rv   rr   r�   rs   r¶   )	r&   Úkeep_categoriesÚexclude_categoriesÚ
keep_whichÚnew_contextÚkeep_macrosÚkeep_environmentsÚkeep_specialsr¢   s	            r   Úfilter_contextÚLatexContextDb.filter_context±  s	  € ô8 %Ó&ˆà)-×)@Ñ)@ˆÔ&Ø/3×/LÑ/LˆÔ,Ø,0×,FÑ,FˆÔ)à$”n×>¨°JÑ(>ˆØ *œN×J¨nÀ
Ñ.JÐØ&œ×B¨*¸
Ñ*Bˆà×%Ô%ˆCÞ 3Ó#=ÙÞ! cÓ&?Ùð ×,Ñ,ØÞ9D�t—v‘v˜c‘{ 8Ñ,×3Ñ3Ô5È"ÞEV˜TŸV™V C™[¨Ñ8×?Ñ?ÔAÐ\^Þ=J˜Ÿ™ ™ ZÑ0×7Ñ7Ô9ÐPRð	 -ó ñ &ð Ðr
   )rr   rs   ru   rt   rv   r   )r9   r:   r;   r<   r=   r!   r�   r“   r—   r›   rŸ   r£   r¦   r©   r²   rº   r¿   rÂ   rÌ   r>   r?   r@   s   @r   rp   rp   ‰  sp   ø† ñ&õN*ð 57ÀRÐRTØ%*¸$ÈTô=
ò~,ò8ò2ò(ò'ò -ò"*ô2ô,ô.ô4ð2 .0ÀBØ"$÷4ò 4r
   rp   )r=   ÚsysÚversion_infoÚmajorr	   Ústrr$   Ú_str_from_unicodeÚ_unicode_from_strÚ
basestringÚ_argparsersr   r   r   r   Úobjectr   rB   rM   rd   rk   rn   rp   r   r
   r   Ú<module>r×      s    ðñ4	ó ð ×Ñ×Ñ˜AÓâØ€KÙ#ÐÙ#Ñð €KÙ<ÐÙ3Ð÷
+ó +ô
%\�ô %\ôR<
�fô <
ô@(
�6ô (
ò\[Lò|=0ò@:ô.\�Võ \r
   