
    Ki                     r    d dl mZmZmZ d dlZ ej        e          Zddlm	Z	m
Z
mZ  G d de          ZdS )    )print_functionabsolute_importunicode_literalsN   )RULE_CALLABLEUnicodeToLatexConversionRuleUnicodeToLatexEncoderc                   ,     e Zd ZdZ	 d fd	Zd Z xZS )PartialLatexToLatexEncoderaQ  
    Encode a string while preserving some (fuzzily detected) LaTeX constructs
    that the input string already has (e.g. accent macros or inline math modes).

    Sometimes you need to fully LaTeX-encode a string that already has some
    LaTeX constructs.  For instance, titles of bibliographic entries might
    include some inline math or accents, but they might also include unicode
    characters that need to be encoded.  Using a
    :py:class:`UnicodeToLatexEncoder` on such strings would result in ugly
    doubly-escaped strings such as ``\textbackslash{}'\{e\}``.  Instead,
    constructs such as ``\'{e}`` should be preserved while other characters
    and/or constructs (say '&' or '%') as well as unicode characters should be
    encoded.

    This class offers a simple partial solution: Characters are encoded as per
    the given `conversion_rules` (or the default conversion rules of
    :py:class:`UnicodeToLatexEncoder` objects), except that the characters in
    `keep_latex_chars` are to be interpreted as LaTeX and are not to be further
    encoded.

    .. versionadded: 2.10
    \${}^_Nc           	          |}|dg} t          t          |           j        ddt          t          | j        d          g|z   i| || _        d S )Ndefaultsconversion_rulesnone)	rule_typerulereplacement_latex_protection )superr   __init__r   r   _do_partial_latex_encode_stepkeep_latex_chars)selfr   r   kwargsbase_conversion_rules	__class__s        /var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/pylatexenc/latexencode/_partial_latex_encoder.pyr   z#PartialLatexToLatexEncoder.__init__E   s    
 !1 (%/L!8($//8 		
 		
 ;'7-3    '	'		
 		
 		
 		
 !1    c                     ddl m} ||         | j        v r\ ||d          }|                    |d          }|j        ||j        |j        |j        z            z   }|j        |j        z   |z
  |fS dS )aY  
        This method is used as a "callable rule" for the
        :py:class:`UnicodeToLatexEncoder` object.

        The strategy is to see if we have something that looks like a LaTeX char
        we want to keep.  If so, keep it as is; if not, return `None` so that
        further rules can be considered by the base unicode encoder.
           )LatexWalkerF)tolerant_parsing)environmentsN)latexwalkerr!   r   	get_token	pre_spaceposlen)r   sr'   r!   lwtoktok_as_latexs          r   r   z8PartialLatexToLatexEncoder._do_partial_latex_encode_step\   s     	.-----S6T***Q777B,,s,77C=1SWswsw-F+GGL GCGOc)<88tr   )r   N)__name__
__module____qualname____doc__r   r   __classcell__)r   s   @r   r   r   .   s\         0 ?C1 1 1 1 1 1.      r   r   )
__future__r   r   r   logging	getLoggerr-   logger_unicode_to_latex_encoderr   r   r	   r   r   r   r   <module>r7      s   4 I H H H H H H H H H 		8	$	$         E E E E E!6 E E E E Er   