
    pf                    n   d dl Z d dlZ	 d Z G d d      Z G d d      Z G d d      Z G d	 d
e      Z G d de      Zd Zd Z	d Z
d Zd Z G d de      Z G d de      Z G d d      Z G d d      Z G d d      Z G d d      Z G d d      Z G d  d!      Z G d" d#      Z G d$ d%      Z G d& d'      Z G d( d)      Z G d* d+ee      Z G d, d-ee      Z G d. d/e      Z G d0 d1e      Z G d2 d3e      Z G d4 d5e      Z G d6 d7      Z G d8 d9e      Z  G d: d;e       Z! G d< d=e e      Z" G d> d?e e      Z# G d@ dAe       Z$ G dB dCe      Z% G dD dEe      Z& G dF dGe&      Z' G dH dIe$      Z( G dJ dKe$      Z) G dL dMe$      Z* G dN dOe$      Z+ G dP dQe$      Z, G dR dSe$      Z- G dT dU      Z. G dV dWe      Z/ G dX dYe       Z0 G dZ d[e0      Z1 G d\ d]e1      Z2 G d^ d_e1      Z3 G d` dae0      Z4 G db dce      Z5 G dd dee      Z6 G df dge6      Z7 G dh die6      Z8 G dj dke6      Z9 G dl dme      Z: G dn doe:      Z; G dp dqe:      Z< G dr dse:      Z= G dt due:      Z> G dv dwe       Z? G dx dye?      Z@ G dz d{e?      ZA G d| d}e?      ZB G d~ de?      ZC G d de      ZD G d deD      ZE G d deE      ZF G d deF      ZG G d deD      ZH G d de?      ZI G d de      ZJ G d deJ      ZK G d deJ      ZL G d deK      ZM G d deK      ZN G d de      ZO G d de      ZP G d deP      ZQ G d deL      ZR G d deL      ZS G d deL      ZT G d deO      ZU G d deO      ZV G d de      ZW G d de      ZX G d de eX      ZY G d deXe      ZZ G d deY      Z[ G d deZ      Z\ G d deY      Z] G d dee      Z^ G d deZ      Z_ G d de_      Z` G d deee      Za G d dea      Zb G d dea      Zc G d dea      Zd G d dea      Ze G dĄ dea      Zf G dƄ def      Zgy)    Nc                 T    t        | t              syt        j                  d|       ryy)zlreturns False if the object is either not a string or empty
    and True if the object is a non empty stringFz\S+T)
isinstancestrregexsearch)strings    7D:\Git_Server-LaTeX-VALEP\py\valeptex\parser_classes.py	non_emptyr
      s#     fc"5	ff	%d    c                   X    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zy)DocNodezMAIN CLASS: a list of text-snippets, blocks, and commands
    each LaTeX string/DocNode is parsed into sections of mere text 
    and commands/environments that again 
    can have arguments being treated as LaTeX strings/DocNodesc                 "    t               | _        y N)listelementsselfs    r	   __init__zDocNode.__init__.   s    r   c                 h   d}| j                   D ]  }t        |t              r;|j                  dk(  r||j	                          dz  }9||j	                          z  }Nt        |t
              r||j	                          z  }st        |t              r|t        |      z  }t        d| d        |S )z_returns a string that prints the object in a (pseudo) LaTeX notation
        is not up to date  par
zERROR: type of  could not be identified!
)r   r   Commandnameexpandr   r   print)r   r   elements      r	   r   zDocNode.expand1   s     }} 	NG'7+<<5(!1 2"55F!1 23FGW-W^^-./GS)#g,&y0KLM	N r   c                    g }| j                   rR| j                   D ]B  }t        |t              r:t        |j                   t              r |j	                  |j                                Nt        |t              rt        |      r|j                  |       {t        |t              sd}|t        |j                        k  rt        |j                  |   j                  t              rtt        |j                  |   j                  j                   t              rC|j                  |   j                  j                         |j                  |   j                  _         |dz  }|t        |j                        k  rd}|t        |j                        k  rt        |j                  |   j                  t              rtt        |j                  |   j                  j                   t              rC|j                  |   j                  j                         |j                  |   j                  _         |dz  }|t        |j                        k  r|j                  |       E |S )zappends each element of a docnode list that is a docnode in itself
        by means of its individual elements and thus flattens the docnode
        does not include tables but only opt and reqargs of Commandsr      )r   r   r   r   extendflatten_docnodesr   r
   appendr   lenoptargscontentreqargs)r   flattened_elementsitemis       r	   r"   zDocNode.flatten_docnodesD   s     == 4dG,DMM41P&--d.C.C.EFc*y&--d3W-Ac$,,//%dll1o&=&=wGJW[WcWcdeWfWnWnWwWwy}L~?C||A?V?V?g?g?iDLLO33<Q c$,,// Ac$,,//%dll1o&=&=wGJW[WcWcdeWfWnWnWwWwy}L~?C||A?V?V?g?g?iDLLO33<Q c$,,// '--d3!4" "!r   c                 :
   d}|t        | j                        k  r t        | j                  |   t              s;t        | j                  |   t              st        | j                  |   t
              rd}d}||z
  dkD  r| j                  ||z
     }t        |t              rd}d| j                  ||z
     _        |}nCt        |      s0t        |t              s t        |t
              st        |t              r|dz  }n|}||z
  dkD  r|dk(  r:t        d      }d|_        d|_        | j                  j                  ||       |dz  }d}|dz  }|r|t        | j                        k  rut        | j                  |         sWt        | j                  |   t              s:t        | j                  |   t
              st        | j                  |   t              r|dz  }nd}|r|t        | j                        k  r3t        | j                  |   t              rd| j                  |   _        nt        d      }d|_        d|_        | j                  j                  ||       nt        | j                  |   t              rd| j                  |   _        d}d}||z
  dkD  r| j                  ||z
     }t        |      s t        |t              st        |t
              rd| j                  |   _        |}nNt        |t              r|dz  }n8t        |t              r|}n%t        |t              rd}|}n|dz  }t        d       ||z
  dkD  rd| j                  |   _        d}||z   t        | j                        k  r| j                  ||z      }t        |      s t        |t              st        |t
              r*d| j                  |   _        t        | j                        }n+t        |t              r|dz  }nt        | j                        }||z   t        | j                        k  r|s8| j                  |   j                  dk(  r.| j                  |   j                  dk(  r| j                  |= |dz  }|dz  }nt        | j                  |   t              r_t        | j                  |   j                         dkD  r:| j                  |   j                   d   j"                  j%                          |dz  }n|dz  }|t        | j                        k  ryy)	zidentifies all paragraphs and marks them with a Par object at 
        the beginning and the end. The Par object uses the parameters parstart
        and parend for thisr   Fr    Tr   z@ERROR: something wrong in adjust_paragraphs - unidentified type.N)r$   r   r   r   FormatmathParparstartr
   Inliner   parendinsertr   r   Divisionr'   r&   adjust_paragraphs)r   r*   par_startedj	test_itemcommis_string_or_formatpar_redundants           r	   r5   zDocNode.adjust_paragraphs^   s    #dmm$$ $--*C0Jt}}Q?OQW4X\fgkgtgtuvgwy}\~#!eai $a!e 4I!)S1&*8<a!e,5"9-Iv1NR\]fhlRmq{  }F  HN  rOQ !eai %'u:D"'DK$(DMMM((D1FA&*#Q *3t}}--9T]]1=M3NR\]a]j]jkl]mouRv  {E  FJ  FS  FS  TU  FV  X\  {]  ak  lp  ly  ly  z{  l|  ~D  aEQ.3+	 * s4==))jq9I3.OkoQUQ^Q^_`QaQhu:D"&DK$)DMMM((40 DMM!,c2*/a ' %!eai $a!e 4I +z)V/LPZ[dfjPk26a(/#Iv6Q#Iw7#Is3(,Q`a !eai -2a )!ec$--00 $a!e 4I +z)V/LPZ[dfjPk48a(1.#Iv6Q. !ec$--00 !T]]1%5%<%<%E$--XYJZJcJcglJla(FAQ DMM!,h7Ca@P@X@X<Y\]<]a ((,44FFHQQi #dmm$$r   c                    d}| j                   D ]s  }t        |t              r||j                  |       z  })t        |t              r||j                  |       z  }Ot        |t
              s`|| j                  |      z  }u |S )zpreturn a string that removes all commands and markup 
        and represents just plain text (is not up to date)r   )r   r   r   	normalizer   r   normalize_stringr   jinjar   r   s       r	   r=   zDocNode.normalize   s     }} 	TG'7+V':K:KE:R9S-TVGW-vG<M<Me<T;U/VvGS)6T5J5J75S+S6		T
 r   c                 v    dg}dg}|D ]  }|j                  |d      } |D ]  }|j                  |d      } |S )zoremoves all strings from delete and 
        replaces all strings from make_whitespace with a single whitespacez&shy;z
&ThinSpacer    )replace)r   r   deletemake_whitespacer   s        r	   r>   zDocNode.normalize_string   sL     '*CGw(CvC&MG1MMr   c                    d}| j                   D ]  }t        |j                  t              r|j	                  |      }|r|c S t        |j                  t              sO|j                  |k(  r|c S |j                  D ]%  }|j                  j	                  |      }|s!|c c S  |j                  D ]%  }|j                  j	                  |      }|s!|c c S   |S )zreturns the first object in the docnode with classname "name"
        does not include tables but only Commands 
        and opt and req args of Commands
        returns False if no such node existsF)r   r   	__class__r   find
issubclassr   r   r%   r&   r'   )r   r   nodeelemoptargreqargs         r	   rH   zDocNode.find   s    
 MM 	)D$..'2yy$..'299$Tk"ll )F!>>..t4DD[) #ll )F!>>..t4DD[)	) r   c                 b   d}| j                   D ]  }t        |j                  t              r|j	                  |      }|s2|c S t        |t              rA|j                  D ]1  }|D ]*  }|j                  d   j                  j	                  |       , 3 t        |j                  t              s|j                  |k(  r|c S |j                  D ]%  }|j                  j	                  |      }|s!|c c S  |j                  D ]%  }|j                  j	                  |      }|s!|c c S   |S )z/similar to find but also searches Table objectsFr,   )r   rI   rG   r   find_objectr   Tablerowsr'   r&   r   r%   )r   objectrJ   rK   rowcellrL   rM   s           r	   rO   zDocNode.find_object   s   MM 	)D$..'2''/D%(99 EC # ER(00<<VDEE DNNG4>>V+D["ll )F!>>55f=DD[) #ll )F!>>55f=DD[)	)  r   c                    | j                   D ]  }t        |t              r|j                  dk(  r|j                  t        |j                        k  r|j                  }t        |j                        |kD  re|j                  |   }t        |t              r|j                  d   |j                  d<   t        d| d       |xj                  d| dz  c_	        t        d       t        d|j                   d|j                   d	       t        |t              r|j                  |       %t        |t              rB|j                  D ]1  }|D ]*  }|j                  d   j                  j                  |       , 3 wt        |t               rZ|j"                  D ]  }|j                  j                  |        |j                  D ]  }|j                  j                  |        t        |t$              s y
)zWadds to each NOTElabel object the content of the 
        corresponding NOTEtext objectlabelr,   zERROR: "z" is not a Note object.z" is not a Note object.
zLERROR: probably a NOTElabel command without a corresponding NOTEtext commandzERROR: marked note z no z' is not available in stack.markednotes!N)r   r   Notenotetype
markednoter$   markednotesr'   r   errorr   r   supplement_note_marksrP   rQ   r&   r   r%   r   )	r   stackrK   numberr9   rS   rT   rL   rM   s	            r	   r\   zDocNode.supplement_note_marks   s    MM 	D$%$--7*B??S):):%;;!__F5,,-6$008%dD1/3||B/?DLL,!HTF2I"JK!KKXdV;T+UUKlm/		{$t>OOvwxD'***51D%(99 NC # NR(00FFuMNN D'*"ll @FNN88?@"ll @FNN88?@D#&7	r   c                    d}| j                   D ]z  }t        |t              r||j                  |      z  }(t        |t              r||j                  |      z  }Mt        |t
              r|t        |      z  }lt        d| d       | |S )a  renders the object on the basis of a jinja dictionary: 
        strings are left unchanged, DocNodes are recursively included, 
        and Commands are rendered by means of 
        the render function of the Command class
        returns the rendered stringr   zRENDERING ERROR: type of r   )r   r   r   renderr   r   r   r?   s       r	   r`   zDocNode.render  s     }} 	XG'7+'..//GW-'..//GS)#g,&1':UVW	X r   c                 \   d}t        |t              r|j                  j                  D ]  }t        |t              r||z  }t        |t
              r6|j                  dk(  r||z  }>|j                  dk(  rN|j                  dk(  s^_t        |t              rp|dz  }t        d        |S y)zrenders the final document on the basis of a string 
        previously rendered with self.render() and a JinjaDocument template
        returns the rendered stringr   objattfilterz: [ERROR: incorrect expression in jinja document template] z/ERROR: "template" is not a JinjaDocument object)	r   JinjaDocumentdocr   r   JinjaExpressiontypeJinjaStatementr   )r   template
doc_stringr   r   s        r	   render_documentzDocNode.render_document-  s     h}-#<<00 Xgs+Vw->V8||u,*, . 17ZZFVWX MDr   c                     t        | j                        dk(  ry| j                  D ]!  }t        |      r|dk(  s yt        |      r! y y)zreturns True if the docnode contains either at least one nonempty string
        or at least one Command, otherwise it returns Falser   Fr   T)r$   r   r   )r   rK   s     r	   nonemptyzDocNode.nonemptyE  sG     t}}"5MM 	,D4yDYt	, r   N)__name__
__module____qualname____doc__r   r   r"   r5   r=   r>   rH   rO   r\   r`   rl   rn    r   r	   r   r   (   sH    B
&"4Y|	(*B&E0r   r   c            
          e Zd ZdZi dddddddd	d
d	dddddddddddddddddddddd d!d"i d#d"d$d"d%d&d'd(d)d*d+d,d-d.d/d.d0d1d2d1d3d4d5d6d7d(d8d9d:d,d;d<d=d>i d?d@dAdBdCdDdEdFdGdHdIdJdKdJdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_i d`dadbdadcdddeddfdgdhdidjdkdldmdndodpdodqdrdsdtdudtdvdtdwdxdydxdzdxi d{dxd|dd}d~ddddgddddddddddddddddddddddddddiZdddddddddZdddddddddd	Zi eeZi eeZd Z	d Z
d Zd Zd Zd Zd Zy)DocStacka  stack/variable with all declarations 
    this object carries several things through the entire parsing process: 
       - All kinds of declarations of commands, environments, counters, and theorems
       - Information about loaded packages and documentclasses
       - Information about default file openings and fileclosings
       - A list of unknown commands
       - An error/log stream
       - variables such as "math" that facilitate the parsing process
    
textemdashu   —
textendashu   –textcent   ¢
textdegree   °textordmasculinetextsection   §textsterling   £textasciitilde~textasciicircum^textunderscore_textvisiblespaceu   ␣textasteriskcenteredu   ⚹ztextbraceleft*{ztextbraceright*}
textbulletu   •textperiodcentered   ·ztextellipsis*u   …ldotsdotsglqqu   „grqqu   “glqu   ‚grqu   ‘flqq   «guillemotleftguillemotright   »frqqflqu   ‹frqu   ›textquotedbllefttextquotedblrightu   ”textquotelefttextquoterightu   ’o   øO   Ølu   łLu   Łr*   u   ır7   u   ȷP   ¶ztextparagraph*ddag   ‡oeu   œOEu   Œae   æAE   Æaa   åAA   Åss   ßSSu   ẞzdh*   ðzDH*u   ĐzDJ*zdj*u   đSdag   †textbar|texttrademarku   ™textexclamdown   ¡textregistered   ®cirlcedRtextquestiondown   ¿	copyright   ©ztextcopyright*textcopyrighteurou   €EURtexteuroEURofcpounds	checkmarku   ✓malteseu   ✠
textdaggertextonehalf   ½textonequarter   ¼textthreequarters   ¾langleu   ⟨rangleu   ⟩lflooru   ⌊rflooru   ⌋lceilu   ⌈rceilu   ⌉dqu   ″zolleshu   ​ʃschwau   əz&amp;#%$\)	VALEPlbrc	VALEPrbrcVALEPand	VALEPhashVALEPpctztextdollar*
textdollartextbackslashz\{z\}z\&z\#z\%z\,z\\z\mathit)	r   r   r   r   r   	VALEPnbspVALEPThinSpaceVALEPlbemphc                 X   t               | _        t               | _        t               | _        d}|dk  rbt        dd|       }|| j                  d| <   |dkD  r1| j                  d|dz
      j                  j                  d|        |dz  }|dk  rbfd t              }|D ]1  }t        d|j                        }|| j                  |j                  <   3 t        dd      }|| j                  d<   t        dd      }|| j                  d<   t        dd	      }|| j                  d	<   t        dd
      }|| j                  d
<   t        dd      }|| j                  d<   t        dd      }|| j                  d<   t        dd      }|| j                  d<   t        dd      }|| j                  d<   t               | _
        t               | _        d| _        d| _        d| _        t               | _        d| _        d| _        d| _        d| _        d| _        d| _        t               | _        | j.                  j                  d       d| _        t3        d|       | _        d| _        d| _        d| _        d| _        d| _        d| _         d| _!        d| _"        d| _#        d| _$        y)a  Declares all variables of the DocStack object:
            - cds = list of all command declarations
            - envs = list of all environment declarations
            - counters = dict of all counters (which will be immediately filled 
                with standard counters)
            - theorems = list of all theorems
            - packages = set of all packages that were already included
            - packagestring = string of all declarations from packages
            - fileopening = default fileopening
            - fileclosing = defult fileclosing
            - unknown = dict of all unknown macros

            - and a bunch of further important global variables
           
newcountersection@r    c                     g }| j                         D ]*  }|j                  |       |j                   |             , |S r   __subclasses__r#   r!   cls
subclassessubclassget_sub_classess      r	   r   z*DocStack.__init__.<locals>.get_sub_classes  I    J..0 =!!(+!!/(";<= r   MarkedNotesenumienumiienumiiienumivequationfiguretabler   z

\begin{document}

z+

\end{document}

%% END DOCUMENT valeptex
Cvalep\(\mathsf{\TeX}\): conversion from \(\mathsf{\LaTeX}\) to HTML   FThtmlN)%r   cdsenvsdictcountersr   
incountersr#   rW   ro   theoremssetpackagespackagestringfileopeningfileclosingunknowntitleauthordate	madetitletocdepthr[   rZ   r.   	JinjaSpecr@   template_stringfilenamer=   writelogwriteunknowndefaultpreamblepreamblemodefirstdoccarnapeditionoutput_format)r   r*   	new_countclassesr   r   s        @r	   r   zDocStack.__init__  s    6F	 "f"<(1#?I,5DMMHQC.)3w1&67BBIIHUVTW.YFA	 "f	 "$' 	4C"<>I*3DMM#,,'	4 |];	'0m$|W5	!*g|X6	"+h|Y7	#,i |X6	"+h|Z8	$-j!|X6	"+h|W5	!*g 6Nv \
	
6#	r4(
!!# "#r   c                 `    | j                   D ]  }| j                   |   j                          ! y)z'resets all counters of the counter dictN)r  reset)r   counters     r	   reset_counterszDocStack.reset_counters  s%    }}DGdmmG&<&B&B&DDr   c                     d| _         d| _        d| _        d| _        t	               | _        | j
                  j                  d       y)zaresets all those transient elements that become refilled 
        for each document in batch moder  r   N)r  r  r  r  r   rZ   r#   r   s    r	   reset_transient_elementsz!DocStack.reset_transient_elements  s?     \
	6#r   c                 z    ddg}| j                   D ](  }|j                  |k(  s|j                  dk(  s#||vs( y y)zchecks if a command of class command_name is a defined text macro
        excludes all text macros being mentioned in the list exceptions
        ltgtr   TF)r  r   narg)r   command_name
exceptionsr9   s       r	   is_defined_textmacrozDocStack.is_defined_textmacro  sF     D\
HH 	lDyyL(TYY!^LT^D^gk	lr   c                 `    | j                   D ]  }|j                  |k(  s|j                  c S  y)zreturns the definition as a DocNode object if it is 
        a defined texmacro (i.e. macro without arguments)
        returns False otherwise
        F)r  r   begdef)r   r/  r9   s      r	   get_definition_textmacroz!DocStack.get_definition_textmacro  s/    
 HH 	=DyyL(*<	=r   c                 P   d}| j                   rd}| j                   D ]8  }t        |t              r||j                          dz  }*t	        d| d       : | j
                  r|dz  }| j
                  D ]8  }t        |t              r||j                          dz  }*t	        d| d       : | j                  r|dz  }| j                  D ]R  }t        | j                  |   t              r$|| j                  |   j                          dz  }Dt	        d| d       T | j                  r|dz  }| j                  D ]8  }t        |t              r||j                          dz  }*t	        d| d       : | j                  r|d	z  }| j                  D ])  }t        |t              s||j                          dz  }+ | j                  r|d
z  }t        | j                  j                               }|j                          |D ]  }|| d| j                  |    dz  } |S )zAexpands the most important variables and returns them as a stringr   z%
LIST OF DECLARATIONS:
(1) Commands:
r   zERROR: z# does not have the type NewCommand!z
(2) Environments:
z
(3) Counters:
z
(4) Theorems:
z
(5) Packages:
$
UNKNOWN COMMANDS AND ENVIRONMENTS

 ()
)r  r   
NewCommandr   r   r	  r  r  r  r   r  r   keyssort)r   r   r   r:  ks        r	   r   zDocStack.expand	  s0   88HVxx 	PG':.W^^=M<Nb:Q0Q''*MNO	P 99f 77fyy 	PG':.W^^=M<Nb:Q0Q''*MNO	P ==&$77&}} 	PG$--0*=vDMMZaLbLiLiLkKllnIo?ov''*MNO	P ==&$77&}} 	PG':.W^^=M<Nb:Q0Q''*MNO	P ==&$77&}} 	OG'7+V'..:J9K27N-NV	O<<#LLDLL%%'(		=AvA3ba(9!==v=r   c                     d}t        | j                  j                               }|j                          |D ]  }|| d| j                  |    dz  } |S )zAexpands the dict of all unknown macros and returns it as a stringr6  r7  r8  )r   r  r:  r;  )r   r   r:  r<  s       r	   expand_unknownzDocStack.expand_unknown%  sV    :DLL%%'(		=AvA3ba(9!==v=r   N)ro   rp   rq   rr   text_macros_generaltext_macros_specialtext_macros_special_mathtext_macrostext_macros_mathr   r(  r*  r1  r4  r   r>  rs   r   r	   ru   ru   N  s   
e
)5
2<d
DPRV
D
"/
7Et
 	#
  1#
 7G
 N`af
 		
 (8	
 ?PQT	

 	e

 24

 :I%

 RYZ_

 bhin
 	
 u
 ',U
 5:5
 	
 &t
 .>t
 FLT
 TYZ_
 bghm
 	E
 $7
 @OPU
 Xhin
 	T
 
 "4
 *-d
 58
 @CD
 KNt
 Vfgk
 ntuz
 	d
 $
 !%d
 -1$
 9=d
 EI$
 QUVZ
 ]abg
 	t
 D
 #(
 05d
 	T
 %
 "+C
 2A%
 JZ[_
 	$
 !+D
 3Ed
 MXY]
 `pqu
 xG  IM
  	!
  e!
  &0!
  9A%!
  JRSW!
" 	U#
" &u#
" /;E#
" DQRV#
" Yijn#
$ 	T%
$ $,U%
$ 5=e%
$ FNu%
$ W_`e%
$ hopu%
& 	'
& e'
& &,U'
* 	w+
*  +
8 sc_b#
 EPUchEvz 

 A(@,?@KJ2J6IJ`$DE	$8r   ru   c                       e Zd ZdZd Zd Zy)r9  a'  comprises all macros of the types 
    newcommand, newcommand*, newcounter, newinvironment, newenvironment*, newtheorem
    this is clumsy but it works. It covers all declarations
    By now onyl text-macros (i.e. LaTeX macros without arguments) 
    are resolved during the parsing process
    c                     t        |      | _        t        |      | _        d| _        t	               | _        t	               | _        t	               | _        t	               | _        y Nr   )	r   rh   r   r.  r   optsecoptr3  enddef)r   rh   r   s      r	   r   zNewCommand.__init__4  sC    I	I		9iiir   c           
      &   | j                   dk(  s| j                   dk(  rd| j                   }n| j                  }| j                  rd| j                   d}nd}| j                  r9| j                  j	                         rd| j                  j	                          d}nd}| j
                  r9| j
                  j	                         rd| j
                  j	                          d}nd}| j                  r9| j                  j	                         rd| j                  j	                          d}nd}| j                  r9| j                  j	                         rd| j                  j	                          d}nd}d| j                    d| d| | | | | 
S )	N
newcommandznewcommand*r   []r   r   r   )rh   r   r.  rG  r   rH  r3  rI  )r   commandr.  rG  rH  r3  rI  s          r	   r   zNewCommand.expandC  sT   99$		](B499+&GiiG99q1-dd88)dhhoo'(*Cc;;4;;--/++-.a0Ff;;4;;--/$++,,./r2Ff;;4;;--/$++,,./r2FfDII;b	D6#vhvhvhOOr   Nro   rp   rq   rr   r   r   rs   r   r	   r9  r9  -  s     Pr   r9  c                       e Zd ZdZy)rK  zMmain subclass of NewCommand, 
    which represents the LaTeX macro newcommandNro   rp   rq   rr   rs   r   r	   rK  rK  X  s
    3r   rK  c                       e Zd ZdZy)newenvironmentzany newenvironment declarationNrQ  rs   r   r	   rS  rS  ]  s    (r   rS  c                     t        |       } t        | t               rDg d}g d}d}d}| dkD  r1t        | ||   z        D ]  }|||   z  }| ||   z  }  |dz  }| dkD  r1|S y)zconverts an int into a string representing the corresponding
    roman number (works for all ints > 0 but only roman numerals 
    up to 100_000 are included), uses uppercase lettersi i_ iP  i@  i'  i(#  i  i  i  i  i  i  d   Z   2   (   
   	      r  r    )   ↈ   ↇↈ   ↇ   ↂↇ   ↂ   ↁↂ   ↁ   MↁMCMDCDCXCr   XLXIXVIVIr   r   r    Nintr   rangenumvalsyb	roman_numr*   r   s         r	   int_to_Romanry  a  s     c(C#s@G	Ag3#a&=) SV#	s1v FA	 Ag
 r   c                     t        |       } t        | t               rDg d}g d}d}d}| dkD  r1t        | ||   z        D ]  }|||   z  }| ||   z  }  |dz  }| dkD  r1|S y)z1just like int_to_Roman but uses lowercase lettersrU  )r]  r^  r_  r`  ra  rb  rc  rd  mcmdcdcxcr   xlxixvivr*   r   r   r    Nrq  rt  s         r	   int_to_romanr  v  s    
c(C#s@G	Ag3#a&=) SV#	s1v FA	 Ag
 r   c                 R    t        |       } t        | t               rg d}|| dz     S y)zD converts each integer into a lowercase letter 
    0 == z, 27 == a )zabr  r}  efghr*   r7   r<  r   r{  nr   pqrstur  wr  y   Nrr  r   ru  alphs     r	   int_to_alphr    s0     c(C#sLC"H~r   c                 R    t        |       } t        | t               rg d}|| dz     S y)z0just like int_to_alph but uses uppercase letters)ZABri  rg  EFGHrp  JKr   re  Nr   r   QRr   TUrn  Wrl  Yr  Nr  r  s     r	   int_to_Alphr    s.    
c(C#sQC"H~r   c                 R    t        |       } t        | t               rg d}|| dz     S y)uR   converts each int into one element of the list fnsymbols
    0 == ‡‡, 10 == * )	u   ‡‡*r   r   r~   r   u   ‖z**u   ††r[  Nr  )ru  fnsymbols     r	   int_to_fnsymbolr    s.     c(C#sTa  r   c                   L     e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
d	 Z xZS )
r   a   all counters are handled with the newcounter class
    In addition to NewCommand there are three variables:
        - counterstyle (Arabic, Roman etc. 
            currently hardly used since the counterstyle is mostly determined
            at jinja level)
        - value = integer, as in LaTeX the initial value is 0
        - incounters = list of all counters that must be reset when the 
            counter is incremented
    c                 P    t         |   ||       d| _        d| _        g | _        y )Nr   r   )superr   counterstylevaluer  )r   rh   r   rG   s      r	   r   znewcounter.__init__  s(    t$
r   c                     t        |t              re||j                  v rW| j                  |j                  |   j                  vr2|j                  |   j                  j                  | j                         |S )z+specifies an element of the list incounters)r   r   r  r   r  r#   )r   r]   r   s      r	   setincounterznewcounter.setincounter  sX    fc"v'?99v 6 A AAv&1188Cr   c                     | j                   S )zreturns the countervaluer  r   s    r	   getvalueznewcounter.getvalue  s    zzr   c                 4    t        |t              r|| _        yy)zsets the countervalue to numNr   rr  r  r   ru  s     r	   setvalueznewcounter.setvalue  s    c3cr   c                 .    | xj                   dz  c_         y)zincrements the countervaluer    Nr  r   s    r	   	incrementznewcounter.increment      

a
r   c                 .    | xj                   dz  c_         y)zdecrements the countervaluer    Nr  r   s    r	   	decrementznewcounter.decrement  r  r   c                 P    t        |t              r| xj                  |z  c_        yy)zadds num to countervalueNr  r  s     r	   addtocounterznewcounter.addtocounter  s    c3s!2r   c                     d| _         y)zresets the countervalue to 0r   Nr  r   s    r	   r&  znewcounter.reset  s	    
r   )ro   rp   rq   rr   r   r  r  r  r  r  r  r&  __classcell__rG   s   @r	   r   r     s0    23r   r   c                       e Zd ZdZy)
newtheoremz6specifies a new theorem (is currently not implemented)NrQ  rs   r   r	   r  r    s    @r   r  c                       e Zd ZdZd Zd Zy)r  aY  class for jinja2h specifications
    parses jinja specifications that have the form 
    

name: LIST OF COMMANDNAMES
SPECIFICATION

    the main variables are: 
    - stack = a Docstack object that is transfered to the object as an argument
    - elements = dict that contains all specifications 
        in the form command: specification
    c                 p   || _         t               | _        t        j                  dd|      }|j                  d      }|D ]s  }|s|j                         d   }|t        |      dz   d }|j                         j                         }t        || j                         }|D ]  }|| j                  |<    u y)zSfills the stack and all specifciations as contained in string
        in the object\{#[^#].*#\}r   z

name:r   r    N)
r]   r
  r   r   subsplit
splitlinesr$   stripJinjaCommSpec)	r   r   r]   specsspecitcommsspecspeclistr9   s	            r	   r   zJinjaSpec.__init__  s     
OBv6[) 	3F))+A.c%jlm,++-(tzz:! 3D*2DMM$'3	3r   c                 <    | j                   D ]  }t        |        y)zsimply prints all elementsN)r   r   )r   r   s     r	   r   zJinjaSpec.expand  s    }} 	G'N	r   NrO  rs   r   r	   r  r    s    3 r   r  c                       e Zd ZdZd Zy)re   zclass for jinja2h document templates, 
        e.g. html header that places the rest of the document with an {{ obj }} expression
    c                 p    || _         || _        t        j                  dd|      }t	        ||      | _        y )Nr  r   )r]   r   r   r  r  rf   )r   r   r  r]   s       r	   r   zJinjaDocument.__init__  s0    
))_RH %8r   Nro   rp   rq   rr   r   rs   r   r	   re   re     s    9r   re   c                       e Zd ZdZd Zy)r  a.  class for a single jinja command specification 
    parses it into a list of text-elements, jinja statements, and jinja expressions
    The variables are: 
    - stack = DocStack object
    - elements = list of all elements of the specification
    - normaltext = string, normaltext representation
    c                    || _         t               | _        d| _        t	        j
                  d|      rt	        j
                  d|      }|}|j                         dkD  r,| j                  j                  |d|j                                 |j                  d      dk(  r|j                  d      dk(  r|j                  d      j                         }|dd dk(  rt	        j
                  d	|      r^t	        j
                  d	|      }t        ||j                         |j                          |      }| j                  j                  |       nF| xj                  d
|j                   dz  c_        t        d       n|xj                  d
|j                   dz  c_        t        d       n|j                  d      dk(  rX|j                  d      dk(  rDt        |j                  d      j                               }| j                  j                  |       n{|j                  d      dk(  r9|j                  d      dk(  r%|j                  d      j                         | _        n.|xj                  d
|j                   dz  c_        t        d       ||j                         d }t	        j
                  d|      r|r| j                  j                  |       yy)z2stores the stack object and parses the spec stringr   z\{(\%|\{|\!)(.*?)(\%|\}|\!)\}r   r    r         if\{\%\s*endif\s*\%\}zjinja ERROR in z: incomplete if statement.
z%jinja ERROR: incomplete if statement.z: statement type not covered.
z(jinja ERROR: statement type not covered.r   r   !z: incorrect syntax.
zjinja ERROR: incorrect syntax.N)r]   r   r   
normaltextr   r   startr#   groupr  ri   endr[   r  r   rg   )r   r  r]   	specstartspecend	statement
expressions          r	   r   zJinjaCommSpec.__init__  s;   
ll;DA%EdKIG 1$dmm&:&:4)//BS;T&Uq!S(Y__Q-?3-F%OOA.446	Qq>T)||$:4@"',,/Ed"K$24	8I'++-3XZ_$`	,,Y7

7GGc&dd
 EGKK_U^^4DDc#ddKDF#s*yq/AS/H,Y__Q-?-E-E-GH
$$Z0#s*yq/AS/H"+//!"4":":"<0@@UVV68(D5 ll;DA6 %%d+4r   Nr  rs   r   r	   r  r    s     ,r   r  c                       e Zd ZdZd Zy)JinjaIfClausezFif clause in jinja statements of the form {% if QUESTION %} ANSWER ...c                 T    || _         t        |      | _        t        ||      | _        y r   )r]   rg   questionr  answer)r   r  r  r]   s       r	   r   zJinjaIfClause.__init__5  s#    
'1#FE2r   Nr  rs   r   r	   r  r  3  s
    P3r   r  c                       e Zd ZdZd Zy)ri   a  jinja statement
    currently the only covered variety is: 
    {% if EXP %} {% elif EXP %} {% else %} {% endif %} 
    for statements might be included later but are currently not needed
    Variables: 
    - stack = DocStack object
    - elifs = list of if/elif clauses
    - else = JinjaCommSpec for else clause
    - fortarget = JinjaExpression for for clause (not implemented)
    - forobject = JinjaExpression for for object (not implemented)
    - forblock = JinjaCommspec for main block of for statement (not implemented)
    c                    || _         t               | _        t        d      | _        t        d      | _        t        d|      | _        t        d|      | _        |dd dk(  r|dd dk(  rt        j                  d|      rt        j                  d	|      }|j                  d
      j                         }|j                  d      }t        |||      }| j                  j                  |       ||j                         d }t        j                  d|      rt        j                  d|      }|j                  d
      j                         }|j                  d      }t        |||      }| j                  j                  |       ||j                         d }t        j                  d|      rt        j                  d|      rKt        j                  d|      }|j                  d
      }t        ||      | _        ||j                         d }t        j                  d|      st!        d|        yt!        d|        yyt!        d|        y)z4stores stack and parses spec into statement elementsr   r   r  z{%Nz%}z	\{\%\s*ifz\{\%\s*if(.*?)\%\}(.*?)(?=\{\%)r    z!\{\%\s*elif(.*?)\%\}(.*?)(?=\{\%)z\{\%\s*else\s*\%\}(.*?)(?=\{\%)r  z$jinja ERROR: if statement ends with z%Something wrong with jinja statement z.There is something wrong with jinja statement )r]   r   elifsrg   	fortarget	forobjectr  forblock
elseclauser   matchr  r  r  r#   r  r   )r   r  r]   r  r  r  clauses          r	   r   zJinjaStatement.__init__H  s   
V
(,(,%b%0'E2!9bcd!2{{<.!KK(J4P	$??1-335"+&x?

!!&)IMMO,-kk"FtL %,PQU VI(q1779H&__Q/F*8VUCFJJ%%f-	 01D kk"FtL ;;A$G %,Nt TI&__Q/F&3FE&BDO	 01D{{#9$?ImnrmsGtAu=dVDE @ B4&IJr   Nr  rs   r   r	   ri   ri   ;  s    $Kr   ri   c                       e Zd ZdZd Zy)rg   zJinja Expression, varieties: obj, obj.attributes, obj.members, obj.counter
    additional functions would be helpful e.g. obj.attributes.XXX.YYY here: .YYYc                 (   |j                         }|dk(  rd| _        d| _        y |dd dk(  rd| _        |dd  | _        y |dd d	k(  rd
| _        |dd  | _        y |dd dk(  r#d| _        t	        j
                  d|dd        r>t        t	        j
                  d|dd        j                  d            | _        d| _	        y t	        j
                  d|dd        r5d| _        t	        j
                  d|dd        j                  d      | _	        y t	        j
                  d|dd        rOt	        j
                  d|dd        }t        |j                  d            | _        |j                  d      | _	        y d| _        d| _	        y d| _        || _        y )Nrb   r   r      zobj.attributesrc         zobj.membersmemb   zobj.counterr'  z\((\-?\d+)\)z\((-?\d+)\)r    arabicz(\(\'[a-zA-Z]+\'\))z\(\'([a-zA-Z]+)\'\)z\(\-?\d+\,\'[a-zA-Z]+\'\)z\((\-?\d+)\,\'([a-zA-Z]+)\'\)r  rd   )
r  rh   	attributememberr   r  rr  r  levelstyle)r   exprr  s      r	   r   zJinjaExpression.__init__s  sk   zz|5=DIDN!BZ++DI!"#YDN!BZ=(DIrs)DK!BZ=(!DI{{?495 ^DI!F!L!LQ!OP
%
3DI>
"[[)?RS	JPPQRS
9$rs)D$DT"#YO Q0
"[[^

%
 DI!DNr   Nr  rs   r   r	   rg   rg   p  s    T"r   rg   c                       e Zd ZdZd Zy)ArgumentzlArgument of a Command. Variables:
    - name = string
    - datatype = string
    - content = DocNode()
    c                 ^    t               | _        t               | _        t               | _        y r   )r   r   datatyper   r&   r   s    r	   r   zArgument.__init__  s    E	yr   Nr  rs   r   r	   r
  r
    s    
!r   r
  c                   >    e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
d	 Zy
)r   a  Any LaTeX command or environment must be specified as a subclass of Command.
    Parameter: 
    Args = string that represents all arguments of the command

    Variables: 
    - name = string (in most cases redundant, i.e. identical with the class name)
    - optargs = list of all optional arguments
    - reqargs = list of all required arguments
    - argdict = dictionary of all argument names r   c                    t        |      | _        t               | _        t               | _        t               | _        d }t        j                  d|| j                  j                        }|j                         }d}d}|D ]  }|d   dk(  r|d   dk(  rz|dd j                  d      }t        |      dkD  r|d   }nd	}t               }	|d   |	_        ||	_        | j                  j                  |	       d
|g| j                  |d   <   |dz  }|j                  d      }t        |      dkD  r|d   }nd	}t               }	|d   |	_        ||	_        | j                  j                  |	       d|g| j                  |d   <   |dz  } y )Nc                 L    d| j                  d      j                          d}|S )NrL  r    rM  )r  r  )r  replacements     r	   replzCommand.__init__.<locals>.repl  s(    ekk!n2245Q7Kr   z\[([^\]]*)\]r   rL  r,   rM  r    :r   rG  req)r   r   r   r%   r'   r
  argdictr   r  rG   argsr  r$   r
  r  r#   )
r   r   r  r  optargnrreqargnrarg
argcontentr  arguments
             r	   r   zCommand.__init__  so   I	vvv	 yy$0C0CDzz| 	C1v}RC 2Y__S1
z?Q&:a=!#h#: *1$,!##H-/4X.>Z]+A YYs^
z?Q&:a=!#h#: *1$,!##H-/4X.>Z]+A)	r   c                 @   d}|j                   D ]  }t        |t              r||z  }t        |t              r1|j                  dk(  r| j
                  rt        | j                  t              r>| j
                  d   j                  j                  |      }|dd  dk(  r|d d dz   }||z  }t        | j                  t              r=| j
                  d   j                  j                  |      j                  d      }||z  }|| j
                  d   j                  j                  |      z  }"|dz  })|j                  dk(  r.|j                  | j                  v r| j                  |j                     d	   d
k(  rG|| j                  | j                  |j                     d      j                  j                  |      z  }| j                  |j                     d	   dk(  rG|| j
                  | j                  |j                     d      j                  j                  |      z  }|dz  }$t!        j"                  d|j                        sFt!        j"                  d|j                        }|j%                  d      }|j                  d	|j'                          }	|| j                  v s| j                  |   d	   d
k(  rI| j                  | j                  |   d      |	   r'|| j                  | j                  |   d      |	   z  }| j                  |   d	   dk(  rI| j
                  | j                  |   d      |	   r'|| j
                  | j                  |   d      |	   z  }`|dz  }g|j                  dk(  rt        | j                  t(              r| j*                  |j*                  z   }
|j,                  }|
| j.                  v s| j.                  |
   }t        |t0              r|dk(  r|t        |      z  }|dk(  r|t3        |      z  }|dk(  r|t5        |      z  }$|dk(  r|t7        |      z  }9|dk(  r|t9        |      z  }N|dk(  sU|t;        |      z  }e|d| dz  }pt        | j                  t<              r| j.                  }|j,                  }t        |t0              r|dk(  r|t        |      z  }|dk(  r|t3        |      z  }|dk(  r|t5        |      z  }|dk(  r|t7        |      z  }|dk(  r|t9        |      z  }|dk(  s"|t;        |      z  }2|d| dz  }=?|j                  dk(  r|dz  }U|dz  }\t        |t>              r|j@                  D ]  }|jB                  r|jD                  rd}|jB                  j                  dk(  r;| j
                  rl| j
                  d   j                  jG                         }|rBd}n>|jB                  j                  dk(  r|jB                  j                  jI                  d      }tK        |      dkD  rn|d	   | j                  v r| j                  |d	      d	   d
k(  ra| j                  | j                  |d	      d      r?| j                  | j                  |d	      d      j                  jG                         }|rid}nf| j                  |d	      d	   dk(  rN| j
                  | j                  |d	      d      r,| j
                  | j                  |d	      d      }|rd}n|dz  }|s|| jM                  |jD                  |      z  }|d z  } |jN                  sf|| jM                  |jN                  |      z  }|dz  } |S )!Nr   rb   r,   z.epsz.svgz{}rc   r   rG  r    r  z[UNKNOWN ARGUMENT]z\[(.*)\]z([something wrong with special attribute]r'  r  Romanromanr  Alphr  zJinja Error: "z" is not an intrd   z  [FILTER (not yet implemented) ]z! [RENDERING ERROR IN JINJA FILE] FTrL  z[FILTER (not yet implemented)]z'[jinja ERROR: if clause is incomplete.])(r   r   r   rg   rh   r'   rI   rG   includegraphicsr&   r`   VerbatimCommandr  r  r  r%   r   r   r  r  Sectionr  r  countervaluerr  ry  r  r  r  r  rW   ri   r  r  r  r   r  r$   render_jinja_specr  )r   r  r@   r9   r   textverbtextindexargprr  counterlevelr  r  quandaqur&   attnames                    r	   r$  zCommand.render_jinja_spec  s   }} {	<G'#&GO4<<5(||%dnnoF#'<<#3#;#;#B#B5#ID#BCyF249v;MD DLD'H'+||B'7'?'?'F'Fu'M'S'STX'YH H,D DLL$4$<$<$C$CE$JJD 
\\U*((DLL8<<(9(9:1=F DLLg>O>O1PQR1S$T$\$\$c$cdi$jjD!\\'*;*;<Q?5H DLLg>O>O1PQR1S$T$\$\$c$cdi$jjD $88D !<<G4E4EF$)LLW=N=N$OE$)KKNE")"3"3Aekkm"DC$4#'<<#6q#9U#Bt||TXT`T`afTghiTjGkloGp$(DLLe9LQ9O,PQT,U$UD%)\\%%8%;u%DVZVbVbchVijkVlImnqIr$(DLLe9LQ9O,PQT,U$UD$(,V$VD\\Y.!$..':'+zzGMM'A'.}}'4+<+<<$($5$5l$CE)%5#/8#;$(CJ$6D%1W%<$(L,?$?D%1W%<$(L,?$?D%1V%;$(K,>$>D%1V%;$(K,>$>D%1Z%?$(OE,B$BD $.(O O#DNND9 $ 1 1'.}}%eS1+x7 $E
 2!-!8 $U(; ;!-!8 $U(; ;!-!7 $E(: :!-!7 $E(: :!-!; $(> > nUG?$KKD \\X->>D??DGN3%mm JF6=="!??//58#||*.,,r*:*B*B*I*I*K#*B#__11U:&,oo&?&?&E&Ec&JG"7|a/ $ $+1:#='+||GAJ'?'Be'KPTP\P\]a]i]ijqrsjt]uvw]xPy26,,t||GTUJ?WXY?Z2[2c2c2j2j2l+2B)-gaj)A!)D)MRVR^R^_c_k_klstulv_wxy_zR{26,,t||GTUJ?WXY?Z2[+2B $DDD D$:$:6==%$PPD II=J> %%D2273E3EuMMD;;w{	<x r   c                    d}t        | j                  t              rt        | t              r|d| j                          dz  }|S t        | t              r|d| j                          dz  }|S t        | t              r|d| j                          dz  }|S t        | t              r|d| j                          d	z  }|S t        | t              r|d
| j                          dz  }|S t        | t              r|d| j                          dz  }|S d}|S t        | j                  t              r| j                  |j                  v r|j                  | j                     j                  d   j                  d      }t               }|D ]  }t!        |      dkD  s|dd  ||dd <    d|vrd|d<   d|vrd|d<   d|vrd|d<   d|vrd|d<   d|vrd|d<   d|vrd|d<   d|vrd|d<   |d|d    z  }| j"                  D ]  }|d|d    z  }|D ]  }|d   }t%        j&                  d|      x}	r|	j)                  d      dz   }n|d   dk(  r|d d dz   }|j*                  r|d z  }|j,                  |j.                  cxk(  r|j0                  cxk(  r|j2                  k(  rn n|d!|j,                   dz  }n:|d"|j,                   d#|j.                   d$|j0                   d%|j2                   d	z  }|d&z  }|j4                  d'k(  r|d(z  }|j4                  d)k(  r|d*z  }|j4                  d+k(  r|d,z  }|j6                  dkD  r|d-t9        |j6                         d.z  }|j:                  dkD  r|d-t9        |j:                         d.z  }|| d|d    |j<                  d   j>                  jA                  |       |d    z  } ||d    z  } |d|d    dz  }|S |d/z  }| j"                  D ]B  }|d0z  }|D ]1  }|d1|j<                  d   j>                  jA                  |       d2z  }3 |d3z  }D |d4z  }|S t        | j                  tB              r| j                  d5z   }
| j                  d6z   }|
|j                  v ro||j                  v ra| jD                  r"|| jG                  |j                  |   |      z  }| jH                  r%|d| jG                  |j                  |
   |      z   z  }|S tK        d7       | j                  |j                  v r+| jG                  |j                  | j                     |      }|S y | j                  |j                  v r+| jG                  |j                  | j                     |      }|S |S )8Nr   z\(z\)z\[z\]z\begin{equation}z\end{equation}z\begin{equation*}z\end{equation*}z\begin{eqnarray}z\end{eqnarray}z\begin{eqnarray*}z\end{eqnarray*}z [ERROR: formula type unknown] r   @r    r  tbrbcbcccereter   z((?:.*?)style="(?:.*?));?">;r,   >z style="zdisplay:none;zborder-style:zborder-left-style:z;border-right-style:z;border-top-style:z;border-bottom-style:zborder-width:1px;padding:5px;r   ztext-align:left;"r  ztext-align:right;"r  ztext-align:center;"z
 colspan=""z	
<table>
z
<tr>z<td>z</td>z</tr>z

</table>
z@startz@endzHERROR: no start and and definition for Par object in jinja specification)&rI   rG   Formular   r.   expand_formuladisplaymathr  	equation_eqnarray	eqnarray_rP   r   r   r  r
  r$   rQ   r   r  r  hidden
left_styleright_style	top_stylebottom_stylealigncolspanr   rowspanr'   r&   r`   r/   r2   r$  r0   r   )r   r@   r9   	tablespec	tabledictr  rS   rT   	cellstyler  r  r  s               r	   r`   zCommand.renderQ  sU   dnng.$t$dD4G4G4I3J#.N&Nd K D-tT=P=P=R<SSV7W/Wt K D(+T7J4K^K^K`Jaar5s-sT K D),d8LTM`M`MbLccu6v.vd
 K	 D(+T7J4K^K^K`Jaar5s-sT K D),d8LTM`M`MbLccu6v.vd K 9K. yyENN*!NN4995>>qAGGL	 F	% FD4y1}T!"XiQq	&:Fy(B)D/y(B)D/y(B)D/y(B)D/y(B)D/y(B)D/y(B)D/"Yt_-..99 1Cb4 122D # z %.dO	%*[[1OQZ%[[E[jojujuvwjx{~j~^g&r]c1y"~PZ?Z9;;	_(D	??d.>.>e$..eTXTeTee%=8I)KKI%+=doo=NNbcgcscsbt  uG  HL  HV  HV  GW  Wl  mq  m~  m~  l  @  *A  AI!%DD	::,i;N.Ni::,i;O.Oi::,i;P.Pi<<!+YJs4<<GXFYYZ:[-[Y<<!+YJs4<<GXFYYZ:[-[Y9+Qy.?R@P@X@X@_@_`e@f?ghqrvhwgx yy'z( y/0D-1. "Yt_-R00 K %99 $CH$D # U$t||B'7'?'?'F'Fu'M&Ne TTUGOD	$
 &K,II(E))f$C&3%..+@;;D225>>#3FNND==D4#9#9%..:OQV#WWWD`a99.11%..2KUSDK / yyENN*--ennTYY.GO  r   c                    t        | j                  t              r| j                         S d}| j                  D ]#  }|d|j
                  j                          dz  }% d}| j                  D ]#  }|d|j
                  j                          dz  }% |s|r(| j                  dk(  r| | S d| j                   | | S d| j                   dS )	Nr   rL  rM  r   r   r.   r   rB   )	rI   rG   rP   expand_tabler%   r&   r   r'   r   r   r%   r  r'   s       r	   r   zCommand.expand  s    dnne,$$&&<<GCa0B0B0D/EQ,G!GG<<ICb1C1C1E0Fb,I!IIgyyF"!7),,DII;wiy99		{!$$r   c                 <   t        | j                  t              ryt        | j                  t              ryt        | j                  t              rF|j
                  | j                     j                  r#|j
                  | j                     j                  S t        | j                  t              ryt        | j                  t              ryt        | j                  t              s6| j                  r*| j                  d   }|j                  j                  |      S y)Nr   rB   z[TABLE]z	[FORMULA]r,   r   )rI   rG   Lineend	NoLineend	TextMacror   r   r  rP   r9  Ignorer'   r&   r=   )r   r@   r  s      r	   r=   zCommand.normalize  s    dnng.t	23	2u~~dii7P7[7[>>$)),777.y0DNNF3||ll2&{{,,U33r   c                 v    d}| j                   D ]'  }|dz  }|D ]  }|j                         }|d| dz  } ) |S )Nr   z	    ROW: zCELL: r   )rQ   r   )r   r   rS   rT   r   s        r	   rK  zCommand.expand_table  sX    99 	+C;C +xr**+	+
 
r   c                    d}| j                   D ]#  }|d|j                  j                          dz  }% d}t        | j                        dkD  r5| j                  dd D ]#  }|d|j                  j                          dz  }% t        | j                        dkD  r*|| j                  d   j                  j                         z  }| | S )	Nr   rL  rM  r    r   r,   r   r   )r%   r&   r   r$   r'   rL  s       r	   r:  zCommand.expand_formula  s    <<GCa0B0B0D/EQ,G!GGt||q ||Ab) 9R 2 2 45R889t||q 'T\\"-=-E-E-L-L-N"N'7)$$r   N)ro   rp   rq   rr   r  r   r$  r`   r   r=   rK  r:  rs   r   r	   r   r     s6    5 D!F~DcL%%r   r   c                       e Zd Zy)r4   Nro   rp   rq   rs   r   r	   r4   r4         r   r4   c                       e Zd Zy)r1   NrU  rs   r   r	   r1   r1     rV  r   r1   c                       e Zd Zy)SystemCommandNrU  rs   r   r	   rY  rY    rV  r   rY  c                       e Zd Zy)UnknownCommandNrU  rs   r   r	   r[  r[    rV  r   r[  c                       e Zd ZdZy)r-   r   Nro   rp   rq   r  rs   r   r	   r-   r-         Dr   r-   c                       e Zd ZdZy)
usepackage[ opt ] selfNr]  rs   r   r	   r`  r`    s    Dr   r`  c                       e Zd ZdZy)inputr   Nr]  rs   r   r	   rc  rc     r^  r   rc  c                       e Zd ZdZy)includer   Nr]  rs   r   r	   re  re    r^  r   re  c                       e Zd Zy)rQ  NrU  rs   r   r	   rQ  rQ  
  rV  r   rQ  c                       e Zd Zy)EnvironmentNrU  rs   r   r	   rh  rh    rV  r   rh  c                       e Zd ZdZy)	FormatEnvr   Nr]  rs   r   r	   rj  rj        Dr   rj  c                       e Zd Zy)UnknownEnvironmentNrU  rs   r   r	   rm  rm    rV  r   rm  c                       e Zd ZdZy)documentr   Nr]  rs   r   r	   ro  ro    rk  r   ro  c                       e Zd Zy)r9  NrU  rs   r   r	   r9  r9    rV  r   r9  c                       e Zd Zy)MathNrU  rs   r   r	   rr  rr    rV  r   rr  c                       e Zd ZdZy)
EnsureMathr   Nr]  rs   r   r	   rt  rt     r^  r   rt  c                       e Zd Zy)
ensuremathNrU  rs   r   r	   rv  rv  #  rV  r   rv  c                       e Zd ZdZy)r.   r   Nr]  rs   r   r	   r.   r.   &  rk  r   r.   c                       e Zd ZdZy)r;  r   Nr]  rs   r   r	   r;  r;  )  rk  r   r;  c                       e Zd ZdZy)r  r   Nr]  rs   r   r	   r  r  ,  rk  r   r  c                       e Zd ZdZy)r<  r   Nr]  rs   r   r	   r<  r<  /  rk  r   r<  c                       e Zd ZdZy)r=  r   Nr]  rs   r   r	   r=  r=  2  rk  r   r=  c                       e Zd ZdZy)r>  r   Nr]  rs   r   r	   r>  r>  5  rk  r   r>  c                       e Zd Zd Zy)Coldefc                 X    d| _         d| _        d| _        d| _        d| _        d| _        y )Nr   r   solid)rD  r  r@  rA  rB  rC  r   s    r	   r   zColdef.__init__;  s.    

!" #r   N)ro   rp   rq   r   rs   r   r	   r~  r~  :  s    $r   r~  c                   "     e Zd ZdZ fdZ xZS )Cellr&   c                     t         |   |       d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _	        y )Nr   noner    F)
r  r   rD  r@  rA  rB  rC  rE  rF  r?  r   r   rG   s     r	   r   zCell.__init__F  sJ    
 !"r   ro   rp   rq   r  r   r  r  s   @r	   r  r  D  s    D	 	r   r  c                   "     e Zd ZdZ fdZ xZS )rP   z[ opt ] defc                 ~    t         |   |       t               | _        t               | _        t               | _        y r   )r  r   r   coldefrQ   r
  rowspansr  s     r	   r   zTable.__init__S  s+    fF	r   r  r  s   @r	   rP   rP   Q  s    D r   rP   c                       e Zd Zy)tabularNrU  rs   r   r	   r  r  Y  rV  r   r  c                       e Zd ZdZy)tabular_zwidth [opt] defNr]  rs   r   r	   r  r  \      Dr   r  c                       e Zd Zy)	mytabularNrU  rs   r   r	   r  r  `  rV  r   r  c                       e Zd ZdZy)tabbingr   Nr]  rs   r   r	   r  r  c  rk  r   r  c                   ,     e Zd ZdZdZ fdZd Z xZS )r"  ra  r    c                 2    t         |   |       i | _        y r   r  r   r#  r  s     r	   r   zSection.__init__{  s    r   c                    | j                   }d}d| |j                  v r|j                  d|    j                          | j                   |j                  d|    j	                         | j                  |<   |dz   }|dk  r<d| |j                  v r |j                  d|    j                          |dz  }|dk  r<d}||k  rId| |j                  v r-|j                  d|    j	                         | j                  |<   |dz  }||k  rIfd|dk(  s|dk(  rS t              }|D ]B  }|j                  |j                  v s|j                  |j                     j                          D |S )Nr   r   r       r   c                     g }| j                         D ]*  }|j                  |       |j                   |             , |S r   r   r   s      r	   r   z+Section.setcounter.<locals>.get_sub_classes  r   r   )r  r  r  r#  r  r&  rW   ro   )	r   r]   r  r*   r  r7   r$  r   r   s	           @r	   
setcounterzSection.setcounter  sy   

eW/NNXeW-.88:',~~6H'I'R'R'TDe$	Ab&aS>U^^3NNXaS>288:Q b&
 %i!~/',~~n'E'N'N'P!!!$FA %i
	 A:"%d+G X<<5>>15>>#,,3O3U3U3WX r   )ro   rp   rq   r  r  r   r  r  r  s   @r	   r"  r"  h  s    DE" r   r"  c                   (     e Zd ZdZ fdZd Z xZS )rW   r   c                     t         |   |       d| _        d| _        d| _        |dd  dk(  rd| _        y |dd  dk(  rd| _        y y )Nr   solor  markrV   r%  )r  r   r#  rX   rY   r  s     r	   r   zNote.__init__  sU    9#DM"#Y& "DM !r   c                    | j                   dk(  rU|j                  | j                     j                          |j                  | j                     j	                         | _        |S | j                   dk(  r| j                  d d }|j                  | j                     j                          |j                  |   j                          |j                  r$|j                  d   j                          d|_        |j                  d   j                          |j                  d   j	                         | _        |j                  |   j	                         | _        |S | j                   dk(  r| j                  d d }|j                  |dz      j	                         dkD  r|j                  |   j                  |j                  |dz      j	                                 |j                  |   j                          |j                  |dz      j                          |j                  |   j	                         | _        |S |j                  |   j                          |j                  |   j	                         | _        |S )	Nr  rV   r  r   Fr%  r  r   )rX   r  r   r  r  r#  r   r  rY   r  r&  r   r]   r   s      r	   r  zNote.setcounter  s   ==F"NN499%//1 %tyy 9 B B DD, + ]]g%99Sb>DNN499%//1NN4 **,~~}-779!&NN=)335#nn];DDFDO %t 4 = = ?D  ]]f$99Sb>D~~dVm,557!;t$11ENN4&=4Q4Z4Z4\2\]t$..0tf}-335$)NN4$8$A$A$C!
  t$..0$)NN4$8$A$A$C!r   )ro   rp   rq   r  r   r  r  r  s   @r	   rW   rW     s    D	#r   rW   c                       e Zd ZdZy)footnotez[ number ] textNr]  rs   r   r	   r  r    r  r   r  c                       e Zd ZdZy)	marginparz[ lefttext ] righttextNr]  rs   r   r	   r  r    s    #Dr   r  c                       e Zd ZdZy)
marginnotezself [ length ]Nr]  rs   r   r	   r  r    r  r   r  c                   4     e Zd ZdZ fdZd Zd Zd Z xZS )Counterr   c                 2    t         |   |       d| _        y rF  r  r  s     r	   r   zCounter.__init__  s    r   c                     | j                   r| j                   d   }nd}||j                  v r?|j                  |   j                          |j                  |   j                         | _        |S Nr   r   )r'   r  r  r  r#  r  s      r	   stepcounterzCounter.stepcounter  sZ    <<Qd5>>!NN4 **, %t 4 = = ?Dr   c                    | j                   r| j                   d   }nd}d}t        |t              sd}||j                  v r@|j                  |   j	                  |       |j                  |   j                         | _        |S r  )r'   r   rr  r  r  r  r#  r   r  r]   r   r*   s        r	   r  zCounter.setcounter  so    <<Qd%%qu5>>!NN4 ))%0 %t 4 = = ?Dr   c                    | j                   r| j                   d   }nd}d}t        |t              sd}||j                  v r@|j                  |   j	                  |       |j                  |   j                         | _        |S r  )r'   r   rr  r  r  r  r#  r  s        r	   r  zCounter.addtocounter  so    <<Qd%%qu5>>!NN4 --e4 %t 4 = = ?Dr   )	ro   rp   rq   r  r   r  r  r  r  r  s   @r	   r  r    s    D		r   r  c                       e Zd ZdZy)r  
name valueNr]  rs   r   r	   r  r        Dr   r  c                       e Zd ZdZy)r  r  Nr]  rs   r   r	   r  r     r  r   r  c                       e Zd ZdZy)r  r   Nr]  rs   r   r	   r  r    r^  r   r  c                       e Zd ZdZy)refstepcounterr   Nr]  rs   r   r	   r  r    r^  r   r  c                       e Zd ZdZy)	LaTeXListr   Nr]  rs   r   r	   r  r  	  rk  r   r  c                       e Zd ZdZy)Listzlabel parameterNr]  rs   r   r	   r  r    r  r   r  c                       e Zd ZdZy)	enumerater   Nr]  rs   r   r	   r  r    rk  r   r  c                       e Zd ZdZy)itemizer   Nr]  rs   r   r	   r  r    rk  r   r  c                       e Zd ZdZy)descriptionr   Nr]  rs   r   r	   r  r    rk  r   r  c                       e Zd ZdZy)Itemz[ label ] contentNr]  rs   r   r	   r  r    s    Dr   r  c                       e Zd ZdZy)ItemWithoutContentz	[ label ]Nr]  rs   r   r	   r  r        Dr   r  c                       e Zd ZdZy)r)   z[ description ]Nr]  rs   r   r	   r)   r)      r  r   r)   c                       e Zd Zy)iitemNrU  rs   r   r	   r  r  #  rV  r   r  c                       e Zd Zy)ItemWithContentNrU  rs   r   r	   r  r  '  rV  r   r  c                       e Zd Zy)BibliographyNrU  rs   r   r	   r  r  +  rV  r   r  c                       e Zd ZdZy)
Whitespacer   Nr]  rs   r   r	   r  r  0  rk  r   r  c                       e Zd ZdZy)rO  r   Nr]  rs   r   r	   rO  rO  4  rk  r   rO  c                       e Zd Zy)rN  NrU  rs   r   r	   rN  rN  7  rV  r   rN  c                       e Zd ZdZy)r   r   Nr]  rs   r   r	   r   r   ;  rk  r   r   c                       e Zd ZdZy)r   r   Nr]  rs   r   r	   r   r   >  rk  r   r   c                       e Zd ZdZy)rP  r   Nr]  rs   r   r	   rP  rP  B  rk  r   rP  c                   "     e Zd ZdZ fdZ xZS )r/   r   c                 @    t         |   |       d| _        d| _        y )NT)r  r   r2   r0   r  s     r	   r   zPar.__init__H  s    r   r  r  s   @r	   r/   r/   F  s    D r   r/   c                       e Zd Zy)r   NrU  rs   r   r	   r   r   M  rV  r   r   c                       e Zd ZdZy)newlinez[ opt ]Nr]  rs   r   r	   r  r  P  s    Dr   r  c                       e Zd ZdZy)r   	[ space ]Nr]  rs   r   r	   r   r   S  r  r   r   c                       e Zd ZdZy)VALEPlb_r  Nr]  rs   r   r	   r  r  V  r  r   r  c                       e Zd ZdZy)r-  r   Nr]  rs   r   r	   r-  r-  ]  rk  r   r-  c                       e Zd ZdZy)r,  r   Nr]  rs   r   r	   r,  r,  a  rk  r   r,  c                       e Zd ZdZy)VALEPshyr   Nr]  rs   r   r	   r  r  e  rk  r   r  c                       e Zd Zy)VerbatimNrU  rs   r   r	   r  r  h  rV  r   r  c                       e Zd Zy)VerbatimEnvironmentNrU  rs   r   r	   r  r  k  rV  r   r  c                       e Zd ZdZy)r!  r   Nr]  rs   r   r	   r!  r!  n  r^  r   r!  c                       e Zd ZdZy)verbatimr   Nr]  rs   r   r	   r  r  q  rk  r   r  c                       e Zd ZdZy)htmlcoder   Nr]  rs   r   r	   r  r  t  r^  r   r  c                       e Zd ZdZy)rawhtmlr   Nr]  rs   r   r	   r  r  w  rk  r   r  c                       e Zd ZdZy)htmlonlyr   Nr]  rs   r   r	   r  r  z  r^  r   r  c                       e Zd ZdZy)	LaTeXOnlyr   Nr]  rs   r   r	   r  r  }  r^  r   r  c                       e Zd ZdZy)	latexonlyr   Nr]  rs   r   r	   r  r    r^  r   r  c                       e Zd ZdZy)	Referencer   Nr]  rs   r   r	   r  r    r^  r   r  c                       e Zd Zy)IndexNrU  rs   r   r	   r  r    rV  r   r  c                       e Zd Zy)LabelNrU  rs   r   r	   r  r    rV  r   r  c                       e Zd Zy)RefNrU  rs   r   r	   r  r    rV  r   r  c                       e Zd ZdZy)Linkz	link textNr]  rs   r   r	   r  r    r  r   r  c                       e Zd ZdZy)GraphicsrcNr]  rs   r   r	   r  r    s    Dr   r  c                       e Zd ZdZy)r   z[ argll ] [ argur ]  selfNr]  rs   r   r	   r   r     s    &Dr   r   )hr   inspectr
   r   ru   r9  rK  rS  ry  r  r  r  r  r   r  r  re   r  r  ri   rg   r
  r   r4   r1   rY  r[  r-   r`  rc  re  rQ  rh  rj  rm  ro  r9  rr  rt  rv  r.   r;  r  r<  r=  r>  r~  r  rP   r  r  r  r  r"  rW   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r)   r  r  r  r  rO  rN  r   r   rP  r/   r   r  r   r  r-  r,  r  r  r  r!  r  r  r  r  r  r  r  r  r  r  r  r  r   rs   r   r	   <module>r     s    
.d dL	] ]~)P )PV	 	
	Z 	*&	. .b	 	
 @9 9(, (,V3 31K 1Kj "  "F	! 	!C% C%P
	 		 		GV 		Wf 	W  M m 	 		' 	 	f 	{H 	k 		7 	 	 	7 ' w  w  
$ $7 K 	e 	w 	 	e 
7g 7t(6 (Vt $ $ #m #L 7 ' W  9 	 i ) 7   	D 		d 		9 	
 
 	j 	Y 	  ' 	# 	g g w   v 	w 		+h 	h "  ! w  	  	I 		I 		) 	9 i 'g 'r   