U
    ãI€e8	  ã                   @   sh   d dl Z d dlmZ d dlmZ d dlmZ dZe  dd 	e¡› de j
¡Zdeeee d
œdd„ZdS )é    N)ÚIterator)Úcommands)Úconvert_symbol)ÚinÚmmÚcmÚptÚemÚexZpcZbpÚddÚccÚspÚmuzë
    (%[^\n]+) |                                 # comment
    (a-zA-Z) |                                  # letter
    ([_^])(\d) |                                # number succeeding an underscore or a caret
    (-?\d+(?:\.\d+)?\s*(?:ú|a>  )) | # dimension
    (\d+(?:\.\d+)?) |                           # integer/decimal
    (\.\d*) |                                   # dot (.) or decimal can start with just a dot
    (\\[\\\[\]{}\s!,:>;|_%#$&]) |             # escaped characters
    (\\(?:begin|end)\s*{[a-zA-Z]+\*?}) |      # begin or end
    (\\operatorname\s*{[a-zA-Z\s*]+\*?\s*}) | # operatorname
    #  color, fbox, href, hbox, mbox, style, text, textbf, textit, textrm, textsf, texttt
    (\\(?:color|fbox|hbox|href|mbox|style|text|textbf|textit|textrm|textsf|texttt))\s*{([^}]*)} |
    (\\[cdt]?frac)\s*([.\d])\s*([.\d])? |       # fractions
    (\\math[a-z]+)({)([a-zA-Z])(}) |          # commands starting with math
    (\\[a-zA-Z]+) |                             # other commands
    (\S)                                        # non-space character
    T)Úlatex_stringÚskip_commentsÚreturnc                 c   sÆ   t  | ¡D ]¶}ttdd„ | ¡ ƒƒ}|d  tj¡rZd |¡}t	|ƒ}|rZd|› dV  q
|D ]`}|rt| d¡rt q
| 
t¡rŽ| dd¡V  q^| tjtjtjf¡r¸d | d¡¡V  q^|V  q^q
d	S )
z”
    Converts Latex string into tokens.

    :param latex_string: Latex string.
    :param skip_comments: Flag to skip comments (default=True).
    c                 S   s   | d k	S )N© )Úxr   r   ú:/tmp/pip-unpacked-wheel-yt1tfwjl/latex2mathml/tokenizer.pyÚ<lambda>'   ó    ztokenize.<locals>.<lambda>r   Ú z&#xú;ú%ú N)ÚPATTERNÚfinditerÚtupleÚfilterÚgroupsÚ
startswithr   ZMATHÚjoinr   ÚendswithÚUNITSÚreplaceZBEGINZENDZOPERATORNAMEÚsplit)r   r   ÚmatchÚtokensZ	full_mathÚsymbolZcapturedr   r   r   Útokenize   s$    

r*   )T)ÚreÚtypingr   Zlatex2mathmlr   Zlatex2mathml.symbols_parserr   r$   Úcompiler"   ÚVERBOSEr   ÚstrÚboolr*   r   r   r   r   Ú<module>   s   üî