403Webshell
Server IP : 127.0.0.1  /  Your IP : 216.73.216.109
Web Server : Apache/2.4.54 (Win64) OpenSSL/1.1.1q PHP/8.1.10
System : Windows NT DESKTOP-E5T4RUN 10.0 build 19045 (Windows 10) AMD64
User : SERVERWEB ( 0)
PHP Version : 8.1.10
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : OFF |  Perl : OFF |  Python : OFF |  Sudo : OFF |  Pkexec : OFF
Directory :  C:/cygwin64/lib/python3.9/site-packages/docutils/utils/math/__pycache__/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : C:/cygwin64/lib/python3.9/site-packages/docutils/utils/math/__pycache__/math2html.cpython-39.pyc
a

OԼa܊�@s�ddlZddlZddlZejdkr0ddlmZnddlmZddlm	Z	ejdkrZe
Ze
ZdZ
Gdd�de�ZGdd	�d	e�ZGd
d�de�ZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGd d!�d!e�ZGd"d#�d#e�ZGd$d%�d%e�ZGd&d'�d'e�ZGd(d)�d)e�Z Gd*d+�d+e�Z!Gd,d-�d-e!�Z"Gd.d/�d/e!�Z#Gd0d1�d1e�Z$Gd2d3�d3e�Z%Gd4d5�d5e�Z&Gd6d7�d7e�Z'Gd8d9�d9e%�Z(Gd:d;�d;e(�Z)Gd<d=�d=e�Z*Gd>d?�d?e*�Z+Gd@dA�dAe*�Z,GdBdC�dCe,�Z-GdDdE�dEe�Z.GdFdG�dGe�Z/GdHdI�dIe*�Z0GdJdK�dKe0�Z1GdLdM�dMe-�Z2GdNdO�dOe0�Z3GdPdQ�dQe0�Z4GdRdS�dSe0�Z5GdTdU�dUe0�Z6GdVdW�dWe0�Z7GdXdY�dYe0�Z8GdZd[�d[e8�Z9Gd\d]�d]e�Z:Gd^d_�d_e�Z;Gd`da�dae*�Z<Gdbdc�dce0�Z=Gddde�dee�Z>Gdfdg�dge0�Z?Gdhdi�die?�Z@Gdjdk�dke@�ZAGdldm�dme@�ZBGdndo�doeA�ZCGdpdq�dqe@�ZDGdrds�dse@�ZEGdtdu�due@�ZFGdvdw�dwe@�ZGGdxdy�dyeD�ZHe>jIe?eEg7_IeCeAeDeHeGeFeBge?_IGdzd{�d{e�ZJGd|d}�d}e@�ZKGd~d�de?�ZLGd�d��d�e?�ZMGd�d��d�e@�ZNGd�d��d�eN�ZOGd�d��d�eN�ZPGd�d��d�eN�ZQGd�d��d�eN�ZRGd�d��d�e@�ZSe?jIeSg7_IGd�d��d�eD�ZTGd�d��d�eD�ZUGd�d��d�eD�ZVGd�d��d�eA�ZWGd�d��d�eW�ZXGd�d��d�e:�ZYGd�d��d�eD�ZZGd�d��d�e:�Z[e?jIeUeVeTeWeZg7_Ie;j\eY�e[�g7_\Gd�d��d�e�Z]Gd�d��d�e@�Z^Gd�d��d�e^�Z_Gd�d��d�e�Z`e?jIe_g7_Id�d��Zad�d��Zbecd�k�r�eb�dS)��N��r)�
quote_plus)�tex2unicharz1.3 (2021-06-02)c@speZdZdZdZdZdZdZdd�Zdd�Z	dd	�Z
d
d�Zdd
�Ze
e�Ze
e	�Z	e
e
�Z
e
e�Ze
e�ZdS)�TracezA tracing classFNcCs"tjrtjrdSt�|tj�dS)zShow a debug messageN)r�	debugmode�	quietmode�show�sys�stdout��cls�message�r�A/usr/lib/python3.9/site-packages/docutils/utils/math/math2html.py�debug5szTrace.debugcCs2tjr
dStjr tjr tj|}t�|tj�dS)zShow a trace messageN)rr�prefix�
showlinesmoder	r
rrrrrr;s

z
Trace.messagecCs0d|}tjrtjrtj|}t�|tj�dS)zShow an error messagez* N)rrrr	r
�stderrrrrr�errorCs
zTrace.errorcCst�d|�td�dS)z#Show an error message and terminatezFATAL: ���N)rr�exitrrrr�fatalJszTrace.fatalcCs&tjdkr|�d�}|�|d�dS)zShow a message out of a channelr�utf-8�
N)r
�version_info�encode�write)r
rZchannelrrrr	Os

z
Trace.show)�__name__�
__module__�__qualname__�__doc__rrrrrrrrr	�classmethodrrrrr,src@s 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)rrr r!�extracttextrrrrr#\s�r#c@s(eZdZdZdddd�Zdddd	�Zd
S)�EscapeConfigr$��’u‘)r�'�`z&amp;z&lt;z&gt;)�&�<�>N)rrr r!�chars�entitiesrrrrr:vs��r:cT@s�eZdZdZdddddddd	d
ddd
ddddddd�Zej��D]\ZZ	e	ede<q@ddddd�Z
gd�gd�gd�gd�gd�gd �d!gd"gd#�Zd$d%d$d$d&d'�Zd(d)d*d+d,d-d.d/d0d1d2d3�Z
ej��D]\ZZ	e	e
de<q�d4d5d5d6d7d8d9d:d;d:d;d;d:d<d=d>d?d"d"d!d4d@dAdAdBd"d!dCdDdd8dEd:dFdFd<dGdHdIdJdKdLdMdNdOdPdQdRd5dSdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdt�SZiZe�ej�e�ej�e�ej�e�ej�e�ej�e�ej�e�ej�e�dudv�e��D��dwdxdydzd{d|dCd}d~�Zdzd{d|d�Zd�d�d�d�d�d��Zd�d�ggd��d�d�gd�d�gd��Zd�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�dd�d
d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d��;Zgd��gd��gd��gd��gd��gd��gd��gd��gd¢gdâgdĢgdŢgdŢgdƢgdǢgdǢgdȢgdɢgdʢgd��gdˢgd̢gd͢gd΢gdϢgdТd�dAggdҢgdӢgdԢgdբgd֢gd¢gdעgd��gdآgdǢgd٢gdڢgdۢgdܢgdݢdޜ*Zd�d�d�d�d�d�d�Zd�d�iZ 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�dd�d�d�d�d�d�d�d�d	�(Z!dAdAdA�d
dM�d�d�d
�d�d�d�d�ddAd@�d�Z"�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#�d"�d#�d$�d%�d&�d'�d(�d)�d*�d+�d,�d-�d.�d/�d0�d1�d2�Z$ej%��D]\ZZ	e	e$de<�q@d��d3�d4d�d5�d6�d7�d8�d9�d:�	Z&d�d;�d<�Z'�d=�d>�d?�d@�dA�dB�dC�dD�dE�dF�dG�dH�Z(�dIg�dJ�iZ)�dKS(L�
FormulaConfigr$z<span class="textsc">AmS</span>�Å�Æ�ÐuŁ�ØuŒ�Þ�å�æ�ðuıuȷuł�øuœ�ß�þ)z\AmSz\AAz\AEz\DHz\Lz\Oz\OEz\THz\aaz\aez\dhz\iz\jz\lz\oz\oez\ssz\th�\z\beginr?z\end�\\)�begin�
cellseparator�end�rowseparator)u⎛u⎜u⎝)u⎞u⎟u⎠)u⎡u⎢u⎣)u⎤u⎥u⎦)u⎧�⎪u⎨u⎩)u⎫rVu⎬u⎭�|�‖)�(�)�[�]�{�}rWrX�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/>� u⬝�: �©u∸u…u⋯�€�«�»u	<i>ħ</i>� r;u  �^�~�°u—rAr@�ª�ºu“u”r<�®u→�§u™�²z!<span class="thickspace"> </span>u△u▽u⌀ZPrZarccosZarcsinZarctan�argZcosZcoshZcotZcothZcscZdegZdetZdimZexpZgcdZhomu	inj limZkerZlgu	lim infu	lim supZln�logu
proj limZsecZsinZsinhZtanZtanh)SrQz\
z\	z
\centerdotz\colonz
\copyrightz	\dotminusz\dotsz\dotsbz\dotscz\dotsiz\dotsmz\dotsoz\euroz\guillemotleftz\guillemotrightz\hbarz\lVertz
\Arrowvertz\lvertz\newlinez
\nobreakspacez	\nolimitsz	\nonumberz\qquadz\rVertz\rvertz\textasciicircumz\textasciitildez\textbackslashz\textcopyrightz\textdegreez
\textellipsisz\textemdashz\textendashz	\texteuroz\textgreaterz	\textlessz\textordfemininez\textordmasculinez\textquotedblleftz\textquotedblrightz\textquoterightz\textregisteredz\textrightarrowz\textsectionz\texttrademarkz\texttwosuperiorz\textvisiblespacez\thickspacez\;z	\trianglez
\triangledownz\varnothingz\Prz\arccosz\arcsinz\arctanz\argz\cosz\coshz\cotz\cothz\cscz\degz\detz\dimz\expz\gcdz\homz\injlimz\kerz\lgz\liminfz\limsupz\lnz\logz\projlimz\secz\sinz\sinhz\tanz\tanhccs|]\}}d||fVqdS)rPNr)�.0�key�valuerrr�	<genexpr>+�zFormulaConfig.<genexpr>u‒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\underrightarrowr^�\]z\end{r\)�bracket�complex�endafter�	endbefore�
squarebracket�r�l)r~�crr�)ZalignZeqnarrayZgatheredZsmallmatrix�bzspan class="blackboard"u𝔸u𝔹uℂu𝔻u𝔼u𝔽u𝔾uℍu𝕁u𝕂u𝕃uℕu𝕆uℙuℚuℝu𝕊u𝕋u𝕎uℤzspan class="scriptfont"uℬuℰuℱuℋuℐuℒuℳuℛzspan class="fraktur"uℭu𝔉uℌuℑuℜuℨ�iuŮuůuẘuẙzspan class="mathrm"zspan class="mathscr"zspan class="mathsf"zspan class="mathtt");z\boldsymbolz\mathbbz
\mathbb{A}z
\mathbb{B}z
\mathbb{C}z
\mathbb{D}z
\mathbb{E}z
\mathbb{F}z
\mathbb{G}z
\mathbb{H}z
\mathbb{J}z
\mathbb{K}z
\mathbb{L}z
\mathbb{N}z
\mathbb{O}z
\mathbb{P}z
\mathbb{Q}z
\mathbb{R}z
\mathbb{S}z
\mathbb{T}z
\mathbb{W}z
\mathbb{Z}z\mathbfz\mathcalz\mathcal{B}z\mathcal{E}z\mathcal{F}z\mathcal{H}z\mathcal{I}z\mathcal{L}z\mathcal{M}z\mathcal{R}z	\mathfrakz\mathfrak{C}z\mathfrak{F}z\mathfrak{H}z\mathfrak{I}z\mathfrak{R}z\mathfrak{Z}z\mathitz\mathring{A}z\mathring{U}z\mathring{a}z\mathring{u}z\mathring{w}z\mathring{y}z\mathrmz\mathscrz\mathscr{B}z\mathscr{E}z\mathscr{F}z\mathscr{H}z\mathscr{I}z\mathscr{L}z\mathscr{M}z\mathscr{R}z\mathsfz\mathttz
\operatorname)z{$p!}{$q!}{$r!}�f0{}�ignored)z
{$p!}{$q!}r�r�)r;r�r�)�{$1}{$2}zf2{(}f0{f1{$1}f1{$2}}f2{)}zspan class="binom"zspan class="binomstack"�span class="bigdelimiter size2")�{$1}�f0{$1}zspan class="boxed")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")�	{$p!}{$1}r�zspan style="color: $p;")r�r�z-span class="colorbox" style="background: $p;")r�u%(f0{f1{f2{$1}}f1{f2{ }}f1{f2{$2}}})zspan class="binomial"zspan class="binomrow"zspan class="binomcell")r�r�r��span class="numerator"r�r�)r�r�zspan class="displaystyle")z
[$p!]{$q!}r�r�)r�r�zspan class="fbox")�{$p!}r�r�)z{$p!}{$q!}{$1}r�z<span class="boxed" style="border-color: $p; background: $q;")r�r��span class="fraction"r�r�r�)z[$p!][$q!]{$1}r�z1span class="framebox align-$q" style="width: $p;")z[$o]{$u!}{$t!}zf0{$t}�a href="$u")r��f0{ }z&span class="hspace" style="width: $p;")r�r�z*span class="leftroot" style="width: $p;px")r�uf0{f1{$1}⁄f2{$2}}r�zsup class="numerator"zsub class="denominator"r�)z[$p!]{$w!}{$1}zf0{1}z$div class="Boxed" style="width: $w;")r�zf0{$1.font}z1span class="raisebox" style="vertical-align: $p;"z{$1!}{$2!}{$3!})z[$v!]{$w!}{$h!}zf0/z.hr class="line" style="width: $w; height: $h;")r�r�zspan class="scriptscriptstyle")r�r�zspan class="scriptstyle")�[$0]{$1}u!f0{f1{$0}f2{√}f4{(}f3{$1}f4{)}}zspan class="sqrt"zsup class="root"zspan class="radical"zspan class="root"r�)r�zf0{f1{$1}f2{$2}}zspan class="stackrel"zspan class="upstackrel"zspan class="downstackrel")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\addcontentslinez\addtocontentsz\backmatter�\binomz\boxed�\cfracz\colorz	\colorbox�\dbinom�\dfracz
\displaystylez
\fancyfootz
\fancyheadz\fboxz	\fboxrulez\fboxsepz
\fcolorbox�\fracz	\frameboxz\frontmatterz\hrefz\hspacez	\leftrootz	\nicefracz\parboxz	\raiseboxz\renewenvironmentz\rulez\scriptscriptstylez\scriptstylez\sqrtz	\stackrel�\tbinomz\tfracz
\textcolorz
\textstylez\thispagestylez\unitz	\unitfracz\uprootz\urlz\vspacez$1+$2z$1+$2+1)r�r�r�r�r�r�z\labelz
a name="#"u⫼�infZlim�max�min�supu-<span class="bigoperator integral">∮</span>u$<span class="bigoperator">⋂</span>u$<span class="bigoperator">⋃</span>u$<span class="bigoperator">⨀</span>u$<span class="bigoperator">⨁</span>u$<span class="bigoperator">⨂</span>u$<span class="bigoperator">⨅</span>u$<span class="bigoperator">⨆</span>u$<span class="bigoperator">⨄</span>u$<span class="bigoperator">⋁</span>u$<span class="bigoperator">⋀</span>u$<span class="bigoperator">∐</span>u-<span class="bigoperator integral">∫</span>u$<span class="bigoperator">∏</span>u$<span class="bigoperator">∑</span>u$<span class="bigoperator">⨉</span>u⨟u⧹u⨠u⨡u-<span class="bigoperator integral">∬</span>u-<span class="bigoperator integral">∭</span>u-<span class="bigoperator integral">⨌</span>u-<span class="bigoperator integral">⨏</span>u3<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="bigoperator integral">∳</span>u-<span class="smallsymbol integral">∫</span>u-<span class="bigoperator integral">⨖</span>)(z\biginterleavez\infz\limz\maxz\minz\supz\ointopz\bigcapz\bigcupz\bigodotz	\bigoplusz
\bigotimesz	\bigsqcapz	\bigsqcupz	\biguplusz\bigveez	\bigwedgez\coprodz\intopz\prodz\sumz\varprodz\zcmpz\zhidez\zpipez	\zprojectz\intz\iintz\iiintz\iiiintz\fintz	\idotsintz\ointz\oiintz\oiiintz\ointclockwisez\ointctrclockwisez	\smallintz\sqintz\varointclockwise�	u + u, u	 − u	 ⁄ z : u
 &lt; u = u
 &gt; )rrb�$r?r=�+�,�-�/�:r@�=rA�@rjzspan class="bigdelimiter size1"r�zspan class="bigdelimiter size3"zspan class="bigdelimiter size4"zspan class="arraydef"zspan class="align-center"zspan class="ensuremath"zspan class="phantom"zspan class="noindent"zspan class="overbrace"zspan class="overline"zspan class="underbrace"�u)z\bigz\biglz\bigrz\Bigz\Biglz\Bigrz\biggz\bigglz\biggrz\Biggz\Bigglz\Biggrz
\begin{array}z
\centeringz\ensuremathz	\hphantomz	\noindentz
\overbracez	\overlinez\phantomz\underbracez
\underlinez	\vphantomu≦̸u≧̸u⩽̸u⩾̸u⫅̸u⫆̸u≶⊏u$<span class="smallsymbol">∣</span>u$<span class="smallsymbol">∥</span>u$<span class="smallsymbol">∤</span>u$<span class="smallsymbol">∦</span>u$<span class="smallsymbol">⌢</span>u$<span class="smallsymbol">⌣</span>u#<span class="boldsymbol">≈</span>u#<span class="boldsymbol">∼</span>u<span class="mathsf">∝</span>)z\nleqqz\ngeqqz
\nleqslantz
\ngeqslantz\nsubseteqqz\nsupseteqqz
\nsqsubsetz	\shortmidz\shortparallelz
\nshortmidz\nshortparallelz\smallfrownz\smallsmilez\thickapproxz	\thicksimz
\varproptoz\begin{r]�%�\[r�r[�*)	�
beginafter�beginbeforery�command�commentrz�simpler}�
unnumbered�sub)ri�_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�rerYrZr[r\�·�!�;rWro�"�?N)*rrr r!�
alphacommandsrZ	mathalpha�itemsrtru�array�bigbrackets�bracketcommands�combiningfunctionsZ
mathaccent�commandsZcmddict�updateZmathbinZmathopenZ	mathcloseZ	mathfenceZmathordZ	mathpunct�space�oversetfunctions�undersetfunctions�endings�environments�
fontfunctions�hybridfunctions�hybridsizes�labelfunctions�
limitcommands�modified�onefunctions�spacedcommandsZmathrel�starts�symbolfunctions�
textfunctions�
unmodifiedrrrrrD�s�����	�
�V���	���1���+���
����rDc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�CommandLineParserzA parser for runtime optionscCs
||_dS�N)�options)�selfr�rrr�__init__2szCommandLineParser.__init__cCslt|�dkrdSt|�dkrh|d�d�rh|�|�\}}|sHd|dS|sXd|dSt|j||�qdS)�Parse command line optionsrN�--zOption z not recognizedz needs a value)�len�
startswith�
readoption�setattrr�)r��argsrtrurrr�parseoptions5szCommandLineParser.parseoptionscCs�|ddd�}|d=d|vr,|�||�}n|�dd�}t|j|�sLd|fSt|j|�}t|t�rj|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�r)
�
readequalskey�replace�hasattrr��getattr�
isinstance�boolr�r��
readquoted�decode�list�append)r�r�rqrt�current�initialrurrrr�Bs,


zCommandLineParser.readoptioncCs�t�d�|dd�}t|�dkrh|d�d�sh|d�d�sht�d|d�|d|d7}|d=qt|�dks�|d�d�r�dS|d|dd	�7}|S)
zRead a value between quotesZOops�Nrr�r�z
Appending rbr)rrr��endswithr�)r�r�r�rurrrr�]s
(zCommandLineParser.readquotedcCs,|�dd�}|d}|d}|�d|�|S)zRead a key using equalsr�r�r)�split�insert)r�rqr�r�rtrurrrr�js
zCommandLineParser.readequalskeyN)	rrr r!r�r�r�r�r�rrrrr�/s

r�c@sZeZdZdZdZdZdZdZdZdZ	dZ
e�Zdd�Z
dd�Zd	d
�Zdd�Zd
d�ZdS)�OptionszA set of runtime optionsNFTcCsD|dt_|d=tt�}|�|�}|r8t�|�|��|��dS)r�rN)r��locationr�r�rr�usage�processoptions)r�r��parser�resultrrrr��s


zOptions.parseoptionsc	CsRtjr|��tjr|��tt�D](}|�d�r$tt|t	||dd���q$dS)zProcess all options parsed.�modeN���)
r��helpr��version�showversion�dirrr�r�r�)r��paramrrrr��s
zOptions.processoptionscCs2t�dtj�tj�d�t�d�|��dS)zShow correct usagezUsage: z [options] "input string"z.Convert input string with LaTeX math to MathMLN)rr�os�path�basenamer�r��showoptions�r�rrrr��s
�
z
Options.usagecCs>t�d�t�d�t�d�t�d�t�d�t��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
rrrrrr�s




zOptions.showoptionscCst�dt�t��dS)z(Return the current eLyXer version stringz
math2html N)rr�__version__r
rrrrrr��szOptions.showversion)rrr r!r�r�quietr�r��
simplemathZ	showlines�dictZbranchesr�r�r�rr�rrrrr�ss	r�c@s0eZdZdZdd�Zdd�Zee�Zee�ZdS)�Clonerz&An object used to clone other objects.cCs|�|j�S)z"Return an exact copy of an object.)�create�	__class__)r
�originalrrr�clone�szCloner.clonecCs|�|�}|��|S)z"Create an object of a given class.)�__new__r�)r
�typerrrrr�s
z
Cloner.createN)rrr r!rrr"rrrrr�s
rc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�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.
  cCs|d|_|d|_dS)Nr7r8r6)r�Zconfigrrrr��s
zContainerExtractor.__init__cs<g��fdd�}�fdd�}��fdd�}|�|||��S)z8Extract a group of selected containers from a container.cs|jj�jvSr�)r	rr7�r�rrr�<lambda>�rwz,ContainerExtractor.extract.<locals>.<lambda>cs|jj�jvSr�)r	rr8rrrrr�rwcs��|��Sr�)�processr�r�r�rrr�rw)�recursivesearch)r��	container�locate�	recursiverrrr�extract�szContainerExtractor.extractcCs0|jj}||jvr|�|�nt�d|�dS)zAdd allowed containers.zUnknown container class N)r	rr7r�rr)r�rr��namerrrr�s
zContainerExtractor.processcCs"t�|�}|j|_|�|�|_|S)zFReturn a new container with contents only in a safe list, recursively.)rr�outputr�contents)r�rrrrr�	safeclone�s
zContainerExtractor.safecloneN)rrr r!r�rrrrrrrr�s
	rc@sNeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	e
jdkrJe	ZdS)�ParserzA generic parsercCsd|_t�|_dS)Nr)rRr�
parametersrrrrr��szParser.__init__cCs |����}|��|j|_|S)zParse the header)�currentliner��nextline�
linenumberrR)r��reader�headerrrr�parseheader�szParser.parseheadercCs�|�����dd�}|��t|�dkr,dS|d}t|�dkrNd|j|<dSd|dvrp|d��|j|<dS|d�d�}|d|j|<dS)zParse a parameterrbr�rNTr�)r�stripr�rr�r)r�r!r�rtZdoublesplitrrr�parseparameter�s
zParser.parseparametercCs8|jst�dt|��dS|���|j�s4|�qdS)z'Parse until the current ending is foundzNo ending for N)�endingrr�unicoderr�)r�r!rrrr�parseendings
zParser.parseendingcCs&|j�|�}|r"|j|_|�|�dSr�)�factoryZcreatecontainer�parentr�)r�r!rrrrr�parsecontainer
szParser.parsecontainercCs|jjdt|j�dS)zReturn a description� (rZ)r	rr'rRrrrr�__unicode__szParser.__unicode__rN)
rrr r!r�r#r%r(r+r-r
r�__str__rrrrr�s
rc@seZdZdZdd�ZdS)�LoneCommandz"A parser for just one command linecCsgS)zRead nothingr�r�r!rrr�parseszLoneCommand.parseN�rrr r!r1rrrrr/sr/c@s,eZdZdZgZdd�Zdd�Zdd�ZdS)	�
TextParserz(A parser for a command and a bit of textcCs8t�|�d|_|jjtjvr.tj|jj|_g|_dSr�)rr�r&r	rr#r��r�rrrrr�'s

zTextParser.__init__cCsNtj�|j�tjtjdtjd|jg|_g}|�|�sJ|�||�q2|S)z$Parse lines as long as they are textZLayoutZInset)r3�stackr�r&r#r��isendingr+�r�r!rrrrr1.s�
zTextParser.parsecCsX|����}t|�dkrdS|d|jvrT|dtjvrJtj�|d�ngt_dSdS)zCheck if text is endingrFT)rr�r�r�r3r5�remove)r�r!r�rrrr68szTextParser.isendingN)rrr r!r5r�r1r6rrrrr3"s

r3c@seZdZdZdd�ZdS)�ExcludingParserz%A parser that excludes the final linecs g�������fdd���S)z5Parse everything up to (and excluding) the final linecs�����Sr�)r+r�rr!r�rrrKrwz'ExcludingParser.parse.<locals>.<lambda>)r(r0rr:rr1HszExcludingParser.parseNr2rrrrr9Esr9c@seZdZdZdd�ZdS)�
BoundedParserzA parser bound by a final linecCst�||�}|��|S)z*Parse everything, including the final line)r9r1rr7rrrr1QszBoundedParser.parseNr2rrrrr;Nsr;c@seZdZdZdd�ZdS)�BoundedDummyz&A bound parser that ignores everythingcs |���fdd�����gS)z#Parse the contents of the containercs���Sr�)rr�r!rrr]rwz$BoundedDummy.parse.<locals>.<lambda>)r(rr0rr=rr1[szBoundedDummy.parseNr2rrrrr<Xsr<c@s eZdZdZdd�Zdd�ZdS)�StringParserzParses just a stringcCs|jd|_gS)zDo nothing, just take noter�)r rRr0rrrr#eszStringParser.parseheadercCs|��}|��|S)zParse a single line)rrr7rrrr1jszStringParser.parseN)rrr r!r#r1rrrrr>bsr>c@s eZdZdZdd�Zdd�ZdS)�ContainerOutputz(The generic HTML output for a container.cCst�dt|��dS)zShow an error.zgethtml() not implemented for N�rrr'r4rrr�gethtmluszContainerOutput.gethtmlcCsdS)z5Decide if the output is empty: by default, not empty.Frrrrr�isemptyyszContainerOutput.isemptyN)rrr r!rArBrrrrr?rsr?c@seZdZdd�Zdd�ZdS)�EmptyOutputcCsgS)zReturn empty HTML code.rr4rrrrAszEmptyOutput.gethtmlcCsdS)z"This output is particularly empty.TrrrrrrB�szEmptyOutput.isemptyN)rrr rArBrrrrrC}srCc@seZdZdZdd�ZdS)�FixedOutputzFixed outputcCs|jS)zReturn constant HTML code)�htmlr4rrrrA�szFixedOutput.gethtmlN�rrr r!rArrrrrD�srDc@seZdZdZdd�ZdS)�ContentsOutputz&Outputs the contents converted to HTMLcCs^g}|jdkr|S|jD]@}t|d�sLt�d|jjdt|��|S||��7}q|S)�Return the HTML codeNrAzNo html in rc)rr�rrr	rr'rA)r�rrE�elementrrrrA�s


zContentsOutput.gethtmlNrFrrrrrG�srGc@sVeZdZdZdZdZdZddd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dS)�TaggedOutputz-Outputs an HTML tag surrounding the contents.NFcCs||_|r||_|r||_|S)z/Set the value for the tag and other attributes.)�tag�
breaklines�empty)r�rKrLrMrrr�settag�szTaggedOutput.settagcCs
||_|S)zSet the value for breaklines.)rL)r�rLrrr�
setbreaklines�szTaggedOutput.setbreaklinescCsB|jr|�|�gS|�|�g}|t�||�7}|�|�|��|S)zReturn the HTML code.)rM�selfclosing�openrGrAr��close)r�rrErrrrA�szTaggedOutput.gethtmlcCs.|�|�sdSd|jd}|jr*|dS|S)zGet opening line.r;r@rAr��checktagrKrL)r�rrQrrrrQ�s
zTaggedOutput.opencCs:|�|�sdSd|j��dd}|jr6d|dS|S)zGet closing line.r;z</rrAr)rTrKr�rL)r�rrRrrrrR�s
zTaggedOutput.closecCs.|�|�sdSd|jd}|jr*|dS|S)zGet self-closing line.r;r@z/>rrS)r�rrPrrrrP�s
zTaggedOutput.selfclosingcCs.|jst�dt|��dS|jdkr*dSdS)zCheck that the tag is valid.z
No tag in Fr;T)rKrrr'r4rrrrT�s
zTaggedOutput.checktag)FF)rrr r!rKrLrMrNrOrArQrRrPrTrrrrrJ�s
					rJc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�FilteredOutputz1Returns the output in the contents, but filtered:cCs
g|_dS)zInitialize the filters.N)�filtersrrrrr��szFilteredOutput.__init__cCs|j�||f�dS)z:Add a new filter: replace the original by the replacement.N)rVr�)r�r
�replacementrrr�	addfilter�szFilteredOutput.addfiltercCs.g}t�||�}|D]}|�|�|��q|S)rH)rGrAr��filter)r�rr�rE�linerrrrA�s
zFilteredOutput.gethtmlcCs(|jD]\}}||vr|�||�}q|S)z0Filter a single line with all available filters.)rVr�)r�rZr
rWrrrrY�szFilteredOutput.filterN)rrr r!r�rXrArYrrrrrU�s
rUc@seZdZdZdd�ZdS)�StringOutputzReturns a bare string as outputcCs|jgS)zReturn a bare string��stringr4rrrrA�szStringOutput.gethtmlNrFrrrrr[�sr[c@s�eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd,d%d&�Zd-d(d)�Zd*d+�Zd'S).�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.FcCst�|_dSr�)�
EndingList�
endinglistrrrrr�
szGlobable.__init__cCs(|��rdSt|���dkr$|��dS)z*Check for a Unicode byte mark and skip it.Ni��)�finished�ordr��skipcurrentrrrr�
checkbytemark
szGlobable.checkbytemarkcCst�d�dS)z+Find out if we are out of the position yet.zUnimplemented isout()T�rrrrrr�isouts
zGlobable.isoutcCst�d�dS)zReturn the current character.zUnimplemented current()r;rerrrrr�s
zGlobable.currentcCst�d�dS)z3Check for the given string in the current position.zUnimplemented checkfor()Fre�r�r]rrr�checkfors
zGlobable.checkforcCs(|��r|js|j��dS|j�|�S)z*Find out if the current text has finished.T)rf�leavependingr`�checkpending�checkinrrrrra#s

zGlobable.finishedcCst�d�dS)�)Return the current character and skip it.zUnimplemented skipcurrent()r;rerrrrrc+s
zGlobable.skipcurrentcCs$d}|��s |�r ||��7}q|S)z>Glob a bit of text that satisfies a check on the current char.r;)rarc)r�Zcurrentcheck�globrrrrm0sz
Globable.globcs���fdd��S)zGlob a bit of alpha textcs�����Sr��r��isalpharrrrr9rwz$Globable.globalpha.<locals>.<lambda>�rmrrrr�	globalpha7szGlobable.globalphacs���fdd��S)zGlob a row of digits.cs�����Sr��r��isdigitrrrrr=rwz%Globable.globnumber.<locals>.<lambda>rprrrr�
globnumber;szGlobable.globnumbercCs |����s|��dkrdSdS)z5Return if the current character is alphanumeric or _.r�TF)r��isalnumrrrr�isidentifier?szGlobable.isidentifiercCs|�|j�S)z Glob alphanumeric and _ symbols.)rmrvrrrr�globidentifierEszGlobable.globidentifiercCs$|����rdS|��dvr dSdS)z5Return if the current character is a value character:Fz{}()T�r��isspacerrrr�isvalueIs
zGlobable.isvaluecCs|�|j�S)z'Glob a value: any symbols but brackets.)rmrzrrrr�	globvalueRszGlobable.globvaluecs���fdd��S)z(Skip all whitespace at current position.cs�����Sr�rxrrrrrXrwz$Globable.skipspace.<locals>.<lambda>rprrrr�	skipspaceVszGlobable.skipspacecs&����fdd���}����|S)z4Glob a bit of text up to (including) the magic char.cs����kSr��r�r��	magiccharr�rrr\rwz(Globable.globincluding.<locals>.<lambda>)rm�skip)r�rrmrr~r�
globincludingZs
zGlobable.globincludingcs����fdd��S)z?Glob a bit of text up until (excluding) any excluded character.cs����vSr�r}r��excludedr�rrrbrwz(Globable.globexcluding.<locals>.<lambda>rp)r�r�rr�r�
globexcluding`szGlobable.globexcludingcCs|j�||�dS)zPush a new ending to the bottomN)r`�add�r�r&�optionalrrr�
pushendingdszGlobable.pushendingNcCsN|��r|jr|S|j�|�}|r@||kr@t�d|d|�|�|�|S)z,Pop the ending found at the current positionzExpected ending z, got )rfrir`�poprrr�)r�Zexpectedr&rrr�	popendinghs
zGlobable.popendingcCs|j�|�}|sdS|jS)z$Return the next ending in the queue.N)r`�
findendingr&)r��
nextendingrrrr�rszGlobable.nextending)F)N)rrr r!rir�rdrfr�rhrarcrmrqrtrvrwrzr{r|r�r�r�r�r�rrrrr^s,	


r^c@s`eZdZdZdd�Zddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zej
dkr\eZdS)r_zA list of position endingscCs
g|_dSr�)r�rrrrr�|szEndingList.__init__FcCs|j�t||��dS)zAdd a new ending to the listN)r�r��PositionEndingr�rrrr�szEndingList.addcCs|j|jj7_dS)z/Pick any pending endings from a parse position.N)r�r`�r��posrrr�pickpending�szEndingList.pickpendingcCs|�|�rdSdS)zSearch for an endingTF)r�r�rrrrk�s
zEndingList.checkincCs�|��rt�d�dS|�|�}|s:t�d|���dSt|j�D]6}|j�|�||krf|jS|j	sDt�d|�qDt�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)
rfrrr�r��reversedr�r8r&r�)r�r�r&Zeachrrrr��s



zEndingList.popcCsLt|j�dkrdStt|j��D]&\}}|�|�r:|S|js dSq dS)z'Find the ending at the current positionrN)r�r��	enumerater�rkr�)r�r��indexr&rrrr��s
zEndingList.findendingcCs(t|j�dkr$t�dt|�d�dS)z&Check if there are any pending endingsrzPending z
 left openN)r�r�rrr'rrrrrj�szEndingList.checkpendingcCsBd}|jD]}|t|�d7}q
t|j�dkr:|dd�}|dS)�Printable representationz	endings [r�rNrr\)r�r'r�)r�r]r&rrrr-�s
zEndingList.__unicode__rN)F)rrr r!r�r�r�rkr�r�rjr-r
rr.rrrrr_ys
	
r_c@s6eZdZdZdd�Zdd�Zdd�Zejdkr2eZ	d	S)
r�z An ending for a parsing positioncCs||_||_dSr��r&r�r�rrrr��szPositionEnding.__init__cCs|�|j�S)zCheck for the ending)rhr&r�rrrrk�szPositionEnding.checkincCsd|j}|jr|d7}|S)r�zEnding z (optional)r�rgrrrr-�s
zPositionEnding.__unicode__rN)
rrr r!r�rkr-r
rr.rrrrr��s
r�c@sneZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zej
dkrZeZdd�Zdd�ZdS)�Positionz�A position in a text to parse.
  Including those in Globable, functions to implement by subclasses are:
  skip(), identifier(), extract(), isout() and current().cCst�|�dSr�)r^r�rrrrr��szPosition.__init__cCst�d�dS)z
Skip a stringzUnimplemented skip()Nrergrrrr��sz
Position.skipcCst�d�dS)z.Return an identifier for the current position.zUnimplemented identifier()�Errorrerrrr�
identifier�s
zPosition.identifiercCst�d�dS)zHExtract the next string of the given length, or None if not enough text,zUnimplemented extract()Nre�r��lengthrrrr�s
zPosition.extractcCs||�t|��kS)z)Check for a string at the given position.)rr�rgrrrrh�szPosition.checkforcCs0|�t|��}|sdS|��|�t|����kS)z!Check for a string in lower case.F)rr��lower)r�r]r8rrr�
checkforlower�szPosition.checkforlowercCs|��}|�|�|S)rl)r�r��r�r�rrrrc�s
zPosition.skipcurrentcCs|��|��S)z3Advance the position and return the next character.)rcr�rrrr�__next__�szPosition.__next__rcCs|�|�sdS|�|�dS)z;Check for a string at the given position; if there, skip itFT)rhr�rgrrr�	checkskips

zPosition.checkskipcCst�|d|���dS)z2Show an error message and the position identifier.rcN)rrr�)r�rrrrr	szPosition.errorN)rrr r!r�r�r�rrhr�rcr�r
r�nextr�rrrrrr��s
r�c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�TextPositionz%A parse position based on a raw text.cCs"t�|�d|_||_|��dS)z#Create the position from some text.rN)r�r�r��textrd�r�r�rrrr�s
zTextPosition.__init__cCs|jt|�7_dS)zSkip a string of characters.N)r�r�rgrrrr�szTextPosition.skipcCsFd}|j|t|j�kr(t|j�|j}d|j|j|j|�dS)z&Return a sample of the remaining text.�r��r�r�r�r�rrrr�szTextPosition.identifiercCs|jt|j�kS)z'Find out if we are out of the text yet.r�rrrrrf"szTextPosition.isoutcCs|j|jS)z6Return the current character, assuming we are not out.)r�r�rrrrr�&szTextPosition.currentcCs.|j|t|j�krdS|j|j|j|�S)zHExtract the next string of the given length, or None if not enough text.Nr�r�rrrr*szTextPosition.extractN)
rrr r!r�r�r�rfr�rrrrrr�
sr�c@s�eZdZdZdZdZdZdd�Zdd�Zdd�Z	e
jfd	d
�Zdd�Z
d
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd)dd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zejd(kr�eZdS)*�	Containerz.A container for text and objects in a lyx fileNcCst�|_dSr�)r�rrrrrr�8szContainer.__init__cCsdS)zProcess contentsNrrrrrr;szContainer.processcCs.|j�|�}t|t�r*t�d|�|g}|S)zGet the resulting HTMLzRaw string )rrAr��
basestringrr)r�rErrrrA?s

zContainer.gethtmlcCs2t|���}|D]}||vr|�|||�}q|S)z*Escape a line with replacements from a map)�sorted�keysr�)r�rZZreplacements�pieces�piecerrr�escapeGs
zContainer.escapecCs�d}t|�}|��s�t|���dkrjtt|����}|dkrPttt|��d�}|d|dd�d7}n||��7}|��q|S)	z/Escape all Unicode characters to HTML entities.r;�Z0xd835i�z&#r�Nr�)r�rarbr��hexr�rc)r�rZr�r�Z	codepointrrr�escapeentitiesPs
zContainer.escapeentitiescsg�|�|�fdd���S)z2Search for all embedded containers of a given typecs
��|�Sr�)r��r�r�rrrbrwz%Container.searchall.<locals>.<lambda>)�
searchprocess�r�r
rr�r�	searchall_szContainer.searchallcCs&|�|�}|D]}|jj�|�q|S)z3Search for all containers of a type and remove them)r�r*rr8)r�r
r�rrrr�searchremovees
zContainer.searchremovecs|��fdd�|�dS)z4Search for elements of a given type and process themcs
t|��Sr�)r�r��r
rrrnrwz)Container.searchprocess.<locals>.<lambda>N)�
locateprocess)r�r
rrr�rr�lszContainer.searchprocesscCs,|jD] }|�||�||�r||�qdS)z3Search for all embedded containers and process themN)rr�)r�rrrrrrr�ps
zContainer.locateprocesscCs6|jD]*}||�r |�|||�||�r||�qdS)z,Perform a recursive search in the container.N)rr)r�rrrrrrrrws

zContainer.recursivesearchcCs(d}ttj��|�}d�dd�|D��S)z)Extract all text from allowed containers.r;css|]}|jVqdSr�r\)rs�constantrrrrv�rwz(Container.extracttext.<locals>.<genexpr>)rr#r9r�join)r�r�Z	constantsrrrr9szContainer.extracttextcCs�|t|j�krdSt|j|d�r&dS|t|j�krn||j|�rnd|j|_|j�|j|�|j�|�q&|j�||�dS)z*Group some adjoining elements into a groupN�groupedT)r�rr�r�r�r�r�)r�r��groupZ	isingrouprrrr��szContainer.groupcCs>|j|}|j�|�t|j�dkr:|j�||j���qdS)z)Remove a container but leave its contentsrN)rr�r�r�)r�r�rrrrr8�s
zContainer.removercCs4t�d|t|��|jD]}|�|d�qdS)zShow in a treez  r�N)rrr'r�tree)r��levelrrrrr��s
zContainer.treecCs||jvrdS|j|S)z)Get the value of a parameter, if present.N)r�r�rrrr�getparameter�s
zContainer.getparametercCs|�|�}|sgS|�d�S)z7Get the value of a comma-separated parameter as a list.r�)r�r�)r�rZ	paramtextrrr�getparameterlist�s
zContainer.getparameterlistcCs$|j}|r |j��rdS|j}qdS)z&Check if the parent's output is empty.TF)r*rrBr�rrr�hasemptyoutput�s
zContainer.hasemptyoutputcCs$|js|jjS|jjdt|j�S)zGet a descriptionr�)rRr	rr'rrrrr-�szContainer.__unicode__r)r)rrr r!�partkeyr*rRr�rrAr:rCr�r�r�r�r�r�rr9r�r8r�r�r�r�r-r
rr.rrrrr�1s0	
	
r�c@seZdZdZdd�ZdS)�BlackBoxz)A container that does not output anythingcCst�|_t�|_g|_dSr�)r/r�rCrrrrrrr��szBlackBox.__init__N)rrr r!r�rrrrr��sr�c@sReZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
ejdkrNe
Z
dS)�StringContainerzA container for a single stringNcCst�|_t�|_d|_dS)Nr;)r>r�r[rr]rrrrr��szStringContainer.__init__cCs|jr|�|j�|_d|_dS)z(Replace special chars from the contents.N)�parsed�replacespecialr]rrrrr�szStringContainer.processcCsf|�|tj�}|�|�}tjd|vrbt|�dkrb|jrLdt|j�d}nd}t	�
||���|S)z%Replace all special chars from a lineZstartcommandr�zUnknown command at rczUnknown command: )r�r:rC�
changeliner#r]r�rRr'rrr$)r�rZZreplacedrrrrr��s
zStringContainer.replacespecialcCs|�|tj�}|Sr�)r�r:rB)r�rZrrrr��szStringContainer.changelinecCs|jS)zReturn all text.r\rrrrr9�szStringContainer.extracttextcCsXd}|jr|dt|j�7}d}t|j���dkr6d}|d|j��dd�|dS)	�"Return a printable representation.r�r�z...�r;r,NrZ)rRr'r�r]r$)r�r�Zellipsisrrrr-�szStringContainer.__unicode__r)rrr r!r�r�rr�r�r9r-r
rr.rrrrr��s


r�c@s.eZdZdZdd�Zdd�Zejdkr*eZdS)�ConstantzA constant stringcCsg|_||_t�|_dSr�)rr]r[rr�rrrr��szConstant.__init__cCs
d|jS)Nz
Constant: r\rrrrr-szConstant.__unicode__rN)	rrr r!r�r-r
rr.rrrrr��s

r�c@seZdZdZdZdS)�DocumentParametersz#Global parameters for the document.FN)rrr r!�displaymoderrrrr�sr�c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�
FormulaParserzParses a formulacCsR|jd|_|�|�}|sL|��|�|�}|sLt�d|�����dgS|gS)zSee if the formula is inlinedr�zUnknown formula type in �unknown)r rR�	parsetyperrrrr$)r�r!r
rrrr#s

zFormulaParser.parseheadercCst|���tjd�dkrdS|���tjd�dkr8dS|���tjd�dkrTdS|���tjd�dkrpdSd	S)
z)Get the formula type from the first line.r�r�inlinerz�blockr�r�ZnumberedN)r�findrDr�r0rrrr�szFormulaParser.parsetypecCsV|�|�}|���|j�sJ|����}t|�dkr@t�d|�|��q
|��|S)zParse the formula until the endrzUnparsed formula line )	�parseformularr�r&r$r�rrr)r�r!�formula�strippedrrrr1)s

zFormulaParser.parsecCs�tjd}||��vrN|���|d�d}||vr@|�|||�S|�|||�Stjd|��vrz|�|tjdtjd�Stjd}tjd}||��v�r8|�����|��r|����}|�|�d�|�}||d|}tjd}	tjd}
|	|d|
}||�|||�|St	�
d	|d
|���dStjd}tjd
}
||��v�r�|
|��v�r�tjd
}|�||
|�St	�
d|��d�dS)zParse the formula contentsr�r�rzr�r�rr|r{zMissing z in r;r�ryzFormula beginning z is unknown)rDr�rr��parsesingleliner�parsemultilinerr�r$r�rr)r�r!r��restr�r�r�ZendsplitZ
startpiecer|r{ZendpieceZbegincommandZbeginbracketZ
endbracketrrrr�4s<
�






zFormulaParser.parseformulacCs�|����}||vr.t�d|d|�dS|�|�sRt�d|d|�dS|�|�}||t|�t|��}|��|S)zParse a formula in one line�Line �  does not contain formula start r;zFormula z does not end with )rr$rrr�r�r�r)r�r!�startr&rZr�r�rrrr�Ws

zFormulaParser.parsesinglelinercCs�d}|��}||vr2t�d|��d|�dS|�|�}||t|�d���}|�|�s|||d7}|��|��}qT||dt|��7}|��|S)z!Parse a formula in multiple linesr;r�r�Nr)rrrr$r�r�r�r)r�r!r�r&r�rZr�rrrr�es


zFormulaParser.parsemultilinerN)
rrr r!r#r�r1r�r�r�rrrrr�s#r�c@sbeZdZdZdZdZdZdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
ejdkr^e
ZdS)�
FormulaBitzA bit of a formulaNr�r;cCsg|_t�|_dS)z6The formula bit type can be 'alpha', 'number', 'font'.N)rrGrrrrrr�~szFormulaBit.__init__cCs
||_|S)z!Set the internal formula factory.)r))r�r)rrr�
setfactory�szFormulaBit.setfactorycCs&|j�|�|j|j7_||_dS)z-Add any kind of formula bit already processedN)rr�r
r*�r��bitrrrr��szFormulaBit.addcCs6|j|7_|�|�s2t�d|d|���dS)z0Skip a string and add it to the original formulazString z not at N)r
r�rrr�)r�r]r�rrr�skiporiginal�s
zFormulaBit.skiporiginalcCs.t|j�dkrdStdd�|jD��|_|jS)zDCompute the size of the bit as the max of the sizes of all contents.rr�cSsg|]
}|j�qSr��size�rsrIrrr�
<listcomp>�rwz*FormulaBit.computesize.<locals>.<listcomp>)r�rr�r�rrrr�computesize�szFormulaBit.computesizecCs|j�|j�S�zReturn a copy of itself.)r)r�r
rrrrr�szFormulaBit.clonecCs|jjd|jS)zGet a string representationz	 read in )r	rr
rrrrr-�szFormulaBit.__unicode__r)rrr r!r
r�r
r�r�r�r�r�rr-r
rr.rrrrr�ws
r�c@s*eZdZdZdd�Zd
dd�Zdd�Zd	S)�	TaggedBitzA tagged string in a formulacCs t��|�|_|�t|��|S�zSet the constant and the tag)rJrNrr�r%)r�r�rKrrrr��szTaggedBit.constantFcCs||_t��||�|_|Sr�)rrJrNr)r�rrKrLrrr�complete�szTaggedBit.completecCst�j|dd�|_|S)z4Set the self-closing tag, no contents (as in <hr/>).T)rM)rJrNr)r�rKrrr�selfcomplete�szTaggedBit.selfcompleteN)F)rrr r!r�r�r�rrrrr��s
r�c@s>eZdZdZdd�Zdd�Zdd�Zdd	�Zej	d
kr:eZ
dS)r%zA constant string in a formulacCs"t�||�||_d|_d|_dS)zSet the constant stringr�N)r�r�r
r�r
rgrrrr��szFormulaConstant.__init__cCs|jS)z+Compute the size of the constant: always 1.r�rrrrr��szFormulaConstant.computesizecCs
t|j�Sr�)r%r
rrrrr�szFormulaConstant.clonecCs
d|jS)r�zFormula constant: r\rrrrr-�szFormulaConstant.__unicode__rN)rrr r!r�r�rr-r
rr.rrrrr%�s
r%c@s eZdZdZdd�Zdd�ZdS)r1zA bit of text inside a formulacCs|����S)zDetect a bit of raw textrnr�rrr�detect�szRawText.detectcCs |��}|�t|��d|_dS)zParse alphabetic text�alphaN)rqr�r%r
)r�r�r�rrr�parsebit�szRawText.parsebitN�rrr r!r�r�rrrrr1�sr1c@s8eZdZdZejZejdZdd�Zdd�Zdd�Z	d	S)
r.zA symbol inside a formular�cCs(|��tjvrdS|��tjvr$dSdS)zDetect a symbolTF)r�r.r�r�r�rrrr��s
zFormulaSymbol.detectcCsd|��tjvr"|�|��|�dS|��tjvrJ|�tj|��|�dSt�d|��d�dS)�Parse the symbolNzSymbol z
 not found)r�r.r��	addsymbolr�rrr�rrrr��szFormulaSymbol.parsebitcCs$|�|��|�|j�t|��dS)zAdd a symbolN)r�r�rr�r%)r��symbolr�rrrr��szFormulaSymbol.addsymbolN)
rrr r!rDr�r�r�r�r�rrrrr.�s

r.c@s eZdZdZdd�Zdd�ZdS)r-zA string of digits in a formulacCs|����S)zDetect a digitrrr�rrrr�szFormulaNumber.detectcs*���fdd��}|�t|��d|_dS)zParse a bunch of digitscs�����Sr�rrr�r�rrrrwz(FormulaNumber.parsebit.<locals>.<lambda>�numberN)rmr�r%r
)r�r��digitsrr�rr�szFormulaNumber.parsebitNr�rrrrr-�sr-c@s*eZdZdZejdZdd�Zdd�ZdS)�Commentz*A LaTeX comment: % to the end of the line.r�cCs|��|jkS)z
Detect the %.)r�r�r�rrrr�szComment.detectcCs|j|�d�7_dS)zParse to the end of the line.rN)r
r�r�rrrr�szComment.parsebitN)	rrr r!rDr�r�r�r�rrrrr�s
r�c@s6eZdZdZdd�Zdd�Zdd�Zejdkr2eZ	d	S)
�
WhiteSpacez"Some white space inside a formula.cCs|����S)zDetect the white space.rxr�rrrr�szWhiteSpace.detectcCs|j|��7_dS)zParse all whitespace.N)r
r|r�rrrr� szWhiteSpace.parsebitcCsd|jdS)r�z
Whitespace: *r�)r
rrrrr-$szWhiteSpace.__unicode__rN)
rrr r!r�r�r-r
rr.rrrrr�s
r�c@sleZdZdZejdZejdZdd�Z	dd�Z
dd�Zd	d
�Zdd�Z
d
d�Zdd�Zdd�Zdd�ZdS)r'zA {} bracket inside a formularycCst�|�d|_dS)z'Create a (possibly literal) new bracketN)r�r��innerrrrrr�2s
zBracket.__init__cCs|�|j�S)zDetect the start of a bracket)rhr�r�rrrr�7szBracket.detectcCs|�||j�|S)zParse the bracket)�
parsecomplete�innerformular�rrrr�;szBracket.parsebitcCs|�||j�|S)zParse a text bracket)r��	innertextr�rrr�	parsetext@szBracket.parsetextcCs|�||j�|S)zParse a literal bracket)r��innerliteralr�rrr�parseliteralEszBracket.parseliteralcCsp|�|j�s,t�d|jd|���dS|�|j|�|�|j�||�|j|�	|j�7_|�
�dS)zParse the start and end markszBracket should start with z at N)rhr�rrr�r�r�r&r
r�r�)r�r�Zinnerparserrrrr�JszBracket.parsecompletecCs |��s|�|j�|��qdS)z(Parse a whole formula inside the bracketN�rar�r)�parseanyr�rrrr�UszBracket.innerformulacCs�ttj���}|�tjd�|�tjd�|�tj�|��s�|�	�|vrz|�
|j�|��|�
d�r�|jd7_q:|�
t|����q:dS)z<Parse some text inside the bracket, following textual rules.r�ryrbN)r�rDr�r�r�r�r�r�rar�r�r)r�r�r
r%rc)r�r�Zspecialcharsrrrr�Zs
zBracket.innertextcCs^d|_|��sJ|��|jksJ|��|jkr6|�|�q|j|��7_q|j|j7_dS)zAParse a literal inside the bracket, which does not generate HTML.r;N)�literalrar�r&r�r�rcr
r�rrrr�hszBracket.innerliteralN)rrr r!rDr�r�r�r&r�r�r�r�r�r�r�r�r�rrrrr',s

r'c@s,eZdZdZejdZejdZdd�Z	dS)�
SquareBracketzA [] bracket inside a formular}cCst�}|j|_|S)z3Return a new square bracket with the same contents.)rr)r�ryrrrrxszSquareBracket.cloneN)
rrr r!rDr�r�r�r&rrrrrrrs

rc@s.eZdZdZdd�Zdd�Zejdkr*eZdS)�MathsProcessorzAA processor for a maths construction inside the FormulaProcessor.cCst�dt|��dS)z$Process an element inside a formula.zUnimplemented process() in Nr@�r�rr�rrrr�szMathsProcessor.processcCsd|jjS)zReturn a printable description.zMaths processor )r	rrrrrr-�szMathsProcessor.__unicode__rN)	rrr r!rr-r
rr.rrrrrs

rc@sDeZdZdZgZdd�Zdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dS)�FormulaProcessorz&A processor specifically for formulas.cCs"|�|�|�|�|�|�dS)z7Process the contents of every formula bit, recursively.N)�processcontents�processinsides�
traversewholer�rrrr�s

zFormulaProcessor.processcCs0t|t�sdS|��|jD]}|�|�qdS)z&Process the contents of a formula bit.N)r�r�rrr)r�r�rIrrrr�s


z FormulaProcessor.processcontentscCsJt|t�sdSt|j�D],\}}|jD]}|�|j|�q&|�|�qdS)z8Process the insides (limits, brackets) in a formula bit.N)r�r�r�r�
processorsrr)r�r�r�rIZ	processorrrrr�s

zFormulaProcessor.processinsidescCsbd}|�|�D]N\}}|jdkr.|�||�n*|jdkrX|rX|jdkrX|j�dtd��|}qdS)z>Traverse over the contents to alter variables and space units.Nr��fontr�r� )�traverser
�	italicizerr�r%)r�r�Zlastr�rrrrr�s
zFormulaProcessor.traversewholeccsN|jD]B}t|d�r(|jr(||jfVqt|t�r|�|�D]
}|Vq<qdS)zHTraverse a formula and yield a flattened structure of (bit, list) pairs.r
N)rr�r
r�r�r)r�r�rIZpairrrrr�s

zFormulaProcessor.traversecCs"|�|�}t��|gd�||<dS)z Italicize the given bit of text.r�N)r�r�r�)r�r�rr�rrrr�s
zFormulaProcessor.italicizeN)rrr r!rrrrrrrrrrrr�s

	rc@sveZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZejdkrreZdS)r,zA LaTeX formulacCst�|_t��d�|_dS)Nzspan class="formula")r�r�rJrNrrrrrr��szFormula.__init__cCs6|jddkrdt_ndt_|j�dd�|��dS)zConvert the formula to tagsrr�FTzdiv class="formula"N)r"r�r�rrN�classicrrrrr�s
zFormula.processcCs,t��|j�}t��|�||_|g|_dS)zEMake the contents using classic output generation with XHTML and CSS.N)�FormulaFactoryr�r�rrr*r)r��wholerrrr
�szFormula.classiccCsr|�d�r|�|�nP|�d�r,|�|�n:|�d�rD|�|d�n"|�d�r\|�|d�n
|�d�|��|S)z4Parse using a parse position instead of self.parser.z$$r�z\(z\)r�rxzUnparseable formula)r��parsedollarblock�parsedollarinline�
parseinlineto�parseblocktorrr�rrrr1�s




z
Formula.parsecCsdg|_|�|�dS)zParse a $...$ formula.r�N)r"�parsedollarr�rrrr�szFormula.parsedollarinlinecCs*dg|_|�|�|�d�s&|�d�dS)zParse a $$...$$ formula.r�r�z1Formula should be $$...$$, but last $ is missing.N)r"rr�rr�rrrr�s

zFormula.parsedollarblockcCs$|�d�|�d�|_|�d�dS)zParse to the next $.r�N)r�r�r�r�r�rrrr�s
zFormula.parsedollarcCsdg|_|�||�dS)zParse a \(...\) formula.r�N�r"�	parseupto�r�r��limitrrrr�szFormula.parseinlinetocCsdg|_|�||�dS)zParse a \[...\] formula.r�NrrrrrrszFormula.parseblocktocCs(|�|�|�dd��|_|�|�dS)z1Parse a formula that ends with the given command.cSsdS)NTrrrrrr	rwz#Formula.parseupto.<locals>.<lambda>N)r�rmr�r�rrrrrs
zFormula.parseuptocCs"|jr|jjrd|jjdSdS)r�z	Formula (rZzUnnumbered formula)r�r�rrrrr-szFormula.__unicode__rN)rrr r!r�rr
r1rrrrrrr-r
rr.rrrrr,�s	
r,c@s eZdZdZdd�Zdd�ZdS)�WholeFormulazParse a whole formulacCs
|��S)z"Not outside the formula is enough.)rar�rrrr�szWholeFormula.detectcCs |��s|�|j�|��qdS)zParse with any formula bitNr�r�rrrr�szWholeFormula.parsebitNr�rrrrrsrc@steZdZdZeeeeee	gZ
ee	gZdZdd�Z
dd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Zdd�Zdd�ZdS)rzConstruct bits of formulaFcCst�|_dS)z Initialize the map of instances.N)r�	instancesrrrrr�*szFormulaFactory.__init__cCs|��rdS|�|��|�S)zDetect a bit of a given type.F)ra�instancer�)r�r
r�rrr�
detecttype.szFormulaFactory.detecttypecCs.||jvs|j|s$|�|�|j|<|j|S)z"Get an instance of the given type.)rrr�rrrr4szFormulaFactory.instancecCst�|��|�S)z+Create a new formula bit of the given type.)rrr�r�rrrr:szFormulaFactory.createcCs|��s|�|�sdSqdS)zClear any skipped types.N)ra�skipanyr�rrr�clearskipped>s
zFormulaFactory.clearskippedcCs0|jD]$}|�|��|�r|�||�SqdS)zSkip any skipped types.N)�skippedtypesrr�r��r�r�r
rrrrEs
zFormulaFactory.skipanycCsL|j|jD] }|�||�r|�||�Sqt�d|���t|���S)z.Parse any formula bit at the current location.zUnrecognized formula at )	�typesrrr�rrr�r%rcr rrrr�Ls
zFormulaFactory.parseanycCs0|�|�}d|j|<|�|�}|r,|�|�S|S)z#Parse the given type and return it.N)rrr�r�)r�r
r�r�Zreturnedbitrrrr�Ts



zFormulaFactory.parsetypecCs\t|�}|�t�}|�|�r*|�|�|S|��sXt�d|���|�	t
��|d��|S)z5Parse a string of text that contains a whole formula.zUnknown formula at: �span class="unknown")r�rrr�r�rarrr�r�r�r�)r�r�r�rrrrr�]s


zFormulaFactory.parseformulaN)rrr r!r.r1r-r'r�r�r!r�definingr�rrrrrr�r�r�rrrrr"s	rc@sZeZdZdZgZejdZdZdd�Z	dd�Z
dd	�Zd
d�Zdd
�Z
dd�Zdd�ZdS)�FormulaCommandz A LaTeX command inside a formular�NcCs|�tj�S)zFind the current command.)rhr$r�r�rrrr�rszFormulaCommand.detectcCs||�|�}|�||�}|r|S|�d�s2|�d�rF|�||�}|rF|S|jjs\t�d|�t��	d�|_
|�t|��dS)zParse the command.�\up�\UpzUnknown command r"N)
�extractcommand�parsewithcommandr��parseupgreekr)r#rrrJrNrr�r%)r�r�r�r��upgreekrrrr�vs
zFormulaCommand.parsebitcCs,tjD] }||jvr|�|||�SqdS)z0Parse the command type once we have the command.N)r$r!�
commandmap�parsecommandtype)r�r�r�r
rrrr(�s

zFormulaCommand.parsewithcommandcCs,|j�|�}|�|�|�|�}|r(|S|S)zParse a given command type.)r)r�
setcommandr�)r�r�r
r�r�Zreturnedrrrr,�s

zFormulaCommand.parsecommandtypecCsh|�tj�s |�dtj�dS|��r2|�|�S|����rZtj|��}|�d�|Stj|�	�S)z.Extract the command from the current position.zMissing command start Nr�)
r�r$r�rra�emptycommandr�rorqrc)r�r�r�rrrr'�s

zFormulaCommand.extractcommandcCs0d}|��s&|��}|r&|�|�r&|}tj|S)zqCheck for an empty command: look for command disguised as ending.
    Special case against '{ \{ \} }' situation.r;)rfr�r�r$r�)r�r�r�r&rrrr.�szFormulaCommand.emptycommandcCs�t|�dkrdS|�d�r,d|dd�}n>|�d�rXd|dd���|dd�}nt�d|�dS|�||�}|r�d|_|S)	zParse the Greek \up command..�Nr%rPrr&zImpossible upgreek command: r	)r�r�r��upperrrr(r
)r�r�r�Z	upcommandr*rrrr)�s

"zFormulaCommand.parseupgreek)rrr r!r!rDr�r�r+r�r�r(r,r'r.r)rrrrr$ks
	
r$c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�
CommandBitz%A formula bit that includes a commandcCs,||_|jr(|j|7_|j|j|_dS)zSet the command in the bitN)r�r+r
�
translated)r�r�rrrr-�szCommandBit.setcommandcCs2|j�|�|��rdS|j�|�}|�|�|S)z)Parse a parameter at the current positionN)r)rrar�r�)r�r��	parameterrrrr%�s
zCommandBit.parseparametercCs:|j�|�|j�t|�sdS|j�t|�}|�|�|S)zParse a square bracketN)r)rrrr�r��r�r�ryrrr�parsesquare�s
zCommandBit.parsesquarecCsd|j�|�|j�t|�s@|��s8t�d|���dS|��St��	|j�}|�
|�|��|jS)zParse a literal bracket.zNo literal parameter found at: N)
r)rrr'rzrrr�r{r�r�r�rr4rrrr��szCommandBit.parseliteralcCsB|j�|�|j�t|�sdSt��|j�}|�|�|��|jS)z!Parse a square bracket literally.N)r)rrrr�r�r�rr4rrr�parsesquareliteral�szCommandBit.parsesquareliteralcCsP|j�|�|j�t|�s.t�d|j�dSt��|j��|�}|�	|�|S)zParse a text parameter.zNo text parameter for N)
r)rrr'rrr�r�r�r�r4rrrr��s
zCommandBit.parsetextN)
rrr r!r-r%r5r�r6r�rrrrr1�s			r1c@seZdZdZejZdd�ZdS)r*z%An empty command (without parameters)cCst|j�g|_dS)z"Parse a command without parametersN�r%r2rr�rrrr�	szEmptyCommand.parsebitN)rrr r!rDr�r+r�rrrrr*�sr*c@seZdZdZejZdd�ZdS)r2z<An empty command which should have math spacing in formulas.cCstd|jd�g|_dS)z4Place as contents the command translated and spaced.r
Nr7r�rrrr�		szSpacedCommand.parsebitN)rrr r!rDr�r+r�rrrrr2	sr2c@s"eZdZdZejZdZdd�ZdS)r&z:A command without parameters whose result is alphabetical.)z\Xiz\Thetaz\Piz\Sigmaz\Gammaz\Lambdaz\Phiz\Psiz\Deltaz\Upsilonz\OmegacCs"t�||�|j|jvrd|_dS)z'Parse the command and set type to alphar�N)r*r�r��greek_capitalsr
r�rrrr�	szAlphaCommand.parsebitN)	rrr r!rDr�r+r8r�rrrrr&	sr&c@s*eZdZdZejZdZdd�Zdd�Z	dS)r/zA function of one parameterFcCs&t��|j�|_|�|�|��dS)z#Parse a function with one parameterN)rJrNr2rr%�simplifyifpossibler�rrrr�&	s
zOneParamFunction.parsebitcCs.|j|jvr*t�|_|j|jg|_d|_dS)z&Try to simplify to a single character.TN)r
r+rDrrE�
simplifiedrrrrr9,	sz#OneParamFunction.simplifyifpossibleN)
rrr r!rDr�r+r:r�r9rrrrr/ 	s
r/c@s&eZdZdZejZdd�Zdd�ZdS)r3z>Find a function which is represented by a symbol (like _ or ^)cCs|��tjvS)zFind the symbol)r�r3r+r�rrrr�8	szSymbolFunction.detectcCs8|�|���|�|j�t��|j�|_|�|�dS)r�N)	r-r�r�r�rJrNr2rr%r�rrrr�<	szSymbolFunction.parsebitN)	rrr r!rDr�r+r�r�rrrrr33	sr3c@s&eZdZdZejZdd�Zdd�ZdS)r4z-A function where parameters are read as text.cCst��|j�|_|�|�dS)zParse a text parameterN)rJrNr2rr�r�rrrr�H	szTextFunction.parsebitcCs
d|_dS)zSet the type to fontr	Nr�rrrrrM	szTextFunction.processN)	rrr r!rDr�r+r�rrrrrr4C	sr4c@s&eZdZdZejZdd�Zdd�ZdS)�
LabelFunctionzA function that acts as a labelcCs|�|�|_dS)zParse a literal parameterN)r�rtr�rrrr�V	szLabelFunction.parsebitcCs8d|_t�jd|jdd�|_|jg|_|jtj|j<dS)z&Add an anchor with the label contents.r	rbZeqnumberr�N)r
ZLabelrrtZlabelr�namesrrrrrZ	s
zLabelFunction.processN)	rrr r!rDr�r+r�rrrrrr;Q	sr;c@seZdZdZejZdd�ZdS)r+z2A function of one parameter that changes the font.cCsd|_|��dS)z.Simplify if possible using a single character.r	N)r
r9rrrrrh	szFontFunction.processN)rrr r!rDr�r+rrrrrr+b	sr+c@sReZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�
BigBracketzA big bracket generator.rcCs2||_||_||_d|_|tjvr.tj||_dS)z(Set the size and symbol for the bracket.N)r�r
�	alignmentr�rDr�)r�r�ryr>rrrr�v	s
zBigBracket.__init__cCs t|dtt|j���}||�S)z%Return the nth piece for the bracket.�getpiece)r�r'r�r�)r�r��functionrrrr?	szBigBracket.getpiececCs
|jdS)z1Return the only piece for a single-piece bracket.r)r��r�r�rrr�	getpiece1�	szBigBracket.getpiece1cCs4|dkr|jdS||jdkr*|jdS|jdS)zGGet the nth piece for a 3-piece bracket: parenthesis or square bracket.rr�r�r�r�rArrr�	getpiece3�	s


zBigBracket.getpiece3cCsP|dkr|jdS||jdkr*|jdS||jddkrF|jdS|jdS)z7Get the nth piece for a 4-piece bracket: curly bracket.rr�rr�rCrArrr�	getpiece4�	s


zBigBracket.getpiece4cCs&|�|�}d|jd}t��||�S)z'Get the bracket piece as an array cell.zspan class="bracket align-r�)r?r>r�r�)r�r�r��spanrrr�getcell�	s
zBigBracket.getcellcCs\|jdks|js|��Sg}t|j�D]$}|�|�}|�t��|gd��q&t��|d�gS)z3Get the bracket as an array or as a single bracket.r��span class="arrayrow"�span class="array")r�r��getsinglebracket�rangerGr�r�r�)r��rowsr��cellrrr�getcontents�	s
zBigBracket.getcontentscCs,|jdkrt��dd�gSt��|jd�gS)z$Return the bracket as a single sign.r�r;zspan class="emptydot"r_)r
r�r�rrrrrJ�	s
zBigBracket.getsinglebracketN)r)rrr r!r�r?rBrDrErGrNrJrrrrr=s	s
	

r=c@seZdZdZdZdd�ZdS)�FormulaEquationzA simple numbered equation.ZequationcCs t�|_|�|j�t|��dS)�Parse the arrayN)rGrr�r)r�rr�rrrr��	szFormulaEquation.parsebitN�rrr r!r�r�rrrrrO�	srOc@s eZdZdZdd�Zdd�ZdS)�FormulaCellzAn array cell inside a rowcCs"||_t��d|dd�|_|S)Nzspan class="arraycell align-r�T)r>rJrNr)r�r>rrr�setalignment�	szFormulaCell.setalignmentcCs0|j�|�|��rdS|�|j�t|��dSr�)r)rrar�r�rr�rrrr��	szFormulaCell.parsebitN)rrr r!rSr�rrrrrR�	srRc@s2eZdZdZejdZdd�Zdd�Zdd�Z	d	S)
�
FormulaRowzAn array row inside an arrayrScCs||_t��dd�|_|S)NrHT)�
alignmentsrJrNr)r�rUrrr�
setalignments�	szFormulaRow.setalignmentscCsjd}|j|jdd�|��sP|�|�}|�|�|�|�|d7}|�|j�qt|j�dkrft	�|_
dS)zParse a whole rowrT)r�r�N)r�rSra�
createcellr�r�r�r�rrCr)r�r�r�rMrrrr��	s


zFormulaRow.parsebitcCs&|j|t|j�}|j�t��|�S)z4Create the cell that corresponds to the given index.)rUr�r)rrRrS)r�r�r>rrrrW�	szFormulaRow.createcellN)
rrr r!rDr�rSrVr�rWrrrrrT�	s


rTc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�MultiRowFormulazA formula with multiple rows.cCsPg|_d}|�|�D]*}|r"d}n|��|�|�|�|�qt|j�|_dS)z,Parse all rows, finish when no more row endsTFN)rL�iteraterows�addemptyr��addrowr�r�)r�r��first�rowrrr�	parserows�	s
zMultiRowFormula.parserowsccsZtjd}|�|d�|j�t�}|�|j�V|�|�rP|j	|�
|�7_	q
dSq
dS)z0Iterate over all rows, end when no more row endsrUTN)rDr�r�r)rrTrVrUrhr
r�)r�r�rUr]rrrrY�	s

zMultiRowFormula.iteraterowscCs^|j�t��|j�}t|jdj�D]*\}}|�|�}|�	t
d��|�	|�q$|�|�dS)zAdd an empty row.ru N)r)rrTrVrUr�rLrrWr�r%r[)r�r]r�ZoriginalcellrMrrrrZ
s
zMultiRowFormula.addemptycCs|j�|�|�|�dS)z2Add a row to the contents and to the list of rows.N)rLr�r�)r�r]rrrr[
szMultiRowFormula.addrowN)rrr r!r^rYrZr[rrrrrX�	s
	rXc@s$eZdZdZdZdd�Zdd�ZdS)�FormulaArrayzAn array within a formular�cCs(t��dd�|_|�|�|�|�dS)rPrIFN)rJrNr�parsealignmentsr^r�rrrr�
s
zFormulaArray.parsebitcCsDd|_|�|�}|r||_|�|�}g|_|D]}|j�|�q.dS)zParse the different alignmentsr�N)�valignr6r�rUr�)r�r�rrrrrr`
s

zFormulaArray.parsealignmentsN)rrr r!r�r�r`rrrrr_
sr_c@seZdZdZdZdd�ZdS)�
FormulaMatrixz'A matrix (array with center alignment).ZmatrixcCs,t��dd�|_d|_dg|_|�|�dS)z(Parse the matrix, set alignments to 'c'.rIFr�N)rJrNrrarUr^r�rrrr�-
szFormulaMatrix.parsebitNrQrrrrrb(
srbc@seZdZdZdZdd�ZdS)�FormulaCaseszA cases statementZcasescCs�t�|_ddg|_|�|�|jD].}|jD]"}|j�dd�|j�td��q,q"t��	|jdd�}t
t|j�dd�}|��|g|_dS)zParse the casesrzspan class="case align-l"Tu zspan class="bracketcases"r]N)
rGrrUr^rrNr�r%r�r�r=r�rN)r�r�r]rMr��bracerrrr�9
s



zFormulaCases.parsebitNrQrrrrrc4
srcc@seZdZdZdd�ZdS)�EquationEnvironmentz;A \begin{}...\end equation environment with rows and cells.cCs�|j�dd�}t��d|d�|_|tjvr:tj||_n8t�	d|j�t��d�|_|�
td|��dg|_|�|�d	S)
zParse the whole environment.r�r;zspan class="environment %s"FzUnknown equation environment r"z\begin{%s} rN)
r�r�rJrNrrDr�rUrrr�r%r^)r�r�Zenvironmentrrrr�I
s�
zEquationEnvironment.parsebitN)rrr r!r�rrrrreF
srec@s:eZdZdZejddiZeee	e
gZdd�Zdd�Z
dS)	�BeginCommandzEA \begin{}...\end command and what it entails (array, cases, aligned)rRr;cCsh|�|�}|�|�}tjdd|d}|�|�|�|�|�|�|j|�|�7_|j	|_	dS)zParse the begin commandrTr]r^N)
r��findbitrDr�r�r�r�r
r�r�)r�r�r�r�r&rrrr�`
s




zBeginCommand.parsebitcCsDtjD]&}|�dd�|jkr|j�|�Sq|j�t�}||_|S)z7Find the command bit corresponding to the \begin{piece}r�r;)rfr!r�r�r)rre)r�r�r
r�rrrrgk
s
zBeginCommand.findbitN)rrr r!rDr�r+rOr_rcrbr!r�rgrrrrrfY
s
rfc@s"eZdZejZdd�Zdd�ZdS)r)cCs�|j}|�|�}|s(t�d|j�dSt|t�stzttj	�}|�
|�d}Wn$tyrt�d|j�YdS0|j�
d�r�d}nd}|jd|�||j|d�|_t�d|j�|_dS)	zParse a combining function.z)Missing parameter for combining function Nrz!No base character found for "%s".r
r�r�ZNFC)r2�parsesingleparameterrrr�r�r%rr#r9r�
IndexErrorr]r��unicodedata�	normalize)r�r�Z	combiningr3Z	extractorr�rrrr�{
s"


"zCombiningFunction.parsebitcCs"|j�|�|��rdS|�|�S)z&Parse a parameter, or a single letter.N)r)rrar%r�rrrrh�
sz&CombiningFunction.parsesingleparameterN)rrr rDr�r+r�rhrrrrr)w
sr)c@seZdZdZejZdd�ZdS)r0z;A function that decorates some bit of text with an overset.cCs\|j}t��|d�|_|�|�|_t��d�|_|j	�
d|j�t��d�|j_|��dS)zParse an overset-functionr��span class="embellished"r�span class="base"N�r2r�r�r�r%r3rJrNrrr�r9�r�r�r�rrrr��
szOversetFunction.parsebitN)rrr r!rDr�r+r�rrrrr0�
sr0c@seZdZdZejZdd�ZdS)r5z<A function that decorates some bit of text with an underset.cCs\|j}t��|d�|_|�|�|_t��d�|_|j	�
d|j�t��d�|j_|��dS)zParse an underset-functionr�rlrrmNrnrorrrr��
szUndersetFunction.parsebitN)rrr r!rDr�r+r�rrrrr5�
sr5c@seZdZdZejZdd�ZdS)�LimitCommandz@A command which accepts limits above and below, in display mode.cCs.t��d�|_|j}|j�t��|d��dS)zParse a limit command.�span class="limits"zspan class="limit"N)rJrNrr2rr�r�r�rorrrr��
szLimitCommand.parsebitN)rrr r!rDr�r+r�rrrrrp�
srpc@s2eZdZdZdZdd�Zdd�Zejdkr.eZ	dS)�LimitPreviousCommandz(A command to limit the previous command.NcCst��d�|_|j�|�dS)zDo nothing.rqN)rJrNrr)rr�rrrr��
szLimitPreviousCommand.parsebitcCsdS)r�zLimit previous commandrrrrrr-�
sz LimitPreviousCommand.__unicode__r)
rrr r!r+r�r-r
rr.rrrrrr�
s
rrc@sXeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)�LimitsProcessorz)A processor for limits inside an element.cCsNtjr
dS|�||�r"|�||�|�||�rJ|�||d�rJ|�||�dS)z"Process the limits for an element.Nr�)r�r�checklimits�modifylimits�checkscript�
modifyscriptsrrrrr�
szLimitsProcessor.processcCsNtjs
dS|�||dt�r,|�||�dSt||t�s>dS|�||d�S)z3Check if the current position has a limits command.Fr�)r�r��checkcommandrr�limitsaheadr�rprvrrrrrt�
szLimitsProcessor.checklimitscCs*||d�||���t�||_dS)z,Limit the current element based on the next.r�N)r�rrCrrrrrry�
szLimitsProcessor.limitsaheadcCsz||}|�||d�}|�||d�r:|�||d�}nt��dd�}|jdkr\||}}|j�|�|j�d|�dS)zCModify a limits commands so that the limits appear above and below.r�r
zsup class="limit"rirN)�getlimitrvr�r�r�rr�r�)r�rr�Zlimited�	subscript�superscriptrrrru�
s

zLimitsProcessor.modifylimitscCs$|�||�}|jj�dd�|j_|S)z#Get the limit for a limits command.Zscriptr)�	getscriptrrKr�)r�rr�rrrrrzszLimitsProcessor.getlimitcCsN|�||�}|�||�}|jdkr,||}}t��||gd�}|�||�dS)z=Modify the super- and subscript to appear vertically aligned.rizspan class="scripts"N)r}r�r�r�r�)r�rr�r{r|Zscriptsrrrrws

zLimitsProcessor.modifyscriptscCs|�||t�S)z6Check if the current element is a sub- or superscript.)rxr3rrrrrvszLimitsProcessor.checkscriptcCst|�|krdSt|||�S)z0Check for the given type as the current element.F)r�r�)r�rr�r
rrrrxszLimitsProcessor.checkcommandcCs"||}|jjd7_||=|S)zGet the sub- or superscript.z class="script")rrK)r�rr�r�rrrr}szLimitsProcessor.getscriptN)
rrr r!rrtryrurzrwrvrxr}rrrrrs�
s	rsc@s&eZdZdZejZdd�Zdd�ZdS)r(z"A command which defines a bracket.cCst�||�dS)zParse the bracket.N)r/r�r�rrrr�)szBracketCommand.parsebitcCs ||_d||_t|�g|_|S)z+Create the bracket for the given character.rP)r
r�r%r�r��	direction�	characterrrrr-s
zBracketCommand.createN)	rrr r!rDr�r+r�rrrrrr($sr(c@sPeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�BracketProcessorz!A processor for bracket commands.cCs&tjr
dS|�||�r"|�||�SdS)z6Convert the bracket using Unicode pieces, if possible.N)r�r�	checkleft�processleftrrrrr7szBracketProcessor.processcCsJ|�||d�}|sdS|�|||�}|�|||�|�|||�dS)zProcess a left bracket.r�N)�	findright�findmax�resize)r�rr��
rightindexr�rrrr�>szBracketProcessor.processleftcCs|�||d�S)z0Check if the command at the given index is left.r`��checkdirectionrrrrr�GszBracketProcessor.checkleftcCs|�||d�S)z1Check if the command at the given index is right.rar�rrrr�
checkrightKszBracketProcessor.checkrightcCst|t�sdS|j|kS)z6Check if the given bit is the desired bracket command.F)r�r(r�)r�r�r�rrrr�Os
zBracketProcessor.checkdirectioncCsRd}|t|�krN|�||�r$|d7}|�||�r8|d8}|dkrD|S|d7}qdS)z9Find the right bracket starting at the given index, or 0.r�rN)r�r�r�)r�rr��depthrrrr�Us
zBracketProcessor.findrightcCs|||�}tdd�|D��S)z@Find the max size of the contents between the two given indices.cSsg|]
}|j�qSrr�r�rrrr�erwz,BracketProcessor.findmax.<locals>.<listcomp>)r�)r�rZ	leftindexr�Zslicedrrrr�bszBracketProcessor.findmaxcCs8|��}|j�dd�}t|||�}t�|_|��|_dS)z+Resize a bracket command to the given size.rPr;N)r9r�r�r=rGrrNr)r�r�r�r�r>ryrrrr�gs
zBracketProcessor.resizeN)rrr r!rr�r�r�r�r�r�r�rrrrr�4s	
r�c@sFeZdZdZddgZdd�Zdd�Zdd	�Zd
d�Ze	j
dkrBeZd
S)�ParameterDefinitionz3The definition of a parameter in a hybrid function.)r[r\)r]r^cCs"d|_d|_d|_d|_d|_dS)NF)rrr�ru�literalvaluerrrrr��s
zParameterDefinition.__init__cCs�tjD]�\}}|�|�r|dkr&d|_|�d�sLt�d|��d�dS|��|_|�d�rfd|_	|�|�s�t�d|���dS|Sqt�d	|���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: )
r��
parambracketsr�r�rrr�rcrr)r�r�Zopening�closingrrrr1�s 





zParameterDefinition.parsecCs^|jr:|jr|�|�|_n|�|�|_|jrZt|j�|_n |jrN|�|�|_n|�|�|_dS)z/Read the parameter itself using the definition.N)	rr�r6r�r�r%rur5r%)r�r�r@rrr�read�szParameterDefinition.readcCs0d|j}|jr$|dt|j�7}n|d7}|S)r�zparam rcz (empty))rrur')r�r�rrrr-�s

zParameterDefinition.__unicode__rN)rrr r!r�r�r1r�r-r
rr.rrrrr�ys	
r�c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�ParameterFunctionzFA function with a variable number of parameters defined in a template.cCs8t�|_|�|�D] }|�||�||jd|j<qdS)z*Read the params according to the template.r�N)r�params�	paramdefsr�r�r��readtemplater�Zparamdefrrr�
readparams�szParameterFunction.readparamsccs,t|�}|��s(t��|�}|r|VqdS)z*Read each param definition in the templateN)r�rar�r1r�rrrr��s
zParameterFunction.paramdefscCs||jvrdS|j|S)zGet a parameter as parsed.N)r�r�rrr�getparam�s
zParameterFunction.getparamcCs|�|�jS)zGet the value of a parameter.)r�rur�rrr�getvalue�szParameterFunction.getvaluecCs|�|�}|r|jsdS|jS)z%Get the literal value of a parameter.N)r�r�)r�rr�rrr�getliteralvalue�s

z!ParameterFunction.getliteralvalueN)	rrr r!r�r�r�r�r�rrrrr��sr�c@sVeZdZdZejZdd�Zdd�Zdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�ZdS)�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/>.
  cCs8|jd}|jd}|�||�|�|�|_|��dS)z*Parse a function with [] and {} parametersrr�N)r2r��writeparamsr�computehybridsize)r�r�r��
writetemplaterrrr��s


zHybridFunction.parsebitcCs|�t|��S)z*Write all params according to the template)�writeposr�)r�r�rrrr��szHybridFunction.writeparamscCs�g}|��s�|�d�r0|�|�}|r�|�|�q|�d�rZ|�|�}|r�d|_|�|�q|�d�rx|�|�dd��q|�d�r�|�|�dd��q|�t|����q|S)z/Write all params as read in the parse position.r��fNrY�leftrZ�right)	rar��
writeparamr��
writefunctionr
�writebracketr%rc)r�r�r�r�r@rrrr��s"





zHybridFunction.writeposcCs^d|��}||jvr(t�d|�dS|j|s6dS|�d�rR|��|j|j_|j|jS)z*Write a single param of the form $0, $x...r�zUnknown parameter Nr�)rcr�rrr�rqrur
)r�r�rrrrr�s


zHybridFunction.writeparamcCsz|�|�}|sdS|�d�r(t��|�S|�d�s@t�d�dS|�d�|�|�}|��t	|�dkrldSt��
||�S)z"Write a single function f0,...,fn.Nr�r]z Function should be defined in {}r^r)�readtagr�r�r�rrr�r�r�r�r�)r�r�rKrrrrr�s





zHybridFunction.writefunctioncCs�|����s"t�d|���dSt|���}d|t|j�krZt�dt|�d�dS|jd|}d|vrt|S|j	D]V}||vrz|j	|}|j
s�t�d|d|d	�qz|jr�|j}nd
}|�||�}qz|S)zJGet the tag corresponding to the given index. Does parameter substitution.zFunction should be f0,...,f9: fNr�z
Function fz is not definedr�zParameters in tag z should be literal: {z!}r;)
r�rsrr�intrcr�r2r'r�rr�r�)r�r�r�rK�variabler�rurrrr�.s*

zHybridFunction.readtagcCs|j�t��||�S)z4Return a new bracket looking at the given direction.)r)rr(r~rrrr�GszHybridFunction.writebracketcCs>|jtjvr|��dSt��|�|_|jD]}|j|_q,dS)z(Compute the size of the hybrid function.N)r��
HybridSize�configsizesr��getsizer�r)r�rIrrrr�Ks
z HybridFunction.computehybridsizeN)rrr r!rDr�r+r�r�r�r�r�r�r�r�rrrrr��sr�c@seZdZdZejZdd�ZdS)r�z+The size associated with a hybrid function.cCsb|j|j}|jD],}||vr|j|j��}|�|t|��}qd|vrZt�d|�dSt	|�S)z*Read the size for a function and parse it.r�z%Unconverted variable in hybrid size: r�)
r�r�r�rur�r�r'rr�eval)r�r@Z
sizestringrr�rrrr�[s
zHybridSize.getsizeN)rrr r!rDr�r�r�rrrrr�Vsr�cCs2t�}|�|�}t��|�|��d�|���S)zConvert some TeX math to HTML.r;)rr�rrr�rA)r�r)rrrr�	math2htmlls

r�cCsHtj}t��|�t|�dkr.t�d�t�t|d�}t�	|�dS)z6Main function, called if invoked from the command liner�z"Usage: math2html.py escaped_stringrN)
r
�argvr�r�r�rrrr�r)r�r�rrr�maints
r��__main__)dZos.pathr�r
rjr�urllib.parserZurllibZdocutils.utils.mathr�strr'r�r�objectrr#r:rDr�r�rrrr/r3r9r;r<r>r?rCrDrGrJrUr[r^r_r�r�r�r�r�r�r�r�r�r�r�r%r1r.r-r�r�r'rrrr,rrr$r1r*r2r&r/r3r4r;r+r!r=rOrRrTrXr_rbrcrerfr)r0r5rprrrsr(r�rr�r�r�r�r�r�rrrrr�<module>s�

0,D:)4#	


BvC;$3i0


F
6RIU;	�>
+%M<
��>${



Youez - 2016 - github.com/yon3zu
LinuXploit