jf٥ ddlZddlZddlZddlmZdZGddZGddZGdd ZGd d Z Gd d Z GddZ GddZ GddZ GddZGddeZGddeZGddeZGddeZGddeZGd d!eZGd"d#ZGd$d%eZGd&d'eZGd(d)eZGd*d+eZGd,d-eZGd.d/eZGd0d1ZGd2d3ZGd4d5ZGd6d7eZGd8d9eZ Gd:d;Z!Gd<d=e!Z"Gd>d?e!Z#Gd@dAe#Z$GdBdCZ%GdDdEeZ&GdFdGe!Z'GdHdIe'Z(GdJdKe$Z)GdLdMe'Z*GdNdOe'Z+GdPdQe'Z,GdRdSe'Z-GdTdUe'Z.GdVdWe'Z/GdXdYe/Z0GdZd[Z1Gd\d]Z2Gd^d_e!Z3Gd`dae'Z4GdbdcZ5Gdddee'Z6Gdfdge6Z7Gdhdie7Z8Gdjdke7Z9Gdldme8Z:Gdndoe7Z;Gdpdqe7Z<Gdrdse7Z=Gdtdue;Z>e5xj?e6ee=e9ge6_?GdvdwZ@Gdxdye7ZAGdzd{e6ZBGd|d}e6ZCGd~de7ZDGddeDZEGddeDZFGddeDZGGddeDZHGdde7ZIe6xj?eIgz c_?Gdde;ZJGdde;ZKGdde;ZLGdde8ZMGddeMZNGdde1ZOGdde;ZPGdde1ZQe6xj?eKeLeJeMePgz c_?e2xjReOeQgz c_RGddZSGdde7ZTGddeTZUGddZVe6xj?eUgz c_?dZWdZXeYdkr eXdSdS)N) tex2unicharz1.3 (2021-06-02)ceZdZdZdZdZdZdZdZdZ dZ dZ dZ e eZe e Z e e Z e e Z e e Z dS) TracezA tracing classFNctjr tjrdSt|tjdS)zShow a debug messageN)r debugmode quietmodeshowsysstdoutclsmessages }/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/docutils/utils/math/math2html.pydebugz Trace.debug+s6 %/  F 7CJ'''''ctjrdStjrtjrtj|z}t|t jdS)zShow a trace messageN)rrprefix showlinesmoder r r r s rrz Trace.message1sM ?  F < -E/ -lW,G 7CJ'''''rcd|z}tjrtjrtj|z}t|tjdS)zShow an error messagez* N)rrrr r stderrr s rerrorz Trace.error9sG. < -E/ -lW,G 7CJ'''''rc^td|ztddS)z#Show an error message and terminatezFATAL: N)rrexitr s rfatalz Trace.fatal@s( I'((( Rrc6||dzdS)zShow a message out of a channel N)write)r rchannels rr z Trace.showEs gn%%%%%r)__name__ __module__ __qualname____doc__rrrrrrrrr classmethodrrrr"sIIM F((( (((((( &&& K  Ek'""G K  E K  E ;t  DDDrrc"eZdZdZdggddZdS)ContainerConfig+Configuration class from elyxer.config fileFormulaConstant) AlphaCommandBracketBracketCommandCombiningFunction EmptyCommand FontFunctionFormula FormulaNumber FormulaSymbolOneParamFunctionOversetFunctionRawText SpacedCommandSymbolFunction TextFunctionUndersetFunctionallowed extractedN)r r!r"r# extracttextr%rrr'r'Ps711&&KKKrr'c*eZdZdZddddZdddd Zd S) EscapeConfigr(’u‘)r'`z&z<z>)&<>N)r r!r"r#charsentitiesr%rrr?r?isB11    E  HHHrr?c eZdZdZidddddddd d d d d ddddddddddddddddddd d!d"d#d$d%iZejD] \ZZ e ed&ez<d'd(d)d*d+Z gd,gd-gd.gd/gd0gd1d2gd3gd4Z d5d6d5d5d7d8Z d9d:d;dd?d@dAdBdCdD Z ejD] \ZZ e e d&ez<id*dEdFdGdHdGdIdJdKdLdMdNdOdPdQdRdSdTdUdRdVdTdWdTdXdRdYdZd[d\d]d^d_d`idad3dbd3dcd2dddEdedfdgdhdidhdjdkdld3dmd2dndodpdqdrd&dsdNdtdudvdRdwdxidydxdzdZd{d|d}d~ddddddddddddddddddddddGddddiddddddddddddddddddddddddddddddddddddddddddddddddddȜZiZeejeejeejeejeejeejeejedɄeDdddddddoddќZddddҜZddddddלZddggdڢddgddgdܜZiddޓddddddddddddddddddddddddddddddddiddddddddddd dޓd d d d ddddddddddddddddddid d!d"d#d$d%d&d'd(d)d*d+d,dd-d.d/dd0d1d2d3d4d5d6d7d8d9d:d d;dd<ddddddd=d>d7d?Zid@gdAdBgdCdDgdEdFgdGdHgdIdJgdKdLgdMdNgdOdPgdQdRgdSdTgdUdVgdWdXgdWdYgdZd[gd\d]gd\d^gd_id`gdadbgdcddgdEdegdfdggdhdigdjdkgdldmgdndogdpdqdrdhgdsgdtdugdvdwgdxdygdzd{gd|d}gdQd~gdgdMgdgd\gdgdgdgdgddZdddddddZddiZ iddddddddddddddddddddddddddddddddddidddddddddddddddddddddd“dÐdēdŐdƓdǐdȓdɐdʓdːdd̐d͓dΐdϐdАdѐdҐdϐdӜZ!dhdhdhdddՐd֐dאdؐdِdڐdېddhdfdݜZ"idސdߓddߓddߓdddddddddddddddddddddddddddddddddhddZ#idddddddddddddd d d d d ddddddddddddddZ$ej%D] \ZZ e e$d&ez<dӐddd&ddd d!d"d# Z&dd$d%Z'd&d'd(d)d*d+d,d-d.d/d0d1 Z(d2gd3iZ)d4S(5 FormulaConfigr(z\AmSzAmSz\AAÅz\AEÆz\DHÐz\LuŁz\OØz\OEuŒz\THÞz\aaåz\aeæz\dhðz\iuız\juȷz\lułz\oøz\oeuœz\ssßz\thþ\z\beginrDz\endz\\)begin cellseparatorend rowseparator)u⎛u⎜u⎝)u⎞u⎟u⎠)u⎡u⎢u⎣)u⎤u⎥u⎦)u⎧⎪u⎨u⎩)u⎫r[u⎬u⎭|‖)()[]{}r\r]span class="stretchy"zz)\leftz\left.z\middle\rightz\right.úüûùũu̧ůu̩u⃝u̥ǔ) z\'z\"z\^z\`z\~z\cz\rz\sz \textcircledz \textsubringz\vz
z\  z\ z \centerdotu⬝z\colon: z \copyright©z \dotminusu∸z\dotsu…z\dotsbu⋯z\dotscz\dotsiz\dotsmz\dotsoz\euro€z\guillemotleft«z\guillemotright»z\hbaru ħz\lVertz \Arrowvertz\lvertz\newlinez \nobreakspace z \nolimitsr@z \nonumberz\qquadu  z\rVertz\rvertz\textasciicircum^z\textasciitilde~z\textbackslashz\textcopyrightz \textdegree°z \textellipsisz \textemdashu—z \textendashz \texteuroz \textgreaterrFz \textlessrEz\textordfeminineªz\textordmasculineºz\textquotedblleftu“z\textquotedblrightu”z\textquoterightrAz\textregistered®z\textrightarrowu→z \textsection§z\texttrademarku™z\texttwosuperior²z\textvisiblespacez \thickspacez! z\;z \triangleu△z \triangledownu▽z \varnothingu⌀z\PrPrz\arccosarccosz\arcsinarcsinz\arctanarctanz\argargz\coscosz\coshcoshz\cotcotz\cothcothz\csccscz\degdegz\detdetz\dimdimz\expexpgcdhomu inj limkerlgu lim infu lim suplnlogu proj limsecsinsinhtantanh)z\gcdz\homz\injlimz\kerz\lgz\liminfz\limsupz\lnz\logz\projlimz\secz\sinz\sinhz\tanz\tanhc#*K|]\}}d|z|fVdS)rVNr%).0keyvalues r zFormulaConfig.s/JJJCTCZ'JJJJJJru‒u$u$u⟵u⟷u⟶u~)z\barz\dddotz\vecz\overleftarrowz\overleftrightarrowz\overrightarrowz\widehatz \widetilde)z\underleftarrowz\underleftrightarrowz\underrightarrowrc\]z\end{ra)bracketcomplexendafter endbefore squarebracketrl)rcrr)aligneqnarraygathered smallmatrixz \boldsymbolbz\mathbbzspan class="blackboard"z \mathbb{A}u𝔸z \mathbb{B}u𝔹z \mathbb{C}uℂz \mathbb{D}u𝔻z \mathbb{E}u𝔼z \mathbb{F}u𝔽z \mathbb{G}u𝔾z \mathbb{H}uℍz \mathbb{J}u𝕁z \mathbb{K}u𝕂z \mathbb{L}u𝕃z \mathbb{N}uℕz \mathbb{O}u𝕆z \mathbb{P}uℙz \mathbb{Q}uℚz \mathbb{R}uℝz \mathbb{S}u𝕊z \mathbb{T}u𝕋z \mathbb{W}u𝕎z \mathbb{Z}uℤz\mathbfz\mathcalzspan class="scriptfont"z \mathcal{B}uℬz \mathcal{E}uℰz \mathcal{F}uℱz \mathcal{H}uℋz \mathcal{I}uℐz \mathcal{L}uℒz \mathcal{M}uℳz \mathcal{R}uℛz \mathfrakzspan class="fraktur"z \mathfrak{C}uℭz \mathfrak{F}u𝔉z \mathfrak{H}uℌz \mathfrak{I}uℑz \mathfrak{R}uℜz \mathfrak{Z}uℨz\mathitiz \mathring{A}z \mathring{U}uŮz \mathring{a}z \mathring{u}uůz \mathring{w}uẘz \mathring{y}uẙz\mathrmzspan class="mathrm"z\mathscrzspan class="mathscr"z \mathscr{B}z \mathscr{E}z \mathscr{F}zspan class="mathsf"zspan class="mathtt")z \mathscr{H}z \mathscr{I}z \mathscr{L}z \mathscr{M}z \mathscr{R}z\mathsfz\mathttz \operatornamez\addcontentsline)z{$p!}{$q!}{$r!}f0{}ignoredz\addtocontents)z {$p!}{$q!}rrz \backmatter)r@rr\binom){$1}{$2}zf2{(}f0{f1{$1}f1{$2}}f2{)}zspan class="binom"zspan class="binomstack"span class="bigdelimiter size2"z\boxed){$1}f0{$1}zspan class="boxed"\cfrac)z [$p!]{$1}{$2}!f0{f3{(}f1{$1}f3{)/(}f2{$2}f3{)}}span class="fullfraction"zspan class="numerator align-$p"span class="denominator"span class="ignored"z\color) {$p!}{$1}rzspan style="color: $p;"z \colorbox)rrz-span class="colorbox" style="background: $p;"\dbinom)ru%(f0{f1{f2{$1}}f1{f2{ }}f1{f2{$2}}})zspan class="binomial"zspan class="binomrow"zspan class="binomcell"\dfrac)rrrspan class="numerator"rrz \displaystyle)rrzspan class="displaystyle"z \fancyfoot)z [$p!]{$q!}rrz \fancyheadz\fbox)rrzspan class="fbox"z \fboxrule){$p!}rrz\fboxsepz \fcolorbox)z{$p!}{$q!}{$1}rzz\bigcapu$z\bigcupu$z\bigodotu$z \bigoplusu$z \bigotimesu$z \bigsqcapu$z \bigsqcupu$z \biguplusu$z\bigveeu$z \bigwedgeu$z\coprodu$z\intopu-z\produ$z\sumu$z\varprodu$z\zcmpu⨟z\zhideu⧹z\zpipeu⨠z \zprojectu⨡z\intz\iintu-z\iiintu-z\iiiintu-z\fintu-z \idotsintu3∫⋯∫z\ointz\oiintu-u-u-u-u-u-)z\oiiintz\ointclockwisez\ointctrclockwisez \smallintz\sqintz\varointclockwise u + u, u  − u  ⁄ z : u  < u = u  > )rrg$rDrB+,-/:rE=rF@roz\bigzspan class="bigdelimiter size1"z\biglz\bigrz\Bigrz\Biglz\Bigrz\biggzspan class="bigdelimiter size3"z\bigglz\biggrz\Biggzspan class="bigdelimiter size4"z\Bigglz\Biggrz \begin{array}zspan class="arraydef"z \centeringzspan class="align-center"z \ensuremathzspan class="ensuremath"z \hphantomzspan class="phantom"z \noindentzspan class="noindent"zspan class="overbrace"zspan class="overline"zspan class="underbrace")z \overbracez \overlinez\phantomz \underbracez \underlinez \vphantomz\nleqqu≦̸z\ngeqqu≧̸z \nleqslantu⩽̸z \ngeqslantu⩾̸z \nsubseteqqu⫅̸z \nsupseteqqu⫆̸z \nsqsubsetu≶⊏z \shortmidu$z\shortparallelu$z \nshortmidu$z\nshortparallelu$z \smallfrownu$z \smallsmileu$z \thickapproxu#z \thicksimu#z \varproptouz\begin{rb%\[rr`*) beginafter beginbeforercommandcommentrsimpler unnumberedsub)rn_zspan class="mbox"zspan class="text"zspan class="textbf"zspan class="textit"zspan class="textnormal"zspan class="textrm"zspan class="textsc"zspan class="textsf"zspan class="textsl"zspan class="texttt"zspan class="normal") z\mboxz\textz\textbfz\textitz \textnormalz\textrmz\textscz\textsfz\textslz\textttz\textup characters).rrjr^r_r`ra·!;r\rt"?N)*r r!r"r# alphacommandsr mathalphaitemsrrarray bigbracketsbracketcommandscombiningfunctions mathaccentcommandscmddictupdatemathbinmathopen mathclose mathfencemathord mathpunctspaceoversetfunctionsundersetfunctionsendings environments fontfunctionshybridfunctions hybridsizeslabelfunctions limitcommandsmodified onefunctionsspacedcommandsmathrelstartssymbolfunctions textfunctions unmodifiedr%rrrJrJysc112t t t  t  t  t t t t t t t t t t!" t#$ t%M("+1133(( U"' d3h   E.-----------444444!'  K*2+*4 O"!!!!!!!!!!  ",2244-- U',48$$UUU U x U 4 U t U eU %U 5U 5U 5U 5U 5U %U 4U D!U" /#UU$ 5%U& 'U( 3)U* W+U, $-U. b/U0 b1U2 83U4 55U6 37U8 S9U: C;U< 4=U> 4?U@ AUB %CUD EUUUF GUH eIUJ KUL cMUN TOUP dQUR eSUT uUUV EWUX DYUZ E[U\ ]U^ 5_U` TaUb ccUd ;eUf 2gUUUh hiUj (kUl mUp qUr HsUt HuUv HwUx yUz {U| &}U~ U@ &AUB CUD EUF GUH IUJ KUUL!iUUUHlG NN;&''' NN;'((( NN;())) NN;())) NN;&''' NN;())) NN;$%%% OOJJ'--//JJJJJJ == %!'."!&" Gs#OO#JSz L')Bv,f6CU v -f7DV v  -e 6CF  v  -f  7DU  v  -e  6CE  u,V6CF v -e6@ .  .u7E u'5e  .u7Ee , !0:I% !09H C!" #" /#$ %$ /%$7Fu%& '( ))* ++, -, .u-,7Ee-.ueu))/7M<.CCC.<<<. ///. RRR . ;;; . ~~~ . EEE. ^^^. VVV. ppp. III. 888. 888. 999. 222. 111!." sss#..$ kkk%.& ggg'.( 000).* ===+., PPP-.. VVV/.4 ___5.6 WWW7.8 ggg9.: 0"5;.< ^^^=.> SSS?.@ GGGA.D rrrE.F HHHG.H VVVI.J qqqK..LJIICCC777DDDKKKRRR333QQQ[...ObwIg9K <N(5(( (  (  (  ( F( =( =( =( =( =( =( =( =( =!(" =#(($ =%(& F'(( =)(* =+(, =-(. %/(.#E/(.,5e/(.>J5/(4 @5(6 A7(8 B9(: C;(< A=(> K?(@ AA(B BC((DDJMEBMO(((MVrE .5FUYk #5BXH 23 3 2  3  3  3 4 4 3 4 4 1 2 1!" ,#$ -%&0-+1,1L8          < A = B > > >!" ;#$ ;%N(")//11)) U#(tCx  *CESCFO &%))1))))))  M <<< JJJrrJc0eZdZdZdZdZdZdZdZdS)CommandLineParserzA parser for runtime optionsc||_dSN)options)selfrs r__init__zCommandLineParser.__init__%s  rclt|dkrdSt|dkr|ddrp||\}}|sd|zdzS|sd|zdzSt|j||t|dkr|ddpdS)Parse command line optionsrN--zOption z not recognizedz needs a value)len startswith readoptionsetattrr)rargsrrs r parseoptionszCommandLineParser.parseoptions(s t99>>4$ii!mmQ 2 24 8 8m..JC = 5(+<<< : 3)999 DL#u - - - $ii!mmQ 2 24 8 8mtrcb|ddd}|d=d|vr|||}n|dd}t|j|sd|fSt |j|}t |t r|dfSt|dkr|dfS|ddr#|d}|d=|| ||fS|d d }|d=t |tr| |||fS||fS) z$Read the key and value for an optionrNrrr@Trzutf-8) readequalskeyreplacehasattrrgetattr isinstanceboolrr readquoteddecodelistappend)rr rzrcurrentinitialrs rr zCommandLineParser.readoption5sH1gabbk G #::$$S$//CC++c2&&Ct|S)) 9 $,,, gt $ $ 9  t99>>9  7  c " " 71gGQg666 6Qw'' G gt $ $ NN5 ! ! !< EzrcZtd|dd}t|dkr|dds|dds}td|dz|d|dzz }|d=t|dkr6|dds|dd}t|dks|ddrdS|d|dd zz }|S) zRead a value between quotesOopsNrrrz Appending rgr)rrrendswithr)rr rrs rrzCommandLineParser.readquotedPs F $ii!mmDG$4$4S$9$9m$q'BTBTUYBZBZm KK tAw. / / / S47] "EQ$ii!mmDG$4$4S$9$9m$q'BTBTUYBZBZm t99>>T!W//55>4 tAbDz!! rc~|dd}|d}|d}|d||S)zRead a key using equalsrrr)splitinsert)rrzr r rrs rrzCommandLineParser.readequalskey]s@ #q!!Aha Au rN) r r!r"r#rr r rrr%rrrr"se""   6   rrcPeZdZdZdZdZdZdZdZdZ dZ iZ dZ dZ dZdZd ZdS) OptionszA set of runtime optionsNFTc |dt_|d=tt}||}|r.t|||dS)rrN)r#locationrr rrusageprocessoptions)rr parserresults rr zOptions.parseoptionstst7 G"7++$$T**   KK    JJLLL rc 6tjr|tjr|t t D]C}|dr,tt |t||ddDdS)zProcess all options parsed.modeN) r#helpr&version showversiondirrrr r)rparams rr'zOptions.processoptionss <  JJLLL ?       ZZ A AE~~f%% AugdE#2#J&?&?@@@ A Arctdtjtjjdtd|dS)zShow correct usagezUsage: z [options] "input string"z.Convert input string with LaTeX math to MathMLN)rrpathlibPathr#r%parent showoptionsrs rr&z Options.usagesi 0gl7+;<<C000 1 1 1 DEEE rc0tdtdtdtdtdtjdS)zShow all possible optionsz1 --help: show this online helpz9 --quiet: disables all runtime messageszF --debug: enable debugging messages (for developers)z@ --version: show version number and release datezD --simplemath: do not generate fancy math constructionsN)rrr rr7s rr6zOptions.showoptionssp GHHH OPPP \]]] VWWW Z[[[  rcptdtztjdS)z(Return the current eLyXer version stringz math2html N)rr __version__r rr7s rr/zOptions.showversions( L,---  r)r r!r"r#r%rquietr.r- simplemath showlinesbranchesr r'r&r6r/r%rrr#r#fsH E EG DJIH    A A Arr#cJeZdZdZdZdZeeZeeZdS)Clonerz&An object used to clone other objects.c8 ||jS)z"Return an exact copy of an object.)create __class__)r originals rclonez Cloner.clones=zz(,---rcX||}||S)z"Create an object of a given class.)__new__r)r typerEs rrBz Cloner.creates( T""  rN)r r!r"r#rErBr$r%rrr@r@sR,,...  K  E [ FFFrr@c*eZdZdZdZdZdZdZdS)ContainerExtractoraA class to extract certain containers. The config parameter is a map containing three lists: allowed, copied and extracted. Each of the three is a list of class names for containers. Allowed containers are included as is into the result. Cloned containers are cloned and placed into the result. Extracted containers are looked into. All other containers are silently ignored. c:|d|_|d|_dS)Nr;r<r:)rconfigs rrzContainerExtractor.__init__si(  ,rc\gfd}fd}fd}||||S)z8Extract a group of selected containers from a container.c*|jjjvSr)rCr r;rrs rz,ContainerExtractor.extract..s1;/4<?rc*|jjjvSr)rCr r<rOs rrPz,ContainerExtractor.extract..sak2dnDrc0|Sr)process)rrrs rrPz,ContainerExtractor.extract..sDLLD11r)recursivesearch)r containerlocate recursiverSrs` @rextractzContainerExtractor.extractsS????DDDD 11111!!&)W=== rc|jj}||jvr||dStd|zdS)zAdd allowed containers.zUnknown container class N)rCr r;rrr)rrUrnames rrSzContainerExtractor.processsP"+ 4<   KK " " " " " KK2T9 : : : : :rct|}|j|_|||_|S)zFReturn a new container with contents only in a safe list, recursively.)r@rEoutputrXcontents)rrUrEs r safeclonezContainerExtractor.safeclones5 Y'' ' i00 rN)r r!r"r#rrXrSr^r%rrrJrJsZ  ---;;;rrJc6eZdZdZdZdZdZdZdZdZ dS) ParserzA generic parserc"d|_i|_dS)Nr)rW parametersr7s rrzParser.__init__s rc|}||j|_|S)zParse the header) currentliner nextline linenumberrW)rreaderheaders r parseheaderzParser.parseheaders>##%%++--&  rc|dd}|t |dkrdS|d}t |dkr d|j|<dSd|dvr$|d|j|<dS|dd}|d|j|<dS)zParse a parameterrgrrNTr)rdstripr rerrb)rrgr r doublesplits rparseparameterzParser.parseparameters""$$**,,223:: u::?? FAh u::??#'DOC F eAh  #(8>>#3#3DOC FAhnnS)) *1~rc4|js,tdt|zdS||js8|||j6dSdS)z'Parse until the current ending is foundzNo ending for N)endingrrstrrdr)rrgrSs r parseendingzParser.parseendings{  KK(3t994 5 5 5 F$$&&11$+>>  GIII$$&&11$+>>     rc|j|}|r#|j|_||dSdSr)factorycreatecontainerr5r)rrgr]rUs rparsecontainerzParser.parsecontainersKL0088  '#{I  OOI & & & & & ' 'rcP|jjdzt|jzdzS)zReturn a description (r_)rCr rprWr7s r__str__zParser.__str__s$~&-DJ?#EErN) r r!r"r#rrirmrqrurxr%rrr`r`sy... ''' FFFFFrr`ceZdZdZdZdS) LoneCommandz"A parser for just one command linecgS)z Read nothingr%rrgs rparsezLoneCommand.parse rNr r!r"r#r}r%rrrzrz s)((rrzc(eZdZdZgZdZdZdZdS) TextParserz(A parser for a command and a bit of textct|d|_|jjt jvr!t j|jj|_g|_dSr)r`rrorCr r'rrrUs rrzTextParser.__init__sO   '?+B B B)1)2E2NODK rcJtj|jtjtjdtjd|jgz|_g}||s+|||||+|S)z$Parse lines as long as they are textLayoutInset)rstackrror'risendingrurrgr]s rr}zTextParser.parse s ,,,!'?+B8+L+:+B7+K+/;+88 --'' 2    1 1 1--'' 2rc*|}t|dkrdS|d|jvrH|dtjvr&tj|dn gt_dSdS)zCheck if text is endingrFT)rdr rrrrremove)rrgrs rrzTextParser.isending+s$$&&,,.. w<<1  5 1: % %qzZ--- '' 3333#%  4urN)r r!r"r#rrr}rr%rrrrsL.. E        rrceZdZdZdZdS)ExcludingParserz%A parser that excludes the final linecFgfdS)z5Parse everything up to (and excluding) the final linec0Sr)ru)r]rgrsrrPz'ExcludingParser.parse..?s)<).Ss):):r)rqrer|s `rr}zBoundedDummy.parseQs8 !:!:!:!:;;; rNrr%rrrrNs),,rrceZdZdZdZdZdS) StringParserzParses just a stringc$|jdz|_gS)zDo nothing, just take noter)rfrWr|s rrizStringParser.parseheader\s&*  rcV|}||S)zParse a single line)rdrers rr}zStringParser.parseas(%%''rN)r r!r"r#rir}r%rrrrYs8 rrceZdZdZdZdZdS)ContainerOutputz(The generic HTML output for a container.cZtdt|zdS)zShow an error.zgethtml() not implemented for Nrrrprs rgethtmlzContainerOutput.gethtmlks& 4s4yy@AAAAArcdS)z5Decide if the output is empty: by default, not empty.Fr%r7s risemptyzContainerOutput.isemptyosurN)r r!r"r#rrr%rrrrhs;..BBBrrceZdZdZdZdS) EmptyOutputcgS)zReturn empty HTML code.r%rs rrzEmptyOutput.gethtmlvr~rcdS)z"This output is particularly empty.Tr%r7s rrzEmptyOutput.isemptyzstrN)r r!r"rrr%rrrrts2rrceZdZdZdZdS) FixedOutputz Fixed outputc|jS)zReturn constant HTML code)htmlrs rrzFixedOutput.gethtmls ~rNr r!r"r#rr%rrrrs(NrrceZdZdZdZdS)ContentsOutputz&Outputs the contents converted to HTMLcg}|j|S|jD]g}t|ds>td|jjzdzt |z|cS||z }h|S)Return the HTML codeNrz No html in rh)r]rrrrCr rpr)rrUrelements rrzContentsOutput.gethtmls   %K ) & &G7I..  MG,=,FFMPST[P\P\\]]] GOO%% %DD rNrr%rrrrs),,     rrcJeZdZdZdZdZdZd dZdZdZ dZ dZ d Z d Z dS) TaggedOutputz-Outputs an HTML tag surrounding the contents.NFc8||_|r||_|r||_|S)z/Set the value for the tag and other attributes.)tag breaklinesempty)rrrrs rsettagzTaggedOutput.settags,  )(DO  DJ rc||_|S)zSet the value for breaklines.)r)rrs r setbreaklineszTaggedOutput.setbreakliness$ rc|jr||gS||g}|t||z }||||S)zReturn the HTML code.)r selfclosingopenrrrclose)rrUrs rrzTaggedOutput.gethtmlst : 1$$Y//0 0 )$$% &&tY777 DJJy))*** rcf||sdSd|jzdz}|jr|dzS|S)zGet opening line.r@rErFrchecktagrr)rrUrs rrzTaggedOutput.opensD}}Y'' 2TX~# ? $;  rc||sdSd|jdzdz}|jrd|zdzS|S)zGet closing line.r@zrr)rrUrs rrzTaggedOutput.selfclosingsF}}Y'' 2DHnt+ ? &% %rc|js,tdt|zdS|jdkrdSdS)zCheck that the tag is valid.z No tag in Fr@T)rrrrprs rrzTaggedOutput.checktagsCx  KK s9~~5 6 6 65 8r>>5tr)FF)r r!r"r#rrrrrrrrrrr%rrrrs33 CJ E rrc,eZdZdZ dZdZdZdZdS)FilteredOutputz1Returns the output in the contents, but filtered:cg|_dS)zInitialize the filters.N)filtersr7s rrzFilteredOutput.__init__s  rc>|j||fdS)z:Add a new filter: replace the original by the replacement.N)rr)rrD replacements r addfilterzFilteredOutput.addfilters# X{344444rcg}t||}|D]*}|||+|S)r)rrrfilter)rrUr)rlines rrzFilteredOutput.gethtmlsQ%%dI66 - -D MM$++d++ , , , , rcT|jD]\}}||vr|||} |S)z0Filter a single line with all available filters.)rr)rrrDrs rrzFilteredOutput.filters<%)\ ; ; !Hk4||Hk:: rN)r r!r"r#rrrrr%rrrrsY77*555rrceZdZdZdZdS) StringOutputzReturns a bare string as outputc|jgS)zReturn a bare stringstringrs rrzStringOutput.gethtmls !!rNrr%rrrrs)%%"""""rrceZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZddZddZdZdS)GlobablezA bit of text which can be globbed (lumped together in bits). Methods current(), skipcurrent(), checkfor() and isout() have to be implemented by subclasses.Fc,t|_dSr) EndingList endinglistr7s rrzGlobable.__init__s$,,rc|rdSt|dkr|dSdS)z*Check for a Unicode byte mark and skip it.Ni)finishedordr skipcurrentr7s r checkbytemarkzGlobable.checkbytemarksR ==??  F t||~~  & ( (         ) (rc:tddS)z+Find out if we are out of the position yet.zUnimplemented isout()Trrr7s risoutzGlobable.isouts +,,,trc:tddS)zReturn the current character.zUnimplemented current()r@rr7s rrzGlobable.currents -...rrc:tddS)z3Check for the given string in the current position.zUnimplemented checkfor()Frrrs rcheckforzGlobable.checkfors .///urc|r"|js|jdS|j|S)z*Find out if the current text has finished.T)r leavependingr checkpendingcheckinr7s rrzGlobable.finishedsL ::<< $ /,,...4&&t,,,rc:tddS))Return the current character and skip it.zUnimplemented skipcurrent()r@rr7s rrzGlobable.skipcurrent&s 1222rrcd}|s?|r5||z }|s |5|S)z>Glob a bit of text that satisfies a check on the current char.r@)rr)r currentcheckglobs rrz Globable.glob+s^--// 'llnn ' D$$&& &D--// 'llnn ' rc4fdS)zGlob a bit of alpha textcPSrrisalphar7srrPz$Globable.globalpha..4!7!7!9!9rrr7s`r globalphazGlobable.globalpha2yy9999:::rc4fdS)zGlob a row of digits.cPSrrisdigitr7srrPz%Globable.globnumber..8rrrr7s`r globnumberzGlobable.globnumber6rrc|s|dkrdSdS)z5Return if the current character is alphanumeric or _.rTF)risalnumr7s r isidentifierzGlobable.isidentifier:s: <<>> ! ! # # t||~~'<'<4urc6||jS)z Glob alphanumeric and _ symbols.)rrr7s rglobidentifierzGlobable.globidentifier@syy*+++rc |rdS|dvrdSdS)z5Return if the current character is a value character:Fz{}()Trisspacer7s risvaluezGlobable.isvalueDsC# <<>> ! ! # # 5 <<>>V # #5trc6||jS)z'Glob a value: any symbols but brackets.)rrr7s r globvaluezGlobable.globvalueMsyy&&&rc4fdS)z(Skip all whitespace at current position.cPSrrr7srrPz$Globable.skipspace..Srrrr7s`r skipspacezGlobable.skipspaceQrrclfdz}|S)z4Glob a bit of text up to (including) the magic char.c4kSrr) magiccharrsrrPz(Globable.globincluding..Ws9!<r)rskip)rr rs`` r globincludingzGlobable.globincludingUs>yy<<<<<== I ) rc8fdS)z?Glob a bit of text up until (excluding) any excluded character.c0vSrr )excludedrsrrPz(Globable.globexcluding..]sx!?rr)rrs``r globexcludingzGlobable.globexcluding[s#yy?????@@@rc<|j||dS)zPush a new ending to the bottomN)raddrrooptionals r pushendingzGlobable.pushending_s  FH-----rNc|r |jr|S|j|}|r)||kr#td|zdz|z|||S)z,Pop the ending found at the current positionzExpected ending z, got )rrrpoprrr )rexpectedros r popendingzGlobable.popendingcs ::<< D- O$$T**  KF** KK*X5@6I J J J & rcL|j|}|sdS|jS)z$Return the next ending in the queue.N)r findendingro)r nextendings rrzGlobable.nextendingms-_//55  4  rFr)r r!r"r#rrrrrrrrrrrrrrrrr rrrrr%rrrrs^""L'''   --- ;;;;;; ,,,''';;; AAA....!!!!!rrcDeZdZdZdZd dZdZdZdZdZ d Z d Z d S) rzA list of position endingscg|_dSr)rr7s rrzEndingList.__init__xs  rFcV|jt||dS)zAdd a new ending to the listN)rrPositionEndingrs rrzEndingList.add{s( N68<<=====rc:|xj|jjz c_dS)z/Pick any pending endings from a parse position.N)rrrposs r pickpendingzEndingList.pickpendings .. rc4||rdSdS)zSearch for an endingTF)rr$s rrzEndingList.checkins ??3   4urc|rtddS||}|s1td|zdSt |jD]O}|j|||kr |jcS|j std|zPtddS)z)Remove the ending at the current positionzNo ending out of boundsr@z No ending at zRemoved non-optional ending zNo endings left) rrrrrreversedrrror)rr%roeachs rrzEndingList.pops 99;;  KK1 2 2 22%%  KK#++--7 8 8 82T\** C CD L   % % %v~~{"""] C :TABBB %&&&rrct|jdkrdStt|jD](\}}||r|cS|jsdS)dS)z'Find the ending at the current positionrN)rr enumerater)rr)rr%indexros rrzEndingList.findendingsy t|   ! !4&x '='=>>  ME6~~c""  ? tt trct|jdkr/tdt |zdzdSdS)z&Check if there are any pending endingsrzPending z left openN)rrrrrpr7s rrzEndingList.checkpendingsG t|   ! ! KK SYY.= > > > > > " !rcd}|jD]}|t|dzz }t|jdkr |dd}|dzS)Printable representationz endings [rrNrra)rrpr)rrros rrxzEndingList.__str__s[l ( (F c&kkC' 'FF t|  q CRC[F|rNr) r r!r"r#rrr&rrrrrxr%rrrrus  >>>>/// $   ??? rrc$eZdZdZdZdZdZdS)r"z An ending for a parsing positionc"||_||_dSrrorrs rrzPositionEnding.__init__s   rc6||jS)zCheck for the ending)rror$s rrzPositionEnding.checkins||DK(((rc2d|jz}|jr|dz }|S)r0zEnding z (optional)r3rs rrxzPositionEnding.__str__s'T[( = $ m #F rN)r r!r"r#rrrxr%rrr"r"sG&&!!!)))rr"cNeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d S) PositionzA position in a text to parse. Including those in Globable, functions to implement by subclasses are: skip(), identifier(), extract(), isout() and current().c:t|dSr)rrr7s rrzPosition.__init__s$rc:tddS)z Skip a stringzUnimplemented skip()Nrrs rr z Position.skips *+++++rc:tddS)z.Return an identifier for the current position.zUnimplemented identifier()Errorrr7s r identifierzPosition.identifiers 0111wrc< tddS)zHExtract the next string of the given length, or None if not enough text,zUnimplemented extract()Nrrlengths rrXzPosition.extracts/ -...trcN||t|kS)z)Check for a string at the given position.)rXrrs rrzPosition.checkforsc&kk2222rc|t|}|sdS||t|kS)z!Check for a string in lower case.F)rXrlower)rrr<s r checkforlowerzPosition.checkforlowersWLLV--  5||~~c&kk!:!:!@!@!B!BBBrcX|}|||S)r)rr rrs rrzPosition.skipcurrents&,,.. 'rcR||S)z3Advance the position and return the next character.)rrr7s r__next__zPosition.__next__s" ||~~rc^||sdS||dS)z;Check for a string at the given position; if there, skip itFT)rr rs r checkskipzPosition.checkskips2}}V$$ 5 &trcjt|dz|zdS)z2Show an error message and the position identifier.rhN)rrr<)rrs rrzPosition.errors- GdNT__%6%6677777rN)r r!r"r#rr r<rXrrCrrGrIrr%rrr7r7s??   ,,,  333CCC  88888rr7c6eZdZdZdZdZdZdZdZdZ dS) TextPositionz%A parse position based on a raw text.c~t|d|_||_|dS)z#Create the position from some text.rN)r7rr%textrrrNs rrzTextPosition.__init__s<$  rc@|xjt|z c_dS)zSkip a string of characters.N)r%rrs rr zTextPosition.skip s CKKrcd}|j|zt|jkrt|j|jz }d|j|j|j|zzdzS)z&Return a sample of the remaining text.rr%rrNr>s rr<zTextPosition.identifiersZ 8f s49~~ - -^^dh.FTYtx6(99::S@@rc<|jt|jkS)z'Find out if we are out of the text yet.rSr7s rrzTextPosition.isoutsx3ty>>))rc&|j|jS)z6Return the current character, assuming we are not out.)rNr%r7s rrzTextPosition.currentsy""rc~|j|zt|jkrdS|j|j|j|zS)zHExtract the next string of the given length, or None if not enough text.NrSr>s rrXzTextPosition.extracts< 8f s49~~ - -4yDHv$5566rN) r r!r"r#rr r<rrrXr%rrrLrLsw++   AAA***###77777rrLceZdZdZdZdZdZdZdZdZ e j fdZ dZ dZd Zd Zd Zd Zd ZdZdZddZdZdZdZdZdS) Containerz.A container for text and objects in a lyx fileNc,t|_dSr)rr]r7s rrzContainer.__init__,s rcdS)zProcess contentsNr%r7s rrSzContainer.process/s rc|j|}t|tr td|z|g}|S)zGet the resulting HTMLz Raw string )r\rrrprr)rrs rrzContainer.gethtml3sL{""4(( dC   KK , - - -6D rct|}|D]"}||vr||||}#|S)z*Escape a line with replacements from a map)sortedkeysr)rr replacementspiecespieces rescapezContainer.escape;sS ))++,, @ @E}}||E<+>?? rcd}t|}|st|dkrtt t|}|dkr,t tt |dz}|d|ddzdzz }n||z }|||S) z/Escape all Unicode characters to HTML entities.r@0xd835iz&#rNr)rLrrrhexnextr)rrr)r% codepoints rescapeentitieszContainer.escapeentitiesDs4  ,,.. 3;;==!!C''CKKMM 2 233 (( #CS NNV$; < g||fdS)z2Search for all embedded containers of a given typec.|Sr)r)rUrs rrPz%Container.searchall..Vs4;;y3I3Ir) searchprocess)rrHrs @r searchallzContainer.searchallSs- 4!I!I!I!IJJJ rcx||}|D]!}|jj|"|S)z3Search for all containers of a type and remove them)rmr5r]r)rrHrrUs r searchremovezContainer.searchremoveYsD~~d## 8 8I   % , ,Y 7 7 7 7 rc:|fd|dS)z4Search for elements of a given type and process themc$t|Sr)r)rUrHs rrPz)Container.searchprocess..bsZ 4-H-HrN) locateprocess)rrHrSs ` rrlzContainer.searchprocess`s) HHHH'RRRRRrcr|jD].}|||||r ||/dS)z3Search for all embedded containers and process themN)r]rr)rrVrSrUs rrrzContainer.locateprocessdsV # #I  # #FG 4 4 4vi   # """ # #rc|jD]:}||r||||||r ||;dS)z,Perform a recursive search in the container.N)r]rT)rrVrWrSrUs rrTzContainer.recursivesearchksk # #Iy## F))&)WEEEvi   # """  # #rcttj|}dd|DS)z)Extract all text from allowed containers.r@c3$K|] }|jV dSrr)rconstants rrz(Container.extracttext..vs$AA8xAAAAAAr)rJr'r=rXjoin)r constantss rr=zContainer.extracttextssA&'BCCKKDQQ wwAAyAAAAAArc|t|jkrdSt|j|drdS|t|jkr||j|rd|j|_|j|j||j||t|jkr||j||j||dS)z*Group some adjoining elements into a groupNgroupedT)rr]rr{rrr!)rr-group isingroups rr|zContainer.groupxs C && & & F 4=' 3 3  Fc$-((((YYt}U7K-L-L(+/DM% ( N ! !$-"6 7 7 7 M  e $ $ $c$-((((YYt}U7K-L-L( UE*****rc|j|}|j|t|jdkrL|j||jt|jdkJdSdS)z)Remove a container but leave its contentsrN)r]rrr!)rr-rUs rrzContainer.removesM%(  %   )$%%)) M  (:(>(>(@(@ A A A)$%%))))))rrctd|zt|z|jD]}||dzdS)zShow in a treez rN)rrrpr]tree)rlevelrUs rrzContainer.treesW D5L3t99,--- & &I NN519 % % % % & &rc2||jvrdS|j|S)z)Get the value of a parameter, if present.N)rbrrZs r getparameterzContainer.getparameters! t & &4t$$rc^||}|sgS|dS)z7Get the value of a comma-separated parameter as a list.r)rr )rrZ paramtexts rgetparameterlistzContainer.getparameterlists4%%d++  Is###rc`|j}|r$|jrdS|j}|$dS)z&Check if the parent's output is empty.TF)r5r\rrEs rhasemptyoutputzContainer.hasemptyoutputsD+ %~%%'' tnG %urcp|js |jjS|jjdzt|jzS)zGet a descriptionr)rWrCr rpr7s rrxzContainer.__str__s4z +>* *~&,s4:>>r)r)r r!r"r#partkeyr5rWrrSrr?rHrbrirmrorlrrrTr=r|rrrrrrxr%rrrXrX%sR44G F E   )5(=    SSS######BBB + + +BBB&&&& %%% $$$?????rrXceZdZdZdZdS)BlackBoxz)A container that does not output anythingc`t|_t|_g|_dSr)rzr(rr\r]r7s rrzBlackBox.__init__s#!mm !mm  rN)r r!r"r#rr%rrrrs)//rrc:eZdZdZdZdZdZdZdZdZ dZ dS) StringContainerzA container for a single stringNc`t|_t|_d|_dS)Nr@)rr(rr\rr7s rrzStringContainer.__init__s#"nn "nn  rcd|jr(||j|_d|_dSdS)z(Replace special chars from the contents.N)parsedreplacespecialrr7s rrSzStringContainer.processs8 ; --dk::DKDKKK  rcd||tj}||}tjd|vrft |dkrS|jrdt|jzdz}nd}t || z|S)z%Replace all special chars from a line startcommandrzUnknown command at rhzUnknown command: ) rbr?rH changeliner'rrrWrprrrk)rrreplacedrs rrzStringContainer.replacespecials;;t\%:;;??8,,  !. 1X = =#h--RSBSBSz ./#dj//ADH- KK(.."2"22 3 3 3rcB||tjSr)rbr?rG)rrs rrzStringContainer.changelines{{4!3444rc|jS)zReturn all text.rr7s rr=zStringContainer.extracttexts {rcd}|jr|dt|jzz }d}t|jdkrd}|dz|jddz|zdzS) "Return a printable representation.rrz...r@rwNr_)rWrprrrk)rr)ellipsiss rrxzStringContainer.__str__s" : , cC OO+ +F t{  "" # #r ) )H}t{00223B377(BSHHr) r r!r"r#rrrSrrr=rxr%rrrrs~%% F    555IIIIIrrceZdZdZdZdZdS)ConstantzA constant stringcHg|_||_t|_dSr)r]rrr\rOs rrzConstant.__init__s  "nn rcd|jzS)Nz Constant: rr7s rrxzConstant.__str__sdk))rN)r r!r"r#rrxr%rrrrs8%%% *****rrceZdZdZdZdS)DocumentParametersz#Global parameters for the document.FN)r r!r"r# displaymoder%rrrrs))KKKrrc6eZdZdZdZdZdZdZdZdZ dS) FormulaParserzParses a formulac2|jdz|_||}|so|||}|sDtd|zdgS|gS)zSee if the formula is inlinedrzUnknown formula type in unknown)rfrW parsetypererrrdrk)rrgrHs rrizFormulaParser.parseheaders&* ~~f%% # OO   >>&))D # 69K9K9M9M9S9S9U9UUVVV!{"v rc|tjddkrdS|tjddkrdS|tjddkrdS|tjddkrdSd S) z)Get the formula type from the first line.rrinlinerblockrrnumberedN)rdfindrJrr|s rrzFormulaParser.parsetypes      $ $]%9(%C D D I I8      $ $]%9)%D E E J J7      $ $]%9,%G H HA M M7      $ $]%9-%H I IQ N N:trc||}||js|}t |dkrt d|z|||j||S)zParse the formula until the endrzUnparsed formula line ) parseformulardrrorkrrrre)rrgformulastrippeds rr}zFormulaParser.parses##F++$$&&11$+>> ))++1133H8}}q   4x?@@@ OO    $$&&11$+>>  rctjd}||vr`||dd}||vr||||S||||Stjd|vr7||tjdtjdStjd}tjd}||vr!||r|}||d|}||dz|z}tjd} tjd} | |dz| z} ||||| z| zSt d |zd z|zd Stjd } tjd } | |vr?| |vr)tjd }||| |St d|zdzd S)zParse the formula contentsrrrrrrrrzMissing z in r@rrzFormula beginning z is unknown) rJrrdr parsesinglelinerparsemultilinerrrkrrr)rrgrrestrrrendsplit startpiecerrendpiece begincommand beginbracket endbrackets rrzFormulaParser.parseformulas%h/ V'')) ) )%%''--fa88;D~~,,VVVDDD''?? ?   *f.@.@.B.B B B'' 0DY0O(5(=i(HJJ J#*=9 "),7 &,,.. . .!!##))++44Z@@ b ,,..4466"==55a8>>zJJ(8A;6C )1+> (0<$x{2X=!D$8$8X$V$VVYaaa KK Z/&86;M;M;O;OO P P P2$+I6 $+I6 6--// / /LFDVDVDXDX4X4X&.y9J'' jII I (6+=+=+?+??-OPPPrrc|}||vr%td|zdz|zdS||s%td|zdz|zdS||}||t |zt | }||S)zParse a formula in one lineLine does not contain formula start r@zFormula z does not end with )rdrkrrrr-rre)rrgstartrorr-rs rrzFormulaParser.parsesinglelinerAs!!##))++    KK$)KKeS T T T2}}V$$  KK T),AAFJ K K K2 5!!ECJJ&F |34 rc<d}|}||vr7td|zdz|zdS||}||t |zd}||sE||dzz }||}||E||dt | z }||S)z!Parse a formula in multiple linesr@rrNr)rdrrrkr-rrre)rrgrrorrr-s rrzFormulaParser.parsemultilinerOs!!##    KK$**,,.1SSV[[ \ \ \2 5!!ECJJ&''(..00--'' ( td{ "G OO   %%''D--'' ( 4 #f++ &&rN) r r!r"r#rirr}rrrr%rrrrsu         !!!F   rrcHeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z dS) FormulaBitzA bit of a formulaNrr@c:g|_t|_dS)z6The formula bit type can be 'alpha', 'number', 'font'.N)r]rr\r7s rrzFormulaBit.__init__hs $&& rc||_|S)z!Set the internal formula factory.)rs)rrss r setfactoryzFormulaBit.setfactoryms  rcr|j||xj|jz c_||_dS)z-Add any kind of formula bit already processedN)r]rrDr5rbits rrzFormulaBit.addrs5 S!!! %  rc|xj|z c_||s7td|zdz|zdSdS)z0Skip a string and add it to the original formulazString z not at N)rDrIrrr<)rrr%s r skiporiginalzFormulaBit.skiporiginalxsd  }}V$$ L KK F*Z7#..:J:JJ K K K K K L Lrct|jdkrdStd|jD|_|jS)zDCompute the size of the bit as the max of the sizes of all contents.rrc3$K|] }|jV dSrsizerrs rrz)FormulaBit.computesize..s$BB BBBBBBr)rr]rrr7s r computesizezFormulaBit.computesize~sD t}   " "1BBDMBBBBB yrc@|j|jSzReturn a copy of itself.)rsrrDr7s rrEzFormulaBit.clones|((777rc0|jjdz|jzS)zGet a string representationz read in )rCr rDr7s rrxzFormulaBit.__str__s~&4t}DDr)r r!r"r#rHrrDrrrrrrErxr%rrrras D DH'''   LLL 888EEEEErrc&eZdZdZdZddZdZdS) TaggedBitzA tagged string in a formulact||_|t ||SzSet the constant and the tag)rrr\rr))rrwrs rrwzTaggedBit.constants:"nn++C00  **+++ rFcb||_t|||_|Sr)r]rrr\)rr]rrs rcompletezTaggedBit.completes)  "nn++C<<  rcVt|d|_|S)z4Set the self-closing tag, no contents (as in
).T)r)rrr\)rrs r selfcompletezTaggedBit.selfcompletes%"nn++Ct+<<  rNr)r r!r"r#rwrrr%rrrrsL""  rrc*eZdZdZdZdZdZdZdS)r)zA constant string in a formulacft||||_d|_d|_dS)zSet the constant stringrN)rrrDrrHrs rrzFormulaConstant.__init__s1$'''   rc|jS)z+Compute the size of the constant: always 1.rr7s rrzFormulaConstant.computesizes yrc*t|jSr)r)rDr7s rrEzFormulaConstant.clonest}---rcd|jzS)rzFormula constant: rr7s rrxzFormulaConstant.__str__s#dk11rN)r r!r"r#rrrErxr%rrr)r)sV$$...22222rr)ceZdZdZdZdZdS)r5zA bit of text inside a formulacN|S)zDetect a bit of raw textrr$s rdetectzRawText.detect{{}}$$&&&rc|}|t|d|_dS)zParse alphabetic textalphaN)rrr)rH)rr%rs rparsebitzRawText.parsebits4  ''((( rNr r!r"r#rrr%rrr5r5s8$$'''rr5cLeZdZdZejZejdZdZdZdZ dS)r2zA symbol inside a formularc|tjvrdS|tjvrdSdS)zDetect a symbolTF)rr2rrr$s rrzFormulaSymbol.detects= ;;==M4 4 44 ;;==M2 2 24urc|tjvr*|||dS|tjvr:|tj||dSt d|zdzdS)Parse the symbolNzSymbol z not found)rr2r addsymbolrrrr$s rrzFormulaSymbol.parsebits ;;==M4 4 4 NN3;;==# . . . F ;;==M2 2 2 NN=1#++--@# F F F F I - <=====rc||||jt |dS)z Add a symbolN)rrr]rr))rsymbolr%s rrzFormulaSymbol.addsymbolsD #++----- _V4455555rN) r r!r"r#rJrrrrrr%rrr2r2s\%H),7J>>>66666rr2ceZdZdZdZdZdS)r1zA string of digits in a formulacN|S)zDetect a digitrr$s rrzFormulaNumber.detectrrcfd}|t|d|_dS)zParse a bunch of digitscPSrr)r%srrPz(FormulaNumber.parsebit..s#++--"7"7"9"9rnumberN)rrr)rH)rr%digitss ` rrzFormulaNumber.parsebitsC9999:: (())) rNrr%rrr1r1s8%%'''rr1c8eZdZdZejdZdZdZdS)Commentz*A LaTeX comment: % to the end of the line.rc<||jkS)z Detect the %.)rrr$s rrzComment.detects{{}} **rcL|xj|dz c_dS)zParse to the end of the line.rN)rDr r$s rrzComment.parsebits$ **4000 rN) r r!r"r#rJrrrrr%rrrrsE00   +E+++11111rrc$eZdZdZdZdZdZdS) WhiteSpacez"Some white space inside a formula.cN|S)zDetect the white space.rr$s rrzWhiteSpace.detectrrcJ|xj|z c_dS)zParse all whitespace.N)rDrr$s rrzWhiteSpace.parsebit s ( rcd|jzdzS)rz Whitespace: *r)rDr7s rrxzWhiteSpace.__str__ s.44rN)r r!r"r#rrrxr%rrrrsG((''')))55555rrc|eZdZdZejdZejdZdZ dZ dZ dZ dZ dZd Zd Zd Zd S) r+zA {} bracket inside a formularcHt|d|_dS)z'Create a (possibly literal) new bracketN)rrinnerr7s rrzBracket.__init__s!D!!! rc6||jS)zDetect the start of a bracket)rrr$s rrzBracket.detects||DJ'''rc<|||j|S)zParse the bracket) parsecomplete innerformular$s rrzBracket.parsebit!  3 1222 rc<|||j|S)zParse a text bracket)r innertextr$s r parsetextzBracket.parsetext&s 3/// rc<|||j|S)zParse a literal bracket)r innerliteralr$s r parseliteralzBracket.parseliteral+rrc||js>@@AA M0;<<<M0;<<<GM***,,.. ={{}} ,,..s33444==%%)MMS(MM):):;;<<< ,,.. = = = = =rcd|_|s||jks||jkr||n"|xj|z c_|s||jk|xj|jz c_dS)zAParse a literal inside the bracket, which does not generate HTML.r@N)literalrrrorrrrDr$s rr zBracket.innerliteralNs ,,.. 2$+)E)E{{}} **!!#&&&&  1 11 ,,.. 2$+)E)E % rN)r r!r"r#rJrrrrorrrr rrrr r r%rrr+r+s##   +E  "9 -F (((     111 = = =&&&&&rr+cLeZdZdZejdZejdZdZ dS) SquareBracketzA [] bracket inside a formularc:t}|j|_|S)z3Return a new square bracket with the same contents.)rr])rrs rrEzSquareBracket.clone_s//=rN) r r!r"r#rJrrrrorEr%rrrrYsC##   1E  "? 3FrrceZdZdZdZdZdS)MathsProcessorzAA processor for a maths construction inside the FormulaProcessor.cZtdt|zdS)z$Process an element inside a formula.zUnimplemented process() in Nrrr]r-s rrSzMathsProcessor.processis& 1CII=>>>>>rc d|jjzS)zReturn a printable description.zMaths processor )rCr r7s rrxzMathsProcessor.__str__ms!DN$;;;rN)r r!r"r#rSrxr%rrrrfs8GG???<<<<Traverse over the contents to alter variables and space units.Nrfontrr )traverserH italicizer]r!r))rrlastrr]s rr&zFormulaProcessor.traversewholes!]]733  MCx7""sH----V###h1F1F ##Ax'@'@AAADD   rc#K|jD]U}t|dr|jr ||jfV%t|tr||Ed{VVdS)zHTraverse a formula and yield a flattened structure of (bit, list) pairs.rHN)r]rrHrrr/r(s rr/zFormulaProcessor.traverses| 2 2Gw'' 2GL 2s|+++++GZ00 2==111111111  2 2rc|||}t|gd||<dS)z Italicize the given bit of text.rN)r-rr)rrr]r-s rr0zFormulaProcessor.italicizes6s###++..uc::rN) r r!r"r#r*rSr$r%r&r/r0r%rrr"r"rsy,,J   ***)))222;;;;;rr"cTeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd S)r0zA LaTeX formulacxt|_td|_dS)Nzspan class="formula")rr(rrr\r7s rrzFormula.__init__s+#oo "nn++,BCC rc|jddkr dt_n'dt_|jdd|dS)zConvert the formula to tagsrrFTzdiv class="formula"N)rhrrr\rclassicr7s rrSzFormula.processsR ;q>X % %-2  * *-1  * K  4d ; ; ; rct|j}t|||_|g|_dS)zEMake the contents using classic output generation with XHTML and CSS.N)FormulaFactoryrrr"rSr5r])rwholes rr7zFormula.classicsK  --dk::""5)))  rc|dr||n|dr||nm|dr||dnA|dr||dn|d||S)z4Parse using a parse position instead of self.parser.z$$rz\(z\)rrzUnparseable formula)rIparsedollarblockparsedollarinline parseinlineto parseblocktorrSr$s rr}z Formula.parses ==   -  ! !# & & & & ]]3   -  " "3 ' ' ' ' ]]5 ! ! -   sE * * * * ]]5 ! ! -   c5 ) ) ) ) II+ , , ,  rc@dg|_||dS)zParse a $...$ formula.rN)rh parsedollarr$s rr=zFormula.parsedollarinlines%j  rcdg|_|||ds|ddSdS)zParse a $$...$$ formula.rrz1Formula should be $$...$$, but last $ is missing.N)rhrArIrr$s rr<zFormula.parsedollarblocksYi  }}S!! K III J J J J J K Krc|d|d|_|ddS)zParse to the next $.rN)rrrrr$s rrAzFormula.parsedollarsA s'',,  crcBdg|_|||dS)zParse a \(...\) formula.rNrh parseuptorr%limits rr>zFormula.parseinlinetos%j  sE"""""rcBdg|_|||dS)zParse a \[...\] formula.rNrErGs rr?zFormula.parseblocktos%i  sE"""""rc|||d|_||dS)z1Parse a formula that ends with the given command.cdS)NTr%r%rrrPz#Formula.parseupto..strN)rrrrrGs rrFzFormula.parseuptosA uhh||,,  ercP|jr|jjrd|jjzdzSdS)rz Formula (r_zUnnumbered formula)rrr7s rrxzFormula.__str__s3 < ;DL/ ;!44s: :##rN)r r!r"r#rrSr7r}r=r<rAr>r?rFrxr%rrr0r0sDDD       KKK ### ###  $$$$$rr0ceZdZdZdZdZdS) WholeFormulazParse a whole formulac,| S)z"Not outside the formula is enough.)rr$s rrzWholeFormula.detects<<>>!!rc|sC||j||AdSdS)zParse with any formula bitNrr$s rrzWholeFormula.parsebitrrNrr%rrrNrNs8"""11111rrNcdeZdZdZeeeeee gZ ee gZ dZ dZ dZdZdZdZdZd Zd Zd Zd S) r9zConstruct bits of formulaFci|_dS)z Initialize the map of instances.N) instancesr7s rrzFormulaFactory.__init__ s rc~|rdS|||S)zDetect a bit of a given type.F)rinstancer)rrHr%s r detecttypezFormulaFactory.detecttypes7 <<>> 5}}T""))#...rc||jvs |j|s|||j|<|j|S)z"Get an instance of the given type.)rSrBrrHs rrUzFormulaFactory.instances@ t~ % %T^D-A %#';;t#4#4DN4 ~d##rc\t||S)z+Create a new formula bit of the given type.)r@rBrrXs rrBzFormulaFactory.creates"}}T""--d333rc|s+||sdS|+dS)zClear any skipped types.N)rskipanyr$s r clearskippedzFormulaFactory.clearskippedsD,,.. <<$$ ,,..  rc|jD]B}|||r|||cSCdS)zSkip any skipped types.N) skippedtypesrUrrrr%rHs rr[zFormulaFactory.skipany&sZ% 1 1D}}T""))#.. 1~~dC00000 1trc"|j|jzD]0}|||r|||cS1td|zt|S)z.Parse any formula bit at the current location.zUnrecognized formula at ) typesr^rVrrrr<r)rr_s rrzFormulaFactory.parseany-sJ!22 1 1DtS)) 1~~dC00000 1 .1A1AABBBs00111rc||}d|j|<||}|r||S|S)z#Parse the given type and return it.N)rUrSrr)rrHr%r returnedbits rrzFormulaFactory.parsetype5sQmmD!!#tll3''  0))$// / rct|}|t}||r|||S|sdt d|z| t |d|S)z5Parse a string of text that contains a whole formula.zUnknown formula at: span class="unknown") rLrBrNrrrrrr<rrrw)rrr%r:s rrzFormulaFactory.parseformula>s7## L)) <<    NN3   L||~~ M KK.1A1AA B B B IIikk**74JKK L L L rN)r r!r"r#r2r5r1r+rrrar^definingrrVrUrBr\r[rrrr%rrr9r9sG]GWj QEZ(LH/// $$$ 444222     rr9c^eZdZdZgZejdZdZdZ dZ dZ dZ dZ d Zd ZdS) FormulaCommandz A LaTeX command inside a formularNc@|tjS)zFind the current command.)rrhrr$s rrzFormulaCommand.detectSs||N0111rc||}|||}|r|S|ds|dr|||}|r|S|jjst d|zt d|_ | t|dS)zParse the command.\up\UpzUnknown command reN) extractcommandparsewithcommandr parseupgreekrsrfrrrrr\rr))rr%rrupgreeks rrzFormulaCommand.parsebitWs%%c**##GS11  J   f % % ););F)C)C ''55G |$ 6 KK*W4 5 5 5"nn++,BCC  ))***trchtjD]$}||jvr||||cS%dS)z0Parse the command type once we have the command.N)rhra commandmapparsecommandtype)rrr%rHs rrnzFormulaCommand.parsewithcommandgsK"( A AD$/)),,WdC@@@@@*trc|j|}||||}|r|S|S)zParse a given command type.)rsrB setcommandr)rrrHr%rreturneds rrszFormulaCommand.parsecommandtypensLl!!$'' w<<$$  O rc|tjs$|dtjzdS|r||S|r8tj|z}|d|Stj| zS)z.Extract the command from the current position.zMissing command start Nr) rIrhrrr emptycommandrrrr)rr%rs rrmzFormulaCommand.extractcommandws}}^122  II.1EE F F F F <<>> *$$S)) ) ;;== " " $*S]]__> 4L))#..  rc|j||jt|sdS|jt|}|||S)zParse a square bracketN)rsr\rVrrrrr%rs r parsesquarezCommandBit.parsesquarese !!#&&&|&&}c:: 4,((<< rc|j||jt|sY|s1t d|zdS|St |j}| | ||j S)zParse a literal bracket.zNo literal parameter found at: N) rsr\rVr+rrrr<rrrrrrs rrzCommandBit.parseliterals !!#&&&|&&w44 #;;==  =@P@PPQQQt==?? "))&&t|44 %%c**+++rc$|j||jt|sdSt|j}||||jS)z!Parse a square bracket literally.N)rsr\rVrrrrrrs rparsesquareliteralzCommandBit.parsesquareliteralsx !!#&&&|&&}c:: 4//,,T\:: %%c**+++rc^|j||jt|s$td|jzdSt|j|}| ||S)zParse a text parameter.zNo text parameter for N) rsr\rVr+rrrrr rrs rr zCommandBit.parsetexts !!#&&&|&&w44  KK04<? @ @ @4))&&t|44>>sCC rN) r r!r"r#rurmrrrr r%rrrrst++<<<   rrc&eZdZdZejZdZdS)r.z%An empty command (without parameters)c:t|jg|_dS)z"Parse a command without parametersNr)rr]r$s rrzEmptyCommand.parsebits(99: rN)r r!r"r#rJrrrrr%rrr.r.s1++'J;;;;;rr.c&eZdZdZejZdZdS)r6zFind a function which is represented by a symbol (like _ or ^)cB|tjvS)zFind the symbol)rr7rrr$s rrzSymbolFunction.detect s{{}} 999rc||||jt |j|_||dS)rN) rurr rrrrr\rmr$s rrzSymbolFunction.parsebit# se  &&& "nn++DO<<  C     rN) r r!r"r#rJrrrrrr%rrr7r7 s@DD.J:::!!!!!rr7c,eZdZdZejZdZdZdS)r8z-A function where parameters are read as text.ct|j|_||dS)zParse a text parameterN)rrrr\r r$s rrzTextFunction.parsebit0 s5"nn++DO<<  srcd|_dS)zSet the type to fontr-N)rHr7s rrSzTextFunction.process5 s  rN) r r!r"r#rJrrrrrSr%rrr8r8+ s@33,J rr8c&eZdZdZejZdZdS)r/z2A function of one parameter that changes the font.c<d|_|dS)z.Simplify if possible using a single character.r-N)rHrr7s rrSzFontFunction.process@ s!  !!!!!rN)r r!r"r#rJrrrrSr%rrr/r/: s3<<,J"""""rr/cDeZdZdZd dZdZdZdZdZdZ d Z d Z d S) BigBracketzA big bracket generator.rc||_||_||_d|_|tjvrtj||_dSdS)z(Set the size and symbol for the bracket.N)rrD alignmentr`rJr)rrrrs rrzBigBracket.__init__O sG  " m/ / /'3G ! DIM ! !;r? "{1~rc|dkr |jdS||jdz kr |jdS||jdz dz kr |jdS|jdS)z7Get the nth piece for a 4-piece bracket: curly bracket.rrr|rrrs r getpiece4zBigBracket.getpiece4i sb A::;q> ! DIM ! !;q> ! TY]A% % %;q> !{1~rc||}d|jzdz}t||S)z'Get the bracket piece as an array cell.zspan class="bracket align-r)rrrrw)rr-raspans rgetcellzBigBracket.getcells s> e$$+dn>>((** *49%% O OE<<&&D KK ,,dV5LMM N N N N $$T+?@@AArc|jdkr#tddgSt|jdgS)z$Return the bracket as a single sign.rr@zspan class="emptydot"rd)rDrrwr7s rrzBigBracket.getsinglebracket sM =C  KK((-DEEF F $$T]4KLLMMrN)r) r r!r"r#rrrrrrrrr%rrrrL s==== 111 BBBNNNNNrrceZdZdZdZdZdS)FormulaEquationzA simple numbered equation.equationct|_||jt |dS)Parse the arrayN)rr\rrsrrNr$s rrzFormulaEquation.parsebit s9$&&  '' c::;;;;;rNr r!r"r#rarr%rrrr s.!! E<<<<?CEE  rc|j||rdS||jt |dSr)rsr\rrrrNr$s rrzFormulaCell.parsebit sW !!#&&& <<>>  F '' c::;;;;;rN)r r!r"r#rrr%rrrr s8   <<<<eZdZdZejdZdZdZdZ dS) FormulaRowzAn array row inside an arrayrXcb||_tdd|_|S)NrT) alignmentsrrr\)rrs r setalignmentszFormulaRow.setalignments s*$"nn++,CTJJ  rcd}||jd|sr||}|||||dz }||j|rt|jdkrt|_ dSdS)zParse a whole rowrT)rrN) rrXr createcellrrrIrr]rr\)rr%r-rs rrzFormulaRow.parsebit s t)D999,,.. .??5))D MM#    HHTNNN QJE MM$, - - - ,,.. . t}   " "%--DKKK # "rc|j|t|jz}|jt|S)z4Create the cell that corresponds to the given index.)rrrsrBrr)rr-rs rrzFormulaRow.createcell sAOEC,@,@$@A |"";//<:   NN< . . .,%%j11C##DO44 4 4 4||L))  |!>%((D HH_U++ , , , GGDMMMM Crcd|j|||dS)z2Add a row to the contents and to the list of rows.N)rrr)rrs rrzMultiRowFormula.addrow s+   rN)r r!r"r#rrrrr%rrrr sV## # # #   rrc"eZdZdZdZdZdZdS) FormulaArrayzAn array within a formularctdd|_||||dS)rrFN)rrr\parsealignmentsrr$s rrzFormulaArray.parsebit sJ"nn++,@%HH  S!!! srcd|_||}|r||_||}g|_|D]}|j|dS)zParse the different alignmentsrN)valignrrrr)rr%rss rrzFormulaArray.parsealignments sy ))#..  "!DK##C(( & &A O " "1 % % % % & &rN)r r!r"r#rarrr%rrrr s= E & & & & &rrceZdZdZdZdZdS) FormulaMatrixz'A matrix (array with center alignment).matrixctdd|_d|_dg|_||dS)z(Parse the matrix, set alignments to 'c'.rFrN)rrr\rrrr$s rrzFormulaMatrix.parsebit sF"nn++,@%HH  % srNrr%rrrr s.-- ErrceZdZdZdZdZdS) FormulaCaseszA cases statementcasesct|_ddg|_|||jD]N}|jD]D}|jdd|jtdEOt |jdd}tt|jdd}| |gz|_dS)zParse the casesrzspan class="case align-l"Tu zspan class="bracketcases"rbN) rr\rrr]rrr)rrrrr)rr%rrrbraces rrzFormulaCases.parsebit s$&& * s= = =C  = = ""#>EEE $$_U%;%;<<<< = $$T]4OQUVV3t}--sC88))++ug5 rNrr%rrrr s. E 6 6 6 6 6rrceZdZdZdZdS)EquationEnvironmentz;A \begin{}...\end equation environment with rows and cells.c|jdd}td|zd|_|t jvrt j||_nut d|jztd|_| td|zdg|_| |d S) zParse the whole environment.rr@zspan class="environment %s"FzUnknown equation environment rez \begin{%s} rN) rarrrr\rJrrrrrr)r)rr% environments rrzEquationEnvironment.parsebit* sj((b11 "nn++5kA5JJ -4 4 4+8EDOO KK7$*D E E E&..//0FGGDK HH_^K%?@@ A A A"eDO srN)r r!r"r#rr%rrrr' s)CCrrcHeZdZdZejddiZeee e gZ dZ dZ dS) BeginCommandzEA \begin{}...\end command and what it entails (array, cases, aligned)rWr@cl||}||}tjddz|zdz}|||||||xj||z c_|j |_ dS)zParse the begin commandrYrbrcN) rfindbitrJrrrrrDrr)rr%rrros rrzBeginCommand.parsebitB s##C((ll7##$U+c1G;cA v S   v... H rctjD]=}|dd|jkr|j|cS>|jt }||_|S)z7Find the command bit corresponding to the \begin{piece}rr@)rrarrarsrBr)rrarHrs rrzBeginCommand.findbitM sr & 1 1D}}S"%%33|**4000004l!!"566  rN)r r!r"r#rJrrrrrrrrarrr%rrrr; sXMM%g.3J lL- HE   rrc(eZdZejZdZdZdS)r-cP|j}||}|s$td|jzdSt |t si ttj }| |d}n3#t$r&td|jzYdSwxYw|j drd}nd}|j d||z|j |dz|_ tjd|j |_ dS) zParse a combining function.z)Missing parameter for combining function Nrz!No base character found for "%s".r.rrNFC)rparsesingleparameterrrrrr)rJr'r=rX IndexErrorrr unicodedata normalize)rr% combiningr extractorrs rrzCombiningFunction.parsebit^ s1O --c22   KKCdlR S S S F)_55  ./JKK %--i88;     ?$,NOOO    & &x 0 0 AAA$+BQB/);i>Nqrr>RR &0 8HII s4B,B>=B>c|j||rdS||S)z&Parse a parameter, or a single letter.N)rsr\rrmr$s rrz&CombiningFunction.parsesingleparameterx sA !!#&&& <<>> 4""3'''rN)r r!r"rJrrrrrr%rrr-r-Z s=1JJJJ4(((((rr-c&eZdZdZejZdZdS)r4z;A function that decorates some bit of text with an overset.c|j}t|d|_|||_t d|_|j d|jt d|j_| dS)zParse an overset-functionrspan class="embellished"rspan class="base"N rrrwrrmrrrr\r]r!rrr%rs rrzOversetFunction.parsebit kk**6599 ,,S11"nn++,FGG  Q ,,, , 5 56I J J !!!!!rN)r r!r"r#rJrrrrr%rrr4r4 s1AA/J"""""rr4c&eZdZdZejZdZdS)r9z>(E * * 5##He44 4 5 5rc|||dz}|sdS||||}||||||||dS)zProcess a left bracket.rN) findrightfindmaxresize)rr]r- rightindexrs rr2zBracketProcessor.processleft$ sr^^Heai88   F||HeZ88 HUOT*** HZ($/////rc:|||dS)z0Check if the command at the given index is left.recheckdirectionrs rr1zBracketProcessor.checkleft- s""8E?H===rc:|||dS)z1Check if the command at the given index is right.rfr9rs r checkrightzBracketProcessor.checkright1 s""8E?I>>>rcFt|tsdS|j|kS)z6Check if the given bit is the desired bracket command.F)rr,r)rrrs rr:zBracketProcessor.checkdirection5 s&#~.. 5{g%%rcd}|t|krV|||r|dz }|||r|dz}|dkr|S|dz }|t|kVdS)z9Find the right bracket starting at the given index, or 0.rrN)rr1r<)rr]r-depths rr4zBracketProcessor.findright; sc(mm##~~h..  x//  zz QJEc(mm##trcH|||}td|DS)z@Find the max size of the contents between the two given indices.c3$K|] }|jV dSrrrs rrz+BracketProcessor.findmax..K s$66G7<666666r)r)rr] leftindexr7sliceds rr5zBracketProcessor.findmaxH s.)J./66v666666rc|}|jdd}t|||}t |_||_dS)z+Resize a bracket command to the given size.rVr@N)r=rrrrr\rr])rrrr-rrs rr6zBracketProcessor.resizeM sb'')) O++D"55 T9i88'))"..00rN) r r!r"r#rSr2r1r<r:r4r5r6r%rrr/r/ s''555000>>>???&&&   777 11111rr/c:eZdZdZ ddgZdZdZdZdZdS) ParameterDefinitionz3The definition of a parameter in a hybrid function.)r`ra)rbrccLd|_d|_d|_d|_d|_dS)NF)rZrrr literalvaluer7s rrzParameterDefinition.__init__g s,     rc`tjD]\}}||r|dkrd|_|ds5td|zdzdS||_|drd|_ ||s2td|zdS|cStd |zdS) z2Parse a parameter definition: [$0], {$x}, {$1!}...r`Trz$Wrong parameter name, did you mean $rNrzWrong parameter closing z'Wrong character in parameter template: ) rF parambracketsrIrrrrrrZr)rr%openingclosings rr}zParameterDefinition.parsen s"5"C   Wg}}W%% c>>$(DM}}S)) KK F VY\ \]]]44OO-- ==%%(#'DL}}W-- KK :S__=N=N NOOO44    =@Q@QQRRRtrcN|jr`|jr|||_n|||_|jrt |j|_dSdS|jr|||_dS|||_dS)z/Read the parameter itself using the definition.N) rrrrHrr)rrrm)rr%rs rreadzParameterDefinition.read s < 6} ?$,$?$?$D$D!!$,$9$9#$>$>!  @,T->??  @ @ ] 6!--c22DJJJ!0055DJJJrchd|jz}|jr|dt|jzz }n|dz }|S)rzparam rhz (empty))rZrrp)rr)s rrxzParameterDefinition.__str__ s@DI% : ! dS__, ,FF j F rN) r r!r"r#rJrr}rNrxr%rrrFrF^ sl99>A9\,M!!!& 6 6 6rrFc2eZdZdZ dZdZdZdZdZdS)ParameterFunctionzFA function with a variable number of parameters defined in a template.ci|_||D]*}|||||jd|jz<+dS)z*Read the params according to the template.rN)params paramdefsrNrZr readtemplater%paramdefs r readparamszParameterFunction.readparams sX |44 8 8H MM#t $ $ $/7DKhm+ , , 8 8rc#Kt|}|s=t|}|r|V|;dSdS)z*Read each param definition in the templateN)rLrrFr}rUs rrTzParameterFunction.paramdefs ss<((,,.. *,,22377H ,,..     rc2||jvrdS|j|S)zGet a parameter as parsed.N)rSrs rgetparamzParameterFunction.getparam s! t{ " "4{4  rc6||jS)zGet the value of a parameter.)r[rrs rgetvaluezParameterFunction.getvalue s}}T""((rcP||}|r|jsdS|jS)z%Get the literal value of a parameter.N)r[rH)rrZr1s rgetliteralvaluez!ParameterFunction.getliteralvalue s3 d## E. 4!!rN) r r!r"r#rXrTr[r]r_r%rrrQrQ shLL;888!!! )))"""""rrQcPeZdZdZejZdZdZdZ dZ dZ dZ dZ d Zd S) HybridFunctiona A parameter function where the output is also defined using a template. The template can use a number of functions; each function has an associated tag. Example: [f0{$1},span class="fbox"] defines a function f0 which corresponds to a span of class fbox, yielding $1. Literal parameters can be used in tags definitions: [f0{$1},span style="color: $p;"] yields $1, 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
. c|jd}|jd}||||||_|dS)z*Parse a function with [] and {} parametersrrN)rrX writeparamsr]computehybridsize)rr%rV writetemplates rrzHybridFunction.parsebit s[q) *   c***((77       rcF|t|S)z*Write all params according to the template)writeposrL)rres rrczHybridFunction.writeparams s}}\-88999rcg}|sR|dr-||}|r||n|dr4||}|rd|_||n|dr*||ddns|dr*||ddn4|t||R|S)z/Write all params as read in the parse position.rfNr^leftr_right) rrI writeparamr writefunctionrH writebracketr)r)rr%r)r1rs rrgzHybridFunction.writepos sU,,.. B}}S!! B,,)MM%(((s## B--c22,$(HMMM(+++s## B d//<<====s## B d//==>>>> ocoo.?.?@@AAA,,.. B  rc>d|z}||jvrtd|zdS|j|sdS|dr)||j|j_|j|jS)z*Write a single param of the form $0, $x...rzUnknown parameter Nr)rrSrrrIrrrH)rr%rZs rrlzHybridFunction.writeparam sS__&&& t{ " " KK,t3 4 4 44{4  4 ==   ;+.==??DK  # ({4 &&rc||}|sdS|dr!t|S|dstddS|d||}|t|dkrdSt ||S)z"Write a single function f0,...,fn.Nrrbz Function should be defined in {}rcr) readtagrIrrrrrrgrrr)rr%rr]s rrmzHybridFunction.writefunction sll3 4 ==   1;;++C00 0}}S!!  KK: ; ; ;4 s==%%  x==A  4{{##Hc222rc|s1td|zdSt |}d|zt |jkr/tdt|zdzdS|jd|z}d|vr|S|j D]h}||vrb|j |}|j s'td|zdz|zd zA|j r|j }nd }| ||}i|S) zJGet the tag corresponding to the given index. Does parameter substitution.zFunction should be f0,...,f9: fNrz Function fz is not definedrzParameters in tag z should be literal: {z!}r@) rrrrintrrrrprSrrHr)rr%r-rvariabler1rs rrqzHybridFunction.readtag sI{{}}$$&&  KK9CKKMMI J J J4COO%%&& u9s4?++ + + KK s5zz14EE F F F4oa%i( c>>J 3 3H3 H-}KK 4s :=T TW_ _bf fggg%!.EEEkk(E22 rch|jt||S)z4Return a new bracket looking at the given direction.)rsrBr,r+s rrnzHybridFunction.writebracket* s(|"">2299)YOOOrc|jtjvr|dSt||_|jD]}|j|_dS)z(Compute the size of the hybrid function.N)r HybridSize configsizesrgetsizerr])rrs rrdz HybridFunction.computehybridsize. sh  s%h&67 O A ADz!!t,2>>@@'//c$ii@@ *   KK?*L M M M1JrN)r r!r"r#rJrrxryr%rrrwrw9 s111+K      rrwct}||}t||d|S)zConvert some TeX math to HTML.r@)r9rr"rSrxr)rrsr:s r math2htmlrN saG   ) )Eu%%% MMOOO 775==?? # ##rc4tj}t|t |dkr(t dtt|d}t |dS)z6Main function, called if invoked from the command linerz"Usage: math2html.py escaped_stringrN) r argvr#r rrrrrr)r r)s rmainrW su 8D II4    4yyA~~ 8999  tAw  F MM&r__main__)Zr3r rdocutils.utils.mathrr:rr'r?rJrr#r@rJr`rzrrrrrrrrrrrrrrr"r7rLrXrrrrrrrr)r5r2r1rrr+rrr"r0rNr9rhrr.r6r*r3r7r8r/rarrrrrrrrrrr-r4r9r r rr,r/r*rFrQrarwrrr r%rrrs0 ++++++! ++++++++\2         f f f f f f f f R AAAAAAAAH77777777t!!!!!!!!$&&&&&&&&R.F.F.F.F.F.F.F.Fb&""""""""JfO6     6           //     _    @@@@@>@@@F^8"""""?"""t!t!t!t!t!t!t!t!n========@&6868686868x686868r!7!7!7!7!78!7!7!7HF?F?F?F?F?F?F?F?Ry,I,I,I,I,Ii,I,I,I^ * * * * * * * * fffffFfffR*E*E*E*E*E*E*E*EZ *22222h222.     j   66666J666<     J    1 1 1 1 1j 1 1 1 5 5 5 5 5 5 5 5 D&D&D&D&D&jD&D&D&N     G    < < < < < < < <2;2;2;2;2;2;2;2;jL$L$L$L$L$iL$L$L$^ 1 1 1 1 1: 1 1 1FFFFFFFFRSSSSSZSSSl99999999x;;;;;:;;; Q Q Q Q QJ Q Q Q     <   "#####z###(!!!!!Z!!!"     :    " " " " "# " " "88, 0,-! ;N;N;N;N;N;N;N;N|<<<<