+
    VBie                   N   ^ RI Ht Rt^ RIt^ RIt^ RIt^ RIHt Rt ! R R4      t	 ! R R	4      t
 ! R
 R4      t ! R R4      t ! R R4      t ! R R4      t ! R R4      t ! R R4      t ! R R4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R  R!]4      t ! R" R#]4      t ! R$ R%4      t ! R& R']4      t ! R( R)]4      t ! R* R+]4      t ! R, R-]4      t ! R. R/]4      t ! R0 R1]4      t ! R2 R34      t ! R4 R54      t  ! R6 R74      t! ! R8 R9]4      t" ! R: R;]"4      t# ! R< R=4      t$ ! R> R?]$4      t% ! R@ RA]$4      t& ! RB RC]&4      t' ! RD RE4      t( ! RF RG]4      t) ! RH RI]$4      t* ! RJ RK]*4      t+ ! RL RM]'4      t, ! RN RO]*4      t- ! RP RQ]*4      t. ! RR RS]*4      t/ ! RT RU]*4      t0 ! RV RW]*4      t1 ! RX RY]*4      t2 ! RZ R[]24      t3 ! R\ R]4      t4 ! R^ R_4      t5 ! R` Ra]$4      t6 ! Rb Rc]*4      t7 ! Rd Re4      t8 ! Rf Rg]*4      t9 ! Rh Ri]94      t: ! Rj Rk]:4      t; ! Rl Rm]:4      t< ! Rn Ro];4      t= ! Rp Rq]:4      t> ! Rr Rs]:4      t? ! Rt Ru]:4      t@ ! Rv Rw]>4      tA]8;P                  ]9]?.,          unB        ]=];]>]A]@]<.]9nB         ! Rx Ry4      tC ! Rz R{]:4      tD ! R| R}]94      tE ! R~ R]94      tF ! R R]:4      tG ! R R]G4      tH ! R R]G4      tI ! R R]G4      tJ ! R R]G4      tK ! R R]:4      tL]9;P                  ]L.,          unB         ! R R]>4      tM ! R R]>4      tN ! R R]>4      tO ! R R];4      tP ! R R]P4      tQ ! R R]44      tR ! R R]>4      tS ! R R]44      tT]9;P                  ]N]O]M]P]S.,          unB        ]5;P                  ]R! 4       ]T! 4       .,          unU         ! R R4      tV ! R R]:4      tW ! R R]W4      tX ! R R4      tY]9;P                  ]X.,          unB        R tZR R lt[]\R8X  d
   ][! 4        R# R# )    )annotationsreStructuredTextN)tex2unicharz1.3 (2021-06-02)c                      ] tR t^%tRtRtRtRtRtR R lt	R R lt
R R	 ltR
 R lt]! ]	4      t	]! ]
4      t
]! ]4      t]! ]4      tRtR# )TracezA tracing classFNc                   V ^8  d   QhRR/#    returnNone )formats   "B/usr/lib/python3.14/site-packages/docutils/utils/math/math2html.py__annotate__Trace.__annotate__.   s     ( (t (    c                    \         P                  '       d   \         P                  '       d   R# \         P                  V\        P
                  4       R# )zShow a debug messageN)r   	debugmode	quietmodeshowsysstdoutclsmessages   &&r   debugTrace.debug.   s(    %///

7CJJ'r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r   4   s     ( ( (r   c                   \         P                  '       d   R# \         P                  '       d.   \         P                  '       d   \         P                  V,           p\         P	                  V\
        P                  4       R# )zShow a trace messageN)r   r   prefixshowlinesmoder   r   r   r   s   &&r   r   Trace.message4   sB    ???<<<E///llW,G

7CJJ'r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r   <   s     ( (t (r   c                    RV,           p\         P                  '       d.   \         P                  '       d   \         P                  V,           p\         P                  V\        P
                  4       R# )zShow an error messagez* N)r   r    r!   r   r   stderrr   s   &&r   errorTrace.error<   s?    .<<<E///llW,G

7CJJ'r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r   C   s     & &t &r   c                6    VP                  VR,           4       R# )zShow a message out of a channel
N)write)r   r   channels   &&&r   r   
Trace.showC   s    gn%r   r   )__name__
__module____qualname____firstlineno____doc__r   r   r!   r    r   r   r&   r   classmethod__static_attributes__r   r   r   r   r   %   sW    IIMF(((& E'"GEtDr   r   c                  ,    ] tR t^MtRtRR.R. RO/tRtR# )ContainerConfig+Configuration class from elyxer.config fileallowedFormulaConstant	extractedr   N)AlphaCommandBracketBracketCommandCombiningFunctionEmptyCommandFontFunctionFormulaFormulaNumberFormulaSymbolOneParamFunctionOversetFunctionRawTextSpacedCommandSymbolFunctionTextFunctionUndersetFunction)r.   r/   r0   r1   r2   extracttextr4   r   r   r   r6   r6   M   s    1 	%& Kr   r6   c                  :    ] tR t^ftRtRRRRRR/tRR	R
RRR/tRtR# )EscapeConfigr7   r*    '   ’`u   ‘&z&amp;<z&lt;>z&gt;r   N)r.   r/   r0   r1   r2   charsentitiesr4   r   r   r   rM   rM   f   s5    1 	bUUE 	WVVHr   rM   c                     ] tR t^vtRt/ RRbRRbRRbRR	bR
RbRRbRRbRRbRRbRRbRRbRRbRRbRRbRRbR R!bR"R#bR$R%R&R'/Ct]P                  P                  4        F  w  t	t
]
]R(]	,           &   K  	  R)R*R+R,R-R.R/R0/tR1. ERiOR2. ERjOR3. ERkOR4. ERlOR5. ERmOR6. ERnOR7R7.R8R8./tR9R:R;R<R=R:R>R:R?R@/tRARBRCRDRERFRGRHRIRJRKRLRMRNRORPRQRRRSRTRURV/t]P                  P                  4        F  w  t	t
]
]R(]	,           &   K  	  / R0RWbRXRYbRZRYbR[R\bR]R^bR_R`bRaRbbRcRdbReRfbRgRdbRhRfbRiRfbRjRdbRkRlbRmRnbRoRpbRqR8b/ RrR8bRsR7bRtRWbRuRvbRwRxbRyRxbRzR{bR|R8bR}R7bR~RbRRbRR(bRR`bRRbRRdbRRbRRbC/ RRlbRRbRRbRRbRRbRRbRRbRRbRRbRRbRRbRRbRRbRRYbRRbRRbRRbC/ RRbRRbRRbRRbRRbRRbRRbRRbRRbRRbRRbRRbRRbRRbRRbRRbRRbCRRRRRRRRRRRRRRRRRRRRRRRRRRRR/Ct/ t]P%                  ]P&                  4       ]P%                  ]P(                  4       ]P%                  ]P*                  4       ]P%                  ]P,                  4       ]P%                  ]P.                  4       ]P%                  ]P0                  4       ]P%                  ]P2                  4       ]P%                  R ]P                  4        4       4       RRRRRRRRRRRRRRRR/tRRRRRR/tRR6RRRR6RRER R4/tERERER.ER. ERoOERERER.ERERER./t/ ERER	bER
ERbERERbERERbERERbERERbERERbERERbERERbERERbERERbERERbER ER!bER"ER#bER$ER%bER&ER'bER(ER)b/ ER*ER+bER,ER-bER.ER/bER0ER1bER2ER3bER4ER	bER5ER6bER7ER8bER9ER:bER;ER<bER=ER>bER?ER@bERAERBbERCERDbEREERFbERGERHbERIERJbC/ ERKERLbERMERNbEROERPbERQERRbERSERTbERUERVbERWRbERXERYbERZRbER[ER\bER]ER^bER_ER`bERaERbbERcERdbEReER8bERfER:bERgER<bCERhER>ERiER@ERjERBERkERDERlERFERmERnERoERpERqERb/Ct/ ERr. ERpObERs. ERqObERt. ERrObERu. ERsObERw. ERtObERx. ERuObERy. ERvObERz. ERwObER{. ERxObER|. ERyObER}. ERzObER~. ER{ObER. ER{ObER. ER|ObER. ER}ObER. ER}ObER. ER~Ob/ ER. ERObER. ERObER. ERrObER. ERObER. ERObER. ERObER. ERObER. ERObER. ERObERERRx.bER. ERObER. ERObER. ERObER. ERObER. ERObER. ERxObER. ERObCER. ERvOER. EROER. ER}OER. EROER. EROER. EROER. EROER. ERO/CtERuERERxERER{ERER|ERERERERER/t ERER/t!/ ERERbERERbERERbERERbERERbERERbERERbERERbERERbERERbERERbERERbERERbERERbERERbERERbERERb/ ERERbERERbERERbERERbERERbERERbERERbERERbERERbERERbERERbERERbERERbERERbERERbERERbERERbCERERERERERERERERERERERER/Ct"ERRxRYRxERRxR,ERERRERERERERERERERERERERRERERERRER ERRxRRv/t#/ ERERbERERbERERbERERvbERERvbERERvbER	ER
bERER
bERER
bERERbERERbERERbERERbERERbERERbERERbERERbERERERERERERER ER!ER"RxER#ER/Ct$/ ER$ER%bER&ER'bER(ER)bER*ER+bER,ER-bER.ER/bER0ER1bER2ER3bER4ER5bER6ER7bER8ER9bER:ER;bER<ER=bER>ER?bER@ERAbERBERCbt%]PL                  P                  4        F  w  t	t
]
]%R(]	,           &   K  	  ERDR6EREERFRR5ERGR(ERHERIRERJERKERER R3ERLERM/	t'RERERNERO/t(ERPERQERRERSERTERUERVERWERXERYERZER[ER\ER]ER^ER_ER`ERaERbERcERdERe/t)ERf. ERO/t*ERgt+ERh# (  FormulaConfigr7   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\hbaru   ħ\beginz\begincellseparatorrR   endz\endrowseparatorz\\()[]{}|u   ‖\leftspan class="stretchy"z\left.z<span class="leftdot"></span>z\middle\rightz\right.z<span class="rightdot"></span>z\'u   ́z\"u   ̈z\^u   ̂z\`u   ̀z\~u   ̃z\cu   ̧z\ru   ̊z\su   ̩z\textcircledu   ⃝z\textsubringu   ̥z\vu   ̌z<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\lVertz
\Arrowvertz\lvertz\newlinez\nobreakspace    z	\nolimitsrN   z	\nonumberz\qquadu     z\rVertz\rvertz\textasciicircum^z\textasciitilde~z\textbackslashz\textcopyrightz\textdegree   °z\textellipsisz\textemdashu   —z\textendashz	\texteuroz\textgreaterrT   z	\textlessrS   z\textordfeminine   ªz\textordmasculine   ºz\textquotedblleftu   “z\textquotedblrightu   ”z\textquoterightrP   z\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expz\gcdgcdz\homhomz\injlimu	   inj limz\kerkerz\lglgz\liminfu	   lim infz\limsupu	   lim supz\lnlnz\loglogz\projlimu
   proj limz\secsecz\sinsinz\sinhsinhz\tantanz\tanhtanhc              #  	<   "   T F  w  rR V,           V3x  K  	  R# 5i)rd   Nr   ).0keyvalues   &  r   	<genexpr>FormulaConfig.<genexpr>  s     J/JCTCZ'/s   z\baru   ‒z\dddotu$   <span class="smallsymbol">⋯</span>z\vecu$   <span class="smallsymbol">→</span>z\overleftarrowu   ⟵z\overleftrightarrowu   ⟷z\overrightarrowu   ⟶z\widehatz
\widetildeu   ～z\underleftarrowz\underleftrightarrowz\underrightarrowbracketcomplex\]endafter	endbeforez\end{squarebracketalignrleqnarraycgatheredsmallmatrixz\boldsymbolbz\mathbbzspan 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\mathcalzspan 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	\mathfrakzspan 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\mathrmzspan class="mathrm"z\mathscrzspan class="mathscr"z\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span class="mathsf"z\mathttzspan class="mathtt"z\operatornamez\addcontentslinez\addtocontentsz\backmatterz\binomspan class="bigdelimiter size2"z\boxedz\cfracz\colorz	\colorboxz\dbinomz\dfracz\displaystylez
\fancyfootz
\fancyheadz\fboxz	\fboxrulez\fboxsepz
\fcolorboxz\fracz	\frameboxz\frontmatterz\hrefz\hspacez	\leftrootz	\nicefracz\parboxz	\raiseboxz\renewenvironmentz{$1!}{$2!}{$3!}z\rulez\scriptscriptstylez\scriptstylez\sqrtz	\stackrelz\tbinomz\tfracz
\textcolorz
\textstylez\thispagestylez\unitz	\unitfracz\uprootz\urlz\vspacez$1+$2z$1+$2+1z\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>z\oiiintu-   <span class="bigoperator integral">∰</span>z\ointclockwiseu-   <span class="bigoperator integral">∲</span>z\ointctrclockwiseu-   <span class="bigoperator integral">∳</span>z	\smallintu-   <span class="smallsymbol integral">∫</span>z\sqintu-   <span class="bigoperator integral">⨖</span>z\varointclockwiser*   $	rO   +u    + ,u   , -u	    − /u	    ⁄ :z : u
    &lt; =u    = u
    &gt; @z\bigzspan class="bigdelimiter size1"z\biglz\bigrz\Bigz\Biglz\Bigrz\biggzspan class="bigdelimiter size3"z\bigglz\biggrz\Biggzspan class="bigdelimiter size4"z\Bigglz\Biggrz\begin{array}zspan class="arraydef"z
\centeringzspan class="align-center"z\ensuremathzspan class="ensuremath"z	\hphantomzspan class="phantom"z	\noindentzspan class="noindent"z
\overbracezspan class="overbrace"z	\overlinezspan class="overline"z\phantomz\underbracezspan class="underbrace"z
\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>
beginafterbeginbeforez\begin{commandcomment%\[simple
unnumbered*_subz\mboxzspan class="mbox"z\textzspan class="text"z\textbfzspan class="textbf"z\textitzspan class="textit"z\textnormalzspan class="textnormal"z\textrmzspan class="textrm"z\textsczspan class="textsc"z\textsfzspan class="textsf"z\textslzspan class="textsl"z\textttzspan class="texttt"z\textupzspan class="normal"
charactersr   N)u   ⎛u   ⎜u   ⎝)u   ⎞u   ⎟u   ⎠)u   ⎡u   ⎢u   ⎣)u   ⎤u   ⎥u   ⎦)u   ⎧   ⎪u   ⎨u   ⎩)u   ⎫r   u   ⎬u   ⎭)r   r   r   )z{$p!}{$q!}{$r!}f0{}ignored)z
{$p!}{$q!}r   r   )rN   r   r   ){$1}{$2}zf2{(}f0{f1{$1}f1{$2}}f2{)}zspan class="binom"zspan class="binomstack"r   ){$1}f0{$1}zspan class="boxed")z[$p!]{$1}{$2}!f0{f3{(}f1{$1}f3{)/(}f2{$2}f3{)}}span class="fullfraction"zspan class="numerator align-$p"span class="denominator"span class="ignored")	{$p!}{$1}r   zspan style="color: $p;")r   r   z-span class="colorbox" style="background: $p;")r   u%   (f0{f1{f2{$1}}f1{f2{ }}f1{f2{$2}}})zspan class="binomial"zspan class="binomrow"zspan class="binomcell")r   r   r   span class="numerator"r   r   )r   r   zspan class="displaystyle")z
[$p!]{$q!}r   r   )r   r   zspan 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!}zf0{$t}a href="$u")r   f0{ }z&span class="hspace" style="width: $p;")r   r   z*span class="leftroot" style="width: $p;px")r   u   f0{f1{$1}⁄f2{$2}}r   zsup class="numerator"zsub class="denominator"r   )z[$p!]{$w!}{$1}zf0{1}z$div class="Boxed" style="width: $w;")r   zf0{$1.font}z1span class="raisebox" style="vertical-align: $p;")z[$v!]{$w!}{$h!}zf0/z.hr class="line" style="width: $w; height: $h;")r   r   zspan class="scriptscriptstyle")r   r   zspan class="scriptstyle")[$0]{$1}u!   f0{f1{$0}f2{√}f4{(}f3{$1}f4{)}}zspan class="sqrt"zsup class="root"zspan class="radical"zspan class="root"r   )r   zf0{f1{$1}f2{$2}}zspan class="stackrel"zspan class="upstackrel"zspan class="downstackrel")r   r   zspan class="textfraction"r   r   r   )r   r   zspan class="textstyle")r   z$0f0{$1.font}zspan class="unit")z[$0]{$1}{$2}u   $0f0{f1{$1.font}⁄f2{$2.font}}r   zsup class="unit"zsub class="unit")r   r   z(span class="uproot" style="width: $p;px")z{$u!}zf0{$u}r   )r   r   z'span class="vspace" style="height: $p;").r   rv   ri   rj   rk   rl      ·!;ro   r   "?),r.   r/   r0   r1   r2   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
unmodifiedr4   r   r   r   rX   rX   v   s!   12t 	t 	t	
 	t 	t 	t 	t 	t 	t 	t 	t 	t 	t 	t  	t!" 	t#$ 	tt'M* "++113
U"'d3h 4 	w	E ----44 5'K 	)2+*4O 	 ",,224
U',48$ 5TTT 	T 	x	T
 	4T 	tT 	eT 	%T 	5T 	5T 	5T 	5T 	5T 	%T 	4T  	D!T" 	5#T$ 	%T& 	3'T( 	W)T* 	$+T, 	b-T. 	b/T0 	81T2 	53T4 	35T6 	S7T8 	C9T: 	4;T< 	4=T> 	?T@ 	%ATB 	CTD 	ETF 	eGTH 	ITJ 	cKTL 	TMTN 	dOTP 	eQTR 	uSTT 	EUTV 	DWTX 	EYTZ 	[T\ 	5]T^ 	T_T` 	caTb 	;cTd 	2eTf 	hgTh 	(iTj 	kTn 	oTp 	HqTr 	HsTt 	HuTv 	wTx 	yTz 	&{T| 	}T~ 	&T@ 	ATB 	CTD 	ETF 	GTH 	ITJ 	KTL 	KKK\&&gTHj GNN;&&'NN;''(NN;(()NN;(()NN;&&'NN;(()NN;$$%OOJ'--/JJ
 	e 	< 	<5ESu'. 	EU 	35CXG 	#sOS#JSz	L')Bv,f6CU 	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 '5e 	  .u 7Ee 	, 	 !0 :I% 	 !0 9H  	C!" 	#"  /#$ 	%$  /%$ 7Fu%& 	'( 	))* 	++, 	-,  .u-, 7Ee-. 	~une~u))/7M<.C.<. 	/. 	  R	.
 	;. 	  ~. 	E. 	^. 	  V. 	  p. 	I. 	8. 	8. 	9. 	2.  	1!." 	s#.$ 	  k%.& 	g'.( 	0).* 	=+., 	P-.. 	V/.4 	  _5.6 	W7.8 	g9.: 	0"5;.< 	^=.> 	S?.@ 	GA.D 	  rE.F 	  HG.H 	  VI.J 	  qK.L 	IC7D  KR3Q[.Ob 	7Iw
I7Hgz9K 	<N(5(( 	( 		(
 	( 	( 	F( 	=( 	=( 	=( 	=( 	=( 	=( 	=( 	=(  	=!(" 	=#($ 	=%(& 	F'(( 	=)(* 	=+(, 	=-(. 	%/(. #E/(. ,5e/(. >J5/(4 	@5(6 	A7(8 	B9(: 	C;(< 	A=(> 	K?(@ 	AA(B 	BC(D 	CJMEBMO(MV 	b#r3CdE3Y.5FUTWYk_c#5sBXH23 	3 	2	
 	3 	3 	3 	4 	4 	3 	4 	4 	1 	2  	1!" 	,#$ 	-%& 	/-+1r,1L8 	 		
 	 	 	 	 	< 	A 	= 	B 	> 	>  	>!" 	;#$ 	;%N( "))//1
U#(tCx  2 	c=*i4CE8SlCF 	UCO
 	%%))1))))))M 	 <
Jr   rX   c                  >    ] tR tRtRtR R ltR tR tR tR t	R	t
R
# )CommandLineParseri  zA parser for runtime optionsc                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   CommandLineParser.__annotate__"  s      4 r   c                	    Wn         R # Noptions)selfr  s   &&r   __init__CommandLineParser.__init__"  s    r   c                <   \        V4      ^ 8X  d   R# \        V4      ^ 8  dz   V^ ,          P                  R4      '       d\   V P                  V4      w  r#V'       g   RV,           R,           # V'       g   RV,           R,           # \        V P                  W#4       K  R# )Parse command line optionsN--zOption z not recognizedz needs a value)len
startswith
readoptionsetattrr  )r  argsr   r   s   &&  r   parseoptionsCommandLineParser.parseoptions%  sw    t9>$i!mQ 2 24 8 8.JC 5(+<<< 3)999DLL#-r   c                N   V^ ,          R,          pV^  RV9   d   V P                  W!4      pMVP                  RR4      p\        V P                  V4      '       g   RV3# \	        V P                  V4      p\        V\        4      '       d   VR3# \        V4      ^ 8X  d   VR3# V^ ,          P                  R4      '       d   V^ ,          pV^  W0P                  W4      3# V^ ,          P                  R4      pV^  \        V\        4      '       d   VP                  V4       W43# W63# )	z$Read the key and value for an option:r
   NNr   r   rN   NTr   zutf-8)readequalskeyreplacehasattrr  getattr
isinstanceboolr  r  
readquoteddecodelistappend)r  r  r   r   currentinitialr   s   &&     r   r  CommandLineParser.readoption2  s   1gbkG#:$$S/C++c2&Ct||S))9$,,,gt$$9t9>97c""1gGQ666Qw'Ggt$$NN5!<zr   c                   \         P                  R4       VR,          p\        V4      ^ 8  d|   V^ ,          P                  R4      '       g^   V^ ,          P	                  R4      '       g@   \         P                  RV^ ,          ,           4       VRV^ ,          ,           ,          pV^  K  \        V4      ^ 8X  g   V^ ,          P	                  R4      '       d   R# VRV^ R ,           ,          pV# )	zRead a value between quotesOops   NNr   r  z
Appending rs   N)r   r&   r  endswithr  )r  r  r&  r   s   &&& r   r!  CommandLineParser.readquotedM  s    F$i!mDG$4$4S$9$9$q'BTBTUYBZBZKKtAw./S47]"EQt9>T!W//55tAbz!!r   c                r    VP                  R^4      pV^ ,          pV^,          pVP                  ^ V4       V# )zRead a key using equalsr   )splitinsert)r  r   r  r0  r   r   s   &&&   r   r  CommandLineParser.readequalskeyZ  s7    		#q!AhaAu
r   r  N)r.   r/   r0   r1   r2   r  r  r  r!  r  r4   r   r   r   r  r    s    "6r   r  c                  v    ] tR tRtRtRtRtRtRtRt	Rt
Rt/ tR R ltR R	 ltR
 R ltR R ltR R ltRtR# )Optionsic  zA set of runtime optionsNFTc                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   Options.__annotate__q  s     	 	D 	r   c                    V^ ,          \         n        V^  \        \         4      pVP                  V4      pV'       d&   \        P                  V4       V P                  4        V P                  4        R# )r  N)r4  locationr  r  r   r&   usageprocessoptions)r  r  parserresults   &&  r   r  Options.parseoptionsq  sS    7G"7+$$T*KKJJLr   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r6  |  s     	A 	A 	Ar   c                6   \         P                  '       d   V P                  4        \         P                  '       d   V P	                  4        \        \        4       F9  pVP                  R4      '       g   K  \        \        V\        WRR 4      4       K;  	  R# )zProcess all options parsed.modeN)
r4  helpr9  versionshowversiondirr   r-  r  r  )r  params   & r   r:  Options.processoptions|  s]    <<<JJL???ZE~~f%%ugd#2J&?@  r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r6    s      t r   c                    \         P                  R\        P                  ! \        P
                  4      P                   R24       \         P                  R4       V P                  4        R# )zShow correct usagezUsage: z [options] "input string"z.Convert input string with LaTeX math to MathMLN)r   r&   pathlibPathr4  r8  parentshowoptionsr  s   &r   r9  Options.usage  sK    ggll7+;+;<CCD/0 	1DEr   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r6    s      T r   c                   \         P                  R4       \         P                  R4       \         P                  R4       \         P                  R4       \         P                  R4       \        P                  ! 4        R# )zShow 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)r   r&   r   exitrN  s   &r   rM  Options.showoptions  sL    GHOP\]VWZ[
r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r6    s      T r   c                p    \         P                  R\        ,           4       \        P                  ! 4        R# )z(Return the current eLyXer version stringz
math2html N)r   r&   __version__r   rR  rN  s   &r   rD  Options.showversion  s    L,-
r   r   )r.   r/   r0   r1   r2   r8  r   quietrC  rB  
simplemath	showlinesbranchesr  r:  r9  rM  rD  r4   r   r   r   r4  r4  c  sL    HEEGDJIH		A r   r4  c                  F    ] tR tRtRtR tR t]! ]4      t]! ]4      tRtR# )Cloneri  z&An object used to clone other objects.c                :     V P                  VP                  4      # )z"Return an exact copy of an object.)create	__class__)r   originals   &&r   cloneCloner.clone  s    =zz(,,--r   c                H    VP                  V4      pVP                  4        V# )z"Create an object of a given class.)__new__r  )r   typerb  s   && r   r_  Cloner.create  s    T"r   r   N)	r.   r/   r0   r1   r2   rb  r_  r3   r4   r   r   r   r]  r]    s%    ,.
 E Fr   r]  c                  >    ] tR tRtRtR R ltR tR R ltR tR	t	R
# )ContainerExtractori  ay  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                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   ContainerExtractor.__annotate__  s     - -$ -r   c                	>    VR ,          V n         VR,          V n        R# )r8   r:   Nr8   r:   )r  configs   &&r   r  ContainerExtractor.__init__  s    i(,r   c                X   a a . oV 3R lpV 3R lpVV 3R lpVP                  W#V4       S# )z8Extract a group of selected containers from a container.c                J   < V P                   P                  SP                  9   # r
  )r`  r.   r8   r   r  s   &r   <lambda>,ContainerExtractor.extract.<locals>.<lambda>  s    1;;//4<<?r   c                J   < V P                   P                  SP                  9   # r
  )r`  r.   r:   rr  s   &r   rs  rt    s    akk22dnnDr   c                (   < SP                  V S4      # r
  )process)r   lstr  s   &r   rs  rt    s    DLLC0r   )recursivesearch)r  	containerlocate	recursiverw  rx  s   f&   @r   extractContainerExtractor.extract  s,    ?D	0!!&W=
r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   rk    s     ; ; ;r   c                    VP                   P                  pW0P                  9   d   VP                  V4       R# \        P                  RV,           4       R# )zAdd allowed containers.zUnknown container class N)r`  r.   r8   r$  r   r&   )r  rz  rx  names   &&& r   rw  ContainerExtractor.process  s;    ""++<<JJy!KK2T9:r   c                ~    \         P                  V4      pVP                  Vn        V P                  V4      Vn        V# )zFReturn a new container with contents only in a safe list, recursively.)r]  rb  outputr}  contents)r  rz  rb  s   && r   	safecloneContainerExtractor.safeclone  s2    Y' ''i0r   rm  N)
r.   r/   r0   r1   r2   r  r}  rw  r  r4   r   r   r   ri  ri    s    	-;r   ri  c                  \    ] tR tRtRtR R ltR tR R ltR R	 ltR
 R lt	R R lt
RtR# )Parseri  zA generic parserc                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   Parser.__annotate__  s      $ r   c                	"    ^ V n         / V n        R# )r   Nre   
parametersrN  s   &r   r  Parser.__init__  s    
r   c                    VP                  4       P                  4       pVP                  4        VP                  V n        V# )zParse the header)currentliner0  nextline
linenumberre   )r  readerheaders   && r   parseheaderParser.parseheader  s5    ##%++-&&
r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r    s     . . .r   c                   VP                  4       P                  4       P                  R^4      pVP                  4        \	        V4      ^ 8X  d   R# V^ ,          p\	        V4      ^8X  d   RV P
                  V&   R# RV^,          9  d'   V^,          P                  4       V P
                  V&   R# V^,          P                  R4      pV^,          V P
                  V&   R# )zParse a parameterrs   NTr   )r  stripr0  r  r  r  )r  r  r0  r   doublesplits   &&   r   parseparameterParser.parseparameter  s    ""$**,223:u:?Ahu:?#'DOOC eAh#(8>>#3DOOC AhnnS)*1~r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r    s      d r   c                    V P                   '       g(   \        P                  R\        V 4      ,           4       R# VP	                  4       P                  V P                   4      '       g
   V! 4        K8  R# )z'Parse until the current ending is foundzNo ending for N)endingr   r&   strr  r  )r  r  rw  s   &&&r   parseendingParser.parseending  sL    {{{KK(3t945$$&11$++>>I ?r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r    s     ' '$ 'r   c                	    V P                   P                  V4      pV'       d%   V P                  Vn        VP                  V4       R # R # r
  )factorycreatecontainerrL  r$  )r  r  r  rz  s   &&& r   parsecontainerParser.parsecontainer  s6    LL008	#{{IOOI& r   c                   V ^8  d   QhRR/# r
   r   r  r   )r   s   "r   r   r    s     F F Fr   c                ~    V P                   P                  R,           \        V P                  4      ,           R,           # )zReturn a description (rj   )r`  r.   r  re   rN  s   &r   __str__Parser.__str__  s)    ~~&&-DJJ?#EEr   r  N)r.   r/   r0   r1   r2   r  r  r  r  r  r  r4   r   r   r   r  r    s*    . 'F Fr   r  c                       ] tR tRtRtR tRtR# )LoneCommandi	  z"A parser for just one command linec                    . # )zRead nothingr   r  r  s   &&r   parseLoneCommand.parse      	r   r   Nr.   r/   r0   r1   r2   r  r4   r   r   r   r  r  	  s
    (r   r  c                  <    ] tR tRtRt. tR R ltR tR R ltRt	R	# )

TextParseri  z(A parser for a command and a bit of textc                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   TextParser.__annotate__  s      T r   c                	    \         P                  V 4       R V n        VP                  P                  \
        P                  9   d1   \
        P                  VP                  P                  ,          V n        . V n        R # r
  )r  r  r  r`  r.   r6   r   r  rz  s   &&r   r  TextParser.__init__  sT    ''?+B+BB)11)2E2E2N2NODKr   c                V   \         P                  P                  V P                  4       \         P                  \        P
                  R,          \        P
                  R,          V P                  .,           V n        . pV P                  V4      '       g   V P                  W4       K*  V# )z$Parse lines as long as they are textLayoutInset)r  stackr$  r  r6   r   isendingr  r  r  r  s   && r   r  TextParser.parse  s|    ,!''?+B+B8+L+:+B+B7+K+/;;+8 8 --''1r   c                   V ^8  d   QhRR/# r
   r   r   r   )r   s   "r   r   r  (  s      $ r   c                8   VP                  4       P                  4       p\        V4      ^ 8X  d   R# V^ ,          V P                  9   dR   V^ ,          \        P
                  9   d)   \        P
                  P                  V^ ,          4       R# . \        n        R# R# )zCheck if text is endingFT)r  r0  r  r   r  r  remove)r  r  r%  s   && r   r  TextParser.isending(  sw    $$&,,.w<11:%qzZ---  ''
3  $&
 r   )r  r   N)
r.   r/   r0   r1   r2   r  r  r  r  r4   r   r   r   r  r    s    .E	 r   r  c                       ] tR tRtRtR tRtR# )ExcludingParseri6  z%A parser that excludes the final linec                @   a aa . oS P                  SVVV 3R l4       S# )z5Parse everything up to (and excluding) the final linec                 (   < SP                  SS 4      # r
  )r  )r  r  r  s   r   rs  'ExcludingParser.parse.<locals>.<lambda><  s    )<)<VX)Nr   )r  r  s   ff@r   r  ExcludingParser.parse9  s    !NOr   r   Nr  r   r   r   r  r  6  s
    +r   r  c                       ] tR tRtRtR tRtR# )BoundedParseri@  zA parser bound by a final linec                P    \         P                  W4      pVP                  4        V# )z*Parse everything, including the final line)r  r  r  r  s   && r   r  BoundedParser.parseC  s!    "((6r   r   Nr  r   r   r   r  r  @  s
    $r   r  c                       ] tR tRtRtR tRtR# )BoundedDummyiK  z&A bound parser that ignores everythingc                \    V P                  WP                  4       VP                  4        . # )z#Parse the contents of the container)r  r  r  s   &&r   r  BoundedDummy.parseN  s#    1	r   r   Nr  r   r   r   r  r  K  s
    ,r   r  c                  &    ] tR tRtRtR tR tRtR# )StringParseriV  zParses just a stringc                6    VP                   ^,           V n        . # )zDo nothing, just take note)r  re   r  s   &&r   r  StringParser.parseheaderY  s    &&*
	r   c                F    VP                  4       pVP                  4        V# )zParse a single line)r  r  r  s   && r   r  StringParser.parse^  s    %%'r   re   N)r.   r/   r0   r1   r2   r  r  r4   r   r   r   r  r  V  s    
r   r  c                  2    ] tR tRtRtR R ltR R ltRtR# )	ContainerOutputie  z(The generic HTML output for a container.c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   ContainerOutput.__annotate__h  s     B BD Br   c                P    \         P                  R\        V 4      ,           4       R# )zShow an error.zgethtml() not implemented for Nr   r&   r  r  s   &&r   gethtmlContainerOutput.gethtmlh  s    4s4y@Ar   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   r  l  s       r   c                    R# )z5Decide if the output is empty: by default, not empty.Fr   rN  s   &r   isemptyContainerOutput.isemptyl  s    r   r   N)r.   r/   r0   r1   r2   r  r  r4   r   r   r   r  r  e  s    .B r   r  c                  (    ] tR tRtR tR R ltRtR# )EmptyOutputiq  c                    . # )zReturn empty HTML code.r   r  s   &&r   r  EmptyOutput.gethtmls  r  r   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   EmptyOutput.__annotate__w  s       r   c                    R# )z"This output is particularly empty.Tr   rN  s   &r   r  EmptyOutput.isemptyw  s    r   r   N)r.   r/   r0   r1   r  r  r4   r   r   r   r  r  q  s     r   r  c                       ] tR tRtRtR tRtR# )FixedOutputi|  zFixed outputc                    VP                   # )zReturn constant HTML code)htmlr  s   &&r   r  FixedOutput.gethtml  s    ~~r   r   Nr.   r/   r0   r1   r2   r  r4   r   r   r   r  r  |  s
    r   r  c                       ] tR tRtRtR tRtR# )ContentsOutputi  z&Outputs the contents converted to HTMLc                6   . pVP                   f   V# VP                    Fv  p\        VR4      '       gL   \        P                  RVP                  P
                  ,           R,           \        V4      ,           4       Vu # W#P                  4       ,          pKx  	  V# )Return the HTML coder  zNo html in rt   )r  r  r   r&   r`  r.   r  r  )r  rz  r  elements   &&  r   r  ContentsOutput.gethtml  s~    %K ))G7I..MG,=,=,F,FFMPST[P\\]OO%%D	 *
 r   r   Nr  r   r   r   r  r    s
    ,
r   r  c                  Z    ] tR tRtRtRtRtRtRR ltR t	R t
R tR	 tR
 tR R ltRtR# )TaggedOutputi  z-Outputs an HTML tag surrounding the contents.NFc                J    Wn         V'       d   W n        V'       d   W0n        V # )z/Set the value for the tag and other attributes.)tag
breaklinesempty)r  r  r  r  s   &&&&r   settagTaggedOutput.settag  s    (OJr   c                    Wn         V # )zSet the value for breaklines.)r  )r  r  s   &&r   setbreaklinesTaggedOutput.setbreaklines  s    $r   c                    V P                   '       d   V P                  V4      .# V P                  V4      .pV\        P	                  W4      ,          pVP                  V P                  V4      4       V# )zReturn the HTML code.)r  selfclosingopenr  r  r$  close)r  rz  r  s   && r   r  TaggedOutput.gethtml  s_    :::$$Y/00		)$%&&t77DJJy)*r   c                    V P                  V4      '       g   R# RV P                  ,           R,           pV P                  '       d
   VR,           # V# )zGet opening line.rN   rS   rT   r*   checktagr  r  )r  rz  open_tags   && r   r  TaggedOutput.open  s>    }}Y''>C'???d?"r   c                    V P                  V4      '       g   R# RV P                  P                  4       ^ ,          ,           R,           pV P                  '       d   RV,           R,           # V# )zGet closing line.rN   z</rT   r*   )r  r  r0  r  )r  rz  r  s   && r   r  TaggedOutput.close  sP    }}Y''txx~~'**S0???%<$&&r   c                    V P                  V4      '       g   R# RV P                  ,           R,           pV P                  '       d
   VR,           # V# )zGet self-closing line.rN   rS   z/>r*   r  )r  rz  r  s   && r   r  TaggedOutput.selfclosing  s@    }}Y''DHHnt+???%%r   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   TaggedOutput.__annotate__  s      T r   c                    V P                   '       g(   \        P                  R\        V4      ,           4       R# V P                   R8X  d   R# R# )zCheck that the tag is valid.z
No tag in FrN   T)r  r   r&   r  r  s   &&r   r  TaggedOutput.checktag  s4    xxxKKs9~5688r>r   )r  r  r  )FF)r.   r/   r0   r1   r2   r  r  r  r  r	  r  r  r  r  r  r4   r   r   r   r  r    s<    3
CJE
 r   r  c                  @    ] tR tRtRt R R ltR R ltR tR tR	t	R
# )FilteredOutputi  z1Returns the output in the contents, but filtered:c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   FilteredOutput.__annotate__  s      $ r   c                    . V n         R# )zInitialize the filters.NfiltersrN  s   &r   r  FilteredOutput.__init__  s	    r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r     s     5 5$ 5r   c                >    V P                   P                  W34       R# )z:Add a new filter: replace the original by the replacement.N)r#  r$  )r  ra  replacements   &&&r   	addfilterFilteredOutput.addfilter  s    X34r   c                x    \         P                  W4      pV Uu. uF  q0P                  V4      NK  	  ppV# u upi )r  )r  r  filter)r  rz  r  liner<  s   &&   r   r  FilteredOutput.gethtml  s7    %%d6045++d#5 6s   7c                b    V P                    F  w  r#W!9   g   K  VP                  W#4      pK   	  V# )z0Filter a single line with all available filters.)r#  r  )r  r,  ra  r'  s   &&  r   r+  FilteredOutput.filter  s.    %)\\!H||H: &2 r   r"  N)
r.   r/   r0   r1   r2   r  r(  r  r+  r4   r   r   r   r  r    s    7*5r   r  c                       ] tR tRtRtR tRtR# )StringOutputi  zReturns a bare string as outputc                    VP                   .# )zReturn a bare stringstringr  s   &&r   r  StringOutput.gethtml  s      !!r   r   Nr  r   r   r   r1  r1    s
    %"r   r1  c                      ] tR tRtRtRtR R ltR R ltR R	 ltR
 R lt	R R lt
R tR R ltR tR tR tR R ltR tR R ltR tR tR tR tR#R R lltR$R  ltR! tR"tR# )%Globablei  zA bit of text which can be globbed (lumped together in bits).
Methods current(), skipcurrent(), checkfor() and isout() have to be
implemented by subclasses.Fc                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   Globable.__annotate__   s     ' '$ 'r   c                	$    \        4       V n        R # r
  )
EndingList
endinglistrN  s   &r   r  Globable.__init__   s    $,r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r9    s      t r   c                    V P                  4       '       d   R# \        V P                  4       4      R8X  d   V P                  4        R# R# )z*Check for a Unicode byte mark and skip it.Ni  )finishedordr%  skipcurrentrN  s   &r   checkbytemarkGlobable.checkbytemark  s4    ==??t||~&( )r   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   r9  
  s      t r   c                0    \         P                  R4       R# )z+Find out if we are out of the position yet.zUnimplemented isout()Tr   r&   rN  s   &r   isoutGlobable.isout
  s    +,r   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   r9    s       r   c                0    \         P                  R4       R# )zReturn the current character.zUnimplemented current()rN   rG  rN  s   &r   r%  Globable.current  s    -.r   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   r9    s      $ r   c                0    \         P                  R4       R# )z3Check for the given string in the current position.zUnimplemented checkfor()FrG  r  r4  s   &&r   checkforGlobable.checkfor  s    ./r   c                    V P                  4       '       d/   V P                  '       g   V P                  P                  4        R# V P                  P	                  V 4      # )z*Find out if the current text has finished.T)rH  leavependingr<  checkpendingcheckinrN  s   &r   r@  Globable.finished  sA    ::<<$$$,,.&&t,,r   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   r9  !  s      S r   c                0    \         P                  R4       R# ))Return the current character and skip it.zUnimplemented skipcurrent()rN   rG  rN  s   &r   rB  Globable.skipcurrent!  s    12r   c                    RpV P                  4       '       g&   V! 4       '       d   W P                  4       ,          pK;  V# )z>Glob a bit of text that satisfies a check on the current char.rN   )r@  rB  )r  currentcheckglobs   && r   r]  Globable.glob&  s.    --//lnn$$&&Dr   c                .   a  S P                  V 3R l4      # )zGlob a bit of alpha textc                 @   < S P                  4       P                  4       # r
  r%  isalpharN  s   r   rs  $Globable.globalpha.<locals>.<lambda>/      !7!7!9r   r]  rN  s   fr   	globalphaGlobable.globalpha-      yy9::r   c                .   a  S P                  V 3R l4      # )zGlob a row of digits.c                 @   < S P                  4       P                  4       # r
  r%  isdigitrN  s   r   rs  %Globable.globnumber.<locals>.<lambda>3  rd  r   re  rN  s   fr   
globnumberGlobable.globnumber1  rh  r   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   r9  5        d r   c                |    V P                  4       P                  4       '       g   V P                  4       R8X  d   R# R# )z5Return if the current character is alphanumeric or _.r   TF)r%  isalnumrN  s   &r   isidentifierGlobable.isidentifier5  s*    <<>!!##t||~'<r   c                8    V P                  V P                  4      # )z Glob alphanumeric and _ symbols.)r]  rt  rN  s   &r   globidentifierGlobable.globidentifier;  s    yy**++r   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   r9  ?  s       r   c                     V P                  4       P                  4       '       d   R# V P                  4       R9   d   R# R# )z5Return if the current character is a value character:Fz{}()Tr%  isspacerN  s   &r   isvalueGlobable.isvalue?  s1    #<<>!!##<<>V#r   c                8    V P                  V P                  4      # )z'Glob a value: any symbols but brackets.)r]  r}  rN  s   &r   	globvalueGlobable.globvalueH  s    yy&&r   c                .   a  S P                  V 3R l4      # )z(Skip all whitespace at current position.c                 @   < S P                  4       P                  4       # r
  r{  rN  s   r   rs  $Globable.skipspace.<locals>.<lambda>N  rd  r   re  rN  s   fr   	skipspaceGlobable.skipspaceL  rh  r   c                f   a a S P                  VV 3R l4      S,           pS P                  S4       V# )z4Glob a bit of text up to (including) the magic char.c                 *   < SP                  4       S 8g  # r
  r%  )	magiccharr  s   r   rs  (Globable.globincluding.<locals>.<lambda>R  s    9!<r   )r]  skip)r  r  r]  s   ff r   globincludingGlobable.globincludingP  s(    yy<=	I		)r   c                2   a a S P                  VV 3R l4      # )z?Glob a bit of text up until (excluding) any excluded character.c                 *   < SP                  4       S 9  # r
  r  )excludedr  s   r   rs  (Globable.globexcluding.<locals>.<lambda>X  s    x!?r   re  )r  r  s   ffr   globexcludingGlobable.globexcludingV  s    yy?@@r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r9  Z  s     . .D .r   c                <    V P                   P                  W4       R# )zPush a new ending to the bottomN)r<  addr  r  optionals   &&&r   
pushendingGlobable.pushendingZ  s    F-r   Nc                "   V P                  4       '       d   V P                  '       d   V# V P                  P                  V 4      pV'       d1   W8w  d+   \        P                  RV,           R,           V,           4       V P                  V4       V# )z,Pop the ending found at the current positionzExpected ending z, got )rH  rS  r<  popr   r&   r  )r  expectedr  s   && r   	popendingGlobable.popending^  sf    ::<<D---O$$T**KK*X5@6IJ		&r   c                d    V P                   P                  V 4      pV'       g   R# VP                  # )z$Return the next ending in the queue.N)r<  
findendingr  )r  
nextendings   & r   r  Globable.nextendingh  s(    __//5
   r   )r<  Fr
  )r.   r/   r0   r1   r2   rS  r  rC  rH  r%  rP  r@  rB  r]  rf  rn  rt  rw  r}  r  r  r  r  r  r  r  r4   r   r   r   r7  r7    ss    " L'


-
;;,';A.!r   r7  c                  r    ] tR tRtRtR R ltRR R lltR R ltR	 R
 ltR t	R t
R R ltR R ltRtR# )r;  ip  zA list of position endingsc                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   EndingList.__annotate__s  s      $ r   c                	    . V n         R # r
  r   rN  s   &r   r  EndingList.__init__s  s	    r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r  v  s     > >T >r   c                N    V P                   P                  \        W4      4       R# )zAdd a new ending to the listN)r   r$  PositionEndingr  s   &&&r   r  EndingList.addv  s    N6<=r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r  z  s     / /$ /r   c                `    V ;P                   VP                  P                   ,          un         R# )z/Pick any pending endings from a parse position.N)r   r<  r  poss   &&r   pickpendingEndingList.pickpendingz  s    ...r   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   r  ~  rq  r   c                8    V P                  V4      '       d   R# R# )zSearch for an endingTF)r  r  s   &&r   rU  EndingList.checkin~  s    ??3r   c                
   VP                  4       '       d   \        P                  R4       R# V P                  V4      pV'       g-   \        P                  RVP	                  4       ,           4       R# \        V P                  4       Fb  pV P                  P                  V4       W28X  d   VP                  u # VP                  '       d   KF  \        P                  RV,           4       Kd  	  \        P                  R4       R# )z)Remove the ending at the current positionzNo ending out of boundsrN   zNo ending at zRemoved non-optional ending zNo endings left)
rH  r   r&   r  r%  reversedr   r  r  r  )r  r  r  eachs   &&  r   r  EndingList.pop  s    99;;KK12%KK#++-78T\\*DLL%~{{"]]]:TAB + 	%&r   c                    \        V P                  4      ^ 8X  d   R# \        \        V P                  4      4       F5  w  r#VP	                  V4      '       d   Vu # VP
                  '       d   K4   R# 	  R# )z'Find the ending at the current positionN)r  r   	enumerater  rU  r  )r  r  indexr  s   &&  r   r  EndingList.findending  sU    t||!&x'=>ME~~c""???	 ?
 r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r    s     ? ?d ?r   c                    \        V P                  4      ^ 8w  d/   \        P                  R\	        V 4      ,           R,           4       R# R# )z&Check if there are any pending endingszPending z
 left openN)r  r   r   r&   r  rN  s   &r   rT  EndingList.checkpending  s2    t||!KK
SY.=> "r   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   r    s       r   c                    RpV P                    F  pV\        V4      R,           ,          pK  	  \        V P                   4      ^ 8  d   VRR pVR,           # )Printable representationz	endings [r   Nrl   r,  )r   r  r  )r  r4  r  s   &  r   r  EndingList.__str__  sN    llFc&kC''F #t||q CR[F|r   r  Nr  )r.   r/   r0   r1   r2   r  r  r  rU  r  r  rT  r  r4   r   r   r   r;  r;  p  s2     >/$	?
 r   r;  c                  8    ] tR tRtRtR R ltR tR R ltRtR	# )
r  i  z An ending for a parsing positionc                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   PositionEnding.__annotate__  s     ! !D !r   c                	    Wn         W n        R # r
  r  r  r  s   &&&r   r  PositionEnding.__init__  s     r   c                8    VP                  V P                  4      # )zCheck for the ending)rP  r  r  s   &&r   rU  PositionEnding.checkin  s    ||DKK((r   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   r    s       r   c                b    RV P                   ,           pV P                  '       d
   VR,          pV# )r  zEnding z (optional)r  rO  s   & r   r  PositionEnding.__str__  s(    T[[(===m#Fr   r  N)	r.   r/   r0   r1   r2   r  rU  r  r4   r   r   r   r  r    s    &!) r   r  c                  t    ] tR tRtRtR R ltR R ltR R ltR	 tR
 t	R t
R tR tR R ltR R ltRtR# )Positioni  zA position in a text to parse.
Including those in Globable, functions to implement by subclasses are:
skip(), identifier(), extract(), isout() and current().c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   Position.__annotate__  s        $  r   c                	0    \         P                  V 4       R # r
  )r7  r  rN  s   &r   r  Position.__init__  s    $r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r    s     , ,d ,r   c                0    \         P                  R4       R# )zSkip a stringzUnimplemented skip()NrG  rO  s   &&r   r  Position.skip  s    *+r   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   r    s      C r   c                0    \         P                  R4       R# )z.Return an identifier for the current position.zUnimplemented identifier()ErrorrG  rN  s   &r   
identifierPosition.identifier  s    01r   c                2     \         P                  R4       R# )zHExtract the next string of the given length, or None if not enough text,zUnimplemented extract()NrG  r  lengths   &&r   r}  Position.extract  s    /-.r   c                :    WP                  \        V4      4      8H  # )z)Check for a string at the given position.)r}  r  rO  s   &&r   rP  Position.checkfor  s    c&k222r   c                    V P                  \        V4      4      pV'       g   R# VP                  4       V P                  \        V4      4      P                  4       8H  # )z!Check for a string in lower case.F)r}  r  lower)r  r4  r:   s   && r   checkforlowerPosition.checkforlower  sA    LLV-	||~c&k!:!@!@!BBBr   c                H    V P                  4       pV P                  V4       V# )rY  )r%  r  r  r%  s   & r   rB  Position.skipcurrent  s    ,,.		'r   c                B    V P                  4        V P                  4       # )z3Advance the position and return the next character.)rB  r%  rN  s   &r   __next__Position.__next__  s    ||~r   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   r    s      4 r   c                Z    V P                  V4      '       g   R# V P                  V4       R# )z;Check for a string at the given position; if there, skip itFT)rP  r  rO  s   &&r   	checkskipPosition.checkskip  s#    }}V$$		&r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r    s     8 8 8r   c                h    \         P                  VR,           V P                  4       ,           4       R# )z2Show an error message and the position identifier.rt   N)r   r&   r  )r  r   s   &&r   r&   Position.error  s    GdNT__%667r   r   N)r.   r/   r0   r1   r2   r  r  r  r}  rP  r  rB  r  r  r&   r4   r   r   r   r  r    s?    ? ,
3C
8 8r   r  c                  J    ] tR tRtRtR R ltR R ltR tR tR	 t	R
 t
RtR# )TextPositioni  z%A parse position based on a raw text.c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   TextPosition.__annotate__  s       r   c                j    \         P                  V 4       ^ V n        Wn        V P	                  4        R# )z#Create the position from some text.N)r  r  r  textrC  r  r  s   &&r   r  TextPosition.__init__  s(    $	r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r    s        d  r   c                J    V ;P                   \        V4      ,          un         R# )zSkip a string of characters.N)r  r  rO  s   &&r   r  TextPosition.skip  s    CKr   c                   ^pV P                   V,           \        V P                  4      8  d'   \        V P                  4      V P                   ,
          pRV P                  V P                   V P                   V,            ,           R,           # )z&Return a sample of the remaining text.r   r  r  r  r  s   & r   r  TextPosition.identifier
  s^    88fs499~-^dhh.FTYYtxx6(9::S@@r   c                F    V P                   \        V P                  4      8  # )z'Find out if we are out of the text yet.r  rN  s   &r   rH  TextPosition.isout  s    xx3tyy>))r   c                <    V P                   V P                  ,          # )z6Return the current character, assuming we are not out.)r  r  rN  s   &r   r%  TextPosition.current  s    yy""r   c                    V P                   V,           \        V P                  4      8  d   R# V P                  V P                   V P                   V,            # )zHExtract the next string of the given length, or None if not enough text.Nr  r  s   &&r   r}  TextPosition.extract  s<    88fs499~-yyDHHv$566r   )r  r  N)r.   r/   r0   r1   r2   r  r  r  rH  r%  r}  r4   r   r   r   r  r    s$    + A*#7r   r  c                      ] tR tRtRtRtRtRtR R ltR R lt	R t
]P                  3R	 ltR
 tR tR tR R ltR R ltR R ltR tR R ltR R ltR!R R lltR tR tR R ltR R ltR tR# )"	Containeri   z.A container for text and objects in a lyx fileNc                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   Container.__annotate__'  s      $ r   c                	    . V n         R # r
  r  rN  s   &r   r  Container.__init__'  s	    r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r  *  s       r   c                    R# )zProcess contentsNr   rN  s   &r   rw  Container.process*  s    r   c                    V P                   P                  V 4      p\        V\        4      '       d    \        P                  RV,           4       V.pV# )zGet the resulting HTMLzRaw string )r  r  r  r  r   r&   )r  r  s   & r   r  Container.gethtml-  s@    {{""4(dC  KK,-6Dr   c                    \        VP                  4       4      pV F#  pWA9   g   K  VP                  WBV,          4      pK%  	  V# )z*Escape a line with replacements from a map)sortedkeysr  )r  r,  replacementspiecespieces   &&&  r   escapeContainer.escape5  s>    ))+,E}||E+>?  r   c                   Rp\        V4      pVP                  4       '       g   \        VP                  4       4      ^8  dm   \	        \        VP                  4       4      4      pVR8X  d%   \	        \        \        V4      4      R,           4      pVRVR,          ,           R,           ,          pMW#P                  4       ,          pVP                  4        K  V# )z/Escape all Unicode characters to HTML entities.rN   0xd835i   z&#r*  r   )r  r@  rA  r%  hexnextrB  )r  r,  r<  r  	codepoints   &&   r   escapeentitiesContainer.escapeentities>  s    4 ,,..3;;=!C'CKKM 23	( #CS	NV$; <I$2.44++-'OOr   c                @    . pV P                  WP                  4       V# )z2Search for all embedded containers of a given type)searchprocessr$  )r  rf  rx  s   && r   	searchallContainer.searchallM  s    4,
r   c                    V P                  V4      pV F(  pVP                  P                  P                  V4       K*  	  V# )z3Search for all containers of a type and remove them)r)  rL  r  r  )r  rf  rx  rz  s   &&  r   searchremoveContainer.searchremoveS  s9    nnT"I%%,,Y7 
r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r  Z  s     S Sd Sr   c                4   a V P                  V3R lV4       R# )z4Search for elements of a given type and process themc                   < \        V S4      # r
  )r  )rz  rf  s   &r   rs  )Container.searchprocess.<locals>.<lambda>\  s    Z	4-Hr   N)locateprocess)r  rf  rw  s   &f&r   r(  Container.searchprocessZ  s    H'Rr   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r  ^  s     # # #r   c                ~    V P                    F,  pVP                  W4       V! V4      '       g   K$  V! V4       K.  	  R# )z3Search for all embedded containers and process themN)r  r2  )r  r{  rw  rz  s   &&& r   r2  Container.locateprocess^  s1    I##F4i  	" 'r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r  e  s     # #T #r   c                    V P                    F;  pV! V4      '       d   VP                  WV4       V! V4      '       g   K3  V! V4       K=  	  R# )z,Perform a recursive search in the container.N)r  ry  )r  r{  r|  rw  rz  s   &&&& r   ry  Container.recursivesearche  s>    I##))&WEi  	"	 'r   c                    \        \        P                  4      P                  V 4      pRP	                  R V 4       4      # )z)Extract all text from allowed containers.rN   c              3  8   "   T F  qP                   x  K  	  R # 5ir
  r3  )r   constants   & r   r   (Container.extracttext.<locals>.<genexpr>p  s     Ay8y   )ri  r6   rK   r}  join)r  	constantss   & r   rK   Container.extracttextm  s2    &'B'BCKKDQ	wwAyAAAr   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r  r  s     
+ 
+ 
+r   c                   V\        V P                  4      8  d   R# \        V P                  V,          R4      '       d   R# V\        V P                  4      8  d   V! V P                  V,          4      '       db   RV P                  V,          n        VP                  P	                  V P                  V,          4       V P                  P                  V4       K  V P                  P                  W4       R# )z*Group some adjoining elements into a groupNgroupedT)r  r  r  rD  r$  r  r1  )r  r  group	isingroups   &&&&r   rE  Container.groupr  s    C&&4=='33c$--((Yt}}U7K-L-L+/DMM% (NN!!$--"67MMe$U*r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r  ~  s     B Bt Br   c                    V P                   V,          pV P                   P                  V4       \        VP                   4      ^ 8  d6   V P                   P                  WP                   P                  4       4       KO  R# )z)Remove a container but leave its contentsN)r  r  r  r1  )r  r  rz  s   && r   r  Container.remove~  s[    MM%(	% )$$%)MM  (:(:(>(>(@A *r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r    s     & &t &r   c                    \         P                  RV,          \        V 4      ,           4       V P                   F  pVP	                  V^,           4       K  	  R# )zShow in a treez  N)r   r   r  r  tree)r  levelrz  s   && r   rM  Container.tree  s9    D5L3t9,-INN519% 'r   c                L    WP                   9  d   R# V P                   V,          # )z)Get the value of a parameter, if present.N)r  r  r  s   &&r   getparameterContainer.getparameter  s    &t$$r   c                Z    V P                  V4      pV'       g   . # VP                  R4      # )z7Get the value of a comma-separated parameter as a list.r   )rR  r0  )r  r  	paramtexts   && r   getparameterlistContainer.getparameterlist  s)    %%d+	Is##r   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   r    s       r   c                    V P                   pV'       d1   VP                  P                  4       '       d   R# VP                   pK8  R# )z&Check if the parent's output is empty.TF)rL  r  r  r  s   & r   hasemptyoutputContainer.hasemptyoutput  s0    ++~~%%''nnGr   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   r    s     ? ? ?r   c                    V P                   '       g   V P                  P                  # V P                  P                  R,           \        V P                   4      ,           # )zGet a descriptionr   )re   r`  r.   r  rN  s   &r   r  Container.__str__  s=    zzz>>***~~&&,s4::>>r   r  )r   )r.   r/   r0   r1   r2   partkeyrL  re   r  rw  r  rM   rV   r  r%  r)  r,  r(  r2  ry  rK   rE  r  rM  rR  rV  rZ  r  r4   r   r   r   r  r     s    4GFE )5(=(= S##B

+B&%$? ?r   r  c                  &    ] tR tRtRtR R ltRtR# )BlackBoxi  z)A container that does not output anythingc                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   BlackBox.__annotate__  s      $ r   c                	P    \        4       V n        \        4       V n        . V n        R # r
  )r  r;  r  r  r  rN  s   &r   r  BlackBox.__init__  s    !m!mr   )r  r  r;  N)r.   r/   r0   r1   r2   r  r4   r   r   r   ra  ra    s    / r   ra  c                  T    ] tR tRtRtRtR R ltR R ltR tR	 t	R
 t
R R ltRtR# )StringContaineri  zA container for a single stringNc                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   StringContainer.__annotate__  s      $ r   c                	P    \        4       V n        \        4       V n        R V n        R# )rN   N)r  r;  r1  r  r4  rN  s   &r   r  StringContainer.__init__  s    "n"nr   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   ri    s       r   c                |    V P                   '       d*   V P                  V P                   4      V n        RV n         R# R# )z(Replace special chars from the contents.N)parsedreplacespecialr4  rN  s   &r   rw  StringContainer.process  s-    ;;;--dkk:DKDK r   c                   V P                  V\        P                  4      pV P                  V4      p\        P
                  R,          V9   dr   \        V4      ^8  db   V P                  '       d%   R\        V P                  4      ,           R,           pMRp\        P                  W2P                  4       ,           4       V# )z%Replace all special chars from a linestartcommandzUnknown command at rt   zUnknown command: )r  rM   rV   
changeliner6   r4  r  re   r  r   r&   r  )r  r,  replacedr   s   &&  r   ro  StringContainer.replacespecial  s    ;;t\%:%:;??8,!!.1X=#h-RSBSzzz/#djj/ADH-KK.."223r   c                	B    V P                  V\        P                  4      # r
  )r  rM   rU   )r  r,  s   &&r   rs  StringContainer.changeline  s    {{4!3!344r   c                    V P                   # )zReturn all text.r3  rN  s   &r   rK   StringContainer.extracttext  s    {{r   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   ri    s     I I Ir   c                B   RpV P                   '       d$   VR\        V P                   4      ,           ,          pRp\        V P                  P	                  4       4      ^8:  d   RpVR,           V P                  P	                  4       R,          ,           V,           R,           # )"Return a printable representation.rg  r   z...rN   r  :N   Nrj   )re   r  r  r4  r  )r  r<  ellipsiss   &  r   r  StringContainer.__str__  sv    ":::cC

O++Ft{{  "#r)H}t{{002377(BSHHr   )r  rn  r;  r4  )r.   r/   r0   r1   r2   rn  r  rw  ro  rs  rK   r  r4   r   r   r   rg  rg    s/    %F
5I Ir   rg  c                  2    ] tR tRtRtR R ltR R ltRtR# )	Constanti  zA constant stringc                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   Constant.__annotate__  s     % % %r   c                	>    . V n         Wn        \        4       V n        R # r
  )r  r4  r1  r  r  s   &&r   r  Constant.__init__  s    "nr   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   r    s     * * *r   c                	(    R V P                   ,           # )z
Constant: r3  rN  s   &r   r  Constant.__str__  s    dkk))r   )r  r  r4  N)r.   r/   r0   r1   r2   r  r  r4   r   r   r   r  r    s    %
* *r   r  c                      ] tR tRtRtRtRtR# )DocumentParametersi  z#Global parameters for the document.Fr   N)r.   r/   r0   r1   r2   displaymoder4   r   r   r   r  r    s
    )Kr   r  c                  >    ] tR tRtRtR tR tR tR tR t	R t
R	tR
# )FormulaParseri  zParses a formulac                2   VP                   ^,           V n        V P                  V4      pV'       ge   VP                  4        V P                  V4      pV'       g<   \        P                  RVP                  4       P                  4       ,           4       R.# V.# )zSee if the formula is inlinedzUnknown formula type in unknown)r  re   	parsetyper  r   r&   r  r  )r  r  rf  s   && r   r  FormulaParser.parseheader  ss    &&*
~~f%OO>>&)D69K9K9M9S9S9UUV!{"vr   c                   VP                  4       P                  \        P                  R,          4      ^ 8  d   R# VP                  4       P                  \        P                  R,          4      ^ 8  d   R# VP                  4       P                  \        P                  R,          4      ^ 8  d   R# VP                  4       P                  \        P                  R,          4      ^ 8  d   R# R# )	z)Get the formula type from the first line.r   inliner   blockr   r   numberedN)r  findrX   r  r  s   &&r   r  FormulaParser.parsetype  s    $$]%9%9(%CDI$$]%9%9)%DEJ$$]%9%9,%GHAM$$]%9%9-%HIQNr   c                ^   V P                  V4      pVP                  4       P                  V P                  4      '       g]   VP                  4       P	                  4       p\        V4      ^ 8  d   \        P                  RV,           4       VP                  4        K  VP                  4        V# )zParse the formula until the endzUnparsed formula line )	parseformular  r  r  r  r  r   r&   r  )r  r  formulastrippeds   &&  r   r  FormulaParser.parse  s~    ##F+$$&11$++>>))+113H8}q 4x?@OOr   c                   \         P                  R,          pW!P                  4       9   dR   VP                  4       P                  V^4      ^,          pW#9   d   V P	                  WV4      # V P                  WV4      # \         P                  R,          VP                  4       9   d>   V P                  V\         P                  R,          \         P                  R,          4      # \         P                  R,          p\         P                  R,          pWAP                  4       9   Ed,   VP                  4       P                  4       P                  V4      '       d   VP                  4       P                  4       pVP                  V4      ^,          P                  V4      pWG^ ,          ,           V,           p\         P                  R,          p	\         P                  R,          p
W^ ,          ,           V
,           pWP                  WV4      ,           V,           # \        P                  RV,           R,           VP                  4       ,           4       R	# \         P                  R
,          p\         P                  R,          pWP                  4       9   d>   WP                  4       9   d*   \         P                  R,          pV P                  WV4      # \        P                  RVP                  4       ,           R,           4       R	# )zParse the formula contentsr   r   r   r   r   r   zMissing z in rN   r   r   zFormula beginning z is unknown)rX   r  r  r0  parsesinglelinerparsemultilinerr   r  r-  r   r&   )r  r  r   restr   r   r%  endsplit
startpiecer   r   endpiecebegincommandbeginbracket
endbrackets   &&             r   r  FormulaParser.parseformula  sI   %%h/''))%%'--fa8;D~,,VVDD''??	*f.@.@.BB''0D0DY0O(5(=(=i(HJ J#**=9")),7
,,..!!#))+44Z@@ ,,.446"==5a8>>zJ(A;6C
)11+>	(00<${2X=!$8$8X$VVYaaaKK
Z/&86;M;M;OOP$++I6$++I6--//LDVDVDX4X&..y9J''jII(6+=+=+??-OPr   c                   VP                  4       P                  4       pW$9  d-   \        P                  RV,           R,           V,           4       R# VP	                  V4      '       g-   \        P                  RV,           R,           V,           4       R# VP                  V4      pWE\        V4      ,           \        V4      )  pVP                  4        V# )zParse a formula in one lineLine   does not contain formula start rN   zFormula z does not end with )r  r  r   r&   r-  r  r  r  )r  r  startr  r,  r  r  s   &&&&   r   r  FormulaParser.parsesingleliner;  s    !!#))+KK$)KKeST}}V$$KK
T),AAFJK

5!CJ&F|4r   c                   RpVP                  4       pW%9  d;   \        P                  RVP                  4       ,           R,           V,           4       R# VP	                  V4      pWV\        V4      ,           R P                  4       pVP                  V4      '       g2   WER,           ,          pVP                  4        VP                  4       pKH  WER\        V4      )  ,          pVP                  4        V# )z!Parse a formula in multiple linesrN   r  r  Nr*   )r  r   r&   r  r  r  r-  r  )r  r  r  r  r  r,  r  s   &&&&   r   r  FormulaParser.parsemultilinerI  s    !!#KK$**,.1SSV[[\

5!CJ&'(..0--''d{"GOO%%'D#f+&&r   r  N)r.   r/   r0   r1   r2   r  r  r  r  r  r  r4   r   r   r   r  r    s$    

	!Fr   r  c                  h    ] tR tRtRtRt^tRtR R ltR t	R R	 lt
R
 R ltR tR tR R ltRtR# )
FormulaBiti[  zA bit of a formulaNrN   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   FormulaBit.__annotate__b  s     ' '$ 'r   c                2    . V n         \        4       V n        R# )z6The formula bit type can be 'alpha', 'number', 'font'.N)r  r  r  rN  s   &r   r  FormulaBit.__init__b  s    $&r   c                    Wn         V # )z!Set the internal formula factory.)r  )r  r  s   &&r   
setfactoryFormulaBit.setfactoryg  s    r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r  l  s      $ r   c                    V P                   P                  V4       V ;P                  VP                  ,          un        Wn        R# )z-Add any kind of formula bit already processedN)r  r$  ra  rL  r  bits   &&r   r  FormulaBit.addl  s+    S!%
r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r  r  s     L L4 Lr   c                    V ;P                   V,          un         VP                  V4      '       g;   \        P                  RV,           R,           VP	                  4       ,           4       R# R# )z0Skip a string and add it to the original formulazString z not at N)ra  r  r   r&   r  )r  r4  r  s   &&&r   skiporiginalFormulaBit.skiporiginalr  sF    }}V$$KK	F*Z7#..:JJK %r   c                    \        V P                  4      ^ 8X  d   ^# \        R V P                   4       4      V n        V P                  # )zDCompute the size of the bit as the max of the sizes of all contents.c              3  8   "   T F  qP                   x  K  	  R # 5ir
  sizer   r  s   & r   r   )FormulaBit.computesize.<locals>.<genexpr>|  s     BMMr>  )r  r  r   r  rN  s   &r   computesizeFormulaBit.computesizex  s6    t}}"BDMMBB	yyr   c                L    V P                   P                  V P                  4      # zReturn a copy of itself.)r  r  ra  rN  s   &r   rb  FormulaBit.clone  s    ||((77r   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   r    s     E E Er   c                ^    V P                   P                  R,           V P                  ,           # )zGet a string representationz	 read in )r`  r.   ra  rN  s   &r   r  FormulaBit.__str__  s     ~~&&4t}}DDr   )r  r  r  r  )r.   r/   r0   r1   r2   rf  r  ra  r  r  r  r  r  rb  r  r4   r   r   r   r  r  [  s?    DDH'

L8E Er   r  c                  0    ] tR tRtRtR tRR ltR tRtR# )		TaggedBiti  zA tagged string in a formulac                v    \        4       P                  V4      V n        V P                  \	        V4      4       V # zSet the constant and the tag)r  r  r  r  r9   )r  r<  r  s   &&&r   r<  TaggedBit.constant  s,    "n++C0*+r   c                N    Wn         \        4       P                  W#4      V n        V # r  )r  r  r  r  )r  r  r  r  s   &&&&r   completeTaggedBit.complete  s      "n++C<r   c                F    \        4       P                  VRR7      V n        V # )z4Set the self-closing tag, no contents (as in <hr/>).T)r  )r  r  r  )r  r  s   &&r   selfcompleteTaggedBit.selfcomplete  s     "n++Ct+<r   )r  r  Nr  )	r.   r/   r0   r1   r2   r<  r  r  r4   r   r   r   r  r    s    "r   r  c                  >    ] tR tRtRtR R ltR tR tR R ltR	t	R
# )r9   i  zA constant string in a formulac                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   FormulaConstant.__annotate__  s      $ r   c                X    \         P                  W4       Wn        ^V n        RV n        R# )zSet the constant stringN)r  r  ra  r  rf  rO  s   &&r   r  FormulaConstant.__init__  s#    $'		r   c                    V P                   # )z+Compute the size of the constant: always 1.r  rN  s   &r   r  FormulaConstant.computesize  s    yyr   c                ,    \        V P                  4      # r  )r9   ra  rN  s   &r   rb  FormulaConstant.clone  s    t}}--r   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   r    s     2 2 2r   c                (    RV P                   ,           # )r|  zFormula constant: r3  rN  s   &r   r  FormulaConstant.__str__  s    #dkk11r   )ra  r  rf  N)
r.   r/   r0   r1   r2   r  r  rb  r  r4   r   r   r   r9   r9     s    $.2 2r   r9   c                  ,    ] tR tRtRtR tR R ltRtR# )rF   i  zA bit of text inside a formulac                >    VP                  4       P                  4       # )zDetect a bit of raw textra  r  s   &&r   detectRawText.detect      {{}$$&&r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   RawText.__annotate__        t r   c                h    VP                  4       pV P                  \        V4      4       RV n        R# )zParse alphabetic textalphaN)rf  r  r9   rf  )r  r  r  s   && r   parsebitRawText.parsebit  s%    '(	r   rf  Nr.   r/   r0   r1   r2   r  r  r4   r   r   r   rF   rF     s    $' r   rF   c                  |    ] tR tRtRt]P                  t]P                  R,          tR R ltR R lt	R R	 lt
R
tR# )rC   i  zA symbol inside a formular   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   FormulaSymbol.__annotate__  s      T r   c                    VP                  4       \        P                  9   d   R# VP                  4       \        P                  9   d   R# R# )zDetect a symbolTF)r%  rC   r  r   r  s   &&r   r  FormulaSymbol.detect  s3    ;;=M444;;=M222r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r    s     > >t >r   c                   VP                  4       \        P                  9   d#   V P                  VP                  4       V4       R# VP                  4       \        P                  9   d8   V P                  \        P                  VP                  4       ,          V4       R# \
        P                  RVP                  4       ,           R,           4       R# )Parse the symbolNzSymbol z
 not found)r%  rC   r  	addsymbolr   r   r&   r  s   &&r   r  FormulaSymbol.parsebit  s    ;;=M444NN3;;=#.;;=M222NN=11#++-@#FI-<=r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r    s     6 6 6r   c                    V P                  VP                  4       V4       V P                  P                  \	        V4      4       R# )zAdd a symbolN)r  r%  r  r$  r9   )r  symbolr  s   &&&r   r  FormulaSymbol.addsymbol  s/    #++--_V45r   r   N)r.   r/   r0   r1   r2   rX   r   r  r  r  r  r4   r   r   r   rC   rC     s4    %%H)),7J>6 6r   rC   c                  ,    ] tR tRtRtR tR R ltRtR# )rB   i  zA string of digits in a formulac                >    VP                  4       P                  4       # )zDetect a digitrk  r  s   &&r   r  FormulaNumber.detect  r  r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   FormulaNumber.__annotate__  s      t r   c                t   a SP                  V3R l4      pV P                  \        V4      4       RV n        R# )zParse a bunch of digitsc                 @   < S P                  4       P                  4       # r
  rk  )r  s   r   rs  (FormulaNumber.parsebit.<locals>.<lambda>  s    #++-"7"7"9r   numberN)r]  r  r9   rf  )r  r  digitss   &f r   r  FormulaNumber.parsebit  s*    9:()	r   r  Nr  r   r   r   rB   rB     s    %' r   rB   c                  R    ] tR tRtRt]P                  R,          tR tR R lt	Rt
R# )	Commenti  z*A LaTeX comment: % to the end of the line.r   c                <    VP                  4       V P                  8H  # )zDetect the %.)r%  r  r  s   &&r   r  Comment.detect  s    {{}

**r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   Comment.__annotate__  s     1 1t 1r   c                V    V ;P                   VP                  R4      ,          un         R# )zParse to the end of the line.r*   N)ra  r  r  s   &&r   r  Comment.parsebit  s    **400r   r   N)r.   r/   r0   r1   r2   rX   r  r  r  r  r4   r   r   r   r  r    s$    0  +E+1 1r   r  c                  8    ] tR tRtRtR tR R ltR R ltRtR	# )

WhiteSpacei  z"Some white space inside a formula.c                >    VP                  4       P                  4       # )zDetect the white space.r{  r  s   &&r   r  WhiteSpace.detect  r  r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   WhiteSpace.__annotate__  s     ) )t )r   c                T    V ;P                   VP                  4       ,          un         R# )zParse all whitespace.N)ra  r  r  s   &&r   r  WhiteSpace.parsebit  s    (r   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   r    s     5 5 5r   c                6    RV P                   ,           R,           # )r|  zWhitespace: *r   )ra  rN  s   &r   r  WhiteSpace.__str__  s    .44r   r   N)	r.   r/   r0   r1   r2   r  r  r  r4   r   r   r   r  r    s    (')5 5r   r  c                      ] tR tRtRt]P                  R,          t]P                  R,          t	R R lt
R tR tR tR	 tR
 tR R ltR R ltR R ltRtR# )r<   i  zA {} bracket inside a formular   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   Bracket.__annotate__  s      $ r   c                >    \         P                  V 4       RV n        R# )z'Create a (possibly literal) new bracketN)r  r  innerrN  s   &r   r  Bracket.__init__  s    D!
r   c                8    VP                  V P                  4      # )zDetect the start of a bracket)rP  r  r  s   &&r   r  Bracket.detect  s    ||DJJ''r   c                <    V P                  WP                  4       V # )zParse the bracket)parsecompleteinnerformular  s   &&r   r  Bracket.parsebit      3 1 12r   c                <    V P                  WP                  4       V # )zParse a text bracket)r)  	innertextr  s   &&r   	parsetextBracket.parsetext   s    3/r   c                <    V P                  WP                  4       V # )zParse a literal bracket)r)  innerliteralr  s   &&r   parseliteralBracket.parseliteral%  r,  r   c                   VP                  V P                  4      '       gE   \        P                  RV P                  ,           R,           VP	                  4       ,           4       R# V P                  V P                  V4       VP                  V P                  4       V! V4       V ;P                  VP                  V P                  4      ,          un        V P                  4        R# )zParse the start and end markszBracket should start with z at N)rP  r  r   r&   r  r  r  r  ra  r  r  )r  r  innerparsers   &&&r   r)  Bracket.parsecomplete*  s    ||DJJ''KK4tzzAFJS^^M]]^$**c*t{{#Ct{{33r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r"  5  s     1 14 1r   c                    VP                  4       '       g-   V P                  V P                  P                  V4      4       KB  R# )z(Parse a whole formula inside the bracketNr@  r  r  parseanyr  s   &&r   r*  Bracket.innerformula5  -    ,,..HHT\\**3/0 !r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r"  :  s     = = =r   c                >   \        \        P                  P                  4       4      \        P                  R,          \        P                  R,          \
        P                  .,           pVP                  4       '       g   VP                  4       V9   d_   V P                  V P                  P                  V4      4       VP                  R4      '       d   V ;P                  R,          un        K  K  V P                  \        VP                  4       4      4       K  R# )z<Parse some text inside the bracket, following textual rules.r   r   rs   N)r#  rX   r  r  r  r  r  r@  r%  r  r  r;  r  ra  r9   rB  )r  r  specialcharss   && r   r.  Bracket.innertext:  s    M99>>@A  +  +MME
 

 ,,..{{},..s34==%%MMS(M & ):;< !r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r"  I  s     & &4 &r   c                z   RV n         VP                  4       '       g{   VP                  4       V P                  8X  g\   VP                  4       V P                  8X  d   V P                  V4       Kg  V ;P                   VP                  4       ,          un         K  V ;P                  V P                   ,          un        R# )zAParse a literal inside the bracket, which does not generate HTML.rN   N)literalr@  r%  r  r  r3  rB  ra  r  s   &&r   r2  Bracket.innerliteralI  sl    ,,..$++)E{{}

*!!#& 11%r   )r$  rD  N)r.   r/   r0   r1   r2   rX   r  r  r   r  r  r  r  r/  r3  r)  r*  r.  r2  r4   r   r   r   r<   r<     sW    #  +E""9-F
(


	1
=& &r   r<   c                  l    ] tR tRtRt]P                  R,          t]P                  R,          t	R t
RtR# )SquareBracketiT  zA [] bracket inside a formular   c                <    \        4       pV P                  Vn        V# )z3Return a new square bracket with the same contents.)rG  r  )r  r   s   & r   rb  SquareBracket.cloneZ  s    /==r   r   N)r.   r/   r0   r1   r2   rX   r  r  r   r  rb  r4   r   r   r   rG  rG  T  s*    #  1E""?3Fr   rG  c                  2    ] tR tRtRtR R ltR R ltRtR# )	MathsProcessoria  zAA processor for a maths construction inside the FormulaProcessor.c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   MathsProcessor.__annotate__d  s     ? ?$ ?r   c                P    \         P                  R\        V 4      ,           4       R# )z$Process an element inside a formula.zUnimplemented process() in Nr  r  r  r  s   &&&r   rw  MathsProcessor.processd  s    1CI=>r   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   rM  h  s     < < <r   c                <    RV P                   P                  ,           # )zReturn a printable description.zMaths processor )r`  r.   rN  s   &r   r  MathsProcessor.__str__h  s    !DNN$;$;;;r   r   N)r.   r/   r0   r1   r2   rw  r  r4   r   r   r   rK  rK  a  s    G?< <r   rK  c                  `    ] tR tRtRt. tR R ltR R ltR R ltR	 R
 lt	R t
R R ltRtR# )FormulaProcessorim  z&A processor specifically for formulas.c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   FormulaProcessor.__annotate__r  s        d  r   c                l    V P                  V4       V P                  V4       V P                  V4       R# )z7Process the contents of every formula bit, recursively.N)processcontentsprocessinsidestraversewholer  s   &&r   rw  FormulaProcessor.processr  s,    S!C 3r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   rW  x  s     * *d *r   c                    \        V\        4      '       g   R# VP                  4        VP                   F  pV P	                  V4       K  	  R# )z&Process the contents of a formula bit.N)r  r  rw  r  rY  r  r  r  s   && r   rY   FormulaProcessor.processcontentsx  s7    #z**||G  ) $r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   rW    s     ) )T )r   c                    \        V\        4      '       g   R# \        VP                  4       FE  w  r#V P                   F  pVP                  VP                  V4       K!  	  V P                  V4       KG  	  R# )z8Process the insides (limits, brackets) in a formula bit.N)r  r  r  r  
processorsrw  rZ  )r  r  r  r  	processors   &&   r   rZ  FormulaProcessor.processinsides  sY    #z**'5NE!__	!!#,,6 - (	 6r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   rW    s       r   c                &   RpV P                  V4       Fy  w  r4VP                  R8X  d   V P                  W44       MOVP                  R8X  d?   V'       d7   VP                  R8X  d&   VP                  P	                  ^ \        R4      4       TpK{  	  R# )z>Traverse over the contents to alter variables and space units.Nr  fontr
      )traverserf  	italicizer  r1  r9   )r  r  lastr  r  s   &&   r   r[  FormulaProcessor.traversewhole  sk    !]]73MCxx7"s-V#h1F##Ax'@AD 4r   c              #    "   VP                    Fi  p\        VR4      '       d$   VP                  '       d   W!P                   3x  K8  \        V\        4      '       g   KP  V P                  V4       Rj  xL
  Kk  	  R#  L
5i)zHTraverse a formula and yield a flattened structure of (bit, list) pairs.rf  N)r  r  rf  r  r  rj  r_  s   && r   rj  FormulaProcessor.traverse  sY     ||Gw''GLLL||++GZ00==111	 $ 2s   3B $B B 3A>4B c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   rW    s     ; ;$ ;r   c                b    VP                  V4      p\        4       P                  V.R4      W#&   R# )z Italicize the given bit of text.r   N)r  r  r  )r  r  r  r  s   &&& r   rk  FormulaProcessor.italicize  s(    s##+..uc:r   r   N)r.   r/   r0   r1   r2   rc  rw  rY  rZ  r[  rj  rk  r4   r   r   r   rU  rU  m  s-    ,J *)2; ;r   rU  c                      ] tR tRtRtR R ltR R ltR R ltR	 tR
 R lt	R R lt
R R ltR R ltR R ltR R ltR R ltRtR# )rA   i  zA LaTeX formulac                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   Formula.__annotate__  s     D D$ Dr   c                	`    \        4       V n        \        4       P                  R 4      V n        R# )zspan class="formula"N)r  r;  r  r  r  rN  s   &r   r  Formula.__init__  s     #o"n++,BCr   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   ru    s       r   c                    V P                   ^ ,          R8X  d   R\        n        M'R\        n        V P                  P	                  RR4       V P                  4        R# )zConvert the formula to tagsr  FTzdiv class="formula"N)r  r  r  r  r  classicrN  s   &r   rw  Formula.process  sB    ;;q>X%-2*-1*KK4d;r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   ru    s          r   c                    \        4       P                  V P                  4      p\        4       P	                  V4       Wn        V.V n        R# )zEMake the contents using classic output generation with XHTML and CSS.N)FormulaFactoryr  rn  rU  rw  rL  r  )r  wholes   & r   rz  Formula.classic  s8     --dkk:""5)r   c                   VP                  R4      '       d   V P                  V4       MVP                  R4      '       d   V P                  V4       MeVP                  R4      '       d   V P                  VR4       M;VP                  R4      '       d   V P	                  VR4       MVP                  R4       V P                  4        V # )z4Parse using a parse position instead of self.parser.z$$r   z\(z\)r   r   zUnparseable formula)r  parsedollarblockparsedollarinlineparseinlinetoparseblocktor&   rw  r  s   &&r   r  Formula.parse  s    ==!!#&]]3""3']]5!!sE*]]5!!c5)II+,r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   ru    s       r   c                8    R.V n         V P                  V4       R# )zParse a $...$ formula.r  N)r  parsedollarr  s   &&r   r  Formula.parsedollarinline  s    jr   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   ru    s     K Kt Kr   c                    R.V n         V P                  V4       VP                  R4      '       g   VP                  R4       R# R# )zParse a $$...$$ formula.r  r   z1Formula should be $$...$$, but last $ is missing.N)r  r  r  r&   r  s   &&r   r  Formula.parsedollarblock  s:    i}}S!!IIIJ "r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   ru    s      $ r   c                v    VP                  R4       VP                  R4      V n        VP                  R4       R# )zParse to the next $.r   N)r  r  rn  r  r  s   &&r   r  Formula.parsedollar  s,    s'',cr   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   ru    s     # #4 #r   c                8    R.V n         V P                  W4       R# )zParse a \(...\) formula.r  Nr  	parseuptor  r  limits   &&&r   r  Formula.parseinlineto  s    js"r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   ru    s     # #$ #r   c                8    R.V n         V P                  W4       R# )zParse a \[...\] formula.r  Nr  r  s   &&&r   r  Formula.parseblockto  s    is"r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   ru    s      t r   c                x    VP                  V4       VP                  R 4      V n        VP                  V4       R# )z1Parse a formula that ends with the given command.c                     R # )Tr   r   r   r   rs  #Formula.parseupto.<locals>.<lambda>  s    tr   N)r  r]  rn  r  r  s   &&&r   r  Formula.parseupto  s*    uhh|,er   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   ru    s     $ $ $r   c                    V P                   '       dA   V P                   P                  '       d%   RV P                   P                  ,           R,           # R# )r|  z	Formula (rj   zUnnumbered formula)r_  r
  rN  s   &r   r  Formula.__str__  s7    <<<DLL///!4!44s::#r   )r  r  r  rn  r;  N)r.   r/   r0   r1   r2   r  rw  rz  r  r  r  r  r  r  r  r  r4   r   r   r   rA   rA     sC    D 
K#
#
$ $r   rA   c                  2    ] tR tRtRtR R ltR R ltRtR# )	WholeFormulai  zParse a whole formulac                   V ^8  d   QhRR/# r  r   )r   s   "r   r   WholeFormula.__annotate__  s     " "T "r   c                ,    VP                  4       '       * # )z"Not outside the formula is enough.)r@  r  s   &&r   r  WholeFormula.detect  s    <<>!!r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r    s     1 1t 1r   c                    VP                  4       '       g-   V P                  V P                  P                  V4      4       KB  R# )zParse with any formula bitNr:  r  s   &&r   r  WholeFormula.parsebit  r=  r   r   Nr  r   r   r   r  r    s    "1 1r   r  c                  x    ] tR tRtRt]]]]]	]
.t]	]
.tRtR R ltR tR tR tR	 R
 ltR tR tR tR tRtR# )r~  i  zConstruct bits of formulaFc                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   FormulaFactory.__annotate__  s      $ r   c                    / V n         R# )z Initialize the map of instances.N	instancesrN  s   &r   r  FormulaFactory.__init__  s	    r   c                r    VP                  4       '       d   R# V P                  V4      P                  V4      # )zDetect a bit of a given type.F)r@  instancer  )r  rf  r  s   &&&r   
detecttypeFormulaFactory.detecttype
  s*    <<>>}}T"))#..r   c                    WP                   9  g   V P                   V,          '       g   V P                  V4      V P                   V&   V P                   V,          # )z"Get an instance of the given type.)r  r_  r  rf  s   &&r   r  FormulaFactory.instance  s@    ~~%T^^D-A-A#';;t#4DNN4 ~~d##r   c                J    \         P                  V4      P                  V 4      # )z+Create a new formula bit of the given type.)r]  r_  r  r  s   &&r   r_  FormulaFactory.create  s    }}T"--d33r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r    s      4 r   c                h    VP                  4       '       g   V P                  V4      '       d   K/  R# R# )zClear any skipped types.N)r@  skipanyr  s   &&r   clearskippedFormulaFactory.clearskipped  s"    ,,..<<$$r   c                    V P                    F<  pV P                  V4      P                  V4      '       g   K+  V P                  W!4      u # 	  R# )zSkip any skipped types.N)skippedtypesr  r  r  r  r  rf  s   && r   r  FormulaFactory.skipany!  s@    %%D}}T"))#..~~d00 & r   c                $   V P                   V P                  ,            F-  pV P                  W!4      '       g   K  V P                  W!4      u # 	  \        P                  RVP                  4       ,           4       \        VP                  4       4      # )z.Parse any formula bit at the current location.zUnrecognized formula at )	typesr  r  r  r   r&   r  r9   rB  r  s   && r   r;  FormulaFactory.parseany(  si    JJ!2!222Dt))~~d00 3 	.1AABs011r   c                    V P                  V4      pRV P                  V&   VP                  V4      pV'       d   VP                  V 4      # V# )z#Parse the given type and return it.N)r  r  r  r  )r  rf  r  r  returnedbits   &&&  r   r  FormulaFactory.parsetype0  sE    mmD!#tll3'))$//
r   c                l   \        V4      pV P                  \        4      pVP                  V4      '       d   VP	                  V4       V# VP                  4       '       gT   \        P                  RVP                  4       ,           4       VP                  \        4       P                  VR4      4       V# )z5Parse a string of text that contains a whole formula.zUnknown formula at: span class="unknown")r  r_  r  r  r  r@  r   r&   r  r  r  r<  )r  r  r  r  s   &&  r   r  FormulaFactory.parseformula9  s    7#L)<<NN3L||~~KK.1AABIIik**74JKLr   r  N)r.   r/   r0   r1   r2   rC   rF   rB   r<   r  r  r  r  definingr  r  r  r_  r  r  r;  r  r  r4   r   r   r   r~  r~    sU     G]GWjQEZ(LH/$42r   r~  c                  r    ] tR tRtRt. t]P                  R,          tRt	R t
R tR tR tR	 tR
 tR tRtR# )FormulaCommandiG  z A LaTeX command inside a formular   Nc                @    VP                  \        P                  4      # )zFind the current command.)rP  r  r  r  s   &&r   r  FormulaCommand.detectN  s    ||N0011r   c                   V P                  V4      pV P                  W!4      pV'       d   V# VP                  R4      '       d   V P                  W!4      pV'       d   V# V P                  P
                  '       g   \        P                  RV,           4       \        4       P                  R4      V n
        V P                  \        V4      4       R# )zParse the command.zUnknown command r  N)\up\Up)extractcommandparsewithcommandr  parseupgreekr  r  r   r&   r  r  r  r  r9   )r  r  r   r  upgreeks   &&   r   r  FormulaCommand.parsebitR  s    %%c*##G1J.//''5G||$$$KK*W45"n++,BC)*r   c                |    \         P                   F'  pWP                  9   g   K  V P                  WV4      u # 	  R# )z0Parse the command type once we have the command.N)r  r  
commandmapparsecommandtype)r  r   r  rf  s   &&& r   r  FormulaCommand.parsewithcommandb  s4    "((D//),,WC@@ ) r   c                    V P                   P                  V4      pVP                  V4       VP                  V4      pV'       d   V# V# )zParse a given command type.)r  r_  
setcommandr  )r  r   rf  r  r  returneds   &&&&  r   r  FormulaCommand.parsecommandtypei  s=    ll!!$'w<<$O
r   c                   VP                  \        P                  4      '       g)   VP                  R\        P                  ,           4       R# VP	                  4       '       d   V P                  V4      # VP                  4       P                  4       '       d9   \        P                  VP                  4       ,           pVP                  R4       V# \        P                  VP                  4       ,           # )z.Extract the command from the current position.zMissing command start Nr   )
r  r  r  r&   r@  emptycommandr%  rb  rf  rB  )r  r  r   s   && r   r  FormulaCommand.extractcommandr  s    }}^1122II.1E1EEF<<>>$$S));;=  ""$**S]]_<GMM#N##coo&777r   c                    RpVP                  4       '       g2   VP                  4       pV'       d   VP                  V4      '       d   Tp\        P                  V,           # )zmCheck for an empty command: look for command disguised as ending.
Special case against '{ \{ \} }' situation.rN   )rH  r  r  r  r  )r  r  r   r  s   &&  r   r  FormulaCommand.emptycommand  sG     yy{{^^%F#--// ##g--r   c                ~   \        V4      ^8  d   R# VP                  R4      '       d   RVR,          ,           pMbVP                  R4      '       d.   RVR,          P                  4       ,           VR,          ,           pM\        P                  RV,           4       R# V P                  W24      pV'       d   R	Vn        V# )
zParse the Greek \up command..Nr  rd   :   NNr  :r     N:r  NNzImpossible upgreek command: rh  )r  r  r  upperr   r&   r  rf  )r  r   r  	upcommandr  s   &&&  r   r  FormulaCommand.parseupgreek  s    w<!f%%wr{*I]]6""ws|1133gbkAIKK6@A''	7!GLr   r  )r.   r/   r0   r1   r2   r  rX   r  r  r  r  r  r  r  r  r  r  r4   r   r   r   r  r  G  sB    &E  +EJ2 8 .r   r  c                  D    ] tR tRtRtR R ltR tR tR tR t	R	 t
R
tR# )
CommandBiti  z%A formula bit that includes a commandc                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   CommandBit.__annotate__  s     < <T <r   c                    Wn         V P                  '       d>   V ;P                  V,          un        V P                  V P                   ,          V n        R# R# )zSet the command in the bitN)r   r  ra  
translated)r  r   s   &&r   r  CommandBit.setcommand  s7    ???MMW$M"oodll;DO r   c                    V P                   P                  V4       VP                  4       '       d   R# V P                   P                  V4      pV P	                  V4       V# )z)Parse a parameter at the current positionN)r  r  r@  r;  r  )r  r  	parameters   && r   r  CommandBit.parseparameter  sH    !!#&<<>>LL))#.	r   c                    V P                   P                  V4       V P                   P                  \        V4      '       g   R# V P                   P	                  \        V4      pV P                  V4       V# )zParse a square bracketN)r  r  r  rG  r  r  r  r  r   s   && r   parsesquareCommandBit.parsesquare  sU    !!#&||&&}c::,,((<r   c                   V P                   P                  V4       V P                   P                  \        V4      '       gS   VP	                  4       '       g-   \
        P                  RVP                  4       ,           4       R# VP                  4       # \        4       P                  V P                   4      pV P                  VP                  V4      4       VP                  # )zParse a literal bracket.zNo literal parameter found at: N)r  r  r  r<   r}  r   r&   r  r  r  r  r3  rD  r  s   && r   r3  CommandBit.parseliteral  s    !!#&||&&w44;;===@PPQ==?")&&t||4%%c*+r   c                &   V P                   P                  V4       V P                   P                  \        V4      '       g   R# \        4       P	                  V P                   4      pV P                  VP                  V4      4       VP                  # )z!Parse a square bracket literally.N)r  r  r  rG  r  r  r3  rD  r  s   && r   parsesquareliteralCommandBit.parsesquareliteral  se    !!#&||&&}c::/,,T\\:%%c*+r   c                ^   V P                   P                  V4       V P                   P                  \        V4      '       g)   \        P                  RV P                  ,           4       R# \        4       P                  V P                   4      P                  V4      pV P                  V4       V# )zParse a text parameter.zNo text parameter for N)
r  r  r  r<   r   r&   r   r  r/  r  r  s   && r   r/  CommandBit.parsetext  sv    !!#&||&&w44KK04<<?@)&&t||4>>sCr   )r   r  N)r.   r/   r0   r1   r2   r  r  r  r3  r   r/  r4   r   r   r   r  r    s#    +<
r   r  c                  >    ] tR tRtRt]P                  tR R ltRt	R# )r?   i  z%An empty command (without parameters)c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   EmptyCommand.__annotate__  s     ; ;t ;r   c                <    \        V P                  4      .V n        R# )z"Parse a command without parametersNr9   r  r  r  s   &&r   r  EmptyCommand.parsebit  s    (9:r   r  N)
r.   r/   r0   r1   r2   rX   r   r  r  r4   r   r   r   r?   r?     s    +''J; ;r   r?   c                  >    ] tR tRtRt]P                  tR R ltRt	R# )rG   i  z<An empty command which should have math spacing in formulas.c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   SpacedCommand.__annotate__  s     Q Qt Qr   c                X    \        RV P                  ,           R,           4      .V n        R# )z4Place as contents the command translated and spaced.ri  Nr  r  s   &&r   r  SpacedCommand.parsebit  s!    
 )DOO)Ch)NOPr   r  N)
r.   r/   r0   r1   r2   rX   r   r  r  r4   r   r   r   rG   rG     s    F--JQ Qr   rG   c                  B    ] tR tRtRt]P                  tRtR R lt	Rt
R# )r;   i  z:A command without parameters whose result is alphabetical.c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   AlphaCommand.__annotate__  s        t  r   c                x    \         P                  W4       V P                  V P                  9  d
   RV n        R# R# )z'Parse the command and set type to alphar  N)r?   r  r   greek_capitalsrf  r  s   &&r   r  AlphaCommand.parsebit  s0    d(<<t222  DI 3r   r  N)z\Xiz\Thetaz\Piz\Sigmaz\Gammaz\Lambdaz\Phiz\Psiz\Deltaz\Upsilonz\Omega)r.   r/   r0   r1   r2   rX   r   r  r  r  r4   r   r   r   r;   r;     s!    D,,J.N   r   r;   c                  N    ] tR tRtRt]P                  tRtR R lt	R R lt
RtR	# )
rD   i	  zA function of one parameterFc                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   OneParamFunction.__annotate__	  s     " "t "r   c                    \        4       P                  V P                  4      V n        V P	                  V4       V P                  4        R# )z#Parse a function with one parameterN)r  r  r  r  r  simplifyifpossibler  s   &&r   r  OneParamFunction.parsebit	  s4    "n++DOO<C !r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r  	  s     # #D #r   c                    V P                   V P                  9   d<   \        4       V n        V P                  V P                   ,          .V n        RV n        R# R# )z&Try to simplify to a single character.TN)ra  r  r  r  r  
simplifiedrN  s   &r   r  #OneParamFunction.simplifyifpossible	  s>    ==DOO+%-DK78DI"DO ,r   )r  r  r  N)r.   r/   r0   r1   r2   rX   r   r  r  r  r  r4   r   r   r   rD   rD   	  s$    !++JJ"# #r   rD   c                  J    ] tR tRtRt]P                  tR R ltR R lt	Rt
R# )	rH   i	  z>Find a function which is represented by a symbol (like _ or ^)c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   SymbolFunction.__annotate__	  s     : :T :r   c                D    VP                  4       \        P                  9   # )zFind the symbol)r%  rH   r  r  s   &&r   r  SymbolFunction.detect	  s    {{} 9 999r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r!  	  s     ! !t !r   c                    V P                  VP                  4       4       VP                  V P                  4       \	        4       P                  V P                  4      V n        V P                  V4       R# )r  N)	r  r%  r  r   r  r  r  r  r  r  s   &&r   r  SymbolFunction.parsebit	  sJ    &"n++DOO<C r   r  N)r.   r/   r0   r1   r2   rX   r  r  r  r  r4   r   r   r   rH   rH   	  s    D..J:! !r   rH   c                  J    ] tR tRtRt]P                  tR R ltR R lt	Rt
R# )	rI   i&	  z-A function where parameters are read as text.c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   TextFunction.__annotate__+	  s      t r   c                x    \        4       P                  V P                  4      V n        V P	                  V4       R# )zParse a text parameterN)r  r  r  r  r/  r  s   &&r   r  TextFunction.parsebit+	  s&    "n++DOO<sr   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r)  0	  s       r   c                    RV n         R# )zSet the type to fontrh  Nr  rN  s   &r   rw  TextFunction.process0	  s	    	r   )r  rf  N)r.   r/   r0   r1   r2   rX   r  r  r  rw  r4   r   r   r   rI   rI   &	  s    3,,J
 r   rI   c                  >    ] tR tRtRt]P                  tR R ltRt	R# )r@   i5	  z2A function of one parameter that changes the font.c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   FontFunction.__annotate__;	  s     " " "r   c                4    RV n         V P                  4        R# )z.Simplify if possible using a single character.rh  N)rf  r  rN  s   &r   rw  FontFunction.process;	  s    	!r   r  N)
r.   r/   r0   r1   r2   rX   r   r  rw  r4   r   r   r   r@   r@   5	  s    < ,,J" "r   r@   c                  T    ] tR tRtRtRR R lltR tR tR tR t	R	 t
R
 tR tRtR# )
BigBracketiG	  zA big bracket generator.c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   BigBracket.__annotate__J	  s     = = =r   c                    Wn         W n        W0n        RV n        V\        P
                  9   d   \        P
                  V,          V n        R# R# )z(Set the size and symbol for the bracket.N)r  ra  	alignmentr  rX   r   )r  r  r   r9  s   &&&&r   r  BigBracket.__init__J	  s=    	"m///'33G<DK 0r   c           	     p    \        V R\        \        V P                  4      4      ,           4      pV! V4      # )z%Return the nth piece for the bracket.getpiece)r  r  r  r  )r  r  functions   && r   r<  BigBracket.getpieceS	  s+    4c#dkk2B.C!CDr   c                (    V P                   ^ ,          # )z1Return the only piece for a single-piece bracket.)r  r  r  s   &&r   	getpiece1BigBracket.getpiece1X	  s    {{1~r   c                    V^ 8X  d   V P                   ^ ,          # WP                  ^,
          8X  d   V P                   R,          # V P                   ^,          # )zGGet the nth piece for a 3-piece bracket: parenthesis or square bracket.r,  r  r  r@  s   &&r   	getpiece3BigBracket.getpiece3\	  sA    A:;;q>!IIM!;;r?"{{1~r   c                   V^ 8X  d   V P                   ^ ,          # WP                  ^,
          8X  d   V P                   ^,          # WP                  ^,
          ^,          8X  d   V P                   ^,          # V P                   ^,          # )z7Get the nth piece for a 4-piece bracket: curly bracket.rD  r@  s   &&r   	getpiece4BigBracket.getpiece4d	  sb    A:;;q>!IIM!;;q>!YY]A%%;;q>!{{1~r   c                    V P                  V4      pRV P                  ,           R,           p\        4       P                  W#4      # )z'Get the bracket piece as an array cell.zspan class="bracket align-r   )r<  r9  r  r<  )r  r  r  spans   &&  r   getcellBigBracket.getcelln	  s6    e$+dnn<sB{##E00r   c                P   V P                   ^8X  g   V P                  '       g   V P                  4       # . p\        V P                   4       F>  pV P	                  V4      pVP                  \        4       P                  V.R4      4       K@  	  \        4       P                  VR4      .# )z3Get the bracket as an array or as a single bracket.span class="arrayrow"span class="array")r  r  getsinglebracketrangerL  r$  r  r  )r  rowsr  cells   &   r   getcontentsBigBracket.getcontentst	  s    99>((**499%E<<&DKK	,,dV5LMN & $$T+?@AAr   c                    V P                   R8X  d   \        4       P                  RR4      .# \        4       P                  V P                   R4      .# )z$Return the bracket as a single sign.r   rN   zspan class="emptydot"rq   )ra  r  r<  rN  s   &r   rQ  BigBracket.getsinglebracket~	  sD    ==CK((-DEFF$$T]]4KLMMr   )r9  ra  r  r  N)r   )r.   r/   r0   r1   r2   r  r<  rA  rE  rH  rL  rU  rQ  r4   r   r   r   r5  r5  G	  s/    =
1BNr   r5  c                  *    ] tR tRtRtRtR R ltRtR# )FormulaEquationi	  zA simple numbered equation.equationc                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   FormulaEquation.__annotate__	  s     < <t <r   c                    \        4       V n        V P                  V P                  P	                  \
        V4      4       R# )Parse the arrayN)r  r  r  r  r  r  r  s   &&r   r  FormulaEquation.parsebit	  s)    $&''c:;r   r  Nr.   r/   r0   r1   r2   r  r  r4   r   r   r   rZ  rZ  	  s    !E< <r   rZ  c                  ,    ] tR tRtRtR tR R ltRtR# )FormulaCelli	  zAn array cell inside a rowc                	l    Wn         \        4       P                  R V,           R,           R4      V n        V # )zspan class="arraycell align-r   T)r9  r  r  r  )r  r9  s   &&r   setalignmentFormulaCell.setalignment	  s7    ""n++,J.7-8:=->?CEr   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   FormulaCell.__annotate__	  s     < <t <r   c                	    V P                   P                  V4       VP                  4       '       d   R # V P                  V P                   P	                  \
        V4      4       R # r
  )r  r  r@  r  r  r  r  s   &&r   r  FormulaCell.parsebit	  s?    !!#&<<>>''c:;r   )r9  r  N)r.   r/   r0   r1   r2   re  r  r4   r   r   r   rc  rc  	  s     < <r   rc  c                  X    ] tR tRtRt]P                  R,          tR tR R lt	R t
RtR	# )

FormulaRowi	  zAn array row inside an arrayrf   c                	P    Wn         \        4       P                  R R4      V n        V # )rO  T)
alignmentsr  r  r  )r  rn  s   &&r   setalignmentsFormulaRow.setalignments	  s#    $"n++,CTJr   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   FormulaRow.__annotate__	  s     ( (t (r   c                x   ^ pVP                  V P                  RR7       VP                  4       '       gZ   V P                  V4      pVP	                  V4       V P                  V4       V^,          pVP                  V P                  4       Ko  \        V P                  4      ^ 8X  d   \        4       V n
        R# R# )zParse a whole rowT)r  N)r  rf   r@  
createcellr  r  r  r  r  r  r  )r  r  r  rT  s   &&  r   r  FormulaRow.parsebit	  s    t))D9,,..??5)DMM#HHTNQJEMM$,,-t}}"%-DK #r   c                    V P                   V\        V P                   4      ,          ,          pV P                  P                  \        4      P                  V4      # )z4Create the cell that corresponds to the given index.)rn  r  r  r_  rc  re  )r  r  r9  s   && r   rt  FormulaRow.createcell	  s>    OOEC,@$@A	||"";/<<YGGr   rn  r  N)r.   r/   r0   r1   r2   rX   r   rf   ro  r  rt  r4   r   r   r   rl  rl  	  s%    "!''8M
(Hr   rl  c                  D    ] tR tRtRtR R ltR tR R ltR R	 ltR
t	R# )MultiRowFormulai	  zA formula with multiple rows.c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   MultiRowFormula.__annotate__	  s     # # #r   c                    . V n         RpV P                  V4       F@  pV'       d   RpMV P                  4        VP                  V4       V P	                  V4       KB  	  \        V P                   4      V n        R# )z,Parse all rows, finish when no more row endsTFN)rS  iteraterowsaddemptyr  addrowr  r  )r  r  firstrows   &&  r   	parserowsMultiRowFormula.parserows	  s_    	##C(C LLKK ) 		N	r   c              #  \  "   \         P                  R,          p VP                  VR4       V P                  P	                  \
        4      pVP                  V P                  4      x  VP                  V4      '       d+   V ;P                  VP                  V4      ,          un	        K  R# 5i)z0Iterate over all rows, end when no more row endsrh   TN)rX   r   r  r  r_  rl  ro  rn  rP  ra  r  )r  r  rh   r  s   &&  r   r~  MultiRowFormula.iteraterows	  sx     $**>:NN<.,,%%j1C##DOO44||L))|!<<s   A=B, ,B,c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r|  	  s      $ r   c                n   V P                   P                  \        4      P                  V P                  4      p\        V P                  R,          P                  4       FA  w  r#VP                  V4      pVP                  \        R4      4       VP                  V4       KC  	  V P                  V4       R# )zAdd an empty row.u    Nr,  )r  r_  rl  ro  rn  r  rS  r  rt  r  r9   r  )r  r  r  originalcellrT  s   &    r   r  MultiRowFormula.addempty	  s~    ll!!*-;;DOOL#,TYYr]-C-C#DE>>%(DHH_U+,GGDM $E 	Cr   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r|  	  s      T r   c                ^    V P                   P                  V4       V P                  V4       R# )z2Add a row to the contents and to the list of rows.N)rS  r$  r  )r  r  s   &&r   r  MultiRowFormula.addrow	  s    		r   )rS  r  N)
r.   r/   r0   r1   r2   r  r~  r  r  r4   r   r   r   rz  rz  	  s    ##
 r   rz  c                  6    ] tR tRtRtRtR R ltR R ltRtR	# )
FormulaArrayi	  zAn array within a formular   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   FormulaArray.__annotate__	  r  r   c                    \        4       P                  RR4      V n        V P                  V4       V P	                  V4       R# )r_  rP  FN)r  r  r  parsealignmentsr  r  s   &&r   r  FormulaArray.parsebit	  s3    "n++,@%HS!sr   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r  	  s     & &d &r   c                    RV n         V P                  V4      pV'       d   W n         V P                  V4      p. V n        V F  pV P                  P	                  V4       K   	  R# )zParse the different alignmentsr   N)valignr   r3  rn  r$  )r  r  rD  ss   &&  r   r  FormulaArray.parsealignments	  sV     ))#.!K##C(AOO""1% r   rn  r  r  N)	r.   r/   r0   r1   r2   r  r  r  r4   r   r   r   r  r  	  s    E& &r   r  c                  *    ] tR tRtRtRtR R ltRtR# )FormulaMatrixi
  z'A matrix (array with center alignment).matrixc                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   FormulaMatrix.__annotate__
  s      t r   c                    \        4       P                  RR4      V n        RV n        R.V n        V P                  V4       R# )z(Parse the matrix, set alignments to 'c'.rP  Fr   N)r  r  r  r  rn  r  r  s   &&r   r  FormulaMatrix.parsebit
  s5    "n++,@%H%sr   r  Nra  r   r   r   r  r  
  s    -E r   r  c                  *    ] tR tRtRtRtR R ltRtR# )FormulaCasesi
  zA cases statementcasesc                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   FormulaCases.__annotate__
  s     6 6t 6r   c                   \        4       V n        RR.V n        V P                  V4       V P                   FV  pVP                   FC  pVP                  P                  RR4       VP                  P                  \        R4      4       KE  	  KX  	  \        4       P                  V P                  RR4      p\        \        V P                  4      RR4      pVP                  4       V.,           V n        R# )zParse the casesr   zspan class="case align-l"Tu    zspan class="bracketcases"rm   N)r  r  rn  r  r  r  r$  r9   r  r  r5  r  rU  )r  r  r  rT  r   braces   &&    r   r  FormulaCases.parsebit
  s    $&*s==C""#>E$$_U%;< % ! $$T]]4OQUV3t}}-sC8))+ug5r   )rn  r  r  Nra  r   r   r   r  r  
  s    E6 6r   r  c                  &    ] tR tRtRtR R ltRtR# )EquationEnvironmenti"
  z;A \begin{}...\end equation environment with rows and cells.c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r    EquationEnvironment.__annotate__%
  s      t r   c                   V P                   P                  RR4      p\        4       P                  RV,          R4      V n        V\
        P                  9   d   \
        P                  V,          V n        Mm\        P                  RV P                   ,           4       \        4       P                  R4      V n        V P                  \        RV,          4      4       R.V n        V P                  V4       R	# )
zParse the whole environment.r   rN   zspan class="environment %s"FzUnknown equation environment r  z\begin{%s} r   N)r  r  r  r  r  rX   r   rn  r   r&   r  r9   r  )r  r  environments   && r   r  EquationEnvironment.parsebit%
  s    jj((b1"n++5kA5J-444+88EDOKK7$**DE&.//0FGDKHH_^K%?@A"eDOsr   rx  N)r.   r/   r0   r1   r2   r  r4   r   r   r   r  r  "
  s    C r   r  c                  b    ] tR tRtRt]P                  R,          R/t]]	]
].tR R ltR tRtR	# )
BeginCommandi6
  zEA \begin{}...\end command and what it entails (array, cases, aligned)re   rN   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   BeginCommand.__annotate__=
  s     	 	t 	r   c                z   V P                  V4      pV P                  V4      p\        P                  R,          R,           V,           R,           pVP	                  V4       VP                  V4       V P                  V4       V ;P                  VP                  V4      ,          un        VP                  V n	        R# )zParse the begin commandrg   rm   rn   N)
r3  findbitrX   r   r  r  r  ra  r  r  )r  r  r   r  r  s   &&   r   r  BeginCommand.parsebit=
  s    ##C(ll7#$$U+c1G;cAvSv..HH	r   c                    \         P                   FA  pVP                  RR4      VP                  8X  g   K&  V P                  P                  V4      u # 	  V P                  P                  \        4      pWn        V# )z7Find the command bit corresponding to the \begin{piece}r   rN   )r  r  r  r  r  r_  r  )r  r  rf  r  s   &&  r   r  BeginCommand.findbitH
  s_     &&D}}S"%3||**400 ' ll!!"56	
r   r  N)r.   r/   r0   r1   r2   rX   r   r  rZ  r  r  r  r  r  r  r4   r   r   r   r  r  6
  s2    M%%g.3JlL-HE	r   r  c                  @    ] tR tRt]P
                  tR R ltR tRt	R# )r>   iU
  c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   CombiningFunction.__annotate__Y
  s     J Jt Jr   c                   V P                   pV P                  V4      pV'       g)   \        P                  RV P                  ,           4       R# \        V\        4      '       g3    \        \        P                  4      pVP                  V4      ^ ,          pVP                  P                  R4      '       d   ^pM^pVP                  RV V,           VP                  VR ,           Vn        \        P                  ! RVP                  4      Vn        R#   \         d+    \        P                  RT P                  ,          4        R# i ; i)zParse a combining function.z)Missing parameter for combining function Nz!No base character found for "%s".ri  NFC)r  parsesingleparameterr   r&   r   r  r9   ri  r6   rK   r}  
IndexErrorr4  r  unicodedata	normalize)r  r  	combiningr  	extractorr   s   &&    r   r  CombiningFunction.parsebitY
  s   OO	--c2	KKCdllRS )_55./J/JK	%--i8;	 &&x00AA$++BQ/);i>N>Nqr>RR	&00	8H8HI	  ?$,,NOs   %1D 1EEc                    V P                   P                  V4       VP                  4       '       d   R# V P                  V4      # )z&Parse a parameter, or a single letter.N)r  r  r@  r  r  s   &&r   r  &CombiningFunction.parsesingleparameters
  s3    !!#&<<>>""3''r   r   N)
r.   r/   r0   r1   rX   r   r  r  r  r4   r   r   r   r>   r>   U
  s    11JJ4(r   r>   c                  >    ] tR tRtRt]P                  tR R ltRt	R# )rE   i{
  z;A function that decorates some bit of text with an overset.c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   OversetFunction.__annotate__
       " "t "r   c                   V P                   p\        4       P                  VR4      V n        V P	                  V4      V n        \        4       P                  R4      V n        V P                  P                  ^ V P                  4       \        4       P                  R4      V P
                  n        V P                  4        R# )zParse an overset-functionr   span class="embellished"span class="base"Nr  r  r<  r   r  r  r  r  r  r  r1  r  r  r  r   s   && r   r  OversetFunction.parsebit
      k**659,,S1"n++,FGQ, , 5 56I J!r   r  r  r   N)
r.   r/   r0   r1   r2   rX   r   r  r  r4   r   r   r   rE   rE   {
  s    A//J" "r   rE   c                  >    ] tR tRtRt]P                  tR R ltRt	R# )rJ   i
  z<A function that decorates some bit of text with an underset.c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   UndersetFunction.__annotate__
  r  r   c                   V P                   p\        4       P                  VR4      V n        V P	                  V4      V n        \        4       P                  R4      V n        V P                  P                  ^ V P                  4       \        4       P                  R4      V P
                  n        V P                  4        R# )zParse an underset-functionr   r  r  Nr  r  s   && r   r  UndersetFunction.parsebit
  r  r   r  N)
r.   r/   r0   r1   r2   rX   r   r  r  r4   r   r   r   rJ   rJ   
  s    B00J" "r   rJ   c                  >    ] tR tRtRt]P                  tR R ltRt	R# )LimitCommandi
  z@A command which accepts limits above and below, in display mode.c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   LimitCommand.__annotate__
  s     Q Qt Qr   c                    \        4       P                  R4      V n        V P                  pV P                  P                  \        4       P                  VR4      4       R# )zParse a limit command.span class="limits"zspan class="limit"N)r  r  r  r  r  r$  r  r<  r  s   && r   r  LimitCommand.parsebit
  sB    "n++,ABY[11&:NOPr   r  N)
r.   r/   r0   r1   r2   rX   r   r  r  r4   r   r   r   r  r  
  s    F,,JQ Qr   r  c                  6    ] tR tRtRtRtR R ltR R ltRtR# )	LimitPreviousCommandi
  z(A command to limit the previous command.Nc                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   !LimitPreviousCommand.__annotate__
  s     ' 't 'r   c                x    \        4       P                  R4      V n        V P                  P	                  V4       R# )zDo nothing.r  N)r  r  r  r  r  r  s   &&r   r  LimitPreviousCommand.parsebit
  s)    "n++,AB!!#&r   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   r  
  s     ( ( (r   c                    R# )r|  zLimit previous commandr   rN  s   &r   r  LimitPreviousCommand.__str__
  s    'r   r  )	r.   r/   r0   r1   r2   r  r  r  r4   r   r   r   r  r  
  s    .J'
( (r   r  c                  h    ] tR tRtRtR R ltR tR R ltR R	 ltR
 t	R R lt
R tR tR tRtR# )LimitsProcessori
  z)A processor for limits inside an element.c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   LimitsProcessor.__annotate__
  s     0 0$ 0r   c                   \         P                  '       d   R# V P                  W4      '       d   V P                  W4       V P	                  W4      '       d4   V P	                  W^,           4      '       d   V P                  W4       R# R# R# )z"Process the limits for an element.N)r4  rY  checklimitsmodifylimitscheckscriptmodifyscriptsrO  s   &&&r   rw  LimitsProcessor.process
  sm    H,,h.H,,1A1A(TUI1V1Vx/ 2W,r   c                
   \         P                  '       g   R# V P                  W^,           \        4      '       d   V P	                  W4       R# \        W,          \        4      '       g   R# V P                  W^,           4      # )z3Check if the current position has a limits command.F)r  r  checkcommandr  limitsaheadr  r  r  rO  s   &&&r   r  LimitsProcessor.checklimits
  sc     "---Xqy2FGGX-(/<88!)44r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r  
  s     / /d /r   c                    W^,           ,          P                  W,          P                  4       4       \        4       W,          n        R# )z,Limit the current element based on the next.N)r  rb  r  r  rO  s   &&&r   r  LimitsProcessor.limitsahead
  s.     5 5 78!,r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r  
  s     0 0t 0r   c                |   W,          pV P                  W^,           4      pV P                  W^,           4      '       d   V P                  W^,           4      pM\        4       P                  RR4      pVP                  R8X  d   YErEVP
                  P                  V4       VP
                  P                  ^ V4       R# )zCModify a limits commands so that the limits appear above and below.ri  zsup class="limit"rz   N)getlimitr  r  r<  r   r  r$  r1  )r  r  r  limited	subscriptsuperscripts   &&&   r   r  LimitsProcessor.modifylimits
  s    /MM(AI6	Hai00--!)<K#+..x9LMK#%.	*;/r   c                    V P                  W4      pVP                  P                  P                  RR4      VP                  n        V# )z#Get the limit for a limits command.scriptr  )	getscriptr  r  r  )r  r  r  r  s   &&& r   r  LimitsProcessor.getlimit
  s8    x/ <<++33HgFr   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r  
  s     	( 	( 	(r   c                    V P                  W4      pV P                  W4      pVP                  R8X  d   Y4r4\        4       P                  WC.R4      pVP	                  W%4       R# )z=Modify the super- and subscript to appear vertically aligned.rz   zspan class="scripts"N)r  r   r  r  r1  )r  r  r  r  r  scriptss   &&&   r   r  LimitsProcessor.modifyscripts
  sU    NN83	nnX5#%.+&&'?AWX'r   c                .    V P                  W\        4      # )z6Check if the current element is a sub- or superscript.)r  rH   rO  s   &&&r   r  LimitsProcessor.checkscript
  s      .AAr   c                J    \        V4      V8:  d   R# \        W,          V4      # )z0Check for the given type as the current element.F)r  r  )r  r  r  rf  s   &&&&r   r  LimitsProcessor.checkcommand
  s     x=E!(/400r   c                `    W,          pVP                   ;P                  R,          un        W V# )zGet the sub- or superscript.z class="script")r  r  )r  r  r  r  s   &&& r   r  LimitsProcessor.getscript
  s&    o

++O
r   r   N)r.   r/   r0   r1   r2   rw  r  r  r  r  r  r  r  r  r4   r   r   r   r  r  
  s3    /0
5/
0	(B1r   r  c                  D    ] tR tRtRt]P                  tR R ltR t	Rt
R# )r=   i  z"A command which defines a bracket.c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   BracketCommand.__annotate__	  s     - -t -r   c                0    \         P                  W4       R# )zParse the bracket.N)rD   r  r  s   &&r   r  BracketCommand.parsebit	  s    !!$,r   c                P    W n         RV,           V n        \        V4      .V n        V # )z+Create the bracket for the given character.rd   )ra  r   r9   r  r  	direction	characters   &&&r   r_  BracketCommand.create  s'    !i'(34r   )r   r  ra  N)r.   r/   r0   r1   r2   rX   r   r  r  r_  r4   r   r   r   r=   r=     s    (..J-r   r=   c                  V    ] tR tRtRtR tR R ltR tR tR t	R	 t
R
 tR R ltRtR# )BracketProcessori  z!A processor for bracket commands.c                    \         P                  '       d   R# V P                  W4      '       d   V P                  W4      # R# )z6Convert the bracket using Unicode pieces, if possible.N)r4  rY  	checkleftprocessleftrO  s   &&&r   rw  BracketProcessor.process  s6    >>(**##H44 +r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   BracketProcessor.__annotate__  s     0 0d 0r   c                    V P                  W^,           4      pV'       g   R# V P                  WV4      pV P                  W,          V4       V P                  W,          V4       R# )zProcess a left bracket.N)	findrightfindmaxresize)r  r  r  
rightindexr  s   &&&  r   r  BracketProcessor.processleft  sK    ^^Hai8
||HZ8HOT*H($/r   c                2    V P                  W,          R4      # )z0Check if the command at the given index is left.rp   checkdirectionrO  s   &&&r   r  BracketProcessor.checkleft(  s    ""8?H==r   c                2    V P                  W,          R4      # )z1Check if the command at the given index is right.rr   r(  rO  s   &&&r   
checkrightBracketProcessor.checkright,  s    ""8?I>>r   c                P    \        V\        4      '       g   R# VP                  V8H  # )z6Check if the given bit is the desired bracket command.F)r  r=   r   )r  r  r   s   &&&r   r)  BracketProcessor.checkdirection0  s!    #~..{{g%%r   c                    ^pV\        V4      8  dU   V P                  W4      '       d
   V^,          pV P                  W4      '       d
   V^,          pV^ 8X  d   V# V^,          pKd  R# )z9Find the right bracket starting at the given index, or 0.N)r  r  r,  )r  r  r  depths   &&& r   r"  BracketProcessor.findright6  s[    c(m#~~h..
x//
zQJEr   c                .    WV p\        R V 4       4      # )z@Find the max size of the contents between the two given indices.c              3  8   "   T F  qP                   x  K  	  R # 5ir
  r  r  s   & r   r   +BracketProcessor.findmax.<locals>.<genexpr>F  s     6vG<<vr>  )r   )r  r  	leftindexr%  sliceds   &&&& r   r#  BracketProcessor.findmaxC  s    J/6v666r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r   H  s     1 1t 1r   c                    VP                  4       pVP                  P                  RR4      p\        W#V4      p\	        4       Vn        VP                  4       Vn        R# )z+Resize a bracket command to the given size.rd   rN   N)rK   r   r  r5  r  r  rU  r  )r  r   r  r  r9  r   s   &&&   r   r$  BracketProcessor.resizeH  sM    '')	OO++D"5	Ti8')"..0r   r   N)r.   r/   r0   r1   r2   rw  r  r  r,  r)  r"  r#  r$  r4   r   r   r   r  r    s2    '50>?&7
1 1r   r  c                  T    ] tR tRtRt    RR.tR R ltR tR R ltR R	 lt	R
t
R# )ParameterDefinitioniY  z3The definition of a parameter in a hybrid function.c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r    ParameterDefinition.__annotate__b  s     ! !$ !r   c                	L    R V n         RV n        RV n        R V n        R V n        R # )NF)r  rD  r  r   literalvaluerN  s   &r   r  ParameterDefinition.__init__b  s&    	
 r   c                b   \         P                   F  w  r#VP                  V4      '       g   K  VR8X  d   RV n        VP                  R4      '       g5   \        P                  RVP                  4       ,           R,           4        R# VP                  4       V n        VP                  R4      '       d   RV n	        VP                  V4      '       g.   \        P                  RVP                  4       ,           4        R# V u # 	  \        P                  R	VP                  4       ,           4       R# )
z2Parse a parameter definition: [$0], {$x}, {$1!}...rk   Tr   z$Wrong parameter name, did you mean $r   Nr   zWrong parameter closing z'Wrong character in parameter template: )
r=  parambracketsr  r  r   r&   r%  rB  r  rD  )r  r  openingclosings   &&  r   r  ParameterDefinition.parsei  s    "5"C"CW}}W%%c>$(DM}}S))KK F VY\ \]OO-	==%%#'DL}}W--KK :S__=N NO #D 	=@QQRr   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r?  |  s     6 6T 6r   c                   V P                   '       dp   V P                  '       d   VP                  V4      V n        MVP	                  V4      V n        V P                  '       d   \        V P                  4      V n        R# R# V P                  '       d   VP                  V4      V n        R# VP                  V4      V n        R# )z/Read the parameter itself using the definition.N)	rD  r  r   rA  r3  r9   r   r  r  )r  r  r=  s   &&&r   readParameterDefinition.read|  s    <<<}}}$,$?$?$D!$,$9$9#$>!   ,T->->?
 !]]]!--c2DJ!005DJr   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   r?    s       r   c                    RV P                   ,           pV P                  '       d&   VR\        V P                  4      ,           ,          pV# VR,          pV# )r|  zparam rt   z (empty))r  r   r  )r  r<  s   & r   r  ParameterDefinition.__str__  sH    DII%:::dS_,,F  j Fr   )rD  rA  r  r  r   N)rk   rl   )rm   rn   )r.   r/   r0   r1   r2   rD  r  r  rJ  r  r4   r   r   r   r=  r=  Y  s4    9>A9\,M!&6 r   r=  c                  @    ] tR tRtRt R R ltR tR tR tR t	R	t
R
# )ParameterFunctioni  zFA function with a variable number of parameters defined in a template.c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   ParameterFunction.__annotate__  s     8 8t 8r   c                    / V n         V P                  V4       F3  pVP                  W 4       W0P                   RVP                  ,           &   K5  	  R# )z*Read the params according to the template.r   N)params	paramdefsrJ  r  r  readtemplater  paramdefs   &&& r   
readparamsParameterFunction.readparams  s=    |4HMM#$/7KKhmm+, 5r   c              #     "   \        V4      pVP                  4       '       g*   \        4       P                  V4      pV'       g   K9  Vx  K?  R# 5i)z*Read each param definition in the templateN)r  r@  r=  r  rV  s   &&  r   rU  ParameterFunction.paramdefs  s<     <(,,..*,2237Hx !s   !AAAc                L    WP                   9  d   R# V P                   V,          # )zGet a parameter as parsed.NrT  rQ  s   &&r   getparamParameterFunction.getparam  s    {{"{{4  r   c                8    V P                  V4      P                  # )zGet the value of a parameter.)r_  r   rQ  s   &&r   getvalueParameterFunction.getvalue  s    }}T"(((r   c                t    V P                  V4      pV'       d   VP                  '       g   R# VP                  # )z%Get the literal value of a parameter.N)r_  rA  )r  r  rF  s   && r   getliteralvalue!ParameterFunction.getliteralvalue  s-    d#E...!!!r   r^  N)r.   r/   r0   r1   r2   rY  rU  r_  rb  re  r4   r   r   r   rP  rP    s!    L;8!)"r   rP  c                  n    ] tR tRtRt]P                  tR R ltR t	R t
R tR tR	 tR
 tR R ltRtR# )HybridFunctioni  a  
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                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   HybridFunction.__annotate__  s     ! !t !r   c                    V P                   ^ ,          pV P                   ^,          pV P                  W!4       V P                  V4      V n        V P	                  4        R# )z*Parse a function with [] and {} parametersN)r  rY  writeparamsr  computehybridsize)r  r  rW  writetemplates   &&  r   r  HybridFunction.parsebit  sH    q)**((7 r   c                6    V P                  \        V4      4      # )z*Write all params according to the template)writeposr  )r  rn  s   &&r   rl  HybridFunction.writeparams  s    }}\-899r   c                   . pVP                  4       '       Eg2   VP                  R4      '       d/   V P                  V4      pV'       d   VP                  V4       KZ  K\  VP                  R4      '       d6   V P	                  V4      pV'       d   RVn        VP                  V4       K  K  VP                  R4      '       d$   VP                  V P                  RR4      4       K  VP                  R4      '       d%   VP                  V P                  RR4      4       EK  VP                  \        VP                  4       4      4       EKH  V# )z/Write all params as read in the parse position.r   fNri   leftrj   right)	r@  r  
writeparamr$  writefunctionrf  writebracketr9   rB  )r  r  r<  rF  r=  s   &&   r   rq  HybridFunction.writepos  s    ,,..}}S!!,MM%( s##--c2$(HMMM(+  s##d//<=s##d//=>ocoo.?@Ar   c                   RVP                  4       ,           pW P                  9  d   \        P                  RV,           4       R# V P                  V,          '       g   R# VP	                  R4      '       d1   VP                  4       V P                  V,          P                  n        V P                  V,          P                  # )z*Write a single param of the form $0, $x...r   zUnknown parameter Nr   )rB  rT  r   r&   r  rf  r   rf  )r  r  r  s   && r   rw  HybridFunction.writeparam  s    S__&&{{"KK,t34{{4  ==+.==?DKK##({{4 &&&r   c                   V P                  V4      pV'       g   R# VP                  R4      '       d   \        4       P                  V4      # VP                  R4      '       g   \        P                  R4       R# VP                  R4       V P                  V4      pVP                  4        \        V4      ^ 8X  d   R# \        4       P                  W24      # )z"Write a single function f0,...,fn.Nr   rm   z Function should be defined in {}rn   )readtagr  r  r  r   r&   r  rq  r  r  r  )r  r  r  r  s   &&  r   rx  HybridFunction.writefunction  s    ll3==;++C00}}S!!KK:;s==%x=A{##H22r   c                   VP                  4       P                  4       '       g-   \        P                  RVP                  4       ,           4       R# \	        VP                  4       4      p^V,           \        V P                  4      8  d/   \        P                  R\        V4      ,           R,           4       R# V P                  ^V,           ,          pRV9  d   V# V P                   F  pWC9   g   K  V P                  V,          pVP                  '       g4   \        P                  RV,           R,           V,           R,           4       Kc  VP                  '       d   VP                  pMR	pVP                  WF4      pK  	  V# )
zJGet the tag corresponding to the given index. Does parameter substitution.zFunction should be f0,...,f9: fNz
Function fz is not definedr   zParameters in tag z should be literal: {z!}rN   )r%  rl  r   r&   intrB  r  r  r  rT  rD  rA  r  )r  r  r  r  variablerF  r   s   &&     r   r~  HybridFunction.readtag  s   {{}$$&&KK9CKKMIJCOO%&u9s4??++KKs5z14EEFooa%i(c>JHH-}}}KK 4s :=T TW_ _bf fg%%%!..EEkk(2 $ 
r   c                ^    V P                   P                  \        4      P                  W4      # )z4Return a new bracket looking at the given direction.)r  r_  r=   r  s   &&&r   ry  HybridFunction.writebracket%  s"    ||"">299)OOr   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   rj  )  s     % %4 %r   c                    V P                   \        P                  9  d   V P                  4        R# \        4       P	                  V 4      V n        V P                   F  pV P
                  Vn        K  	  R# )z(Compute the size of the hybrid function.N)r   
HybridSizeconfigsizesr  getsizer  r  )r  r  s   & r   rm   HybridFunction.computehybridsize)  sP    <<z555L((.	}}G99GL %r   )r  r  N)r.   r/   r0   r1   r2   rX   r   r  r  rl  rq  rw  rx  r~  ry  rm  r4   r   r   r   rh  rh    sB    " ..J!:*
'3$2P% %r   rh  c                  8    ] tR tRtRt]P                  tR tRt	R# )r  i4  z+The size associated with a hybrid function.c                ^   V P                   VP                  ,          pVP                   FQ  pW29   g   K  VP                  V,          P                  P	                  4       pVP                  V\        V4      4      pKS  	  RV9   d   \        P                  RV,           4       ^# \        V4      # )z*Read the size for a function and parse it.r   z%Unconverted variable in hybrid size: )
r  r   rT  r   r  r  r  r   r&   eval)r  r=  
sizestringr  r  s   &&   r   r  HybridSize.getsize9  s    %%h&6&67
OOD!t,22>>@'//c$i@
 $ *KK?*LMJr   r   N)
r.   r/   r0   r1   r2   rX   r   r  r  r4   r   r   r   r  r  4  s    1++K
 r   r  c                    \        4       pVP                  V 4      p\        4       P                  V4       VP                  4        RP	                  VP                  4       4      # )zConvert some TeX math to HTML.rN   )r~  r  rU  rw  r?  r  )r  r  r  s   &  r   	math2htmlr  I  sI    G  )Eu%	MMO775==?##r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r   R  s      d r   c                    \         P                  p \        4       P                  V 4       \	        V 4      ^8w  d    \
        P                  R4       \        4        \        V ^ ,          4      p\
        P                  V4       R# )z6Main function, called if invoked from the command linez"Usage: math2html.py escaped_stringN)
r   argvr4  r  r  r   r&   rR  r  r   )r  r<  s     r   mainr  R  sR    88DI4 
4yA~89tAwF	MM&r   __main__)]
__future__r   __docformat__rJ  r   r  docutils.utils.mathr   rV  r   r6   rM   rX   r  r4  r]  ri  r  r  r  r  r  r  r  r  r  r  r  r  r  r1  r7  r;  r  r  r  r  ra  rg  r  r  r  r  r  r9   rF   rC   rB   r  r  r<   rG  rK  rU  rA   r  r~  r  r  r?   rG   r;   rD   rH   rI   r@   r  r5  rZ  rc  rl  rz  r  r  r  r  r  r>   rE   rJ   r  r  r  r=   r  rc  r=  rP  rh  r  r  r  r.   r   r   r   <module>r     s  0 #"  
  + % %P 2  f
 f
RA AH7 7t! !$& &R.F .Fb& " "Jf O 6 6 	 	/ / _  @> @F^ 4"? "t! t!n= =@ &68x 68r!78 !7HE? E?Py ,Ii ,I^	* 	* fF fR*E *EZ
 *2h 2.j 6J 6<J 1j 15 5 E&j E&P
G 
	< 	<2; 2;jL$i L$^
1: 
1F FRSZ Sl9 9x;: ;
QJ 
Q <  "#z #(!Z !": 	"# 	"   8 8 , 0,-! 
;N ;N|<j <<. < H H:)j )X&? &2
O 
6? 6&/ (: 8    & #(( #(L"& " "' " 	Q< 	Q(< (Kn K\% "91~ 91x   *:*L.J J    ')   
8 8v""
 ""Jx%& x%v   $   ( ( $ zF r   