o
    iq                     @   s  d Z ddlZddlZddlmZmZmZmZ ddlm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddiZe ej! ej"Z#ddd	d
ddddddddZ$dddddddddd	Z%e% dd dD  ddddd Z&d!d"d#d$d%d&d'd$d(d)d)d*d+d,Z'i d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdDdHdFdIdFZ(e( ej) e( ej* e( ej+ i dJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdedidedgddjdkdldmdnZ,e, ej- e, ej. e, ej/ e, ej0 e, e( dodpdqZ1drdsdtdudvdwdxdyZ2dzZ3d{d|d}d}d~d~dddddddddZ4ddddddddddddddZ5ddddddddZ6ddddddZ7ddddZ8ddddddZ9dddddddddd	Z:dddddddddddddZ;i dddde;d e;d ddie;d ddiB e;d ddiB dZ<g dZ=ddddddddddd
Z>dd Z?ddÄ Z@ddń ZAddǄ ZBddɄ ZCdd˄ ZDdd̈́ ZEddτ ZFddф ZGdddԄZHddք ZIdd؄ ZJddڄ ZKdd܄ ZLdddބZMdS )zConvert LaTex maths code into presentational MathML.

This module is provisional:
the API is not settled and may change with any minor Docutils version.
    N)	MathErrormathalphabet2unichartex2unichartoplevel_code)mathmtablemrowmtrmtdmenclosemphantommsqrtmimnmomtextmsubmsupmsubsupmundermover
munderovermrootmfracmspaceMathRowhbaru   ℏu   Φu   Ξ   Σu   Ψu   Δu   Θu   ϒ   Πu   Ω   Γu   Λ)PhiXiSigmaPsiDeltaThetaUpsilonPiOmegaGammaLambdau	   lim infu	   lim supu	   inj limu
   proj limlim)	liminflimsupinjlimprojlim	varlimsup	varliminf
varprojlim	varinjlimoperatornamec                 c   s    | ]}||fV  qd S N ).0namer6   r6   f/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/docutils/utils/math/latex2mathml.py	<genexpr>I   s    r:   )arccosarcsinarctanargcoscoshcotcothcscdegdetdimexpgcdhomkerlglnlogPrsecsinsinhtantanh)TTFz0.278em)FTT0.444em)FTFz0.667em)FFTrT   )bmodpmodmodpodzdouble-struckboldzbold-italicscriptfrakturitalicnormalz
sans-serifzsans-serif-bold-italiczsans-serif-italic	monospace)mathbbmathbfmathbfitmathcalmathfrakmathitmathrmmathscrmathsf
mathbfsfit
mathsfbfitmathsfitmathtt	backslash\uparrowu   ↑	downarrowu   ↓updownarrowu   ↕Uparrowu   ⇑	Downarrowu   ⇓Updownarrowu   ⇕
lmoustacheu   ⎰
rmoustacheu   ⎱	arrowvertu   ⏐	bracevertu   ⎪lvert|lVert   ‖rvertrVert	Arrowvertnleqqu   ≦̸ngeqqu   ≧̸	nleqslantu   ⩽̸	ngeqslantu   ⩾̸ngtrlessu   ≹nlessgtru   ≸
nsubseteqqu   ⫅̸
nsupseteqqu   ⫆̸	centerdotu   ⬝
varnothingu   ⌀	varproptou   ∝triangleu   △triangledownu   ▽dotsbu   ⋯dotscu   …dotsidotsmsupinfmaxmin)dotsor+   r   r   r   r   u   ∼u   ≈)thicksimthickapproxu   ∣u   ∥u   ∤u   ∦u   ⌢u   ⌣u   ∫)shortmidshortparallel	nshortmidnshortparallel
smallfrown
smallsmilesmallint)bigcapbigcupbigodotbigoplus	bigotimesbigsqcupbiguplusbigveebigwedgecoprodintopointopprodsumr+   r   r   r   r   2em1emz0.2778emz0.25emz0.2222emz0.1667emz	-0.1667emz	-0.2222emz	-0.2778em)qquadquad
thickspace; 
medspace:	thinspace,negthinspace!negmedspacenegthickspace   ´u   ˉu   ˘u   ˇu   ˙   ¨u   ˙˙˙u   ˙˙˙˙`u   ˆu   ˚~   →)acutebarbrevecheckdotddotdddotddddotgravehatmathringtildevec)u   ⏞皙ɿ)   ←r   )u   ↔r   )_r   )r   r   )^g      )r   g333333ӿ)	overbraceoverleftarrowoverleftrightarrowoverlineoverrightarrowwidehat	widetilde)u   ⏟g?)r   g)
underbraceunderleftarrowunderleftrightarrow	underlineunderrightarrowu   −u   ∶    )-r   r   u   ℾu   ℿu   ⅀u   ℽu   ℼ)r   r   r   u   γu   π) r   )())[]){})ry   ry   )r{   r{   )r   r   )	matrixsmallmatrixpmatrixbmatrixBmatrixvmatrixVmatrixalignedcasesT)displaystylescriptlevelF      )r   	textstylescriptstylescriptscriptstylecfrac)r   r   classr   r   linethickness)fracr   dfractfracbinomdbinomtbinom)r   z1.2emz1.623emz2.047emz2.470em      )
leftrightbiglbigrBiglBigrbigglbiggrBigglBiggrc                 C   s<   t d| t j}|du rt d| t j}|d|dfS )a"  Return leading TeX command name and remainder of `string`.

    >>> tex_cmdname('mymacro2') # up to first non-letter
    ('mymacro', '2')
    >>> tex_cmdname('name 2') # strip trailing whitespace
    ('name', '2')
    >>> tex_cmdname('_2') # single non-letter character
    ('_', '2')

    z([a-zA-Z]+)[ \n]*(.*)Nz(.?)(.*)r   r   rematchDOTALLgroupstringmr6   r6   r9   tex_cmdnameO  s   r  c                 C   s4   t d| t j}|du rd| fS |d|dfS )zmReturn leading number literal and remainder of `string`.

    >>> tex_number('123.4')
    ('123.4', '')

    z([0-9.,]*[0-9]+)(.*)Nr   r   r   r  r  r6   r6   r9   
tex_numberr  s   r  c                 C   s>   t d| t jt jB }|dddd\}}}}|p|p||fS )zReturn first simple TeX token and remainder of `string`.

    >>> tex_token('\command{without argument}')
    ('\command', '{without argument}')
    >>> tex_token('or first character')
    ('o', 'r first character')

    a%  ((?P<cmd>\\[a-zA-Z]+)\s* # TeX command, skip whitespace
                      |(?P<chcmd>\\.)          # one-character TeX command
                      |(?P<ch>.?))            # first character (or empty)
                     (?P<remainder>.*$)    # remaining part of string
                 cmdchcmdch	remainder)r  r  VERBOSEr  r  )r  r  r  r  r  r  r6   r6   r9   	tex_token  s
   	r  c                 C   s   d}d}d}|  ds| dd | dd fS | D ])}|d7 }|r$d}n|dkr+d}n|dkr4|d7 }n|dkr<|d8 }|dkrB nqtd	| d|d  | |d fS )
zReturn first TeX group or token and remainder of `string`.

    >>> tex_group('{first group} returned without brackets')
    ('first group', ' returned without brackets')

    r   Fr   Nr   rm   Tr   zGroup without closing bracket!)
startswithr   )r  split_index
nest_levelescapecr6   r6   r9   	tex_group  s(   

r!  c                 C   s,   t | \}}|dkrt|  \}}||fS )a  Return first TeX group or token and remainder of `string`.

    >>> tex_token_or_group('\command{without argument}')
    ('\command', '{without argument}')
    >>> tex_token_or_group('first character')
    ('f', 'irst character')
    >>> tex_token_or_group(' also whitespace')
    (' ', 'also whitespace')
    >>> tex_token_or_group('{first group} keep rest')
    ('first group', ' keep rest')

    r   )r  r!  lstrip)r  r>   r  r6   r6   r9   tex_token_or_group  s   r#  c                 C   sf   t d| t jt jB }|du r| dsd| fS z|d|dfW S  ty2   td|  dw )	a$  Return optional argument and remainder.

    >>> tex_optarg('[optional argument] returned without brackets')
    ('optional argument', ' returned without brackets')
    >>> tex_optarg('{empty string, if there is no optional arg}')
    ('', '{empty string, if there is no optional arg}')

    z\s*                            # leading whitespace
                 \[(?P<optarg>(\\]|[^\[\]]|\\])*)\] # [group] without nested groups
                 (?P<remainder>.*$)
                 Nr   r   optargr  z*Could not extract optional argument from ""!)r  r  r  r  r  r  AttributeErrorr   r  r6   r6   r9   
tex_optarg  s   	r'  c           
      C   s,  |}| }t |dkr|d |dd }}|dv rq|dkr.t|\}}t|||\}}n|dv r8t||}n|dkrUt|trJ|jdkrJd|_nt }|| |}n|dkr^|	 }n|d	krot
 }|	 | |}nu| r{|t|}ni| rt|\}}|t|| }nU|tv ri }|d
krt |r|d }	|	jr|	jdv s|	ddkrd|d< |tt| fi |}n"|dv r|t|dd}n|dv r|t|}ntd| d|du r|s| S td| d|dt |   dt |dks|jrt ||jk rtd| S )u   Append MathML conversion of `string` to `node` and return it.

    >>> parse_latex_math(math(), r'lpha')
    math(mi('α'))
    >>> parse_latex_math(mrow(), r'x_{n}')
    mrow(msub(mi('x'), mi('n')))

    r   r   Nz 
rm   _^r   r   &r   z([=r   mathopenprefixformz/()[]|Fstretchyz+*=<>,.!?`';@zUnsupported character: "r%  zNo insertion point for "z". Unbalanced braces in "z"?z.Last node missing children. Source incomplete?)lenr  
handle_cmdhandle_script_or_limit
isinstancer   	nchildrenr   appendcloser
   isalphar   isdigitr  r   anomalous_charstextgetr   r   )
rootsourcer  noder   cmdnamenew_nodenumber
attributesprevious_noder6   r6   r9   parse_latex_math  sf   




4rD  c              	   C   s|	  | t v rtt |  }| tv r|dd ||}||fS | tv r,|tt|  |fS | tv r| dkrAt|\}}t|dd}ntt|  }| dkrSt|t	d}n%| dkrat
|t	d	d
d}n| dkrmt|t	d}n| dkrxt|t	d}||}|r|d dvr|t	d}||fS | tv rt|  \}}}}|r|t	d||d}||fS | rd}|t|d}|r|t	dd
d}|r|td}|tdd}t|\}}t||}|r|t	dd
d}||fS | dv rtdd}|| ||fS | tv rt| ||S | dkr"|t	dd d!d"d#}||fS | d$kr0t|d%}||fS | tv rD|t	t|  d&d'}||fS | tv rX|t	t|  d(d)}||fS | tv ri }	| tv rs|rs|d d*v rsd+|	d,< n	| d-v r|d.|	d< |t	t|  fi |	}||fS | tv r	i }
tt|   }t|\}}|d/vrz	t|d0 }W n ty   td1|  d2| d3w |r||
d4< ||
d5< d+|
d6< | d7ks| d8rt }|| |}|d9kr|t	|fi |
 | d:ks| d;r| }||fS | d<krSt|\}}|d=kr|d>| fS |d0r@z
t|d?d@  }W n ty?   tdA| d3w t !dB|dC }|t	|}||fS | dDv rt|\}}|"dE}t#|D ]!\}}|dF dkrt$%dGdH|}|t&|}qgt|| qg||fS | t'v r|tdIt'|   d}||fS | dJv rt(|\}}|dKrdLt)|d@dM dN  }|tdI| d}||fS | dOkrt* }|| ||fS | dPkrt+dQdPdR}|| ||fS | dSkrt,|\}}|rt }t-|d+dT}t|| |  nt. }|| ||fS | t/v rzt/|  }	| dUkrSt,|\}}d7d:dV}||v rS|	0 }	|| |	dW< |	d  dX||  7  < t1dmi |	 }}| dYrqtt	d|t	ddYd}dZ|_2|| ||fS | d0krt3 }t4|}|  | ||fS | t5v rt	t5|  d
d}| d[kr|d\d] t
|d+d+d^}|| ||fS | t6v rt
t	t6|  d d+dd+d
d_}|| ||fS | d`krt
d+dT}|| ||fS | t7v rtt	t7|  d d+dT}|| ||fS | dakrtd+dT}|| ||fS | dbv rZt,|\}}t	tdc| d?d@   }|rMt8|}tt |}t9|d?krG|d }|| nt
|}|| ||fS | t:v rt9|dkrntdd|  det:|  ; D ]\}}||| qt||fS | dfrt|\}}|dgv r|}t<||| dh}||fS | dikrt=||S | djkrt>||S tdk|  dl)nuj  Process LaTeX command `name` followed by `string`.

    Append result to `node`.
    If needed, parse `string` for command argument.
    Return new current node and remainder of `string`:

    >>> handle_cmd('hbar', math(), r' rac')
    (math(mi('ℏ')), ' \frac')
    >>> handle_cmd('hspace', math(), r'{1ex} (x)')
    (math(mspace(width='1ex')), ' (x)')

    r   zcapital-greekr4   r]   )mathvariantr1   r   r0      ¯F)accentr2   r   r3   r   r   )r   r   u   ⁡rW   )lspacerspacer   )widthr   r.  0.333emr   )
boldsymbolpmbrL  )CLASScolonr   postfix0z0.28em)r-  rH  rI  idotsintz\int\dotsi\intzfont-weight: bold)stylez75%)mathsizez _^Tmovablelimits)rx   rz   r+  z()[]/|.rm   zUnsupported "\z" delimiter "r%  maxsizeminsize	symmetricr  l.r  rnotr   z{\not r   Nz"\not" cannot negate: "NFCu   ̸)r:  mboxtextrm$r   z(^[ 
]|[ 
]$)r   z%s)hspacer   muz%sem   phantomboxedbox)notationrN  sqrt)switchr   )rY  r[  numalignz
 numalign-r   r   r   r   z+1)rG  rj  )rj  rG  oversetunderset)
xleftarrowxrightarrowlongzDeclaration "\z#" must be first command in a group!limitsr(  )rq  beginendzUnknown LaTeX command "\z".r6   )?lettersr   greek_capitalssetr5  ordinary	functionsr#  r   r   r   modulo_functionsin_blockr   rD  r   math_alphabetshandle_math_alphabetthick_operatorssmall_operators	operatorsrU  bigdelimitersdelimiter_sizesstretchablesr"  KeyErrorr   endswithr6  r  r  unicodedata	normalizesplit	enumerater  subr   spacesr!  floatr   r   r'  r   r   	fractionscopyr   r4  r
   r	   accentsoverunderr   r0  layout_stylesitemsr2  begin_environmentend_environment)r8   r>  r  r@  r>   binarynamedparenthesespaddingrB  delimiter_attributessize	delimiterrowpartsipartradix	indexnoder$  optargsr   entryaccent_node	subscriptbasesub_nodekvr  r6   r6   r9   r1    s  





























































r1  c                    s  i }| dkr
d|d< t |\}}| dkr)| r)t|dkr)|t|}||fS tdi |}|| t|| | dddd}tt	|i  |
 D ]3}t|trdd fd	d
|jD |_qNt|tr |j|j|_| dkr|j r|dd qN| |fS )Nrf   r   re   r   rb   rh   ri   r   c                 3   s    | ]	}  ||V  qd S r5   )r;  )r7   r  a2chr6   r9   r:     s    z'handle_math_alphabet.<locals>.<genexpr>rE  r]   r6   )r#  r7  r0  r5  r   r   rD  replacegetattrr   iterr3  r   joinr:  r;  rv  r6  )r8   r>  r  rB  r>   	containerkeysubnoder6   r  r9   r|    s*   



r|  r   c                 C   s  |   }|dkr|dd n|dkst|ddtv r!|dd |dkrWt|tr2t|dd	i}nTt|tr?t|dd	i}nG|d
v sM|dkrR|	ddrRt
|}n4t|}n/|dkrt|t
ret| }n!t|trot| }n|d
v s}|dkr|	ddrt|}nt|}| | |S )z)Append script or limit element to `node`.rq  rU  falser:  r   truer   rj  T)rq  rU  Nr   )poprv  r  rU  r3  r   r   r   r   r;  r   r   r5  )r>  r   rq  childr@  r6   r6   r9   r2    s4   









r2  c                 C   s   t |\}}|tv ret| d }i }|r6tt|}|dkr.tt|dd}d|d< d|d< | | |} n|dkrGd	|d
< d|d< d|d< n|dkrOd|d< t }| tt|fi | |} | |fS td| d)Nr   r   z0.17em)rI  r  columnalignr   r   z0.02em
rowspacingrK  columnspacing1r   r   	ams-alignEnvironment "" not supported!)	r!  matricesr   r   r5  r
   r   r	   r   )r>  r  r8   left_delimiterrB  wrapperr  r6   r6   r9   r  $  s.   

r  c                 C   sz   t |\}}|tv r5|    } t| d }|r)| t|} |  } | |fS |dkr1|  } | |fS td| d)Nr   r   r  r  )r!  r  r6  r5  r   r   )r>  r  r8   right_delimiterr6   r6   r9   r  @  s   r  c                 C   s.   t dd | D }|dkrdS t|d d S )Nc                 s   $    | ]}| d | d V  qdS r)  z\&Ncountr7   r  r6   r6   r9   r:   R     " z'tex_equation_columns.<locals>.<genexpr>r   r   r   )r   int)rowstabsr6   r6   r9   tex_equation_columnsQ  s   r  c                 C   sl   ddd}t dd | D }|r4ddg| }dd	g| }d
|d |d  |d< d
|d | |d< |S )Nr  T)r   r   c                 s   r  r  r  r  r6   r6   r9   r:   h  r  z#align_attributes.<locals>.<genexpr>r  r  rQ  r   r   r   r  r  )r   r  )r  attsr  alignsspacingr6   r6   r9   align_attributesd  s   r  c                 C   sp   t dd}|}|r+|dd t| d}t|dkr+t }|tt|ddd	 t	||  |
  | S )
zxReturn string with MathML code corresponding to `tex_math`.

    Set `as_block` to ``True`` for displayed formulas.
    z"http://www.w3.org/1998/Math/MathML)xmlnsdisplayblockz\\r   r  T)rN  r   )r   rv  r   r  r0  r
   r5  r   r	   rD  
indent_xmltoxml)tex_mathas_block	math_treer>  r  r6   r6   r9   
tex2mathml~  s   

r  )r   )F)N__doc__r  r  docutils.utils.mathr   r   r   r   #docutils.utils.math.mathml_elementsr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rt  update	mathalphamathordrw  ru  rx  ry  r{  r  	mathfencer+  	mathcloser  mathbinmathrel	mathpunctmathopr}  r~  rU  r  r  r  r  r9  r_   r  r  r  r  r  r  r  r  r!  r#  r'  rD  r1  r|  r2  r  r  r  r  r  r6   r6   r6   r9   <module>   s  
`	
	
	



#1!k  ^
(!