Hacked By AnonymousFox

Current Path : /opt/imunify360/venv/lib/python3.11/site-packages/docutils/utils/math/__pycache__/
Upload File :
Current File : //opt/imunify360/venv/lib/python3.11/site-packages/docutils/utils/math/__pycache__/math2html.cpython-311.pyc

�

j��f٥���	�ddlZddlZddlZddlmZdZGd�d��ZGd�d��ZGd�d	��ZGd
�d��Z	Gd�d
��Z
Gd�d��ZGd�d��ZGd�d��Z
Gd�d��ZGd�de��ZGd�de��ZGd�de��ZGd�de��ZGd�de��ZGd �d!e��ZGd"�d#��ZGd$�d%e��ZGd&�d'e��ZGd(�d)e��ZGd*�d+e��ZGd,�d-e��ZGd.�d/e��ZGd0�d1��ZGd2�d3��ZGd4�d5��ZGd6�d7e��ZGd8�d9e��Z Gd:�d;��Z!Gd<�d=e!��Z"Gd>�d?e!��Z#Gd@�dAe#��Z$GdB�dC��Z%GdD�dEe��Z&GdF�dGe!��Z'GdH�dIe'��Z(GdJ�dKe$��Z)GdL�dMe'��Z*GdN�dOe'��Z+GdP�dQe'��Z,GdR�dSe'��Z-GdT�dUe'��Z.GdV�dWe'��Z/GdX�dYe/��Z0GdZ�d[��Z1Gd\�d]��Z2Gd^�d_e!��Z3Gd`�dae'��Z4Gdb�dc��Z5Gdd�dee'��Z6Gdf�dge6��Z7Gdh�die7��Z8Gdj�dke7��Z9Gdl�dme8��Z:Gdn�doe7��Z;Gdp�dqe7��Z<Gdr�dse7��Z=Gdt�due;��Z>e5xj?e6e<gz
c_?e:e8e;e>e=e9ge6_?Gdv�dw��Z@Gdx�dye7��ZAGdz�d{e6��ZBGd|�d}e6��ZCGd~�de7��ZDGd��d�eD��ZEGd��d�eD��ZFGd��d�eD��ZGGd��d�eD��ZHGd��d�e7��ZIe6xj?eIgz
c_?Gd��d�e;��ZJGd��d�e;��ZKGd��d�e;��ZLGd��d�e8��ZMGd��d�eM��ZNGd��d�e1��ZOGd��d�e;��ZPGd��d�e1��ZQe6xj?eKeLeJeMePgz
c_?e2xjReO��eQ��gz
c_RGd��d���ZSGd��d�e7��ZTGd��d�eT��ZUGd��d���ZVe6xj?eUgz
c_?d��ZWd��ZXeYd�kreX��dSdS)��N)�tex2unicharz1.3 (2021-06-02)c��eZdZdZdZdZdZdZd�Zd�Z	d�Z
d�Zd�Ze
e��Ze
e	��Z	e
e
��Z
e
e��Ze
e��ZdS)	�TracezA tracing classFNc��tjrtjrdSt�|tj��dS)zShow a debug messageN)r�	debugmode�	quietmode�show�sys�stdout��cls�messages  �}/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/docutils/utils/math/math2html.py�debugzTrace.debug+s6����	�%�/�	��F�
�
�
�7�C�J�'�'�'�'�'�c��tjrdStjrtjrtj|z}t�|t
j��dS)zShow a trace messageN)rr�prefix�
showlinesmoder	r
rrs  rrz
Trace.message1sM���?�	��F��<�	-�E�/�	-��l�W�,�G�
�
�
�7�C�J�'�'�'�'�'rc��d|z}tjrtjrtj|z}t�|tj��dS)zShow an error messagez* N)rrrr	r
�stderrrs  r�errorzTrace.error9sG����.���<�	-�E�/�	-��l�W�,�G�
�
�
�7�C�J�'�'�'�'�'rc�^�t�d|z��td��dS)z#Show an error message and terminatezFATAL: ���N)rr�exitrs  r�fatalzTrace.fatal@s(��
���I��'�(�(�(��R�����rc�6�|�|dz��dS)zShow a message out of a channel�
N)�write)r
r�channels   rr	z
Trace.showEs���
�
�g��n�%�%�%�%�%r)�__name__�
__module__�__qualname__�__doc__rrrrrrrrr	�classmethod�rrrr"s����������I��I��M�
�F�(�(�(�(�(�(�(�(�(����
&�&�&�
�K����E��k�'�"�"�G��K����E��K����E��;�t���D�D�Drrc�"�eZdZdZdggd�d�ZdS)�ContainerConfig�+Configuration class from elyxer.config file�FormulaConstant)�AlphaCommand�Bracket�BracketCommand�CombiningFunction�EmptyCommand�FontFunction�Formula�
FormulaNumber�
FormulaSymbol�OneParamFunction�OversetFunction�RawText�
SpacedCommand�SymbolFunction�TextFunction�UndersetFunction��allowed�	extractedN)r r!r"r#�extracttextr%rrr'r'Ps7������1�1�&�&������K�K�Krr'c�*�eZdZdZdddd�Zdddd	�Zd
S)�EscapeConfigr(��’u‘)r�'�`z&amp;z&lt;z&gt;)�&�<�>N)r r!r"r#�chars�entitiesr%rrr?r?isB������1�1��
�
�
�
�E��
�
���H�H�Hrr?c�
�eZdZdZidd�dd�dd�dd	�d
d�dd
�dd�dd�dd�dd�dd�dd�dd�dd�dd�d d!�d"d#�d$d%i�Zej���D]
\ZZ	e	ed&ez<�d'd(d)d*d+�Z
gd,�gd-�gd.�gd/�gd0�gd1�d2gd3gd4�Zd5d6d5d5d7d8�Zd9d:d;d<d=d>d?d@dAdBdCdD�Z
ej���D]
\ZZ	e	e
d&ez<�id*dE�dFdG�dHdG�dIdJ�dKdL�dMdN�dOdP�dQdR�dSdT�dUdR�dVdT�dWdT�dXdR�dYdZ�d[d\�d]d^�d_d`�idad3�dbd3�dcd2�dddE�dedf�dgdh�didh�djdk�dld3�dmd2�dndo�dpdq�drd&�dsdN�dtdu�dvdR�dwdx��idydx�dzdZ�d{d|�d}d~�dd��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�dG�d�d��d�d���id�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d���d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�dȜ�ZiZe�ej��e�ej��e�ej��e�ej��e�ej��e�ej��e�ej��e�dɄe���D����d�d�d�d�d�d�dod�dќZd�d�d�dҜZd�d�d�d�d�dלZd�d�ggdڢd�d�gd�d�gdܜZid�dޓd�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d��d�d��d�d��d�d��d�d��id��d��d�d��d�d��d�d��d�d��d	dޓ�d
�d��d�d
��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��i�d �d!��d"�d#��d$�d%��d&�d'��d(�d)��d*�d+��d,d��d-�d.��d/d��d0�d1��d2�d3��d4�d5��d6�d7��d8�d9��d:�d
��d;�d��d<�d���d�d�d�d�d�d=�d>�d7�d?��Zi�d@g�dA���dBg�dC���dDg�dE���dFg�dG���dHg�dI���dJg�dK���dLg�dM���dNg�dO���dPg�dQ���dRg�dS���dTg�dU���dVg�dW���dXg�dW���dYg�dZ���d[g�d\���d]g�d\���d^g�d_��i�d`g�da���dbg�dc���ddg�dE���deg�df���dgg�dh���dig�dj���dkg�dl���dmg�dn���dog�dp���dq�drdhg��dsg�dt���dug�dv���dwg�dx���dyg�dz���d{g�d|���d}g�dQ���d~g�d���g�dM�g�d��g�d\�g�d��g�d��g�d��g�d��g�d���d���Z�d��d��d��d��d��d��d��Z�d��d�iZ i�d��d���d��d���d��d���d��d���d��d���d��d���d��d���d��d���d��d���d��d���d��d���d��d���d��d���d��d���d��d���d��d���d��d��i�d��d���d��d���d��d���d��d���d��d���d��d���d��d���d��d���d��d���d��d���d��d“�dÐdē�dŐdƓ�dǐdȓ�dɐdʓ�dːd���d̐d͓��dΐdϐdАdѐdҐdϐdӜ�Z!dhdhdh�d�d��dՐd֐dאdؐdِdڐdېd�dhdf�dݜZ"i�dސdߓ�d�dߓ�d�dߓ�d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d���d��d���d��d��d��d�dh�d��d���Z#i�d��d���d��d���d�d��d�d��d�d��d�d��d�d	��d
�d��d�d
��d�d��d�d��d�d��d�d��d�d��d�d��d�d�Z$ej%���D]
\ZZ	e	e$d&ez<�dӐd�dd&�d�d�d �d!�d"�d#�	Z&�d��d$�d%�Z'�d&�d'�d(�d)�d*�d+�d,�d-�d.�d/�d0�d1�Z(�d2g�d3�iZ)�d4S(5�
FormulaConfigr(z\AmSz<span class="textsc">AmS</span>z\AA�Åz\AE�Æz\DH�Ðz\LuŁz\O�Øz\OEuŒz\TH�Þz\aa�åz\ae�æz\dh�ðz\iuız\juȷz\lułz\o�øz\oeuœz\ss�ßz\th�þ�\z\beginrDz\endz\\)�begin�
cellseparator�end�rowseparator)u⎛u⎜u⎝)u⎞u⎟u⎠)u⎡u⎢u⎣)u⎤u⎥u⎦)u⎧�⎪u⎨u⎩)u⎫r[u⎬u⎭�|�‖)�(�)�[�]�{�}r\r]�span class="stretchy"z<span class="leftdot"></span>z<span class="rightdot"></span>)�\leftz\left.z\middle�\rightz\right.úüûùũu̧ůu̩u⃝u̥ǔ)z\'z\"z\^z\`z\~z\cz\rz\sz\textcircledz\textsubringz\vz<br/>z\
� z\	z
\centerdotu⬝z\colon�: z
\copyright�©z	\dotminusu∸z\dotsu…z\dotsbu⋯z\dotscz\dotsiz\dotsmz\dotsoz\euro�€z\guillemotleft�«z\guillemotright�»z\hbaru	<i>ħ</i>z\lVertz
\Arrowvertz\lvertz\newlinez
\nobreakspace� z	\nolimitsr@z	\nonumberz\qquadu  z\rVertz\rvertz\textasciicircum�^z\textasciitilde�~z\textbackslashz\textcopyrightz\textdegree�°z
\textellipsisz\textemdashu—z\textendashz	\texteuroz\textgreaterrFz	\textlessrEz\textordfeminine�ªz\textordmasculine�ºz\textquotedblleftu“z\textquotedblrightu”z\textquoterightrAz\textregistered�®z\textrightarrowu→z\textsection�§z\texttrademarku™z\texttwosuperior�²z\textvisiblespacez\thickspacez!<span class="thickspace"> </span>z\;z	\triangleu△z
\triangledownu▽z\varnothingu⌀z\Pr�Prz\arccos�arccosz\arcsin�arcsinz\arctan�arctanz\arg�argz\cos�cosz\cosh�coshz\cot�cotz\coth�cothz\csc�cscz\deg�degz\det�detz\dim�dimz\exp�exp�gcd�homu	inj lim�ker�lgu	lim infu	lim sup�ln�logu
proj lim�sec�sin�sinh�tan�tanh)z\gcdz\homz\injlimz\kerz\lgz\liminfz\limsupz\lnz\logz\projlimz\secz\sinz\sinhz\tanz\tanhc#�*K�|]\}}d|z|fV��dS)rVNr%)�.0�key�values   r�	<genexpr>zFormulaConfig.<genexpr>s/����J�J�J�C��T�C�Z��'�J�J�J�J�J�Jru‒u$<span class="smallsymbol">⋯</span>u$<span class="smallsymbol">→</span>u⟵u⟷u⟶u~)z\barz\dddotz\vecz\overleftarrowz\overleftrightarrowz\overrightarrowz\widehatz
\widetilde)z\underleftarrowz\underleftrightarrowz\underrightarrowrc�\]z\end{ra)�bracket�complex�endafter�	endbefore�
squarebracket�r�l)r��cr�r�)�align�eqnarray�gathered�smallmatrixz\boldsymbol�bz\mathbbzspan class="blackboard"z
\mathbb{A}u𝔸z
\mathbb{B}u𝔹z
\mathbb{C}uℂz
\mathbb{D}u𝔻z
\mathbb{E}u𝔼z
\mathbb{F}u𝔽z
\mathbb{G}u𝔾z
\mathbb{H}uℍz
\mathbb{J}u𝕁z
\mathbb{K}u𝕂z
\mathbb{L}u𝕃z
\mathbb{N}uℕz
\mathbb{O}u𝕆z
\mathbb{P}uℙz
\mathbb{Q}uℚz
\mathbb{R}uℝz
\mathbb{S}u𝕊z
\mathbb{T}u𝕋z
\mathbb{W}u𝕎z
\mathbb{Z}uℤz\mathbfz\mathcalzspan class="scriptfont"z\mathcal{B}uℬz\mathcal{E}uℰz\mathcal{F}uℱz\mathcal{H}uℋz\mathcal{I}uℐz\mathcal{L}uℒz\mathcal{M}uℳz\mathcal{R}uℛz	\mathfrakzspan class="fraktur"z\mathfrak{C}uℭz\mathfrak{F}u𝔉z\mathfrak{H}uℌz\mathfrak{I}uℑz\mathfrak{R}uℜz\mathfrak{Z}uℨz\mathit�iz\mathring{A}z\mathring{U}uŮz\mathring{a}z\mathring{u}uůz\mathring{w}uẘz\mathring{y}uẙz\mathrmzspan class="mathrm"z\mathscrzspan class="mathscr"z\mathscr{B}z\mathscr{E}z\mathscr{F}zspan class="mathsf"zspan class="mathtt")z\mathscr{H}z\mathscr{I}z\mathscr{L}z\mathscr{M}z\mathscr{R}z\mathsfz\mathttz
\operatornamez\addcontentsline)z{$p!}{$q!}{$r!}�f0{}�ignoredz\addtocontents)z
{$p!}{$q!}r�r�z\backmatter)r@r�r��\binom)�{$1}{$2}zf2{(}f0{f1{$1}f1{$2}}f2{)}zspan class="binom"zspan class="binomstack"�span class="bigdelimiter size2"z\boxed)�{$1}�f0{$1}zspan class="boxed"�\cfrac)z
[$p!]{$1}{$2}�!f0{f3{(}f1{$1}f3{)/(}f2{$2}f3{)}}�span class="fullfraction"zspan class="numerator align-$p"�span class="denominator"�span class="ignored"z\color)�	{$p!}{$1}r�zspan style="color: $p;"z	\colorbox)r�r�z-span class="colorbox" style="background: $p;"�\dbinom)r�u%(f0{f1{f2{$1}}f1{f2{ }}f1{f2{$2}}})zspan class="binomial"zspan class="binomrow"zspan class="binomcell"�\dfrac)r�r�r��span class="numerator"r�r�z
\displaystyle)r�r�zspan class="displaystyle"z
\fancyfoot)z
[$p!]{$q!}r�r�z
\fancyheadz\fbox)r�r�zspan class="fbox"z	\fboxrule)�{$p!}r�r�z\fboxsepz
\fcolorbox)z{$p!}{$q!}{$1}r�z<span class="boxed" style="border-color: $p; background: $q;"�\frac)r�r��span class="fraction"r�r�r�z	\framebox)z[$p!][$q!]{$1}r�z1span class="framebox align-$q" style="width: $p;"z\frontmatterz\href)z[$o]{$u!}{$t!}zf0{$t}�a href="$u"z\hspace)r��f0{ }z&span class="hspace" style="width: $p;"z	\leftroot)r�r�z*span class="leftroot" style="width: $p;px"z	\nicefrac)r�uf0{f1{$1}⁄f2{$2}}r�zsup class="numerator"zsub class="denominator"r�z\parbox)z[$p!]{$w!}{$1}zf0{1}z$div class="Boxed" style="width: $w;"z	\raisebox)r�zf0{$1.font}z1span class="raisebox" style="vertical-align: $p;"z\renewenvironmentz{$1!}{$2!}{$3!}z\rule)z[$v!]{$w!}{$h!}zf0/z.hr class="line" style="width: $w; height: $h;"z\scriptscriptstyle)r�r�zspan class="scriptscriptstyle"z\scriptstyle)r�r�zspan class="scriptstyle"z\sqrt)�[$0]{$1}u!f0{f1{$0}f2{√}f4{(}f3{$1}f4{)}}zspan class="sqrt"zsup class="root"zspan class="radical"zspan class="root"r�z	\stackrel)r�zf0{f1{$1}f2{$2}}zspan class="stackrel"zspan class="upstackrel"zspan class="downstackrel"�\tbinomz\tfrac)r�r�zspan class="textfraction"r�r�r�)r�r�zspan class="textstyle")r�z
$0f0{$1.font}zspan class="unit")z[$0]{$1}{$2}u$0f0{f1{$1.font}⁄f2{$2.font}}r�zsup class="unit"zsub class="unit")r�r�z(span class="uproot" style="width: $p;px")z{$u!}zf0{$u}r�)r�r�z'span class="vspace" style="height: $p;")z
\textcolorz
\textstylez\thispagestylez\unitz	\unitfracz\uprootz\urlz\vspacez$1+$2z$1+$2+1)r�r�r�r�r�r�z\labelz
a name="#"z\biginterleaveu⫼z\inf�infz\lim�limz\max�maxz\min�minz\sup�supz\ointopu-<span class="bigoperator integral">∮</span>z\bigcapu$<span class="bigoperator">⋂</span>z\bigcupu$<span class="bigoperator">⋃</span>z\bigodotu$<span class="bigoperator">⨀</span>z	\bigoplusu$<span class="bigoperator">⨁</span>z
\bigotimesu$<span class="bigoperator">⨂</span>z	\bigsqcapu$<span class="bigoperator">⨅</span>z	\bigsqcupu$<span class="bigoperator">⨆</span>z	\biguplusu$<span class="bigoperator">⨄</span>z\bigveeu$<span class="bigoperator">⋁</span>z	\bigwedgeu$<span class="bigoperator">⋀</span>z\coprodu$<span class="bigoperator">∐</span>z\intopu-<span class="bigoperator integral">∫</span>z\produ$<span class="bigoperator">∏</span>z\sumu$<span class="bigoperator">∑</span>z\varprodu$<span class="bigoperator">⨉</span>z\zcmpu⨟z\zhideu⧹z\zpipeu⨠z	\zprojectu⨡z\intz\iintu-<span class="bigoperator integral">∬</span>z\iiintu-<span class="bigoperator integral">∭</span>z\iiiintu-<span class="bigoperator integral">⨌</span>z\fintu-<span class="bigoperator integral">⨏</span>z	\idotsintu3<span class="bigoperator integral">∫⋯∫</span>z\ointz\oiintu-<span class="bigoperator integral">∯</span>u-<span class="bigoperator integral">∰</span>u-<span class="bigoperator integral">∲</span>u-<span class="bigoperator integral">∳</span>u-<span class="smallsymbol integral">∫</span>u-<span class="bigoperator integral">⨖</span>)z\oiiintz\ointclockwisez\ointctrclockwisez	\smallintz\sqintz\varointclockwise�	u + u, u	 − u	 ⁄ z : u
 &lt; u = u
 &gt; )rrg�$rDrB�+�,�-�/�:rE�=rF�@roz\bigzspan class="bigdelimiter size1"z\biglz\bigrz\Bigr�z\Biglz\Bigrz\biggzspan class="bigdelimiter size3"z\bigglz\biggrz\Biggzspan class="bigdelimiter size4"z\Bigglz\Biggrz
\begin{array}zspan class="arraydef"z
\centeringzspan class="align-center"z\ensuremathzspan class="ensuremath"z	\hphantomzspan class="phantom"z	\noindentzspan class="noindent"zspan class="overbrace"zspan class="overline"zspan class="underbrace")z
\overbracez	\overlinez\phantomz\underbracez
\underlinez	\vphantomz\nleqqu≦̸z\ngeqqu≧̸z
\nleqslantu⩽̸z
\ngeqslantu⩾̸z\nsubseteqqu⫅̸z\nsupseteqqu⫆̸z
\nsqsubsetu≶⊏z	\shortmidu$<span class="smallsymbol">∣</span>z\shortparallelu$<span class="smallsymbol">∥</span>z
\nshortmidu$<span class="smallsymbol">∤</span>z\nshortparallelu$<span class="smallsymbol">∦</span>z\smallfrownu$<span class="smallsymbol">⌢</span>z\smallsmileu$<span class="smallsymbol">⌣</span>z\thickapproxu#<span class="boldsymbol">≈</span>z	\thicksimu#<span class="boldsymbol">∼</span>z
\varproptou<span class="mathsf">∝</span>z\begin{rb�%�\[r�r`�*)	�
beginafter�beginbeforer��command�commentr��simpler��
unnumbered�sub)rn�_zspan class="mbox"zspan class="text"zspan class="textbf"zspan class="textit"zspan class="textnormal"zspan class="textrm"zspan class="textsc"zspan class="textsf"zspan class="textsl"zspan class="texttt"zspan class="normal")z\mboxz\textz\textbfz\textitz\textnormalz\textrmz\textscz\textsfz\textslz\textttz\textup�
characters)�.r�rjr^r_r`ra�·�!�;r\rt�"�?N)*r r!r"r#�
alphacommandsr�	mathalpha�itemsr�r��array�bigbrackets�bracketcommands�combiningfunctions�
mathaccent�commands�cmddict�update�mathbin�mathopen�	mathclose�	mathfence�mathord�	mathpunct�space�oversetfunctions�undersetfunctions�endings�environments�
fontfunctions�hybridfunctions�hybridsizes�labelfunctions�
limitcommands�modified�onefunctions�spacedcommands�mathrel�starts�symbolfunctions�
textfunctions�
unmodifiedr%rrrJrJysc������1�1���2���t��	�t��	�t�	�
	�t��	�t�
�	�t��	�t��	�t��	�t��	�t��	�t��	�t��	�t��	�t�� 	�t�!�"	�t�#�$	�t�%��M�("�+�1�1�3�3�(�(�
��U�"'�
�d�3�h�������	
�
�E�.�-�-�-�-�-�-�-�-�-�-�-�4�4�4�4�4�4���!�'���K�*�2�+�*�4���O�"�!�!�!�!�!�!�!�!�!�!����"�,�2�2�4�4�-�-�
��U�',��4��8�$�$�U���U���U�	��U�	�x�	U�
	�4�U�	�t�
U�	�e�U�	�%�U�	�5�U�	�5�U�	�5�U�	�5�U�	�5�U�	�%�U�	�4�U� 	�D�!U�"	�/�#U�U�$	�5�%U�&	��'U�(	�3�)U�*	�W�+U�,	�$�-U�.	�b�/U�0	�b�1U�2	�8�3U�4	�5�5U�6	�3�7U�8	�S�9U�:	�C�;U�<	�4�=U�>	�4�?U�@	��AU�B	�%�CU�D	��EU�U�U�F	��GU�H	�e�IU�J	��KU�L	�c�MU�N	�T�OU�P	�d�QU�R	�e�SU�T	�u�UU�V	�E�WU�X	�D�YU�Z	�E�[U�\	��]U�^	�5�_U�`	�T�aU�b	�c�cU�d	�;�eU�f	�2�gU�U�U�h	�h�iU�j	�(�kU�l	��mU�p	��qU�r	�H�sU�t	�H�uU�v	�H�wU�x	��yU�z	��{U�|	�&�}U�~	��U�@	�&�AU�B	��CU�D	��EU�F	��GU�H	��IU�J	��KU�U�L���������!������iU�U�U�H�l�G��N�N�;�&�'�'�'��N�N�;�'�(�(�(��N�N�;�(�)�)�)��N�N�;�(�)�)�)��N�N�;�&�'�'�'��N�N�;�(�)�)�)��N�N�;�$�%�%�%��O�O�J�J�'�-�-�/�/�J�J�J�J�J�J�
�=�=� � %�!���'���."�!&�"�����������G��s��#�O�O��#�J��S�z�	��L�����'�)B���v��,�f��6C�U��	�v�� -�f��7D�V��	�v�	� -�e�	�6C�F�	�
	�v��
 -�f��
7D�U��	�v�
� -�e�
�6C�E�
��	�u��,�V��6C�F��	�v�� -�e��6@���	�.��	��� .�u��7E�
���u��'5�e��	��� .�u��7E�e��	�,��	�����!0���:I�%��	���!0���9H��� 	�C�!�"	��#�" /��#�$	��%�$ /��%�$7F�u�%�&	��'�(	�)�)�*	�+�+�,	��-�, .�u�-�,7E�e�-��.�u�e��u�)�)�/�7���M�<.��C�C�C�.��<�<�<�.�	�/�/�/�.�	�R�R�R�	.�
	�;�;�;�.�	�~�~�~�
.�	�E�E�E�.�	�^�^�^�.�	�V�V�V�.�	�p�p�p�.�	�I�I�I�.�	�8�8�8�.�	�8�8�8�.�	�9�9�9�.�	�2�2�2�.� 	�1�1�1�!.�"	�s�s�s�#.�.�$	�k�k�k�%.�&	�g�g�g�'.�(	�0�0�0�).�*	�=�=�=�+.�,	�P�P�P�-.�.	�V�V�V�/.�4	�_�_�_�5.�6	�W�W�W�7.�8	�g�g�g�9.�:	�0�"�5�;.�<	�^�^�^�=.�>	�S�S�S�?.�@	�G�G�G�A.�D	�r�r�r�E.�F	�H�H�H�G.�H	�V�V�V�I.�J	�q�q�q�K.�.�LJ�I�I�C�C�C�7�7�7�D�D�D�K�K�K�R�R�R�3�3�3�Q�Q�Q�[.�.�.�O�b�w�I��g�9���K�	�<��N�(��5�(���(�	��(�	��	(�
	��(�	��
(�	�F�(�	�=�(�	�=�(�	�=�(�	�=�(�	�=�(�	�=�(�	�=�(�	�=�(� 	�=�!(�"	�=�#(�(�$	�=�%(�&	�F�'(�(	�=�)(�*	�=�+(�,	�=�-(�.	�%�/(�.#�E�/(�.,5�e�/(�.>J�5�/(�4	�@�5(�6	�A�7(�8	�B�9(�:	�C�;(�<	�A�=(�>	�K�?(�@	�A�A(�B	�B�C(�(�DD�J�M�E�B�M�O(�(�(�M�V�r���E��
�.�5F�U�Yk�
�#5�B�X���H���2���3��	�3��	�2�	�
	�3��	�3�
�	�3��	�4��	�4��	�3��	�4��	�4��	�1��	�2�� 	�1�!�"	�,�#�$	�-�%�&0�-�+�1��,�1���L�8����	���	��	�
	���	��
�	���	���	�<��	�A��	�=��	�B��	�>��	�>�� 	�>�!�"	�;�#�$	�;�%�N�("�)�/�/�1�1�)�)�
��U�#(��t�C�x� � ��*���C�E�S��C���F�����O�
&�%�)�)�1�)�)�)�)�)�)���M�	�<�<�<�
�J�J�JrrJc�0�eZdZdZd�Zd�Zd�Zd�Zd�ZdS)�CommandLineParserzA parser for runtime optionsc��||_dS�N)�options)�selfrs  r�__init__zCommandLineParser.__init__%s
������rc�l�t|��dkrdSt|��dkr�|d�d��rp|�|��\}}|sd|zdzS|sd|zdzSt|j||��t|��dkr|d�d���pdS)�Parse command line optionsrN�--zOption z not recognizedz needs a value)�len�
startswith�
readoption�setattrr)r�argsr�r�s    r�parseoptionszCommandLineParser.parseoptions(s����t�9�9��>�>��4��$�i�i�!�m�m��Q�� 2� 2�4� 8� 8�m�����.�.�J�C���
=� �5�(�+<�<�<��
:� �3��)9�9�9��D�L�#�u�-�-�-�
�$�i�i�!�m�m��Q�� 2� 2�4� 8� 8�m��trc�b�|ddd�}|d=d|vr|�||��}n|�dd��}t|j|��sd|fSt	|j|��}t|t��r|dfSt|��dkr|dfS|d�d��r#|d}|d=||�	||��fS|d�
d	��}|d=t|t��r|�|��||fS||fS)
z$Read the key and value for an optionr�Nr�r�r@Tr�zutf-8)
�
readequalskey�replace�hasattrr�getattr�
isinstance�boolrr�
readquoted�decode�list�append)rrrzr��current�initialr�s       rr	zCommandLineParser.readoption5sH���1�g�a�b�b�k����G��#�:�:��$�$�S�$�/�/�C�C��+�+�c�2�&�&�C��t�|�S�)�)�	���9���$�,��,�,���g�t�$�$�	���9���t�9�9��>�>���9����7���c�"�"�	7��1�g�G��Q�������g�6�6�6�6��Q����w�'�'����G��g�t�$�$�	 ��N�N�5�!�!�!���<���E�z�rc�Z�t�d��|dd�}t|��dkr�|d�d��s�|d�d��s}t�d|dz��|d|dzz
}|d=t|��dkr6|d�d��s|d�d���}t|��dks|d�d��rdS|d|dd	�zz
}|S)
zRead a value between quotes�Oops�Nrr�rz
Appending rgr)rrr�endswithr)rrrr�s    rrzCommandLineParser.readquotedPs��
���F�����������$�i�i�!�m�m�D��G�$4�$4�S�$9�$9�m�$�q�'�BT�BT�UY�BZ�BZ�m��K�K��t�A�w�.�/�/�/��S�4��7�]�"�E��Q���$�i�i�!�m�m�D��G�$4�$4�S�$9�$9�m�$�q�'�BT�BT�UY�BZ�BZ�m��t�9�9��>�>�T�!�W�/�/��5�5�>��4�
��t�A�b�D�z�!�!���rc�~�|�dd��}|d}|d}|�d|��|S)zRead a key using equalsr�rr)�split�insert)rrzrr r�r�s      rrzCommandLineParser.readequalskey]s@���	�	�#�q�!�!���A�h���a������A�u�����
rN)	r r!r"r#rrr	rrr%rrr�r�"se������"�"����������6�������rr�c�P�eZdZdZdZdZdZdZdZdZ	dZ
iZd�Zd�Z
d�Zd�Zd	�ZdS)
�OptionszA set of runtime optionsNFTc�
�|dt_|d=tt��}|�|��}|r.t�|��|���|���dS)rrN)r#�locationr�rrr�usage�processoptions)rr�parser�results    rrzOptions.parseoptionstst����7�����G�"�7�+�+���$�$�T�*�*���	��K�K������J�J�L�L�L��������rc�6�tjr|���tjr|���tt��D]C}|�d��r,tt|t||dd������DdS)zProcess all options parsed.�modeN���)
r#�helpr&�version�showversion�dirrrr
r)r�params  rr'zOptions.processoptionss����<�	��J�J�L�L�L��?�	���������Z�Z�	A�	A�E��~�~�f�%�%�
A���u�g�d�E�#�2�#�J�&?�&?�@�@�@��	A�	Arc���t�dtjtj��j�d���t�d��|���dS)zShow correct usagezUsage: z [options] "input string"z.Convert input string with LaTeX math to MathMLN)rr�pathlib�Pathr#r%�parent�showoptions�rs rr&z
Options.usage�si��
���0�g�l�7�+;�<�<�C�0�0�0�	1�	1�	1�
���D�E�E�E��������rc�0�t�d��t�d��t�d��t�d��t�d��tj��dS)zShow all possible optionsz1    --help:                 show this online helpz9    --quiet:                disables all runtime messageszF    --debug:                enable debugging messages (for developers)z@    --version:              show version number and release datezD    --simplemath:           do not generate fancy math constructionsN)rrr
rr7s rr6zOptions.showoptions�sp��
���G�H�H�H�
���O�P�P�P�
���\�]�]�]�
���V�W�W�W�
���Z�[�[�[���
�
�
�
�
rc�p�t�dtz��tj��dS)z(Return the current eLyXer version stringz
math2html N)rr�__version__r
rr7s rr/zOptions.showversion�s(��
���L��,�-�-�-���
�
�
�
�
r)r r!r"r#r%r�quietr.r-�
simplemath�	showlines�branchesrr'r&r6r/r%rrr#r#fs����������H��E��E��G��D��J��I��H�	�	�	�	A�	A�	A�����������rr#c�J�eZdZdZd�Zd�Zee��Zee��ZdS)�Clonerz&An object used to clone other objects.c�8�	|�|j��S)z"Return an exact copy of an object.)�create�	__class__)r
�originals  r�clonezCloner.clone�s��=��z�z�(�,�-�-�-rc�X�|�|��}|���|S)z"Create an object of a given class.)�__new__r)r
�typerEs   rrBz
Cloner.create�s(�����T�"�"��
�������rN)r r!r"r#rErBr$r%rrr@r@�sR������,�,�.�.�.�
���
�K����E�
�[��
 �
 �F�F�Frr@c�*�eZdZdZd�Zd�Zd�Zd�ZdS)�ContainerExtractora�A class to extract certain containers.

    The config parameter is a map containing three lists:
    allowed, copied and extracted.
    Each of the three is a list of class names for containers.
    Allowed containers are included as is into the result.
    Cloned containers are cloned and placed into the result.
    Extracted containers are looked into.
    All other containers are silently ignored.
    c�:�|d|_|d|_dS)Nr;r<r:)r�configs  rrzContainerExtractor.__init__�s���i�(�����,����rc�\���g��fd�}�fd�}��fd�}|�|||���S)z8Extract a group of selected containers from a container.c�*��|jj�jvSr)rCr r;�r�rs �r�<lambda>z,ContainerExtractor.extract.<locals>.<lambda>�s���1�;�/�4�<�?�rc�*��|jj�jvSr)rCr r<rOs �rrPz,ContainerExtractor.extract.<locals>.<lambda>�s���a�k�2�d�n�D�rc�0����|���Sr)�process)r�rrs ��rrPz,ContainerExtractor.extract.<locals>.<lambda>�s���D�L�L��D�1�1�r)�recursivesearch)r�	container�locate�	recursiverSrs`    @r�extractzContainerExtractor.extract�sS������?�?�?�?��D�D�D�D�	�1�1�1�1�1���!�!�&�)�W�=�=�=��rc��|jj}||jvr|�|��dSt�d|z��dS)zAdd allowed containers.zUnknown container class N)rCr r;rrr)rrUr�names    rrSzContainerExtractor.process�sP���"�+���4�<����K�K�	�"�"�"�"�"��K�K�2�T�9�:�:�:�:�:rc��t�|��}|j|_|�|��|_|S)zFReturn a new container with contents only in a safe list, recursively.)r@rE�outputrX�contents)rrUrEs   r�	safeclonezContainerExtractor.safeclone�s5�����Y�'�'�� �'������i�0�0����rN)r r!r"r#rrXrSr^r%rrrJrJ�sZ������	�	�-�-�-����;�;�;�����rrJc�6�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	dS)	�ParserzA generic parserc�"�d|_i|_dS)Nr)rW�
parametersr7s rrzParser.__init__�s����
�����rc��|������}|���|j|_|S)zParse the header)�currentliner �nextline�
linenumberrW)r�reader�headers   r�parseheaderzParser.parseheader�s>���#�#�%�%�+�+�-�-���������&��
��
rc���|�������dd��}|���t	|��dkrdS|d}t	|��dkrd|j|<dSd|dvr$|d���|j|<dS|d�d��}|d|j|<dS)zParse a parameterrgrrNTr�)rd�stripr rerrb)rrgr r��doublesplits     r�parseparameterzParser.parseparameter�s����"�"�$�$�*�*�,�,�2�2�3��:�:���������u�:�:��?�?��F��A�h���u�:�:��?�?�#'�D�O�C� ��F��e�A�h���#(��8�>�>�#3�#3�D�O�C� ��F��A�h�n�n�S�)�)��*�1�~������rc�4�|js,t�dt|��z��dS|����|j��s8|��|����|j���6dSdS)z'Parse until the current ending is foundzNo ending for N)�endingrr�strrdr)rrgrSs   r�parseendingzParser.parseending�s����{�	��K�K�(�3�t�9�9�4�5�5�5��F��$�$�&�&�1�1�$�+�>�>�	��G�I�I�I��$�$�&�&�1�1�$�+�>�>�	�	�	�	�	rc��|j�|��}|r#|j|_|�|��dSdSr)�factory�createcontainerr5r)rrgr]rUs    r�parsecontainerzParser.parsecontainersK���L�0�0��8�8�	��	'�#�{�I���O�O�I�&�&�&�&�&�	'�	'rc�P�|jjdzt|j��zdzS)zReturn a description� (r_)rCr rprWr7s r�__str__zParser.__str__s$���~�&��-��D�J���?�#�E�ErN)
r r!r"r#rrirmrqrurxr%rrr`r`�sy��������������.�.�.� ���'�'�'�F�F�F�F�Frr`c��eZdZdZd�ZdS)�LoneCommandz"A parser for just one command linec��gS)zRead nothingr%�rrgs  r�parsezLoneCommand.parse����	rN�r r!r"r#r}r%rrrzrzs)������(�(�����rrzc�(�eZdZdZgZd�Zd�Zd�ZdS)�
TextParserz(A parser for a command and a bit of textc���t�|��d|_|jjt
jvr!t
j|jj|_g|_dSr)r`rrorCr r'r��rrUs  rrzTextParser.__init__sO��������������'�?�+B�B�B�)�1�)�2E�2N�O�D�K�����rc�J�tj�|j��tjtjdtjd|jgz|_g}|�|��s+|�||��|�|���+|S)z$Parse lines as long as they are text�Layout�Inset)r��stackrror'r��isendingru�rrgr]s   rr}zTextParser.parse s���������,�,�,�!�'�?�+B�8�+L�+:�+B�7�+K�+/�;�+8�8������-�-��'�'�	2������1�1�1��-�-��'�'�	2��rc�*�|������}t|��dkrdS|d|jvrH|dtjvr&tj�|d��ngt_dSdS)zCheck if text is endingrFT)rdr rr�r�r��remove)rrgrs   rr�zTextParser.isending+s����$�$�&�&�,�,�.�.���w�<�<�1����5��1�:���%�%��q�z�Z�-�-�-�� �'�'���
�3�3�3�3�#%�
� ��4��urN)r r!r"r#r�rr}r�r%rrr�r�sL������.�.��E����	�	�	�����rr�c��eZdZdZd�ZdS)�ExcludingParserz%A parser that excludes the final linec�F����g�������fd����S)z5Parse everything up to (and excluding) the final linec�0��������Sr)ru)r]rgrs���rrPz'ExcludingParser.parse.<locals>.<lambda>?s����)<�)<�V�X�)N�)N�r)rqr�s``@rr}zExcludingParser.parse<s5�����������!N�!N�!N�!N�!N�!N�O�O�O��rNrr%rrr�r�9s)������+�+�����rr�c��eZdZdZd�ZdS)�
BoundedParserzA parser bound by a final linec�d�t�||��}|���|S)z*Parse everything, including the final line)r�r}rer�s   rr}zBoundedParser.parseFs,��"�(�(��v�6�6���������rNrr%rrr�r�Cs)������$�$�����rr�c��eZdZdZd�ZdS)�BoundedDummyz&A bound parser that ignores everythingc�b��|���fd�������gS)z#Parse the contents of the containerc�,������Sr)re)rgs�rrPz$BoundedDummy.parse.<locals>.<lambda>Ss������):�):�r)rqrer|s `rr}zBoundedDummy.parseQs8�������!:�!:�!:�!:�;�;�;��������	rNrr%rrr�r�Ns)������,�,�����rr�c��eZdZdZd�Zd�ZdS)�StringParserzParses just a stringc�$�|jdz|_gS)zDo nothing, just take noter)rfrWr|s  rrizStringParser.parseheader\s���&��*��
��	rc�V�|���}|���|S)zParse a single line)rdrer�s   rr}zStringParser.parseas(���%�%�'�'���������rN)r r!r"r#rir}r%rrr�r�Ys8�����������
����rr�c��eZdZdZd�Zd�ZdS)�ContainerOutputz(The generic HTML output for a container.c�Z�t�dt|��z��dS)zShow an error.zgethtml() not implemented for N�rrrpr�s  r�gethtmlzContainerOutput.gethtmlks&��
���4�s�4�y�y�@�A�A�A�A�Arc��dS)z5Decide if the output is empty: by default, not empty.Fr%r7s r�isemptyzContainerOutput.isemptyos���urN)r r!r"r#r�r�r%rrr�r�hs;������.�.�B�B�B�����rr�c��eZdZd�Zd�ZdS)�EmptyOutputc��gS)zReturn empty HTML code.r%r�s  rr�zEmptyOutput.gethtmlvr~rc��dS)z"This output is particularly empty.Tr%r7s rr�zEmptyOutput.isemptyzs���trN)r r!r"r�r�r%rrr�r�ts2�������������rr�c��eZdZdZd�ZdS)�FixedOutputzFixed outputc��|jS)zReturn constant HTML code)�htmlr�s  rr�zFixedOutput.gethtml�s
���~�rN�r r!r"r#r�r%rrr�r�s(�������N�����rr�c��eZdZdZd�ZdS)�ContentsOutputz&Outputs the contents converted to HTMLc��g}|j�|S|jD]g}t|d��s>t�d|jjzdzt
|��z��|cS||���z
}�h|S)�Return the HTML codeNr�zNo html in rh)r]rrrrCr rpr�)rrUr��elements    rr�zContentsOutput.gethtml�s�������%��K� �)�	&�	&�G��7�I�.�.�
����M�G�,=�,F�F��M�PS�T[�P\�P\�\�]�]�]������G�O�O�%�%�%�D�D��rNr�r%rrr�r��s)������,�,�
�
�
�
�
rr�c�J�eZdZdZdZdZdZdd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
dS)�TaggedOutputz-Outputs an HTML tag surrounding the contents.NFc�8�||_|r||_|r||_|S)z/Set the value for the tag and other attributes.)�tag�
breaklines�empty)rr�r�r�s    r�settagzTaggedOutput.settag�s,������	)�(�D�O��	��D�J��rc��||_|S)zSet the value for breaklines.)r�)rr�s  r�
setbreaklineszTaggedOutput.setbreaklines�s��$����rc��|jr|�|��gS|�|��g}|t�||��z
}|�|�|����|S)zReturn the HTML code.)r��selfclosing�openr�r�r�close)rrUr�s   rr�zTaggedOutput.gethtml�st���:�	1��$�$�Y�/�/�0�0��	�	�)�$�$�%����&�&�t�Y�7�7�7�����D�J�J�y�)�)�*�*�*��rc�f�|�|��sdSd|jzdz}|jr|dzS|S)zGet opening line.r@rErFr��checktagr�r�)rrUr�s   rr�zTaggedOutput.open�sD���}�}�Y�'�'�	��2��T�X�~��#���?�	��$�;���rc��|�|��sdSd|j���dzdz}|jrd|zdzS|S)zGet closing line.r@z</rrFr)r�r�r r�)rrUr�s   rr�zTaggedOutput.close�sY���}�}�Y�'�'�	��2��t�x�~�~�'�'��*�*�S�0���?�	'��%�<�$�&�&��rc�f�|�|��sdSd|jzdz}|jr|dzS|S)zGet self-closing line.r@rEz/>rr�)rrUr�s   rr�zTaggedOutput.selfclosing�sF���}�}�Y�'�'�	��2��D�H�n�t�+���?�	&���%�%��rc��|js,t�dt|��z��dS|jdkrdSdS)zCheck that the tag is valid.z
No tag in Fr@T)r�rrrpr�s  rr�zTaggedOutput.checktag�sC���x�	��K�K��s�9�~�~�5�6�6�6��5��8�r�>�>��5��tr)FF)r r!r"r#r�r�r�r�r�r�r�r�r�r�r%rrr�r��s�������3�3�
�C��J��E��������
����������������rr�c�,�eZdZdZ	d�Zd�Zd�Zd�ZdS)�FilteredOutputz1Returns the output in the contents, but filtered:c��g|_dS)zInitialize the filters.N)�filtersr7s rrzFilteredOutput.__init__�s
������rc�>�|j�||f��dS)z:Add a new filter: replace the original by the replacement.N)r�r)rrD�replacements   r�	addfilterzFilteredOutput.addfilter�s#������X�{�3�4�4�4�4�4rc��g}t�||��}|D]*}|�|�|�����+|S)r�)r�r�r�filter)rrUr)r��lines     rr�zFilteredOutput.gethtml�sQ�����%�%�d�I�6�6���	-�	-�D��M�M�$�+�+�d�+�+�,�,�,�,��
rc�T�|jD]\}}||vr|�||��}� |S)z0Filter a single line with all available filters.)r�r)rr�rDr�s    rr�zFilteredOutput.filter�s<��%)�\�	;�	;�!�H�k��4����|�|�H�k�:�:����rN)r r!r"r#rr�r�r�r%rrr�r��sY������7�7�*����5�5�5��������rr�c��eZdZdZd�ZdS)�StringOutputzReturns a bare string as outputc��|jgS)zReturn a bare string��stringr�s  rr�zStringOutput.gethtml�s��� �!�!rNr�r%rrr�r��s)������%�%�"�"�"�"�"rr�c��eZdZdZdZd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zdd�Zdd�Zd�ZdS)�Globablez�A bit of text which can be globbed (lumped together in bits).
    Methods current(), skipcurrent(), checkfor() and isout() have to be
    implemented by subclasses.Fc�,�t��|_dSr)�
EndingList�
endinglistr7s rrzGlobable.__init__s��$�,�,����rc��|���rdSt|�����dkr|���dSdS)z*Check for a Unicode byte mark and skip it.Ni��)�finished�ordr�skipcurrentr7s r�
checkbytemarkzGlobable.checkbytemarksR���=�=�?�?�	��F��t�|�|�~�~���&�(�(���������)�(rc�:�t�d��dS)z+Find out if we are out of the position yet.zUnimplemented isout()T�rrr7s r�isoutzGlobable.isouts��
���+�,�,�,��trc�:�t�d��dS)zReturn the current character.zUnimplemented current()r@r�r7s rrzGlobable.currents��
���-�.�.�.��rrc�:�t�d��dS)z3Check for the given string in the current position.zUnimplemented checkfor()Fr��rr�s  r�checkforzGlobable.checkfors��
���.�/�/�/��urc��|���r"|js|j���dS|j�|��S)z*Find out if the current text has finished.T)r��leavependingr��checkpending�checkinr7s rr�zGlobable.finishedsL���:�:�<�<�	��$�
/���,�,�.�.�.��4���&�&�t�,�,�,rc�:�t�d��dS)�)Return the current character and skip it.zUnimplemented skipcurrent()r@r�r7s rr�zGlobable.skipcurrent&s��
���1�2�2�2��rrc��d}|���s?|��r5||���z
}|���s
|���5|S)z>Glob a bit of text that satisfies a check on the current char.r@)r�r�)r�currentcheck�globs   rr�z
Globable.glob+s^�����-�-�/�/�	'�l�l�n�n�	'��D�$�$�&�&�&�D��-�-�/�/�	'�l�l�n�n�	'��rc�4�����fd���S)zGlob a bit of alpha textc�P���������Sr�r�isalphar7s�rrPz$Globable.globalpha.<locals>.<lambda>4���������!7�!7�!9�!9�r�r�r7s`r�	globalphazGlobable.globalpha2�����y�y�9�9�9�9�:�:�:rc�4�����fd���S)zGlob a row of digits.c�P���������Sr�r�isdigitr7s�rrPz%Globable.globnumber.<locals>.<lambda>8r�rr�r7s`r�
globnumberzGlobable.globnumber6r�rc��|������s|���dkrdSdS)z5Return if the current character is alphanumeric or _.r�TF)r�isalnumr7s r�isidentifierzGlobable.isidentifier:s:���<�<�>�>�!�!�#�#�	�t�|�|�~�~��'<�'<��4��urc�6�|�|j��S)z Glob alphanumeric and _ symbols.)r�r�r7s r�globidentifierzGlobable.globidentifier@s���y�y��*�+�+�+rc��	|������rdS|���dvrdSdS)z5Return if the current character is a value character:Fz{}()T�r�isspacer7s r�isvaluezGlobable.isvalueDsC��#��<�<�>�>�!�!�#�#�	��5��<�<�>�>�V�#�#��5��trc�6�|�|j��S)z'Glob a value: any symbols but brackets.)r�rr7s r�	globvaluezGlobable.globvalueMs���y�y���&�&�&rc�4�����fd���S)z(Skip all whitespace at current position.c�P���������Srrr7s�rrPz$Globable.skipspace.<locals>.<lambda>Sr�rr�r7s`r�	skipspacezGlobable.skipspaceQr�rc�l�������fd����z}�����|S)z4Glob a bit of text up to (including) the magic char.c�4�������kSr�r)�	magiccharrs��rrPz(Globable.globincluding.<locals>.<lambda>Ws��������9�!<�r)r��skip)rrr�s`` r�
globincludingzGlobable.globincludingUs>�����y�y�<�<�<�<�<�=�=�	�I���	�	�)�����rc�8�������fd���S)z?Glob a bit of text up until (excluding) any excluded character.c�0�������vSrr
)�excludedrs��rrPz(Globable.globexcluding.<locals>.<lambda>]s��������x�!?�rr�)rrs``r�
globexcludingzGlobable.globexcluding[s#�����y�y�?�?�?�?�?�@�@�@rc�<�|j�||��dS)zPush a new ending to the bottomN)r��add�rro�optionals   r�
pushendingzGlobable.pushending_s ������F�H�-�-�-�-�-rNc���|���r	|jr|S|j�|��}|r)||kr#t�d|zdz|z��|�|��|S)z,Pop the ending found at the current positionzExpected ending z, got )r�r�r��poprrr)r�expectedros   r�	popendingzGlobable.popendingcs����:�:�<�<�	�D�-�	��O���$�$�T�*�*���	K��F�*�*��K�K�*�X�5��@�6�I�J�J�J��	�	�&�����
rc�L�|j�|��}|sdS|jS)z$Return the next ending in the queue.N)r��
findendingro)r�
nextendings  rrzGlobable.nextendingms-���_�/�/��5�5�
��	��4�� � r�Fr)r r!r"r#r�rr�r�rr�r�r�r�r�r�r�r�rrrr
rrrrr%rrr�r��s^������"�"��L�'�'�'�������
���
���
-�-�-����
���;�;�;�;�;�;����,�,�,����'�'�'�;�;�;����A�A�A�.�.�.�.�����!�!�!�!�!rr�c�D�eZdZdZd�Zdd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�ZdS)
r�zA list of position endingsc��g|_dSr)r�r7s rrzEndingList.__init__xs
������rFc�V�|j�t||����dS)zAdd a new ending to the listN)r�r�PositionEndingrs   rrzEndingList.add{s(������N�6�8�<�<�=�=�=�=�=rc�:�|xj|jjz
c_dS)z/Pick any pending endings from a parse position.N)r�r��r�poss  r�pickpendingzEndingList.pickpendings�������.�.����rc�4�|�|��rdSdS)zSearch for an endingTF)rr$s  rr�zEndingList.checkin�s ���?�?�3���	��4��urc���|���rt�d��dS|�|��}|s1t�d|���z��dSt|j��D]O}|j�|��||kr	|jcS|j	st�d|z���Pt�d��dS)z)Remove the ending at the current positionzNo ending out of boundsr@z
No ending at zRemoved non-optional ending zNo endings left)
r�rrrr�reversedr�r�ror)rr%ro�eachs    rrzEndingList.pop�s����9�9�;�;�	��K�K�1�2�2�2��2�����%�%���	��K�K��#�+�+�-�-�7�8�8�8��2��T�\�*�*�	C�	C�D��L����%�%�%��v�~�~��{�"�"�"��]�
C����:�T�A�B�B�B��
���%�&�&�&��rrc���t|j��dkrdStt|j����D](\}}|�|��r|cS|jsdS�)dS)z'Find the ending at the current positionrN)rr��	enumerater)r�r)rr%�indexros    rrzEndingList.findending�sy���t�|����!�!��4�&�x���'=�'=�>�>�	�	�M�E�6��~�~�c�"�"�
��
�
�
��?�
��t�t�
��trc��t|j��dkr/t�dt	|��zdz��dSdS)z&Check if there are any pending endingsrzPending z
 left openN)rr�rrrpr7s rr�zEndingList.checkpending�sG���t�|����!�!��K�K�
�S��Y�Y�.��=�>�>�>�>�>�"�!rc��d}|jD]}|t|��dzz
}�t|j��dkr
|dd�}|dzS)�Printable representationz	endings [r�rNrra)r�rpr)rr�ros   rrxzEndingList.__str__�s[�����l�	(�	(�F��c�&�k�k�C�'�'�F�F��t�|���q� � ��C�R�C�[�F���|�rNr)r r!r"r#rrr&r�rrr�rxr%rrr�r�us������� � ����>�>�>�>�/�/�/�������$	�	�	�?�?�?�
����rr�c�$�eZdZdZd�Zd�Zd�ZdS)r"z An ending for a parsing positionc�"�||_||_dSr�rorrs   rrzPositionEnding.__init__�s����� ��
�
�
rc�6�|�|j��S)zCheck for the ending)r�ror$s  rr�zPositionEnding.checkin�s���|�|�D�K�(�(�(rc�2�d|jz}|jr|dz
}|S)r0zEnding z (optional)r3r�s  rrxzPositionEnding.__str__�s'���T�[�(���=�	$��m�#�F��
rN)r r!r"r#rr�rxr%rrr"r"�sG������&�&�!�!�!�)�)�)�����rr"c�N�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
dS)
�Positionz�A position in a text to parse.
    Including those in Globable, functions to implement by subclasses are:
    skip(), identifier(), extract(), isout() and current().c�:�t�|��dSr)r�rr7s rrzPosition.__init__�s�����$�����rc�:�t�d��dS)z
Skip a stringzUnimplemented skip()Nr�r�s  rrz
Position.skip�s��
���*�+�+�+�+�+rc�:�t�d��dS)z.Return an identifier for the current position.zUnimplemented identifier()�Errorr�r7s r�
identifierzPosition.identifier�s��
���0�1�1�1��wrc�<�	t�d��dS)zHExtract the next string of the given length, or None if not enough text,zUnimplemented extract()Nr��r�lengths  rrXzPosition.extract�s��/�
���-�.�.�.��trc�N�||�t|����kS)z)Check for a string at the given position.)rXrr�s  rr�zPosition.checkfor�s������c�&�k�k�2�2�2�2rc���|�t|����}|sdS|���|�t|�������kS)z!Check for a string in lower case.F)rXr�lower)rr�r<s   r�
checkforlowerzPosition.checkforlower�sW���L�L��V���-�-�	��	��5��|�|�~�~����c�&�k�k�!:�!:�!@�!@�!B�!B�B�Brc�X�|���}|�|��|S)r�)rr�rrs  rr�zPosition.skipcurrent�s&���,�,�.�.���	�	�'�����rc�R�|���|���S)z3Advance the position and return the next character.)r�rr7s r�__next__zPosition.__next__�s"���������|�|�~�~�rc�^�|�|��sdS|�|��dS)z;Check for a string at the given position; if there, skip itFT)r�rr�s  r�	checkskipzPosition.checkskip�s2���}�}�V�$�$�	��5��	�	�&�����trc�j�t�|dz|���z��dS)z2Show an error message and the position identifier.rhN)rrr<)rrs  rrzPosition.error�s-��
���G�d�N�T�_�_�%6�%6�6�7�7�7�7�7rN)r r!r"r#rrr<rXr�rCr�rGrIrr%rrr7r7�s�������?�?� � � �,�,�,����
���3�3�3�C�C�C�������
���8�8�8�8�8rr7c�6�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	dS)	�TextPositionz%A parse position based on a raw text.c�~�t�|��d|_||_|���dS)z#Create the position from some text.rN)r7rr%�textr��rrNs  rrzTextPosition.__init__s<�����$���������	��������rc�@�|xjt|��z
c_dS)zSkip a string of characters.N)r%rr�s  rrzTextPosition.skips�����C��K�K�����rc���d}|j|zt|j��krt|j��|jz
}d|j|j|j|z�zdzS)z&Return a sample of the remaining text.�r��r%rrNr>s  rr<zTextPosition.identifiersZ�����8�f��s�4�9�~�~�-�-����^�^�d�h�.�F��T�Y�t�x���6�(9�9�:�:�S�@�@rc�<�|jt|j��kS)z'Find out if we are out of the text yet.rSr7s rr�zTextPosition.isouts���x�3�t�y�>�>�)�)rc�&�|j|jS)z6Return the current character, assuming we are not out.)rNr%r7s rrzTextPosition.currents���y���"�"rc�~�|j|zt|j��krdS|j|j|j|z�S)zHExtract the next string of the given length, or None if not enough text.NrSr>s  rrXzTextPosition.extracts<���8�f��s�4�9�~�~�-�-��4��y���D�H�v�$5�5�6�6rN)
r r!r"r#rrr<r�rrXr%rrrLrLsw������+�+���� � � �A�A�A�*�*�*�#�#�#�7�7�7�7�7rrLc��eZdZdZdZdZdZd�Zd�Zd�Z	e
jfd�Zd�Z
d�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zdd�Zd�Zd�Zd�Zd�ZdS)�	Containerz.A container for text and objects in a lyx fileNc�,�t��|_dSr)rr]r7s rrzContainer.__init__,s������
�
�
rc��dS)zProcess contentsNr%r7s rrSzContainer.process/s���rc��|j�|��}t|t��r t�d|z��|g}|S)zGet the resulting HTMLzRaw string )r\r�rrprr)rr�s  rr�zContainer.gethtml3sL���{�"�"�4�(�(���d�C� � �	��K�K�
��,�-�-�-��6�D��rc��t|�����}|D]"}||vr|�|||��}�#|S)z*Escape a line with replacements from a map)�sorted�keysr)rr��replacements�pieces�pieces     r�escapezContainer.escape;sS����)�)�+�+�,�,���	@�	@�E���}�}��|�|�E�<��+>�?�?����rc��d}t|��}|���s�t|�����dkrtt	t|�������}|dkr,t	tt|����dz��}|d|dd�zdzz
}n||���z
}|���|�����|S)	z/Escape all Unicode characters to HTML entities.r@��0xd835i�z&#rNr�)rLr�r�r�hex�nextr�)rr�r)r%�	codepoints     r�escapeentitieszContainer.escapeentitiesDs������4� � ���,�,�.�.�	��3�;�;�=�=�!�!�C�'�'���C�K�K�M�M� 2� 2�3�3�	���(�(� #�C��S�	�	�N�N�V�$;� <� <�I��$��1�2�2��.��4�4����#�+�+�-�-�'���O�O�����,�,�.�.�	��
rc�>��g�|�|�fd����S)z2Search for all embedded containers of a given typec�.����|��Sr)r)rUrs �rrPz%Container.searchall.<locals>.<lambda>Vs���4�;�;�y�3I�3I�r)�
searchprocess)rrHrs  @r�	searchallzContainer.searchallSs-��������4�!I�!I�!I�!I�J�J�J��rc�x�|�|��}|D]!}|jj�|���"|S)z3Search for all containers of a type and remove them)rmr5r]r�)rrHrrUs    r�searchremovezContainer.searchremoveYsD���~�~�d�#�#���	8�	8�I���%�,�,�Y�7�7�7�7��rc�:��|��fd�|��dS)z4Search for elements of a given type and process themc�$��t|���Sr)r)rUrHs �rrPz)Container.searchprocess.<locals>.<lambda>bs���Z�	�4�-H�-H�rN)�
locateprocess)rrHrSs ` rrlzContainer.searchprocess`s)������H�H�H�H�'�R�R�R�R�Rrc�r�|jD].}|�||��||��r||���/dS)z3Search for all embedded containers and process themN)r]rr)rrVrSrUs    rrrzContainer.locateprocessdsV����	#�	#�I��#�#�F�G�4�4�4��v�i� � �
#���	�"�"�"��	#�	#rc��|jD]:}||��r|�|||��||��r||���;dS)z,Perform a recursive search in the container.N)r]rT)rrVrWrSrUs     rrTzContainer.recursivesearchksk����	#�	#�I��y��#�#�
F��)�)�&�)�W�E�E�E��v�i� � �
#���	�"�"�"��		#�	#rc��ttj���|��}d�d�|D����S)z)Extract all text from allowed containers.r@c3�$K�|]}|jV��dSrr�)r��constants  rr�z(Container.extracttext.<locals>.<genexpr>vs$����A�A�8�x��A�A�A�A�A�Ar)rJr'r=rX�join)r�	constantss  rr=zContainer.extracttextssA��&��'B�C�C�K�K�D�Q�Q�	��w�w�A�A�y�A�A�A�A�A�Arc��|t|j��krdSt|j|d��rdS|t|j��kr�||j|��rd|j|_|j�|j|��|j�|��|t|j��kr||j|���|j�||��dS)z*Group some adjoining elements into a groupN�groupedT)rr]rr{rrr!)rr-�group�	isingroups    rr|zContainer.groupxs����C��
�&�&�&�&��F��4�=��'��3�3�	��F��c�$�-�(�(�(�(�Y�Y�t�}�U�7K�-L�-L�(�+/�D�M�%� �(��N�!�!�$�-��"6�7�7�7��M���e�$�$�$��c�$�-�(�(�(�(�Y�Y�t�}�U�7K�-L�-L�(�	
�
���U�E�*�*�*�*�*rc��|j|}|j�|��t|j��dkrL|j�||j�����t|j��dk�JdSdS)z)Remove a container but leave its contentsrN)r]rrr!)rr-rUs   rr�zContainer.remove�s����M�%�(�	��
���%� � � ��)�$�%�%��)�)��M� � ��	�(:�(>�(>�(@�(@�A�A�A��)�$�%�%��)�)�)�)�)�)rrc��t�d|zt|��z��|jD]}|�|dz���dS)zShow in a treez  rN)rrrpr]�tree)r�levelrUs   rr�zContainer.tree�sW��
���D�5�L�3�t�9�9�,�-�-�-���	&�	&�I��N�N�5�1�9�%�%�%�%�	&�	&rc�2�||jvrdS|j|S)z)Get the value of a parameter, if present.N)rb�rrZs  r�getparameterzContainer.getparameter�s!���t��&�&��4���t�$�$rc�^�|�|��}|sgS|�d��S)z7Get the value of a comma-separated parameter as a list.r�)r�r )rrZ�	paramtexts   r�getparameterlistzContainer.getparameterlist�s4���%�%�d�+�+�	��	��I����s�#�#�#rc�`�|j}|r$|j���rdS|j}|�$dS)z&Check if the parent's output is empty.TF)r5r\r�rEs  r�hasemptyoutputzContainer.hasemptyoutput�sD���+���	%��~�%�%�'�'�
��t��n�G��	%��urc�p�|js|jjS|jjdzt|j��zS)zGet a descriptionr�)rWrCr rpr7s rrxzContainer.__str__�s4���z�	+��>�*�*��~�&��,�s�4�:���>�>r)r)r r!r"r#�partkeyr5rWrrSr�r?rHrbrirmrorlrrrTr=r|r�r�r�r�r�rxr%rrrXrX%sR������4�4��G�
�F��E����
�
�
����)5�(=�����
�
�
�������S�S�S�#�#�#�#�#�#�B�B�B�

+�
+�
+�B�B�B�&�&�&�&�%�%�%�$�$�$����?�?�?�?�?rrXc��eZdZdZd�ZdS)�BlackBoxz)A container that does not output anythingc�`�t��|_t��|_g|_dSr)rzr(r�r\r]r7s rrzBlackBox.__init__�s#��!�m�m���!�m�m�����
�
�
rN)r r!r"r#rr%rrr�r��s)������/�/�����rr�c�:�eZdZdZdZd�Zd�Zd�Zd�Zd�Z	d�Z
dS)	�StringContainerzA container for a single stringNc�`�t��|_t��|_d|_dS)Nr@)r�r(r�r\r�r7s rrzStringContainer.__init__�s#��"�n�n���"�n�n�������rc�d�|jr(|�|j��|_d|_dSdS)z(Replace special chars from the contents.N)�parsed�replacespecialr�r7s rrSzStringContainer.process�s8���;�	��-�-�d�k�:�:�D�K��D�K�K�K�	�	rc�d�|�|tj��}|�|��}tjd|vrft
|��dkrS|jrdt|j��zdz}nd}t�
||���z��|S)z%Replace all special chars from a line�startcommandrzUnknown command at rhzUnknown command: )rbr?rH�
changeliner'r�rrWrprrrk)rr��replacedrs    rr�zStringContainer.replacespecial�s����;�;�t�\�%:�;�;���?�?�8�,�,���!�.�1�X�=�=�#�h�-�-�RS�BS�BS��z�
.�/�#�d�j�/�/�A�D�H���-���K�K��(�.�.�"2�"2�2�3�3�3��rc�B�|�|tj��Sr)rbr?rG)rr�s  rr�zStringContainer.changeline�s���{�{�4��!3�4�4�4rc��|jS)zReturn all text.r�r7s rr=zStringContainer.extracttext�s
���{�rc��d}|jr|dt|j��zz
}d}t|j�����dkrd}|dz|j���dd�z|zdzS)	�"Return a printable representation.r�r�z...�r@rwNr_)rWrprr�rk)rr)�ellipsiss   rrxzStringContainer.__str__�s���"���:�	,��c�C��
�O�O�+�+�F����t�{� � �"�"�#�#�r�)�)��H���}�t�{�0�0�2�2�3�B�3�7�7�(�B�S�H�Hr)r r!r"r#r�rrSr�r�r=rxr%rrr�r��s~������%�%�
�F����
������5�5�5����I�I�I�I�Irr�c��eZdZdZd�Zd�ZdS)�ConstantzA constant stringc�H�g|_||_t��|_dSr)r]r�r�r\rOs  rrzConstant.__init__�s����
����"�n�n����rc��d|jzS)Nz
Constant: r�r7s rrxzConstant.__str__�s���d�k�)�)rN)r r!r"r#rrxr%rrr�r��s8��������%�%�%�
*�*�*�*�*rr�c��eZdZdZdZdS)�DocumentParametersz#Global parameters for the document.FN)r r!r"r#�displaymoder%rrr�r��s������)�)��K�K�Krr�c�6�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	dS)	�
FormulaParserzParses a formulac�2�|jdz|_|�|��}|so|���|�|��}|sDt�d|������z��dgS|gS)zSee if the formula is inlinedrzUnknown formula type in �unknown)rfrW�	parsetypererrrdrk)rrgrHs   rrizFormulaParser.parseheader�s����&��*��
��~�~�f�%�%���	#��O�O�����>�>�&�)�)�D��
#����6��9K�9K�9M�9M�9S�9S�9U�9U�U�V�V�V�!�{�"��v�
rc���|����tjd��dkrdS|����tjd��dkrdS|����tjd��dkrdS|����tjd��dkrdSd	S)
z)Get the formula type from the first line.r�r�inliner��blockr�r��numberedN)rd�findrJr�r|s  rr�zFormulaParser.parsetypes��������$�$�]�%9�(�%C�D�D��I�I��8������$�$�]�%9�)�%D�E�E��J�J��7������$�$�]�%9�,�%G�H�H�A�M�M��7������$�$�]�%9�-�%H�I�I�Q�N�N��:��trc���|�|��}|����|j��s�|������}t|��dkrt�d|z��|���|����|j����|���|S)zParse the formula until the endrzUnparsed formula line )	�parseformulardrrorkrrrre)rrg�formula�strippeds    rr}zFormulaParser.parses����#�#�F�+�+���$�$�&�&�1�1�$�+�>�>�	��)�)�+�+�1�1�3�3�H��8�}�}�q� � ����4�x�?�@�@�@��O�O����	�$�$�&�&�1�1�$�+�>�>�	�
	�������rc���tjd}||���vr`|����|d��d}||vr|�|||��S|�|||��Stjd|���vr7|�|tjdtjd��Stjd}tjd}||���v�r!|�������|��r�|������}|�|��d�|��}||dz|z}tjd}	tjd}
|	|dz|
z}||�|||��z|zSt�
d	|zd
z|���z��dStjd}tjd
}
||���vr?|
|���vr)tjd
}|�||
|��St�
d|���zdz��dS)zParse the formula contentsr�rr�r�r�rr�r�zMissing z in r@r�r�zFormula beginning z is unknown)rJr�rdr �parsesingleliner�parsemultilinerr�rkrrr)rrgr��restr�r�r�endsplit�
startpiecer�r��endpiece�begincommand�beginbracket�
endbrackets               rr�zFormulaParser.parseformulas����%�h�/���V�'�'�)�)�)�)��%�%�'�'�-�-�f�a�8�8��;�D���~�~��,�,�V�V�V�D�D�D��'�'����?�?�?���	�*�f�.@�.@�.B�.B�B�B��'�'��
�0D�Y�0O�(5�(=�i�(H�J�J�
J�#�*�=�9��"�)�,�7�
��&�,�,�.�.�.�.��!�!�#�#�)�)�+�+�4�4�Z�@�@�
b� �,�,�.�.�4�4�6�6��"�=�=��5�5�a�8�>�>�z�J�J��(�8�A�;�6��C�
�)�1�+�>�	�(�0��<��$�x��{�2�X�=��!�D�$8�$8���X�$V�$V�V�Ya�a�a��K�K�
�Z�/�&�8�6�;M�;M�;O�;O�O�P�P�P��2�$�+�I�6��$�+�I�6���6�-�-�/�/�/�/�L�F�DV�DV�DX�DX�4X�4X�&�.�y�9�J��'�'���j�I�I�I�
���(�6�+=�+=�+?�+?�?�-�O�P�P�P��rrc��|������}||vr%t�d|zdz|z��dS|�|��s%t�d|zdz|z��dS|�|��}||t
|��zt
|���}|���|S)zParse a formula in one line�Line �  does not contain formula start r@zFormula z does not end with )rdrkrrrr-rre)rrg�startror�r-r�s       rr�zFormulaParser.parsesinglelinerAs����!�!�#�#�)�)�+�+�������K�K��$��)K�K�e�S�T�T�T��2��}�}�V�$�$�	��K�K�
�T�)�,A�A�F�J�K�K�K��2��
�
�5�!�!���E�C��J�J�&��F���|�3�4���������rc�<�d}|���}||vr7t�d|���zdz|z��dS|�|��}||t|��zd����}|�|��sE||dzz
}|���|���}|�|���E||dt|���z
}|���|S)z!Parse a formula in multiple linesr@r�r�Nr)rdrrrkr-rrre)rrgr�ror�r�r-s       rr�zFormulaParser.parsemultilinerOs�����!�!�#�#�������K�K��$�*�*�,�,�.�1S�S�V[�[�\�\�\��2��
�
�5�!�!���E�C��J�J�&�'�'�(�.�.�0�0���-�-��'�'�	(��t�d�{�"�G��O�O�����%�%�'�'�D��-�-��'�'�	(�	�4�
�#�f�+�+��
�&�&���������rN)
r r!r"r#rir�r}r�r�r�r%rrr�r��su��������
�
�
�
�
�
�	�	�	�!�!�!�F�������rr�c�H�eZdZdZdZdZdZd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
dS)�
FormulaBitzA bit of a formulaNrr@c�:�g|_t��|_dS)z6The formula bit type can be 'alpha', 'number', 'font'.N)r]r�r\r7s rrzFormulaBit.__init__hs����
�$�&�&����rc��||_|S)z!Set the internal formula factory.)rs)rrss  r�
setfactoryzFormulaBit.setfactoryms������rc�r�|j�|��|xj|jz
c_||_dS)z-Add any kind of formula bit already processedN)r]rrDr5�r�bits  rrzFormulaBit.addrs5���
���S�!�!�!��
�
���%�
�
���
�
�
rc��|xj|z
c_|�|��s7t�d|zdz|���z��dSdS)z0Skip a string and add it to the original formulazString z not at N)rDrIrrr<)rr�r%s   r�skiporiginalzFormulaBit.skiporiginalxsd���
�
���
�
��}�}�V�$�$�	L��K�K�	�F�*�Z�7�#�.�.�:J�:J�J�K�K�K�K�K�	L�	Lrc��t|j��dkrdStd�|jD����|_|jS)zDCompute the size of the bit as the max of the sizes of all contents.rrc3�$K�|]}|jV��dSr��size�r�r�s  rr�z)FormulaBit.computesize.<locals>.<genexpr>�s$����B�B����B�B�B�B�B�Br)rr]r�r�r7s r�computesizezFormulaBit.computesize~sD���t�}����"�"��1��B�B�D�M�B�B�B�B�B��	��y�rc�@�|j�|j��S�zReturn a copy of itself.)rsr�rDr7s rrEzFormulaBit.clone�s���|�(�(���7�7�7rc�0�|jjdz|jzS)zGet a string representationz	 read in )rCr rDr7s rrxzFormulaBit.__str__�s���~�&��4�t�}�D�Dr)r r!r"r#rHr�rDrr�rr�r�rErxr%rrr�r�as����������D��D��H�'�'�'�
���
���L�L�L����8�8�8�E�E�E�E�Err�c�&�eZdZdZd�Zdd�Zd�ZdS)�	TaggedBitzA tagged string in a formulac��t���|��|_|�t	|����|S�zSet the constant and the tag)r�r�r\rr))rrwr�s   rrwzTaggedBit.constant�s:��"�n�n�+�+�C�0�0��������*�*�+�+�+��rFc�b�||_t���||��|_|Sr�)r]r�r�r\)rr]r�r�s    r�completezTaggedBit.complete�s)�� ��
�"�n�n�+�+�C��<�<����rc�V�t���|d���|_|S)z4Set the self-closing tag, no contents (as in <hr/>).T)r�)r�r�r\)rr�s  r�selfcompletezTaggedBit.selfcomplete�s%��"�n�n�+�+�C�t�+�<�<����rNr)r r!r"r#rwr�r�r%rrr�r��sL������"�"������������rr�c�*�eZdZdZd�Zd�Zd�Zd�ZdS)r)zA constant string in a formulac�f�t�||��||_d|_d|_dS)zSet the constant stringrN)r�rrDr�rHr�s  rrzFormulaConstant.__init__�s1�����$��'�'�'���
���	���	�	�	rc��|jS)z+Compute the size of the constant: always 1.r�r7s rr�zFormulaConstant.computesize�s
���y�rc�*�t|j��Sr�)r)rDr7s rrEzFormulaConstant.clone�s���t�}�-�-�-rc��d|jzS)r�zFormula constant: r�r7s rrxzFormulaConstant.__str__�s��#�d�k�1�1rN)r r!r"r#rr�rErxr%rrr)r)�sV������$�$�������.�.�.�2�2�2�2�2rr)c��eZdZdZd�Zd�ZdS)r5zA bit of text inside a formulac�N�|������S)zDetect a bit of raw textr�r$s  r�detectzRawText.detect�����{�{�}�}�$�$�&�&�&rc��|���}|�t|����d|_dS)zParse alphabetic text�alphaN)r�rr)rH)rr%r�s   r�parsebitzRawText.parsebit�s4���
�
���������'�'�(�(�(���	�	�	rN�r r!r"r#r�r�r%rrr5r5�s8������$�$�'�'�'�����rr5c�L�eZdZdZejZejdZd�Zd�Zd�Z	dS)r2zA symbol inside a formular�c��|���tjvrdS|���tjvrdSdS)zDetect a symbolTF)rr2r�r�r$s  rr�zFormulaSymbol.detect�s=���;�;�=�=�M�4�4�4��4��;�;�=�=�M�2�2�2��4��urc��|���tjvr*|�|���|��dS|���tjvr:|�tj|���|��dSt
�d|���zdz��dS)�Parse the symbolNzSymbol z
 not found)rr2r��	addsymbolr�rrr$s  rr�zFormulaSymbol.parsebit�s����;�;�=�=�M�4�4�4��N�N�3�;�;�=�=�#�.�.�.��F��;�;�=�=�M�2�2�2��N�N�=�1�#�+�+�-�-�@�#�F�F�F��F�
���I����
�
�-��<�=�=�=�=�=rc��|�|���|��|j�t	|����dS)zAdd a symbolN)r�rr]rr))r�symbolr%s   rr�zFormulaSymbol.addsymbol�sD�����#�+�+�-�-��-�-�-��
���_�V�4�4�5�5�5�5�5rN)
r r!r"r#rJr�r�r�r�r�r%rrr2r2�s\���������%�H��)�,�7�J����>�>�>�6�6�6�6�6rr2c��eZdZdZd�Zd�ZdS)r1zA string of digits in a formulac�N�|������S)zDetect a digitr�r$s  rr�zFormulaNumber.detect�r�rc������fd���}|�t|����d|_dS)zParse a bunch of digitsc�P���������Srr�)r%s�rrPz(FormulaNumber.parsebit.<locals>.<lambda>�s���#�+�+�-�-�"7�"7�"9�"9�r�numberN)r�rr)rH)rr%�digitss ` rr�zFormulaNumber.parsebit�sC������9�9�9�9�:�:�������(�(�)�)�)���	�	�	rNr�r%rrr1r1�s8������%�%�'�'�'�����rr1c�8�eZdZdZejdZd�Zd�ZdS)�Commentz*A LaTeX comment: % to the end of the line.r�c�<�|���|jkS)z
Detect the %.)rr�r$s  rr�zComment.detect�s���{�{�}�}��
�*�*rc�L�|xj|�d��z
c_dS)zParse to the end of the line.rN)rDr
r$s  rr�zComment.parsebit�s$���
�
��*�*�4�0�0�0�
�
�
�
rN)	r r!r"r#rJr�r�r�r�r%rrr�r��sE������0�0�� ��+�E�+�+�+�1�1�1�1�1rr�c�$�eZdZdZd�Zd�Zd�ZdS)�
WhiteSpacez"Some white space inside a formula.c�N�|������S)zDetect the white space.rr$s  rr�zWhiteSpace.detectr�rc�J�|xj|���z
c_dS)zParse all whitespace.N)rDrr$s  rr�zWhiteSpace.parsebit	s���
�
������(�
�
�
�
rc��d|jzdzS)r�z
Whitespace: *r�)rDr7s rrxzWhiteSpace.__str__
s�����.��4�4rN)r r!r"r#r�r�rxr%rrr�r�sG������(�(�'�'�'�)�)�)�5�5�5�5�5rr�c�|�eZdZdZejdZejdZd�Z	d�Z
d�Zd�Zd�Z
d�Zd	�Zd
�Zd�ZdS)
r+zA {} bracket inside a formular�c�H�t�|��d|_dS)z'Create a (possibly literal) new bracketN)r�r�innerr7s rrzBracket.__init__s!�����D�!�!�!���
�
�
rc�6�|�|j��S)zDetect the start of a bracket)r�r�r$s  rr�zBracket.detects���|�|�D�J�'�'�'rc�<�|�||j��|S)zParse the bracket)�
parsecomplete�innerformular$s  rr�zBracket.parsebit!� �����3�� 1�2�2�2��rc�<�|�||j��|S)zParse a text bracket)r�	innertextr$s  r�	parsetextzBracket.parsetext&s�����3���/�/�/��rc�<�|�||j��|S)zParse a literal bracket)r�innerliteralr$s  r�parseliteralzBracket.parseliteral+rrc��|�|j��s<t�d|jzdz|���z��dS|�|j|��|�|j��||��|xj|�	|j��z
c_|�
��dS)zParse the start and end markszBracket should start with z at N)r�r�rrr<r�rrorDrr�)rr%�innerparsers   rrzBracket.parsecomplete0s����|�|�D�J�'�'�	��K�K�4�t�z�A�F�J�S�^�^�M]�M]�]�^�^�^��4����$�*�c�*�*�*����t�{�#�#�#���C�����
�
����t�{�3�3�3�
�
��������rc��|���sC|�|j�|����|����AdSdS)z(Parse a whole formula inside the bracketN�r�rrs�parseanyr$s  rrzBracket.innerformula;�Z���,�,�.�.�	1��H�H�T�\�*�*�3�/�/�0�0�0��,�,�.�.�	1�	1�	1�	1�	1rc��ttj�����}|�tjd��|�tjd��|�tj��|���s�|�	��|vrS|�
|j�|����|�
d��r|xjdz
c_n4|�
t|�������|�����dSdS)z<Parse some text inside the bracket, following textual rules.r�r�rgN)rrJr�r^rr�r�r�r�rrrsrrIrDr)r�)rr%�specialcharss   rr
zBracket.innertext@s ���M�9�>�>�@�@�A�A�����M�0��;�<�<�<����M�0��;�<�<�<����G�M�*�*�*��,�,�.�.�	=��{�{�}�}��,�,������.�.�s�3�3�4�4�4��=�=��%�%�)��M�M�S�(�M�M���������):�):�;�;�<�<�<�
�,�,�.�.�	=�	=�	=�	=�	=rc��d|_|���s�|���|jks�|���|jkr|�|��n"|xj|���z
c_|���s|���|jk��|xj|jz
c_dS)zAParse a literal inside the bracket, which does not generate HTML.r@N)�literalr�rror�rr�rDr$s  rr
zBracket.innerliteralNs�������,�,�.�.�	2������$�+�)E�)E��{�{�}�}��
�*�*��!�!�#�&�&�&�&������� 1� 1�1���	�,�,�.�.�	2������$�+�)E�)E�
	
�
�
���%�
�
�
�
rN)r r!r"r#rJr�r�r�rorr�r�rrrrr
r
r%rrr+r+s�������#�#�� ��+�E�
�
"�9�
-�F����
(�(�(����
���
���
	�	�	�1�1�1�
=�=�=�&�&�&�&�&rr+c�L�eZdZdZejdZejdZd�Z	dS)�
SquareBracketzA [] bracket inside a formular�c�:�t��}|j|_|S)z3Return a new square bracket with the same contents.)rr])rr�s  rrEzSquareBracket.clone_s���/�/���=����rN)
r r!r"r#rJr�r�r�rorEr%rrrrYsC������#�#�� ��1�E�
�
"�?�
3�F�����rrc��eZdZdZd�Zd�ZdS)�MathsProcessorzAA processor for a maths construction inside the FormulaProcessor.c�Z�t�dt|��z��dS)z$Process an element inside a formula.zUnimplemented process() in Nr��rr]r-s   rrSzMathsProcessor.processis&��
���1�C��I�I�=�>�>�>�>�>rc� �d|jjzS)zReturn a printable description.zMaths processor )rCr r7s rrxzMathsProcessor.__str__ms��!�D�N�$;�;�;rN)r r!r"r#rSrxr%rrrrfs8������G�G�?�?�?�<�<�<�<�<rrc�:�eZdZdZgZd�Zd�Zd�Zd�Zd�Z	d�Z
dS)	�FormulaProcessorz&A processor specifically for formulas.c��|�|��|�|��|�|��dS)z7Process the contents of every formula bit, recursively.N)�processcontents�processinsides�
traversewholer�s  rrSzFormulaProcessor.processwsD�����S�!�!�!����C� � � ����3�����rc��t|t��sdS|���|jD]}|�|���dS)z&Process the contents of a formula bit.N)rr�rSr]r$�rr�r�s   rr$z FormulaProcessor.processcontents}sX���#�z�*�*�	��F����
�
�
��|�	*�	*�G�� � ��)�)�)�)�	*�	*rc���t|t��sdSt|j��D]?\}}|jD]}|�|j|���|�|���@dS)z8Process the insides (limits, brackets) in a formula bit.N)rr�r,r]�
processorsrSr%)rr�r-r��	processors     rr%zFormulaProcessor.processinsides�s����#�z�*�*�	��F�'���5�5�	)�	)�N�E�7�!�_�
7�
7�	��!�!�#�,��6�6�6�6�����(�(�(�(�		)�	)rc��d}|�|��D]i\}}|jdkr|�||��n@|jdkr5|r3|jdkr(|j�dtd����|}�jdS)z>Traverse over the contents to alter variables and space units.Nr��fontr�r� )�traverserH�	italicizer]r!r))rr��lastr�r]s     rr&zFormulaProcessor.traversewhole�s�����!�]�]�7�3�3�	�	�M�C���x�7�"�"����s�H�-�-�-�-���V�#�#��#���h�1F�1F���#�#�A��x�'@�'@�A�A�A��D�D�	�	rc#��K�|jD]U}t|d��r|jr||jfV��%t|t��r|�|��Ed{V���VdS)zHTraverse a formula and yield a flattened structure of (bit, list) pairs.rHN)r]rrHrr�r/r(s   rr/zFormulaProcessor.traverse�s������|�	2�	2�G��w��'�'�
2�G�L�
2��s�|�+�+�+�+�+��G�Z�0�0�
2��=�=��1�1�1�1�1�1�1�1�1��		2�	2rc�|�|�|��}t���|gd��||<dS)z Italicize the given bit of text.r�N)r-r�r�)rr�r]r-s    rr0zFormulaProcessor.italicize�s6�����s�#�#��#�+�+�.�.��u�c�:�:�����rN)r r!r"r#r*rSr$r%r&r/r0r%rrr"r"rsy������,�,��J� � � �*�*�*�)�)�)����2�2�2�;�;�;�;�;rr"c�T�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
S)r0zA LaTeX formulac�x�t��|_t���d��|_dS)Nzspan class="formula")r�r(r�r�r\r7s rrzFormula.__init__�s+��#�o�o���"�n�n�+�+�,B�C�C����rc��|jddkr
dt_n'dt_|j�dd��|���dS)zConvert the formula to tagsrr�FTzdiv class="formula"N)rhr�r�r\r��classicr7s rrSzFormula.process�sR���;�q�>�X�%�%�-2��*�*�-1��*��K���4�d�;�;�;��������rc��t���|j��}t���|��||_|g|_dS)zEMake the contents using classic output generation with XHTML and CSS.N)�FormulaFactoryr�r�r"rSr5r])r�wholes  rr7zFormula.classic�sK��� � �-�-�d�k�:�:�����"�"�5�)�)�)�������
�
�
rc��|�d��r|�|��n�|�d��r|�|��nm|�d��r|�|d��nA|�d��r|�|d��n|�d��|���|S)z4Parse using a parse position instead of self.parser.z$$r�z\(z\)r�r�zUnparseable formula)rI�parsedollarblock�parsedollarinline�
parseinlineto�parseblocktorrSr$s  rr}z
Formula.parse�s����=�=����		-��!�!�#�&�&�&�&�
�]�]�3�
�
�	-��"�"�3�'�'�'�'�
�]�]�5�
!�
!�	-����s�E�*�*�*�*�
�]�]�5�
!�
!�	-����c�5�)�)�)�)��I�I�+�,�,�,��������rc�@�dg|_|�|��dS)zParse a $...$ formula.r�N)rh�parsedollarr$s  rr=zFormula.parsedollarinline�s%���j�����������rc��dg|_|�|��|�d��s|�d��dSdS)zParse a $$...$$ formula.r�r�z1Formula should be $$...$$, but last $ is missing.N)rhrArIrr$s  rr<zFormula.parsedollarblock�sY���i�����������}�}�S�!�!�	K��I�I�I�J�J�J�J�J�	K�	Krc��|�d��|�d��|_|�d��dS)zParse to the next $.r�N)rrr�rr$s  rrAzFormula.parsedollar�sA�����s�����'�'��,�,����
�
�c�����rc�B�dg|_|�||��dS)zParse a \(...\) formula.r�N�rh�	parseupto�rr%�limits   rr>zFormula.parseinlineto�s%���j������s�E�"�"�"�"�"rc�B�dg|_|�||��dS)zParse a \[...\] formula.r�NrErGs   rr?zFormula.parseblockto�s%���i������s�E�"�"�"�"�"rc��|�|��|�d���|_|�|��dS)z1Parse a formula that ends with the given command.c��dS)NTr%r%rrrPz#Formula.parseupto.<locals>.<lambda>�s��t�rN)rr�r�rrGs   rrFzFormula.parseupto�sA�����u�����h�h�|�|�,�,����
�
�e�����rc�P�|jr|jjrd|jjzdzSdS)r�z	Formula (r_zUnnumbered formula)r�r�r7s rrxzFormula.__str__�s3���<�	;�D�L�/�	;����!4�4�s�:�:�#�#rN)r r!r"r#rrSr7r}r=r<rAr>r?rFrxr%rrr0r0�s���������D�D�D���� � � �
�
�
����
K�K�K����#�#�#�
#�#�#�
���$�$�$�$�$rr0c��eZdZdZd�Zd�ZdS)�WholeFormulazParse a whole formulac�,�|���S)z"Not outside the formula is enough.)r�r$s  rr�zWholeFormula.detect�s���<�<�>�>�!�!rc��|���sC|�|j�|����|����AdSdS)zParse with any formula bitNrr$s  rr�zWholeFormula.parsebit�rrNr�r%rrrNrN�s8��������"�"�"�1�1�1�1�1rrNc�d�eZdZdZeeeeee	gZ
ee	gZdZd�Z
d�Zd�Zd�Zd�Zd�Zd	�Zd
�Zd�ZdS)
r9zConstruct bits of formulaFc��i|_dS)z Initialize the map of instances.N)�	instancesr7s rrzFormulaFactory.__init__s
������rc�~�|���rdS|�|���|��S)zDetect a bit of a given type.F)r��instancer�)rrHr%s   r�
detecttypezFormulaFactory.detecttypes7���<�<�>�>�	��5��}�}�T�"�"�)�)�#�.�.�.rc��||jvs
|j|s|�|��|j|<|j|S)z"Get an instance of the given type.)rSrB�rrHs  rrUzFormulaFactory.instances@���t�~�%�%�T�^�D�-A�%�#'�;�;�t�#4�#4�D�N�4� ��~�d�#�#rc�\�t�|���|��S)z+Create a new formula bit of the given type.)r@rBr�rXs  rrBzFormulaFactory.creates"���}�}�T�"�"�-�-�d�3�3�3rc��|���s+|�|��sdS|����+dS)zClear any skipped types.N)r��skipanyr$s  r�clearskippedzFormulaFactory.clearskippedsD���,�,�.�.�	��<�<��$�$�
����,�,�.�.�	�	�rc��|jD]B}|�|���|��r|�||��cS�CdS)zSkip any skipped types.N)�skippedtypesrUr�r��rr%rHs   rr[zFormulaFactory.skipany&sZ���%�	1�	1�D��}�}�T�"�"�)�)�#�.�.�
1��~�~�d�C�0�0�0�0�0�
1��trc�"�|j|jzD]0}|�||��r|�||��cS�1t�d|���z��t|�����S)z.Parse any formula bit at the current location.zUnrecognized formula at )	�typesr^rVr�rrr<r)r�r_s   rrzFormulaFactory.parseany-s����J��!2�2�	1�	1�D����t�S�)�)�
1��~�~�d�C�0�0�0�0�0�
1�
���.����1A�1A�A�B�B�B��s���0�0�1�1�1rc��|�|��}d|j|<|�|��}|r|�|��S|S)z#Parse the given type and return it.N)rUrSr�r�)rrHr%r��returnedbits     rr�zFormulaFactory.parsetype5sQ���m�m�D�!�!��#���t���l�l�3�'�'���	0��)�)�$�/�/�/��
rc��t|��}|�t��}|�|��r|�|��|S|���sdt�d|���z��|�	t���|d����|S)z5Parse a string of text that contains a whole formula.zUnknown formula at: �span class="unknown")rLrBrNr�r�r�rrr<rr�rw)rr�r%r:s    rr�zFormulaFactory.parseformula>s����7�#�#�����L�)�)���<�<����	��N�N�3�����L��|�|�~�~�	M��K�K�.����1A�1A�A�B�B�B��I�I�i�k�k�*�*�7�4J�K�K�L�L�L��rN)r r!r"r#r2r5r1r+r�r�rar^�definingrrVrUrBr\r[rr�r�r%rrr9r9s����������G�]�G�W�j�Q�E��Z�(�L��H����/�/�/�$�$�$�4�4�4�������2�2�2��������rr9c�^�eZdZdZgZejdZdZd�Z	d�Z
d�Zd�Zd�Z
d	�Zd
�ZdS)�FormulaCommandz A LaTeX command inside a formular�Nc�@�|�tj��S)zFind the current command.)r�rhr�r$s  rr�zFormulaCommand.detectSs���|�|�N�0�1�1�1rc���|�|��}|�||��}|r|S|�d��s|�d��r|�||��}|r|S|jjst�d|z��t���	d��|_
|�t|����dS)zParse the command.�\up�\UpzUnknown command reN)
�extractcommand�parsewithcommandr�parseupgreekrsrfrrr�r�r\rr))rr%r�r��upgreeks     rr�zFormulaCommand.parsebitWs����%�%�c�*�*���#�#�G�S�1�1���	��J����f�%�%�	��);�);�F�)C�)C�	��'�'���5�5�G��
����|�$�	6��K�K�*�W�4�5�5�5�"�n�n�+�+�,B�C�C��������)�)�*�*�*��trc�h�tjD]$}||jvr|�|||��cS�%dS)z0Parse the command type once we have the command.N)rhra�
commandmap�parsecommandtype)rr�r%rHs    rrnzFormulaCommand.parsewithcommandgsK��"�(�	A�	A�D��$�/�)�)��,�,�W�d�C�@�@�@�@�@�*��trc��|j�|��}|�|��|�|��}|r|S|S)zParse a given command type.)rsrB�
setcommandr�)rr�rHr%r��returneds      rrszFormulaCommand.parsecommandtypensL���l�!�!�$�'�'�����w�����<�<��$�$���	��O��
rc���|�tj��s$|�dtjz��dS|���r|�|��S|������r8tj|���z}|�d��|Stj|�	��zS)z.Extract the command from the current position.zMissing command start Nr�)
rIrhr�rr��emptycommandrr�r�r�)rr%r�s   rrmzFormulaCommand.extractcommandws����}�}�^�1�2�2�	��I�I�.��1E�E�F�F�F��F��<�<�>�>�	*��$�$�S�)�)�)��;�;�=�=� � �"�"�	�$�*�S�]�]�_�_�<�G��M�M�#�����N��#�c�o�o�&7�&7�7�7rc��d}|���s-|���}|r|�|��r|}tj|zS)zuCheck for an empty command: look for command disguised as ending.
        Special case against '{ \{ \} }' situation.r@)r�rrIrhr�)rr%r�ros    rrxzFormulaCommand.emptycommand�sV�����y�y�{�{�	!��^�^�%�%�F��
!�#�-�-��/�/�
!� ���#�g�-�-rc�r�t|��dkrdS|�d��rd|dd�z}n_|�d��r+d|dd����z|dd�z}nt�d|z��dS|�||��}|rd|_|S)	zParse the Greek \up command..�NrkrV�rlzImpossible upgreek command: r-)rrrI�upperrrrnrH)rr�r%�	upcommandrps     rrozFormulaCommand.parseupgreek�s����w�<�<�!����4����f�%�%�	��w�q�r�r�{�*�I�I�
�]�]�6�
"�
"�	��w�q��s�|�1�1�3�3�3�g�a�b�b�k�A�I�I��K�K�6��@�A�A�A��F��'�'�	�3�7�7���	"�!�G�L��r)r r!r"r#rarJr�r�rrr�r�rnrsrmrxror%rrrhrhLs�������&�&��E�� ��+�E��J�2�2�2���� ������8�8�8� .�.�.�����rrhc�6�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	dS)	�
CommandBitz%A formula bit that includes a commandc�t�||_|jr)|xj|z
c_|j|j|_dSdS)zSet the command in the bitN)r�rrrD�
translated)rr�s  rruzCommandBit.setcommand�sA������?�	<��M�M�W�$�M�M�"�o�d�l�;�D�O�O�O�	<�	<rc���|j�|��|���rdS|j�|��}|�|��|S)z)Parse a parameter at the current positionN)rsr\r�rr)rr%�	parameters   rrmzCommandBit.parseparameter�sZ����!�!�#�&�&�&��<�<�>�>�	��4��L�)�)�#�.�.�	���������rc���|j�|��|j�t|��sdS|j�t|��}|�|��|S)zParse a square bracketN)rsr\rVrr�r�rr%r�s   r�parsesquarezCommandBit.parsesquare�se����!�!�#�&�&�&��|�&�&�}�c�:�:�	��4��,�(�(���<�<����������rc���|j�|��|j�t|��sY|���s1t
�d|���z��dS|���St���	|j��}|�
|�|����|jS)zParse a literal bracket.zNo literal parameter found at: N)
rsr\rVr+rrrr<rr�rrrr�s   rrzCommandBit.parseliteral�s�����!�!�#�&�&�&��|�&�&�w��4�4�	#��;�;�=�=�
����=����@P�@P�P�Q�Q�Q��t��=�=�?�?�"��)�)�&�&�t�|�4�4������%�%�c�*�*�+�+�+���rc�$�|j�|��|j�t|��sdSt���|j��}|�|�|����|jS)z!Parse a square bracket literally.N)rsr\rVrr�rrrr�s   r�parsesquareliteralzCommandBit.parsesquareliteral�sx����!�!�#�&�&�&��|�&�&�}�c�:�:�	��4��/�/�,�,�T�\�:�:������%�%�c�*�*�+�+�+���rc�^�|j�|��|j�t|��s$t�d|jz��dSt���|j���|��}|�	|��|S)zParse a text parameter.zNo text parameter for N)
rsr\rVr+rrr�r�rrr�s   rrzCommandBit.parsetext�s�����!�!�#�&�&�&��|�&�&�w��4�4�	��K�K�0�4�<�?�@�@�@��4��)�)�&�&�t�|�4�4�>�>�s�C�C����������rN)
r r!r"r#rurmr�rr�rr%rrr�r��st������+�+�<�<�<�������
�
�
��������rr�c�&�eZdZdZejZd�ZdS)r.z%An empty command (without parameters)c�:�t|j��g|_dS)z"Parse a command without parametersN�r)r�r]r$s  rr�zEmptyCommand.parsebit�s��(���9�9�:��
�
�
rN)r r!r"r#rJr�rrr�r%rrr.r.�s1������+�+��'�J�;�;�;�;�;rr.c�&�eZdZdZejZd�ZdS)r6z<An empty command which should have math spacing in formulas.c�F�td|jzdz��g|_dS)z4Place as contents the command translated and spaced.r.Nr�r$s  rr�zSpacedCommand.parsebit�s&��
)��D�O�)C�h�)N�O�O�P��
�
�
rN)r r!r"r#rJr�rrr�r%rrr6r6�s6������F�F��-�J�Q�Q�Q�Q�Qrr6c�*�eZdZdZejZdZd�ZdS)r*z:A command without parameters whose result is alphabetical.)z\Xiz\Thetaz\Piz\Sigmaz\Gammaz\Lambdaz\Phiz\Psiz\Deltaz\Upsilonz\Omegac�j�t�||��|j|jvr	d|_dSdS)z'Parse the command and set type to alphar�N)r.r�r��greek_capitalsrHr$s  rr�zAlphaCommand.parsebit�s=�����d�C�(�(�(��<�t�2�2�2� �D�I�I�I�3�2rN)	r r!r"r#rJr�rrr�r�r%rrr*r*�s8������D�D��,�J�.�N� � � � � rr*c�0�eZdZdZejZdZd�Zd�Z	dS)r3zA function of one parameterFc��t���|j��|_|�|��|���dS)z#Parse a function with one parameterN)r�r�r�r\rm�simplifyifpossibler$s  rr�zOneParamFunction.parsebit	sI��"�n�n�+�+�D�O�<�<������C� � � ����!�!�!�!�!rc��|j|jvr4t��|_|j|jg|_d|_dSdS)z&Try to simplify to a single character.TN)rDrrr�r\r��
simplifiedr7s rr�z#OneParamFunction.simplifyifpossible	sB���=�D�O�+�+�%�-�-�D�K�����7�8�D�I�"�D�O�O�O�,�+rN)
r r!r"r#rJr�rrr�r�r�r%rrr3r3	sE������!�!��+�J��J�"�"�"�#�#�#�#�#rr3c�,�eZdZdZejZd�Zd�ZdS)r7z>Find a function which is represented by a symbol (like _ or ^)c�B�|���tjvS)zFind the symbol)rr7rrr$s  rr�zSymbolFunction.detect	s���{�{�}�}�� 9�9�9rc��|�|�����|�|j��t	���|j��|_|�|��dS)r�N)	rurrr�r�r�r�r\rmr$s  rr�zSymbolFunction.parsebit#	se��������
�
�&�&�&���������"�n�n�+�+�D�O�<�<������C� � � � � rN)	r r!r"r#rJr�rrr�r�r%rrr7r7	s@������D�D��.�J�:�:�:�!�!�!�!�!rr7c�,�eZdZdZejZd�Zd�ZdS)r8z-A function where parameters are read as text.c��t���|j��|_|�|��dS)zParse a text parameterN)r�r�r�r\rr$s  rr�zTextFunction.parsebit0	s5��"�n�n�+�+�D�O�<�<������s�����rc��d|_dS)zSet the type to fontr-N)rHr7s rrSzTextFunction.process5	s
����	�	�	rN)	r r!r"r#rJr�rrr�rSr%rrr8r8+	s@������3�3��,�J����
����rr8c�&�eZdZdZejZd�ZdS)r/z2A function of one parameter that changes the font.c�<�d|_|���dS)z.Simplify if possible using a single character.r-N)rHr�r7s rrSzFontFunction.process@	s!����	����!�!�!�!�!rN)r r!r"r#rJr�rrrSr%rrr/r/:	s3������<�<��,�J�"�"�"�"�"rr/c�D�eZdZdZdd�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�ZdS)
�
BigBracketzA big bracket generator.r�c��||_||_||_d|_|tjvrtj||_dSdS)z(Set the size and symbol for the bracket.N)r�rD�	alignmentr`rJr�)rr�r�r�s    rrzBigBracket.__init__O	sG����	���
�"�������m�/�/�/�'�3�G�<�D�K�K�K�0�/rc	�|�t|dtt|j����z��}||��S)z%Return the nth piece for the bracket.�getpiece)rrprr`)rr-�functions   rr�zBigBracket.getpieceX	s6���4��c�#�d�k�2B�2B�.C�.C�!C�D�D���x����rc��|jdS)z1Return the only piece for a single-piece bracket.r)r`�rr-s  r�	getpiece1zBigBracket.getpiece1]	s���{�1�~�rc�x�|dkr
|jdS||jdz
kr
|jdS|jdS)zGGet the nth piece for a 3-piece bracket: parenthesis or square bracket.rrr�r`r�r�s  r�	getpiece3zBigBracket.getpiece3a	s@���A�:�:��;�q�>�!��D�I��M�!�!��;�r�?�"��{�1�~�rc��|dkr
|jdS||jdz
kr
|jdS||jdz
dzkr
|jdS|jdS)z7Get the nth piece for a 4-piece bracket: curly bracket.rrr|rr�r�s  r�	getpiece4zBigBracket.getpiece4i	sb���A�:�:��;�q�>�!��D�I��M�!�!��;�q�>�!��T�Y��]�A�%�%�%��;�q�>�!��{�1�~�rc��|�|��}d|jzdz}t���||��S)z'Get the bracket piece as an array cell.zspan class="bracket align-r�)r�r�r�rw)rr-ra�spans    r�getcellzBigBracket.getcells	s>���
�
�e�$�$��+�d�n�<�s�B���{�{�#�#�E�4�0�0�0rc�\�|jdks|js|���Sg}t|j��D]M}|�|��}|�t
���|gd�����Nt
���|d��gS)z3Get the bracket as an array or as a single bracket.r�span class="arrayrow"�span class="array")r�r`�getsinglebracket�ranger�rr�r�)r�rowsr-�cells    r�getcontentszBigBracket.getcontentsy	s����9��>�>���>��(�(�*�*�*����4�9�%�%�	O�	O�E��<�<��&�&�D��K�K�	���,�,�d�V�5L�M�M�N�N�N�N����$�$�T�+?�@�@�A�Arc��|jdkr#t���dd��gSt���|jd��gS)z$Return the bracket as a single sign.r�r@zspan class="emptydot"rd)rDr�rwr7s rr�zBigBracket.getsinglebracket�	sM���=�C����K�K�(�(��-D�E�E�F�F����$�$�T�]�4K�L�L�M�MrN)r�)r r!r"r#rr�r�r�r�r�r�r�r%rrr�r�L	s���������=�=�=�=����
���������1�1�1�B�B�B�N�N�N�N�Nrr�c��eZdZdZdZd�ZdS)�FormulaEquationzA simple numbered equation.�equationc��t��|_|�|j�t
|����dS)�Parse the arrayN)r�r\rrsr�rNr$s  rr�zFormulaEquation.parsebit�	s9��$�&�&��������'�'��c�:�:�;�;�;�;�;rN�r r!r"r#rar�r%rrr�r��	s.������!�!��E�<�<�<�<�<rr�c��eZdZdZd�Zd�ZdS)�FormulaCellzAn array cell inside a rowc�n�||_t���d|zdzd��|_|S)Nzspan class="arraycell align-r�T)r�r�r�r\)rr�s  r�setalignmentzFormulaCell.setalignment�	sA��"���"�n�n�+�+�,J�.7�-8�:=�->�?C�E�E����rc���|j�|��|���rdS|�|j�t
|����dSr)rsr\r�rr�rNr$s  rr�zFormulaCell.parsebit�	sW����!�!�#�&�&�&��<�<�>�>�	��F������'�'��c�:�:�;�;�;�;�;rN)r r!r"r#r�r�r%rrr�r��	s8������ � ����<�<�<�<�<rr�c�>�eZdZdZejdZd�Zd�Zd�Z	dS)�
FormulaRowzAn array row inside an arrayrXc�b�||_t���dd��|_|S)Nr�T)�
alignmentsr�r�r\)rr�s  r�
setalignmentszFormulaRow.setalignments�	s*��$���"�n�n�+�+�,C�T�J�J����rc��d}|�|jd���|���sr|�|��}|�|��|�|��|dz
}|�|j��|����rt|j��dkrt��|_
dSdS)zParse a whole rowrT)rrN)rrXr��
createcellr�rrIrr]r�r\)rr%r-r�s    rr�zFormulaRow.parsebit�	s��������t�)�D��9�9�9��,�,�.�.�	.��?�?�5�)�)�D��M�M�#�����H�H�T�N�N�N��Q�J�E��M�M�$�,�-�-�-��,�,�.�.�	.��t�}����"�"�%�-�-�D�K�K�K�#�"rc��|j|t|j��z}|j�t���|��S)z4Create the cell that corresponds to the given index.)r�rrsrBr�r�)rr-r�s   rr�zFormulaRow.createcell�	sA���O�E�C���,@�,@�$@�A�	��|�"�"�;�/�/�<�<�Y�G�G�GrN)
r r!r"r#rJr�rXr�r�r�r%rrr�r��	sY������"�"�!�'��8�M����
(�(�(�H�H�H�H�Hrr�c�*�eZdZdZd�Zd�Zd�Zd�ZdS)�MultiRowFormulazA formula with multiple rows.c��g|_d}|�|��D]E}|rd}n|���|�|��|�|���Ft|j��|_dS)z,Parse all rows, finish when no more row endsTFN)r��iteraterows�addemptyr��addrowrr�)rr%�first�rows    r�	parserowszMultiRowFormula.parserows�	s�����	����#�#�C�(�(�	�	�C��
 �����
�
�����L�L������K�K��������	�N�N��	�	�	rc#�FK�tjd}	|�|d��|j�t
��}|�|j��V�|�|��r$|xj	|�
|��z
c_	ndS��)z0Iterate over all rows, end when no more row endsrZTN)rJr�rrsrBr�r�r�r�rDr)rr%rZr�s    rr�zMultiRowFormula.iteraterows�	s�����$�*�>�:��	��N�N�<��.�.�.��,�%�%�j�1�1�C��#�#�D�O�4�4�4�4�4��|�|�L�)�)�
��
�
����|�!<�!<�<�
�
�
���	rc��|j�t���|j��}t|jdj��D]Q\}}|�|��}|�	td����|�	|���R|�|��dS)zAdd an empty row.ru N)rsrBr�r�r�r,r�r]r�rr)r�)rr�r-�originalcellr�s     rr�zMultiRowFormula.addempty�	s����l�!�!�*�-�-�;�;�D�O�L�L��#,�T�Y�r�]�-C�#D�#D�	�	��E�<��>�>�%�(�(�D��H�H�_�U�+�+�,�,�,��G�G�D�M�M�M�M����C�����rc�d�|j�|��|�|��dS)z2Add a row to the contents and to the list of rows.N)r�rr)rr�s  rr�zMultiRowFormula.addrow�	s+���	�����������
�
�
�
�
rN)r r!r"r#r�r�r�r�r%rrr�r��	sV������#�#�#�#�#�
�
�
��������rr�c�"�eZdZdZdZd�Zd�ZdS)�FormulaArrayzAn array within a formular�c��t���dd��|_|�|��|�|��dS)r�r�FN)r�r�r\�parsealignmentsr�r$s  rr�zFormulaArray.parsebit�	sJ��"�n�n�+�+�,@�%�H�H������S�!�!�!����s�����rc���d|_|�|��}|r||_|�|��}g|_|D]}|j�|���dS)zParse the different alignmentsr�N)�valignr�rr�r)rr%r�ss    rr�zFormulaArray.parsealignments�	sy������)�)�#�.�.���	"�!�D�K��#�#�C�(�(������	&�	&�A��O�"�"�1�%�%�%�%�	&�	&rN)r r!r"r#rar�r�r%rrr�r��	s=���������E����&�&�&�&�&rr�c��eZdZdZdZd�ZdS)�
FormulaMatrixz'A matrix (array with center alignment).�matrixc��t���dd��|_d|_dg|_|�|��dS)z(Parse the matrix, set alignments to 'c'.r�Fr�N)r�r�r\r�r�r�r$s  rr�zFormulaMatrix.parsebit
sF��"�n�n�+�+�,@�%�H�H�������%������s�����rNr�r%rrr�r�
s.������-�-��E�����rr�c��eZdZdZdZd�ZdS)�FormulaCaseszA cases statement�casesc���t��|_ddg|_|�|��|jD]N}|jD]D}|j�dd��|j�td�����E�Ot���	|jdd��}tt|j��dd��}|���|gz|_dS)zParse the casesr�zspan class="case align-l"Tu zspan class="bracketcases"rbN)
r�r\r�r�r]r�rr)r�r�r�rr�)rr%r�r�r��braces      rr�zFormulaCases.parsebit
s���$�&�&�����*������s�����=�	=�	=�C���
=�
=����"�"�#>��E�E�E��
�$�$�_�U�%;�%;�<�<�<�<�
=����$�$�T�]�4O�QU�V�V���3�t�}�-�-�s�C�8�8���)�)�+�+�u�g�5��
�
�
rNr�r%rrr�r�
s.���������E�6�6�6�6�6rr�c��eZdZdZd�ZdS)�EquationEnvironmentz;A \begin{}...\end equation environment with rows and cells.c���|j�dd��}t���d|zd��|_|t
jvrt
j||_nut�	d|jz��t���d��|_|�
td|z����dg|_|�|��d	S)
zParse the whole environment.r�r@zspan class="environment %s"FzUnknown equation environment rez\begin{%s} r�N)
rarr�r�r\rJr�r�rrrr)r�)rr%�environments   rr�zEquationEnvironment.parsebit*
s����j�(�(��b�1�1��"�n�n�+�+�5�k�A�5�J�J����-�4�4�4�+�8��E�D�O�O��K�K�7�$�*�D�E�E�E�&�.�.�/�/�0F�G�G�D�K��H�H�_�^�K�%?�@�@�A�A�A�"�e�D�O����s�����rN)r r!r"r#r�r%rrr�r�'
s)������C�C�����rr�c�H�eZdZdZejddiZeee	e
gZd�Zd�Z
dS)�BeginCommandzEA \begin{}...\end command and what it entails (array, cases, aligned)rWr@c�l�|�|��}|�|��}tjddz|zdz}|�|��|�|��|�|��|xj|�|��z
c_|j	|_	dS)zParse the begin commandrYrbrcN)
r�findbitrJr�rr�rrDrr�)rr%r�r�ros     rr�zBeginCommand.parsebitB
s����#�#�C�(�(���l�l�7�#�#���$�U�+�c�1�G�;�c�A�����v�������S��������
�
�
��
�
����v�.�.�.�
�
��H��	�	�	rc���tjD]=}|�dd��|jkr|j�|��cS�>|j�t��}||_|S)z7Find the command bit corresponding to the \begin{piece}r�r@)r�rarrarsrBr�)rrarHr�s    rr�zBeginCommand.findbitM
sr�� �&�	1�	1�D��}�}�S�"�%�%���3�3��|�*�*�4�0�0�0�0�0�4��l�!�!�"5�6�6����	��
rN)r r!r"r#rJr�rrr�r�r�r�rar�r�r%rrr�r�;
sX������M�M��%�g�.��3�J�
�l�L�-�H�E�	�	�	�����rr�c�(�eZdZejZd�Zd�ZdS)r-c�P�|j}|�|��}|s$t�d|jz��dSt|t��si	ttj	��}|�
|��d}n3#t$r&t�d|jz��YdSwxYw|j�
d��rd}nd}|jd|�|z|j|d�z|_tjd|j��|_dS)	zParse a combining function.z)Missing parameter for combining function Nrz!No base character found for "%s".r.rr�NFC)r��parsesingleparameterrrr�rr)rJr'r=rX�
IndexErrorr�r�unicodedata�	normalize)rr%�	combiningr��	extractorr�s      rr�zCombiningFunction.parsebit^
s1���O�	��-�-�c�2�2�	��	��K�K�C�d�l�R�S�S�S��F��)�_�5�5�	�
�.��/J�K�K�	�%�-�-�i�8�8��;�	�	���
�
�
����?�$�,�N�O�O�O����
����
��&�&�x�0�0�	��A�A��A�$�+�B�Q�B�/�)�;�i�>N�q�r�r�>R�R�	��&�0��	�8H�I�I�	���s�4B�,B>�=B>c��|j�|��|���rdS|�|��S)z&Parse a parameter, or a single letter.N)rsr\r�rmr$s  rr�z&CombiningFunction.parsesingleparameterx
sA����!�!�#�&�&�&��<�<�>�>�	��4��"�"�3�'�'�'rN)r r!r"rJr�rrr�r�r%rrr-r-Z
s=�������1�J�J�J�J�4(�(�(�(�(rr-c�&�eZdZdZejZd�ZdS)r4z;A function that decorates some bit of text with an overset.c��|j}t���|d��|_|�|��|_t
���d��|_|j	�
d|j��t
���d��|j_|���dS)zParse an overset-functionr��span class="embellished"r�span class="base"N�r�r�rwr�rmr�r�r�r\r]r!r��rr%r�s   rr�zOversetFunction.parsebit�
�������k�k�*�*�6�5�9�9����,�,�S�1�1���"�n�n�+�+�,F�G�G����
���Q���,�,�,� ,��� 5� 5�6I� J� J�������!�!�!�!�!rN)r r!r"r#rJr�rrr�r%rrr4r4�
s1������A�A��/�J�"�"�"�"�"rr4c�&�eZdZdZejZd�ZdS)r9z<A function that decorates some bit of text with an underset.c��|j}t���|d��|_|�|��|_t
���d��|_|j	�
d|j��t
���d��|j_|���dS)zParse an underset-functionr�rrrNrrs   rr�zUndersetFunction.parsebit�
rrN)r r!r"r#rJr�rrr�r%rrr9r9�
s1������B�B��0�J�"�"�"�"�"rr9c�&�eZdZdZejZd�ZdS)�LimitCommandz@A command which accepts limits above and below, in display mode.c���t���d��|_|j}|j�t
���|d����dS)zParse a limit command.�span class="limits"zspan class="limit"N)r�r�r\r�r]rr�rwrs   rr�zLimitCommand.parsebit�
sT��"�n�n�+�+�,A�B�B�������
���Y�[�[�1�1�&�:N�O�O�P�P�P�P�PrN)r r!r"r#rJr�rrr�r%rrr	r	�
s6������F�F��,�J�Q�Q�Q�Q�Qrr	c�"�eZdZdZdZd�Zd�ZdS)�LimitPreviousCommandz(A command to limit the previous command.Nc��t���d��|_|j�|��dS)zDo nothing.rN)r�r�r\rsr\r$s  rr�zLimitPreviousCommand.parsebit�
s8��"�n�n�+�+�,A�B�B�����!�!�#�&�&�&�&�&rc��dS)r�zLimit previous commandr%r7s rrxzLimitPreviousCommand.__str__�
s��'�'r)r r!r"r#rrr�rxr%rrr
r
�
s=������.�.��J�'�'�'�
(�(�(�(�(rr
c�H�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�ZdS)�LimitsProcessorz)A processor for limits inside an element.c��tjrdS|�||��r|�||��|�||��r1|�||dz��r|�||��dSdSdS)z"Process the limits for an element.Nr)r#r<�checklimits�modifylimits�checkscript�
modifyscriptsrs   rrSzLimitsProcessor.process�
s�����	��F����H�e�,�,�	/����h��.�.�.����H�e�,�,�	0��1A�1A�(�E�TU�I�1V�1V�	0����x��/�/�/�/�/�	0�	0�	0�	0rc��tjsdS|�||dzt��r|�||��dSt||t��sdS|�||dz��S)z3Check if the current position has a limits command.Fr)r�r��checkcommandr
�limitsaheadrr	rrs   rrzLimitsProcessor.checklimits�
s���"�-�	��5����X�u�q�y�2F�G�G�	����X�u�-�-�-��5��(�5�/�<�8�8�	��5�����%�!�)�4�4�4rc��||dz�||�����t��||_dS)z,Limit the current element based on the next.rN)rrEr�r\rs   rrzLimitsProcessor.limitsahead�
sE������������ 5� 5� 7� 7�8�8�8�!,��������rc�z�||}|�||dz��}|�||dz��r|�||dz��}n"t���dd��}|jdkr||}}|j�|��|j�d|��dS)zCModify a limits commands so that the limits appear above and below.rr.zsup class="limit"rnrN)�getlimitrr�rwr�r]rr!)rr]r-�limited�	subscript�superscripts      rrzLimitsProcessor.modifylimits�
s����5�/���M�M�(�E�A�I�6�6�	����H�e�a�i�0�0�	N��-�-��%�!�)�<�<�K�K�#�+�+�.�.�x�9L�M�M�K����#�#�%.���K�����	�*�*�*������;�/�/�/�/�/rc��|�||��}|jj�dd��|j_|S)z#Get the limit for a limits command.�scriptrH)�	getscriptr\r�r)rr]r-rHs    rrzLimitsProcessor.getlimit�
s9�����x��/�/�� �<�+�3�3�H�g�F�F�����rc���|�||��}|�||��}|jdkr||}}t���||gd��}|�||��dS)z=Modify the super- and subscript to appear vertically aligned.rnzspan class="scripts"N)r"r�r�r�r!)rr]r-rr�scriptss      rrzLimitsProcessor.modifyscripts�
sx���N�N�8�U�3�3�	��n�n�X�u�5�5�����#�#�%.���K��+�+�&�&��Y�'?�AW�X�X������w�'�'�'�'�'rc�:�|�||t��S)z6Check if the current element is a sub- or superscript.)rr7rs   rrzLimitsProcessor.checkscript�
s��� � ��5�.�A�A�Arc�X�t|��|krdSt|||��S)z0Check for the given type as the current element.F)rr)rr]r-rHs    rrzLimitsProcessor.checkcommand�
s,���x�=�=�E�!�!��5��(�5�/�4�0�0�0rc�F�||}|jxjdz
c_||=|S)zGet the sub- or superscript.z class="script")r\r�)rr]r-r�s    rr"zLimitsProcessor.getscripts*���u�o���
���+�+����U�O��
rN)
r r!r"r#rSrrrrrrrr"r%rrrr�
s�������/�/�0�0�0�
5�
5�
5�/�/�/�
0�0�0����	(�	(�	(�B�B�B�1�1�1�����rrc�,�eZdZdZejZd�Zd�ZdS)r,z"A command which defines a bracket.c�<�t�||��dS)zParse the bracket.N)r3r�r$s  rr�zBracketCommand.parsebits���!�!�$��,�,�,�,�,rc�R�||_d|z|_t|��g|_|S)z+Create the bracket for the given character.rV)rDr�r)r]�r�	direction�	characters   rrBzBracketCommand.creates,��!��
��i�'���(��3�3�4��
��rN)	r r!r"r#rJr�rrr�rBr%rrr,r,	s@������(�(��.�J�-�-�-�����rr,c�B�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
S)�BracketProcessorz!A processor for bracket commands.c�z�tjrdS|�||��r|�||��SdS)z6Convert the bracket using Unicode pieces, if possible.N)r#r<�	checkleft�processleftrs   rrSzBracketProcessor.processsH����	��F��>�>�(�E�*�*�	5��#�#�H�e�4�4�4�	5�	5rc���|�||dz��}|sdS|�|||��}|�|||��|�|||��dS)zProcess a left bracket.rN)�	findright�findmax�resize)rr]r-�
rightindexr�s     rr2zBracketProcessor.processleft$sr���^�^�H�e�a�i�8�8�
��	��F��|�|�H�e�Z�8�8�����H�U�O�T�*�*�*����H�Z�(�$�/�/�/�/�/rc�:�|�||d��S)z0Check if the command at the given index is left.re��checkdirectionrs   rr1zBracketProcessor.checkleft-s���"�"�8�E�?�H�=�=�=rc�:�|�||d��S)z1Check if the command at the given index is right.rfr9rs   r�
checkrightzBracketProcessor.checkright1s���"�"�8�E�?�I�>�>�>rc�F�t|t��sdS|j|kS)z6Check if the given bit is the desired bracket command.F)rr,r�)rr�r�s   rr:zBracketProcessor.checkdirection5s&���#�~�.�.�	��5��{�g�%�%rc���d}|t|��krV|�||��r|dz
}|�||��r|dz}|dkr|S|dz
}|t|��k�VdS)z9Find the right bracket starting at the given index, or 0.rrN)rr1r<)rr]r-�depths    rr4zBracketProcessor.findright;s������c�(�m�m�#�#��~�~�h��.�.�
���
�����x��/�/�
���
����z�z����Q�J�E��c�(�m�m�#�#��trc�H�|||�}td�|D����S)z@Find the max size of the contents between the two given indices.c3�$K�|]}|jV��dSrr�r�s  rr�z+BracketProcessor.findmax.<locals>.<genexpr>Ks$����6�6�G�7�<�6�6�6�6�6�6r)r�)rr]�	leftindexr7�sliceds     rr5zBracketProcessor.findmaxHs.���)�J�.�/���6�6�v�6�6�6�6�6�6rc���|���}|j�dd��}t|||��}t	��|_|���|_dS)z+Resize a bracket command to the given size.rVr@N)r=r�rr�r�r\r�r])rr�r�r-r�r�s      rr6zBracketProcessor.resizeMsb���'�'�)�)�	��O�+�+�D�"�5�5�	��T�9�i�8�8��'�)�)���"�.�.�0�0����rN)r r!r"r#rSr2r1r<r:r4r5r6r%rrr/r/s�������'�'�5�5�5�0�0�0�>�>�>�?�?�?�&�&�&����7�7�7�
1�1�1�1�1rr/c�:�eZdZdZ				ddgZd�Zd�Zd�Zd�ZdS)	�ParameterDefinitionz3The definition of a parameter in a hybrid function.)r`ra)rbrcc�L�d|_d|_d|_d|_d|_dS)NF)rZrrr��literalvaluer7s rrzParameterDefinition.__init__gs,����	������
���
� ����rc�`�tjD]�\}}|�|��r�|dkrd|_|�d��s5t�d|���zdz��dS|���|_|�d��rd|_	|�|��s2t�d|���z��dS|cS��t�d	|���z��dS)
z2Parse a parameter definition: [$0], {$x}, {$1!}...r`Tr�z$Wrong parameter name, did you mean $r�Nr�zWrong parameter closing z'Wrong character in parameter template: )
rF�
parambracketsrIrrrrr�rZr)rr%�opening�closings    rr}zParameterDefinition.parsens��"5�"C�
	�
	��W�g��}�}�W�%�%�
��c�>�>�$(�D�M��}�}�S�)�)� ��K�K� F������ V�Y\� \�]�]�]��4�4��O�O�-�-��	��=�=��%�%�(�#'�D�L��}�}�W�-�-� ��K�K� :�S�_�_�=N�=N� N�O�O�O��4�4�����
�	���=����@Q�@Q�Q�R�R�R��trc�N�|jr`|jr|�|��|_n|�|��|_|jrt|j��|_dSdS|jr|�|��|_dS|�|��|_dS)z/Read the parameter itself using the definition.N)	rrr�rHrr)r�r�rm)rr%r�s   r�readzParameterDefinition.read�s����<�
	6��}�
?�$,�$?�$?��$D�$D��!�!�$,�$9�$9�#�$>�$>��!�� �
@�,�T�->�?�?��
�
�
�
@�
@�
�]�	6�!�-�-�c�2�2�D�J�J�J�!�0�0��5�5�D�J�J�Jrc�h�d|jz}|jr|dt|j��zz
}n|dz
}|S)r�zparam rhz (empty))rZr�rp)rr)s  rrxzParameterDefinition.__str__�s@���D�I�%���:�	!��d�S���_�_�,�,�F�F��j� �F��
rN)	r r!r"r#rJrr}rNrxr%rrrFrF^sl������9�9�>�A�9�\���,�M�!�!�!����&6�6�6�����rrFc�2�eZdZdZ	d�Zd�Zd�Zd�Zd�ZdS)�ParameterFunctionzFA function with a variable number of parameters defined in a template.c��i|_|�|��D]*}|�||��||jd|jz<�+dS)z*Read the params according to the template.r�N)�params�	paramdefsrNrZ�r�readtemplater%�paramdefs    r�
readparamszParameterFunction.readparams�sX��������|�4�4�	8�	8�H��M�M�#�t�$�$�$�/7�D�K��h�m�+�,�,�	8�	8rc#��K�t|��}|���s=t���|��}|r|V�|����;dSdS)z*Read each param definition in the templateN)rLr�rFr}rUs    rrTzParameterFunction.paramdefs�ss�����<�(�(���,�,�.�.�	�*�,�,�2�2�3�7�7�H��
������,�,�.�.�	�	�	�	�	rc�2�||jvrdS|j|S)zGet a parameter as parsed.N)rSr�s  r�getparamzParameterFunction.getparam�s!���t�{�"�"��4��{�4� � rc�6�|�|��jS)zGet the value of a parameter.)r[r�r�s  r�getvaluezParameterFunction.getvalue�s���}�}�T�"�"�(�(rc�P�|�|��}|r|jsdS|jS)z%Get the literal value of a parameter.N)r[rH)rrZr1s   r�getliteralvaluez!ParameterFunction.getliteralvalue�s3���
�
�d�#�#���	�E�.�	��4��!�!rN)	r r!r"r#rXrTr[r]r_r%rrrQrQ�sh������L�L�;�8�8�8����!�!�!�)�)�)�"�"�"�"�"rrQc�P�eZdZdZejZd�Zd�Zd�Z	d�Z
d�Zd�Zd�Z
d	�Zd
S)�HybridFunctiona
    A parameter function where the output is also defined using a template.
    The template can use a number of functions; each function has an associated
    tag.
    Example: [f0{$1},span class="fbox"] defines a function f0 which corresponds
    to a span of class fbox, yielding <span class="fbox">$1</span>.
    Literal parameters can be used in tags definitions:
      [f0{$1},span style="color: $p;"]
    yields <span style="color: $p;">$1</span>, where $p is a literal parameter.
    Sizes can be specified in hybridsizes, e.g. adding parameter sizes. By
    default the resulting size is the max of all arguments. Sizes are used
    to generate the right parameters.
    A function followed by a single / is output as a self-closing XHTML tag:
      [f0/,hr]
    will generate <hr/>.
    c���|jd}|jd}|�||��|�|��|_|���dS)z*Parse a function with [] and {} parametersrrN)r�rX�writeparamsr]�computehybridsize)rr%rV�
writetemplates    rr�zHybridFunction.parsebit�s[����q�)�����*�
�����c�*�*�*��(�(��7�7��
���� � � � � rc�F�|�t|����S)z*Write all params according to the template)�writeposrL)rres  rrczHybridFunction.writeparams�s���}�}�\�-�8�8�9�9�9rc���g}|����sR|�d��r-|�|��}|r|�|��n�|�d��r4|�|��}|rd|_|�|��n�|�d��r*|�|�dd����ns|�d��r*|�|�dd����n4|�t|�������|�����R|S)z/Write all params as read in the parse position.r��fNr^�leftr_�right)	r�rI�
writeparamr�
writefunctionrH�writebracketr)r�)rr%r)r1r�s     rrgzHybridFunction.writepos�sU�����,�,�.�.�	B��}�}�S�!�!�
B�����,�,���)��M�M�%�(�(�(�����s�#�#�

B��-�-�c�2�2���,�$(�H�M��M�M�(�+�+�+�����s�#�#�
B��
�
�d�/�/���<�<�=�=�=�=����s�#�#�
B��
�
�d�/�/���=�=�>�>�>�>��
�
�o�c�o�o�.?�.?�@�@�A�A�A��,�,�.�.�	B� �
rc�>�d|���z}||jvrt�d|z��dS|j|sdS|�d��r)|���|j|j_|j|jS)z*Write a single param of the form $0, $x...r�zUnknown parameter Nr�)r�rSrrrIr�r�rH)rr%rZs   rrlzHybridFunction.writeparam�s����S�_�_�&�&�&���t�{�"�"��K�K�,�t�3�4�4�4��4��{�4� �	��4��=�=����	;�+.�=�=�?�?�D�K���#�(��{�4� �&�&rc���|�|��}|sdS|�d��r!t���|��S|�d��st�d��dS|�d��|�|��}|���t|��dkrdSt���
||��S)z"Write a single function f0,...,fn.Nr�rbz Function should be defined in {}rcr)�readtagrIr�r�rrrrgrrr�)rr%r�r]s    rrmzHybridFunction.writefunction�s����l�l�3�����	��4��=�=����	1��;�;�+�+�C�0�0�0��}�}�S�!�!�	��K�K�:�;�;�;��4����s�����=�=��%�%���
�
�����x�=�=�A����4��{�{�#�#�H�c�2�2�2rc��|������s1t�d|���z��dSt	|�����}d|zt
|j��kr/t�dt|��zdz��dS|jd|z}d|vr|S|j	D]h}||vrb|j	|}|j
s't�d|zdz|zd	z���A|jr|j}nd
}|�||��}�i|S)zJGet the tag corresponding to the given index. Does parameter substitution.zFunction should be f0,...,f9: fNrz
Function fz is not definedr�zParameters in tag z should be literal: {z!}r@)
rr�rr�intr�rr�rprSrrHr)rr%r-r��variabler1r�s       rrqzHybridFunction.readtagsI���{�{�}�}�$�$�&�&�	��K�K�9�C�K�K�M�M�I�J�J�J��4��C�O�O�%�%�&�&���u�9�s�4�?�+�+�+�+��K�K��s�5�z�z�1�4E�E�F�F�F��4��o�a�%�i�(���c�>�>��J���
	3�
	3�H��3�����H�-���}���K�K� 4�s� :�=T� T�W_� _�bf� f�g�g�g���%��!�.�E�E��E��k�k�(�E�2�2����
rc�h�|j�t���||��S)z4Return a new bracket looking at the given direction.)rsrBr,r+s   rrnzHybridFunction.writebracket*s(���|�"�"�>�2�2�9�9�)�Y�O�O�Orc���|jtjvr|���dSt���|��|_|jD]}|j|_�dS)z(Compute the size of the hybrid function.N)r��
HybridSize�configsizesr��getsizer�r])rr�s  rrdz HybridFunction.computehybridsize.sh���<�z�5�5�5��������F��L�L�(�(��.�.��	��}�	%�	%�G��9�G�L�L�	%�	%rN)r r!r"r#rJr�rrr�rcrgrlrmrqrnrdr%rrrara�s���������"�.�J�!�!�!�:�:�:����*
'�
'�
'�3�3�3�$���2P�P�P�%�%�%�%�%rrac�&�eZdZdZejZd�ZdS)rwz+The size associated with a hybrid function.c�4�|j|j}|jD]M}||vrG|j|j���}|�|t
|����}�Nd|vrt�d|z��dSt|��S)z*Read the size for a function and parse it.r�z%Unconverted variable in hybrid size: r)
rxr�rSr�r�rrprr�eval)rr��
sizestringrZr�s     rryzHybridSize.getsize>s����%�h�&6�7�
��O�	A�	A�D��z�!�!���t�,�2�>�>�@�@��'�/�/��c�$�i�i�@�@�
���*����K�K�?�*�L�M�M�M��1��J���rN)r r!r"r#rJr�rxryr%rrrwrw9s1������1�1��+�K�
 �
 �
 �
 �
 rrwc��t��}|�|��}t���|��|���d�|�����S)zConvert some TeX math to HTML.r@)r9r�r"rSrxr�)r�rsr:s   r�	math2htmlrNsa�����G�� � ��)�)�E������u�%�%�%�	�M�M�O�O�O�
�7�7�5�=�=�?�?�#�#�#rc�4�tj}t���|��t	|��dkr(t
�d��t��t|d��}t
�	|��dS)z6Main function, called if invoked from the command linerz"Usage: math2html.py escaped_stringrN)
r
�argvr#rrrrrrr)rr)s  r�mainr�Wsu���8�D��I�I���4� � � �
�4�y�y�A�~�~�
���8�9�9�9�����
�t�A�w�
�
�F�	�M�M�&�����r�__main__)Zr3r
r��docutils.utils.mathrr:rr'r?rJr�r#r@rJr`rzr�r�r�r�r�r�r�r�r�r�r�r�r�r�r"r7rLrXr�r�r�r�r�r�r�r)r5r2r1r�r�r+rrr"r0rNr9rhr�r.r6r*r3r7r8r/rar�r�r�r�r�r�r�r�r�r�r-r4r9r	r
rr,r/r*rFrQrarwrr�r r%rr�<module>r�s���0����
�
�
�
�����+�+�+�+�+�+�!��+�+�+�+�+�+�+�+�\��������2
�
�
�
�
�
�
�
� f
�f
�f
�f
�f
�f
�f
�f
�R
A�A�A�A�A�A�A�A�H7�7�7�7�7�7�7�7�t!�!�!�!�!�!�!�!�$&�&�&�&�&�&�&�&�R.F�.F�.F�.F�.F�.F�.F�.F�b�����&����"�"�"�"�"��"�"�"�J�����f���������O���������6���������6����	�	�	�	�	�	�	�	������/���������/����
�
�
�
�
�_�
�
�
� @�@�@�@�@�>�@�@�@�F�����^����8"�"�"�"�"�?�"�"�"�t!�t!�t!�t!�t!�t!�t!�t!�n=�=�=�=�=�=�=�=�@��������&68�68�68�68�68�x�68�68�68�r!7�!7�!7�!7�!7�8�!7�!7�!7�HF?�F?�F?�F?�F?�F?�F?�F?�R�����y����,I�,I�,I�,I�,I�i�,I�,I�,I�^	*�	*�	*�	*�	*��	*�	*�	*���������f�f�f�f�f�F�f�f�f�R*E�*E�*E�*E�*E��*E�*E�*E�Z�����
����*2�2�2�2�2�h�2�2�2�.�����j����6�6�6�6�6�J�6�6�6�<�����J����1�1�1�1�1�j�1�1�1�
5�
5�
5�
5�
5��
5�
5�
5� D&�D&�D&�D&�D&�j�D&�D&�D&�N
�
�
�
�
�G�
�
�
�	<�	<�	<�	<�	<�	<�	<�	<�2;�2;�2;�2;�2;�2;�2;�2;�jL$�L$�L$�L$�L$�i�L$�L$�L$�^
1�
1�
1�
1�
1�:�
1�
1�
1�F�F�F�F�F�F�F�F�RS�S�S�S�S�Z�S�S�S�l9�9�9�9�9��9�9�9�x;�;�;�;�;�:�;�;�;�
Q�
Q�
Q�
Q�
Q�J�
Q�
Q�
Q� � � � � �<� � � �"#�#�#�#�#�z�#�#�#�(!�!�!�!�!�Z�!�!�!�"�����:����	"�	"�	"�	"�	"�#�	"�	"�	"������8�8����,� 0�,��-�!���
;N�;N�;N�;N�;N�;N�;N�;N�|<�<�<�<�<�j�<�<�<�
<�
<�
<�
<�
<�.�
<�
<�
<� H�H�H�H�H��H�H�H�:)�)�)�)�)�j�)�)�)�X&�&�&�&�&�?�&�&�&�2
�
�
�
�
�O�
�
�
�6�6�6�6�6�?�6�6�6�&�����/����(�����:����8�����&���#(�#(�#(�#(�#(�(�#(�#(�#(�L
"�
"�
"�
"�
"�&�
"�
"�
"� 
"�
"�
"�
"�
"�'�
"�
"�
"� 	Q�	Q�	Q�	Q�	Q�<�	Q�	Q�	Q�(�(�(�(�(�<�(�(�(�K�K�K�K�K�n�K�K�K�\�����%����"91�91�91�91�91�~�91�91�91�x����*:�*�L�.�J�J�������O���'�'�)�)� ����
8�8�8�8�8�8�8�8�v""�""�""�""�""�
�""�""�""�Jx%�x%�x%�x%�x%�&�x%�x%�x%�v � � � � � � � �$����(�(���$�$�$�����z����D�F�F�F�F�F��r

Hacked By AnonymousFox1.0, Coded By AnonymousFox