
    Ki2                     :   d Z ddlmZmZmZ ddlZddlZddlZddlZddl	Z	ej
        j        dk    reZeZddlmZ ddlmZ neZddlmZ  ej        e          ZddlmZ d	d
lmZmZmZmZm Z m!Z!m"Z" d	dl#m$Z$ i Z%	 	 ddZ&d Z' ej(        e'          Z)	 	 	 ddZ*dS )u	  
The `latexencode` module provides a set of routines that allows you to
convert a unicode string to LaTeX escape sequences.

For basic usage you can use the :py:func:`unicode_to_latex()` function
directly::

  >>> from pylatexenc.latexencode import unicode_to_latex
  >>> print(unicode_to_latex('À votre santé'))
  \`A votre sant\'e
  >>> print(unicode_to_latex('The length of samples #3 & #4 is 3μm'))
  The length of samples \#3 \& \#4 is 3\ensuremath{\mu}m

The conversion is handled by the class :py:class:`UnicodeToLatexEncoder`.  If
you are converting multiple strings, you may create an instance with the flags
you like and invoke its method
:py:meth:`~UnicodeToLatexEncoder.unicode_to_latex()` as many times as necessary::

  >>> from pylatexenc.latexencode import UnicodeToLatexEncoder
  >>> u = UnicodeToLatexEncoder(unknown_char_policy='replace')
  >>> print(u.unicode_to_latex('À votre santé'))
  \`A votre sant\'e
  >>> print(u.unicode_to_latex('The length of samples #3 & #4 is 3μm'))
  The length of samples \#3 \& \#4 is 3\ensuremath{\mu}m
  >>> print(u.unicode_to_latex('À votre santé: 乾杯'))
  No known latex representation for character: U+4E7E - ‘乾’
  No known latex representation for character: U+676F - ‘杯’
  \`A votre sant\'e: {\bfseries ?}{\bfseries ?}

Example using custom conversion rules::

  >>> from pylatexenc.latexencode import UnicodeToLatexEncoder, \
  ...     UnicodeToLatexConversionRule, RULE_REGEX
  >>> u = UnicodeToLatexEncoder(
  ...     conversion_rules=[
  ...         UnicodeToLatexConversionRule(rule_type=RULE_REGEX, rule=[
  ...             (re.compile(r'-->'), r'\\textrightarrow'),
  ...             (re.compile(r'<--'), r'\\textleftarrow'),
  ...         ]),
  ...         'defaults'
  ...     ]
  ... )
  >>> print(u.unicode_to_latex("Cheers --> À votre santé"))
  Cheers {\textrightarrow} \`A votre sant\'e

See :py:class:`UnicodeToLatexEncoder` and
:py:class:`UnicodeToLatexConversionRule`.  Note for regex rules, the replacement
text is expanded like the second argument of `re.sub()` and backslashes need to
be escaped even inside raw strings.

.. versionadded:: 2.0

   The class :py:class:`UnicodeToLatexEncoder` along with its helper functions
   and classes were introduced in `pylatexenc 2.0`.

   The earlier function :py:func:`utf8tolatex()` that was available in
   `pylatexenc 1.x` is still provided unchanged, so code written for `pylatexenc
   1.x` should work without changes.  New code is however strongly encouraged to
   employ the new API.
    )print_functionabsolute_importunicode_literalsN   )MappingProxyType)getfullargspec)
getargspec)_util   )get_builtin_uni2latex_dict	RULE_DICT
RULE_REGEXRULE_CALLABLEUnicodeToLatexConversionRuleget_builtin_conversion_rulesUnicodeToLatexEncoder)PartialLatexToLatexEncoderFbraceskeepTc                     ||||f}|t           v rt           |         }nt          ||||          }|t           |<   |                    |           S )a  
    Shorthand for constructing a :py:class:`UnicodeToLatexEncoder` instance and
    calling its :py:meth:`~UnicodeToLatexEncoder.unicode_to_latex()` method.

    The :py:class:`UnicodeToLatexEncoder` instances for given option settings
    are cached, making repeated calls to :py:func:`unicode_to_latex()` possible
    without creating a new instance upon each call.

    The parameters `non_ascii_only`, `replacement_latex_protection`,
    `unknown_char_policy`, and `unknown_char_warning` are directly passed on to
    the :py:class:`UnicodeToLatexEncoder` constructor.  See the class doc for
    :py:class:`UnicodeToLatexEncoder` for more information about what they do.

    You may only use arguments to this function that are python hashable (like
    `True`, `False`, or simple strings) to help us keep a cache of previously
    constructed :py:class:`UnicodeToLatexEncoder` instances.  For instance, it
    is not possible to provide a callable to `unknown_char_policy`.  It is also
    not possible to specify custom conversion rules with this helper function.
    If you need any of these features, simply create a
    :py:class:`UnicodeToLatexEncoder` instance directly.
    )non_ascii_onlyreplacement_latex_protectionunknown_char_policyunknown_char_warning)_u2l_obj_cacher   unicode_to_latex)sr   r   r   r   keyus          w/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/pylatexenc/latexencode/__init__.pyr   r      sr    0 79L!C n3!?[6I7KM M M  sa       c                  6    ddl m}  |                                 S )Nr   )	uni2latex)_uni2latexmapr#   copy)
_uni2latexs    r    _get_deprecated_utf82latexr'      s&    " 766666??r!   )generate_dict_fnc                 "   t          |           } t          j        d|           } | sdS d}| D ]}|rt          |          dk     r||z  }t                              t          |          d          }|||r|dd         dk    rd|z   d	z   n|z  }et          |          d
k    rt          |          dk    s|dv r||z  }dt          |          |fz  }|rt          |          t                              |           |r|dz  }||z  }|S )u  
    .. note::

       Since `pylatexenc 2.0`, it is recommended to use the the
       :py:func:`unicode_to_latex()` function or the
       :py:class:`UnicodeToLatexEncoder` class instead of the earlier function
       `utf8tolatex()`.

       The new routines provide much more flexibility and versatility.  For
       instance, you can specify custom escape sequences for certain characters.
       Some cheap benchmarks seem to indicate that the new routines are not
       significantly slower than the `utf8tolatex()` function.  Also, the name
       `utf8tolatex()` was poorly chosen, since the argument is in fact not
       'utf-8'-encoded but rather a Python unicode string object.

       The function `utf8tolatex()` is still provided unchanged from `pylatexenc
       1.x`.  We do not plan to remove this function in the near future so it is
       not (yet) considered as deprecated and we will continue to provide it in
       near future versions of `pylatexenc`.  Bug reports, improvements, and new
       features will however be directed to :py:func:`UnicodeToLatexEncoder()`.

    Encode a UTF-8 string to a LaTeX snippet.

    If `non_ascii_only` is set to `True`, then usual (ascii) characters such as ``#``,
    ``{``, ``}`` etc. will not be escaped.  If set to `False` (the default), they are
    escaped to their respective LaTeX escape sequences.

    If `brackets` is set to `True` (the default), then LaTeX macros are enclosed in
    brackets.  For example, ``santé`` is replaced by
    ``sant{\'e}`` if `brackets=True` and by ``sant\'e`` if `brackets=False`.

    .. warning::
        Using `brackets=False` might give you an invalid LaTeX string, so avoid
        it! (for instance, ``maître`` will be
        replaced incorrectly by ``ma\^\itre`` resulting in an unknown macro ``\itre``).

    If `substitute_bad_chars=True`, then any non-ascii character for which no LaTeX escape
    sequence is known is replaced by a question mark in boldface. Otherwise (by default),
    the character is left as it is.

    If `fail_bad_chars=True`, then a `ValueError` is raised if we cannot find a
    character substitution for any non-ascii character.

    .. versionchanged:: 1.3

        Added `fail_bad_chars` switch
    NFC    Nr   r   \{}    z
	z5Character cannot be encoded into LaTeX: U+%04X - `%s'z{\bfseries ?})	unicodeunicodedata	normalizeord
utf82latexget
ValueErrorloggerwarning)	r   r   bracketssubstitute_bad_charsfail_bad_charsresultchlchmsgs	            r    utf8tolatexrA      sU   d 	

AeQ''A rF ! ! 	!s2ww}}bLFF ..R$//C H !QqST9I9ISWS[[ $r77b==SWW^^>>" ORUVXRYRY[]Q^^! *$S//)s###' !..FF bLFFMr!   )Fr   r   T)FTFF)+__doc__
__future__r   r   r   r2   loggingsys	functools	itertoolsversion_infomajorstrr1   
basestringtypesr   _MappingProxyTypeinspectr   dictr	   	getLogger__name__r8   r+   r
   _unicode_to_latex_encoderr   r   r   r   r   r   r   _partial_latex_encoderr   r   r   r'   LazyDictr5   rA    r!   r    <module>rV      s  4; ;z I H H H H H H H H H      



        AGJ;;;;;;&&&&&&&444444		8	$	$                              LTFJ$! $! $! $!\  * U^-GHHH
8 NS$W W W W W Wr!   