
    k7i{9                       S r SSKJr  SrSSKrSSKJs  Jr  Sr	  " S S\R                  5      r " S S	\5      r " S
 S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S  S!\5      r " S" S#\5      r " S$ S%\5      r " S& S'\5      r " S( S)\5      r " S* S+\5      r " S, S-\5      r " S. S/\5      r " S0 S1\5      r  " S2 S3\5      r! " S4 S5\5      r" " S6 S7\ 5      r# " S8 S9\5      r$ " S: S;\5      r% " S< S=\5      r&g)>ah  MathML element classes based on `xml.etree`.

The module is intended for programmatic generation of MathML
and covers the part of `MathML Core`_ that is required by
Docutil's *TeX math to MathML* converter.

This module is PROVISIONAL:
the API is not settled and may change with any minor Docutils version.

.. _MathML Core: https://www.w3.org/TR/mathml-core/
    )annotationsreStructuredTextN)classdirdisplaystyleidnoncescriptlevelstyletabindexc                     ^  \ rS rSrSrSr Sr SU 4S jjr\S 5       r	SS jr
SS jrSU 4S jjrSU 4S	 jjrS
 rS rU 4S jrS rSS jrS rSSS jjrSS jrSS jrSrU =r$ )MathElement<   zBase class for MathML elements.Nc                  > UR                  5        VVs0 s H%  u  p4UR                  5       U R                  U5      _M'     nnn[        TU ]  " U R
                  R                  40 UD6  U R                  U5        gs  snnf )a  Set up node with `children` and `attributes`.

Attribute names are normalised to lowercase.
You may use "CLASS" to set a "class" attribute.
Attribute values are converted to strings
(with True -> "true" and False -> "false").

>>> math(CLASS='test', level=3, split=True)
math(class='test', level='3', split='true')
>>> math(CLASS='test', level=3, split=True).toxml()
'<math class="test" level="3" split="true"></math>'

N)itemslowera_strsuper__init__	__class____name__extend)selfchildren
attributeskvattribr   s         ]/home/james-whalen/.local/lib/python3.13/site-packages/docutils/utils/math/mathml_elements.pyr   MathElement.__init__E   sh     8B7G7G7IJ7Itq!'')TZZ]*7IJ00;F;H Ks   ,A;c                t    [        U [        5      (       a  [        U 5      R                  5       $ [        U 5      $ N)
isinstanceboolstrr   )r   s    r   r   MathElement.a_strW   s*     aq6<<>!1v    c                (   U  Vs/ s H  n[        U5      PM     nnU R                  (       a$  UR                  [        U R                  5      5        U R                  U R                  R                  :w  a  UR                  SU R                   35        [        U SS5      (       a  UR                  S5        X R                  5        VVs/ s H  u  p4Uc  M
  U SU< 3PM     snn-  nU R                   SSR                  U5       S3$ s  snf s  snnf )	z"Return full string representation.z
nchildren=switchNzswitch=True=(, ))	reprtextappend	nchildrenr   getattrr   tagjoin)r   childargsr   r   s        r   __repr__MathElement.__repr__^   s    )-.U.99KKTYY(>>T^^555KK*T^^$45644((KK&**,H,$!!A3au,HH((1TYYt_-Q// / Is   D			DDc                    U R                   (       a  [        U R                   5      nOSR                  S U  5       5      nU R                   SU S3$ )z/Return concise, informal string representation.r,   c              3  &   #    U  H  o v   M	     g 7fr"    ).0r5   s     r   	<genexpr>&MathElement.__str__.<locals>.<genexpr>o   s     :TEwZTs   r+   r-   )r/   r.   r4   r3   )r   r6   s     r   __str__MathElement.__str__j   sA    99		?D99:T::D((1TF!$$r'   c                B   > [         TU ]  XR                  U5      5        g r"   )r   setr   )r   keyvaluer   s      r   rB   MathElement.setr   s    CE*+r'   c                \  > U R                   S:X  a  [        SU  S35      e[        U[        5      (       a  Xl        OaU R                   (       aA  [        U 5      [        U5      -   U R                   :  a  [        SU  SU R                    S35      eU H	  nXl        M     [        TU ]  X5        g )Nr   	Element "z" does not take children.z" takes only 	 children)r1   	TypeErrorr#   r   parentlenr   __setitem__)r   rC   rD   er   s       r   rL   MathElement.__setitem__u   s    >>Qiv-FGHHe[))L~~#d)c%j"84>>"I)D6t~~>N +!, - - C'r'   c                \    U R                   SL=(       a    [        U 5      U R                   :  $ )z;Return boolean indicating whether children may be appended.N)r1   rK   r   s    r   is_fullMathElement.is_full   s#    ~~T)Ic$i4>>.IIr'   c                    [        U 5      U l        U R                  nUb;  UR                  5       (       a&  UR                  nUb  UR                  5       (       a  M&  U$ )z:Close element and return first non-full anchestor or None.)rK   r1   rJ   rQ   )r   rJ   s     r   closeMathElement.close   sJ    T V^^%5%5]]F  V^^%5%5r'   c                  > U R                  5       (       a6  U R                  (       a  SU R                   S3nOSn[        SU  SU S35      e[        TU ]  U5        Xl        U R                  5       (       a  U R                  5       $ U $ )a$  Append `element` and return new "current node" (insertion point).

Append as child element and set the internal `parent` attribute.

If self is already full, raise TypeError.

If self is full after appending, call `self.close()`
(returns first non-full anchestor or None) else return `self`.
ztakes only rH   zdoes not take childrenrG   z" .)rQ   r1   rI   r   r0   rJ   rT   )r   elementstatusr   s      r   r0   MathElement.append   sv     <<>>~~&t~~&6i@1ivRxq9::w<<>>::<r'   c                >    U nU H  nU R                  U5      nM     U$ )zYSequentially append `elements`. Return new "current node".

Raise TypeError if overfull.
)r0   )r   elementscurrent_noderX   s       r   r   MathElement.extend   s'    
 G;;w/L  r'   c                    X   nX	 U$ r"   r;   )r   indexrX   s      r   popMathElement.pop   s    +Kr'   c                    U R                  S5      c   U R                  R                  5       $ U R                  S5      S:H  $ ! [         a     gf = f)zReturn True, if `self` or an ancestor has ``display='block'``.

Used to find out whether we are in inline vs. displayed maths.
displayFblock)getrJ   in_blockAttributeErrorrP   s    r   rg   MathElement.in_block   sU    
 88I&{{++-- xx	"g-- " s   A 
AAc                2    [         R                  " XU5        g)zFormat XML output with indents.

Use with care:
  Formatting whitespace is permanently added to the
  `text` and `tail` attributes of `self` and anchestors!
N)ETindent)r   spacelevels      r   
indent_xmlMathElement.indent_xml   s     			$u%r'   c                    U R                  5        Hz  n[        U[        5      (       d0  UR                  (       a  UR                  R	                  5       Ul        UR
                  (       d  M[  UR
                  R	                  5       Ul        M|     g)zStrip whitespace at the end of `text` and `tail` attributes...

to revert changes made by the `indent_xml()` method.
Use with care, trailing whitespace from the original may be lost.
N)iterr#   	MathTokenr/   rstriptail)r   rM   s     r   unindent_xmlMathElement.unindent_xml   sR     Aa++vvv	 r'   c                    [         R                  " X=(       d    SSS9n UR                  SS5      nU$ ! [         a%    UR                  SR	                  U5      S5      n U$ f = f)a  Return an XML representation of the element.

By default, the return value is a `str` instance. With an explicit
`encoding` argument, the result is a `bytes` instance in the
specified encoding. The XML default encoding is UTF-8, any other
encoding must be specified in an XML document header.

Name and encoding handling match `xml.dom.minidom.Node.toxml()`
while `etree.Element.tostring()` returns `bytes` by default.
unicodeF)short_empty_elementsu   ⁡z&ApplyFunction;s   &ApplyFunction;)rk   tostringreplacerI   encode)r   encodingxmls      r   toxmlMathElement.toxml   sl     kk$ 5I/46	M++h(9:C 
  	M++hooh79KLC
	Ms   4 +A#"A#)r1   returnNone)r   r%   ))z  r   r"   )r   
__module____qualname____firstlineno____doc__r1   rJ   r   staticmethodr   r7   r?   rB   rL   rQ   rT   r0   r   ra   rg   ro   rv   r   __static_attributes____classcell__r   s   @r   r   r   <   sv    )I-F-$  
0%,(J,

.&
) r'   r   c                      \ rS rSrSrSrg)MathRow   z:Base class for elements treating content as a single mrow.r;   Nr   r   r   r   r   r   r;   r'   r   r   r      s    Dr'   r   c                  @   ^  \ rS rSrSrSrSU 4S jjrU 4S jrSrU =r	$ )
MathSchema   zBase class for schemata expecting 2 or more children.

The special attribute `switch` indicates that the last two child
elements are in reversed order and must be switched before XML-export.
See `msub` for an example.
   c                T   > UR                  SS5      U l        [        TU ]  " U0 UD6  g )Nr)   F)ra   r)   r   r   )r   r   kwargsr   s      r   r   MathSchema.__init__  s'    jj51(-f-r'   c                   > [         TU ]  U5      nU R                  (       a-  U R                  5       (       a  U S   U S   sU S'   U S'   SU l        U$ )z2Append element. Normalize order and close if full.r   F)r   r0   r)   rQ   )r   rX   r]   r   s      r   r0   MathSchema.append  sK    w~g.;;4<<>>!%b48DHd2hDKr'   )r)   r   )
r   r   r   r   r   r1   r   r0   r   r   r   s   @r   r   r      s     I. r'   r   c                  4   ^  \ rS rSrSrSrSU 4S jjrSrU =r$ )rs   i  z_Token Element: contains textual data instead of children.

Expect text data on initialisation.
r   c                   > [         TU ]  " S0 UD6  [        U[        [        R
                  45      (       d  [        SU S35      e[        U5      U l        g )Nz0MathToken element expects `str` or number, not "z".r;   )r   r   r#   r%   numbersNumber
ValueErrorr/   )r   r/   r   r   s      r   r   MathToken.__init__  sR    &:&$gnn 566 &&*V2/ 0 0I	r'   )r/   r   )	r   r   r   r   r   r1   r   r   r   r   s   @r   rs   rs     s     I r'   rs   c                      \ rS rSrSrSrg)mathi%  z8Top-level MathML element, a single mathematical formula.r;   Nr   r;   r'   r   r   r   %  s    Br'   r   c                      \ rS rSrSrSrg)mtexti,  z*Arbitrary text with no notational meaning.r;   Nr   r;   r'   r   r   r   ,  s    4r'   r   c                      \ rS rSrSrSrg)mii0  zCIdentifier, such as a function name, variable or symbolic constant.r;   Nr   r;   r'   r   r   r   0  s    Mr'   r   c                      \ rS rSrSrSrg)mni4  zNumeric literal.

>>> mn(3.41).toxml()
'<mn>3.41</mn>'

Normally a sequence of digits with a possible separator (a dot or a comma).
(Values with comma must be specified as `str`.)
r;   Nr   r;   r'   r   r   r   4  s    r'   r   c                      \ rS rSrSrSrg)moi?  zOperator, Fence, Separator, or Accent.

>>> mo('<').toxml()
'<mo>&lt;</mo>'

Besides operators in strict mathematical meaning, this element also
includes "operators" like parentheses, separators like comma and
semicolon, or "absolute value" bars.
r;   Nr   r;   r'   r   r   r   ?  s    r'   r   c                      \ rS rSrSrSrSrg)mspaceiK  zBlank space, whose size is set by its attributes.

Takes additional attributes `depth`, `height`, `width`.
Takes no children and no text.

See also `mphantom`.
r   r;   Nr   r   r   r   r   r1   r   r;   r'   r   r   r   K  s     Ir'   r   c                  6   ^  \ rS rSrSrSS jrU 4S jrSrU =r$ )mrowiY  zqGeneric element to group children as a horizontal row.

Removed on closing if not required (see `mrow.close()`).
c                   SSS.nU R                  5        Hn  u  p4US;   aR  U(       aK  UR                  U5      (       a5  X#   R                  UR                  U5      R                  X#   5      U45      nUR	                  X45        Mp     g)zTransfer attributes from self to other.

"List values" (class, style) are appended to existing values,
other values replace existing values.
 z; )r   r   N)r   rf   r4   rt   rB   )r   other
delimitersr   r   s        r   transfer_attributesmrow.transfer_attributes_  ss      #T2
JJLDA&&199Q<<"**1,,Z];Q?AAIIaO !r'   c                   > U R                   nUbH  [        U 5      S:X  a9  U S   n X![        U5      R                  U 5      '   Xl         U R                  U5        [        TU ]!  5       $ ! [        [
        4 a     gf = f)zlClose element and return first non-full anchestor or None.

Remove <mrow> if it has only one child element.
N   r   )	rJ   rK   listr`   rh   r   r   r   rT   )r   rJ   r5   r   s      r   rT   
mrow.closem  s}    
 #d)q.GE38tF|))$/0% $$U+w} #J/ s   "A' 'A:9A:r;   r   )	r   r   r   r   r   r   rT   r   r   r   s   @r   r   r   Y  s    
 r'   r   c                      \ rS rSrSrSrg)mfraci  zAFractions or fraction-like objects such as binomial coefficients.r;   Nr   r;   r'   r   r   r     s    Kr'   r   c                      \ rS rSrSrSrSrg)msqrti  zSquare root. See also `mroot`.r   r;   Nr   r;   r'   r   r   r     s
    (Ir'   r   c                      \ rS rSrSrSrg)mrooti  z/Roots with an explicit index. See also `msqrt`.r;   Nr   r;   r'   r   r   r         9r'   r   c                      \ rS rSrSrSrg)mstylei  zStyle Change.

In modern browsers, <mstyle> is equivalent to an <mrow> element.
However, <mstyle> may still be relevant for compatibility with
MathML implementations outside browsers.
r;   Nr   r;   r'   r   r   r     s    r'   r   c                      \ rS rSrSrSrg)merrori  z#Display contents as error messages.r;   Nr   r;   r'   r   r   r     s    -r'   r   c                      \ rS rSrSrSrSrg)menclosei  zRenders content inside an enclosing notation...

... specified by the notation attribute.

Non-standard but still required by Firefox for boxed expressions.
r   r;   Nr   r;   r'   r   r   r     s     Ir'   r   c                      \ rS rSrSrSrg)mpaddedi  zAdjust space around content.r;   Nr   r;   r'   r   r   r     s    &r'   r   c                      \ rS rSrSrSrSrg)mphantomi  z8Placeholder: Rendered invisibly but dimensions are kept.r   r;   Nr   r;   r'   r   r   r     s
    BIr'   r   c                      \ rS rSrSrSrg)msubi  z$Attach a subscript to an expression.r;   Nr   r;   r'   r   r   r     s    .r'   r   c                      \ rS rSrSrSrg)msupi  z&Attach a superscript to an expression.r;   Nr   r;   r'   r   r   r     s    0r'   r   c                      \ rS rSrSrSrSrg)msubsupi  z;Attach both a subscript and a superscript to an expression.   r;   Nr   r;   r'   r   r   r     s
    EIr'   r   c                      \ rS rSrSrSrg)munderi  z0Attach an accent or a limit under an expression.r;   Nr   r;   r'   r   r   r     s    :r'   r   c                      \ rS rSrSrSrg)moveri  z/Attach an accent or a limit over an expression.r;   Nr   r;   r'   r   r   r     r   r'   r   c                      \ rS rSrSrSrg)
munderoveri  z;Attach accents or limits both under and over an expression.r;   Nr   r;   r'   r   r   r     s    Er'   r   c                      \ rS rSrSrSrg)mtablei  zTable or matrix element.r;   Nr   r;   r'   r   r   r     s    "r'   r   c                      \ rS rSrSrSrg)mtri  zRow in a table or a matrix.r;   Nr   r;   r'   r   r   r         %r'   r   c                      \ rS rSrSrSrg)mtdi  zCell in a table or a matrixr;   Nr   r;   r'   r   r   r     r   r'   r   )'r   
__future__r   __docformat__r   xml.etree.ElementTreeetreeElementTreerk   GLOBAL_ATTRIBUTESElementr   r   r   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r;   r'   r   <module>r      s  
 #"  " " l"** lpEk E 2 $C7 C5I 5N N 	 	[ #7 #LLJ LG 
:J :W .W .w 'g '
w /: /1: 1j $;T ;:D :F F#[ #&' &&' &r'   