home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 June / maximum-cd-2011-06.iso / DiscContents / LibO_3.3.1_Win_x86_install_multi.exe / libreoffice1.cab / cmarkup.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2011-02-15  |  37.1 KB  |  1,114 lines

  1. <?xml version='1.0' encoding="UTF-8"?>
  2. <xsl:stylesheet
  3.         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4.         xmlns:m="http://www.w3.org/1998/Math/MathML"
  5.         version='1.0'>
  6.                 
  7. <!-- ====================================================================== -->
  8. <!-- $Id: cmarkup.xsl 2755 2008-03-07 20:35:56Z hauma $
  9.      This file is part of the XSLT MathML Library distribution.
  10.      See ./README or http://xsltml.sf.net for
  11.      copyright and other information                                        -->
  12. <!-- ====================================================================== -->
  13.  
  14. <!-- 4.4.1.1 cn -->
  15. <xsl:template match="m:cn"><xsl:apply-templates/></xsl:template>
  16.  
  17. <xsl:template match="m:cn[@type='complex-cartesian']">
  18.     <xsl:apply-templates select="text()[1]"/>
  19.       <xsl:text>+</xsl:text>
  20.     <xsl:apply-templates select="text()[2]"/>
  21.     <xsl:text>i</xsl:text>
  22. </xsl:template>
  23.  
  24. <xsl:template match="m:cn[@type='rational']">
  25.     <xsl:apply-templates select="text()[1]"/>
  26.     <xsl:text>/</xsl:text>
  27.     <xsl:apply-templates select="text()[2]"/>
  28. </xsl:template>
  29.  
  30. <xsl:template match="m:cn[@type='integer' and @base!=10]">
  31.         <xsl:apply-templates/>
  32.         <xsl:text>_{</xsl:text><xsl:value-of select="@base"/><xsl:text>}</xsl:text>
  33. </xsl:template>
  34.  
  35. <xsl:template match="m:cn[@type='complex-polar']">
  36.     <xsl:apply-templates select="text()[1]"/>
  37.     <xsl:text>e^{i </xsl:text>
  38.     <xsl:apply-templates select="text()[2]"/>
  39.     <xsl:text>}</xsl:text>
  40. </xsl:template>
  41.  
  42. <xsl:template match="m:cn[@type='e-notation']">
  43.     <xsl:apply-templates select="text()[1]"/>
  44.     <xsl:text>E</xsl:text>
  45.     <xsl:apply-templates select="text()[2]"/>
  46. </xsl:template>
  47.  
  48. <!-- 4.4.1.1 ci 4.4.1.2 csymbol -->
  49. <xsl:template match="m:ci | m:csymbol">
  50.     <xsl:choose>
  51.         <xsl:when test="string-length(normalize-space(text()))>1">
  52.             <xsl:text>\mathrm{</xsl:text><xsl:apply-templates/><xsl:text>}</xsl:text>
  53.         </xsl:when>
  54.         <xsl:otherwise><xsl:apply-templates/></xsl:otherwise>
  55.     </xsl:choose>
  56. </xsl:template>
  57.  
  58. <!-- 4.4.2.1 apply 4.4.2.2 reln -->
  59. <xsl:template match="m:apply | m:reln">
  60.     <xsl:apply-templates select="*[1]">
  61.     <!-- <? -->
  62.         <xsl:with-param name="p" select="10"/>
  63.     </xsl:apply-templates>
  64.     <!-- ?> -->
  65.      <xsl:text>(</xsl:text>
  66.     <xsl:for-each select="*[position()>1]">
  67.         <xsl:apply-templates select="."/>
  68.         <xsl:if test="not(position()=last())"><xsl:text>, </xsl:text></xsl:if>
  69.     </xsl:for-each>
  70.      <xsl:text>)</xsl:text>
  71. </xsl:template>
  72.  
  73. <!-- 4.4.2.3 fn -->
  74. <xsl:template match="m:fn[m:apply[1]]"> <!-- for m:fn using default rule -->
  75.     <xsl:text>(</xsl:text><xsl:apply-templates/><xsl:text>)</xsl:text>
  76. </xsl:template>
  77.  
  78. <!-- 4.4.2.4 interval -->
  79. <xsl:template match="m:interval[*[2]]">
  80.     <xsl:choose>
  81.         <xsl:when test="@closure='open' or @closure='open-closed'">
  82.             <xsl:text>\left(</xsl:text>        
  83.         </xsl:when>
  84.         <xsl:otherwise><xsl:text>\left[</xsl:text></xsl:otherwise> 
  85.     </xsl:choose>
  86.     <xsl:apply-templates select="*[1]"/>
  87.     <xsl:text> , </xsl:text>
  88.     <xsl:apply-templates select="*[2]"/>
  89.     <xsl:choose>
  90.         <xsl:when test="@closure='open' or @closure='closed-open'">
  91.             <xsl:text>\right)</xsl:text>        
  92.         </xsl:when>
  93.         <xsl:otherwise><xsl:text>\right]</xsl:text></xsl:otherwise> 
  94.     </xsl:choose>
  95. </xsl:template>
  96.  
  97. <xsl:template match="m:interval">
  98.     <xsl:text>\left\{</xsl:text><xsl:apply-templates/><xsl:text>\right\}</xsl:text>
  99. </xsl:template>
  100.  
  101. <!-- 4.4.2.5 inverse -->
  102. <xsl:template match="m:apply[*[1][self::m:inverse]]">
  103.     <xsl:apply-templates select="*[2]"/><xsl:text>^{(-1)}</xsl:text>
  104. </xsl:template>
  105.  
  106. <!-- 4.4.2.6 sep 4.4.2.7 condition -->
  107. <xsl:template match="m:sep | m:condition"><xsl:apply-templates/></xsl:template>
  108.  
  109. <!-- 4.4.2.9 lambda -->
  110. <xsl:template match="m:lambda">
  111.     <xsl:apply-templates select="m:bvar/*"/>
  112.   <xsl:text>\mapsto </xsl:text>
  113.   <xsl:apply-templates select="*[last()]"/>
  114. <!--    Other variant 
  115.     <xsl:text>\mathrm{lambda}\: </xsl:text>
  116.       <xsl:apply-templates select="m:bvar/*"/>
  117.       <xsl:text>.\: </xsl:text>
  118.   <xsl:apply-templates select="*[last()]"/> -->
  119. </xsl:template>
  120.  
  121. <!-- 4.4.2.10 compose -->
  122. <xsl:template match="m:apply[*[1][self::m:compose]]">
  123.     <xsl:param name="p" select="0"/>
  124.     <xsl:call-template name="infix">
  125.         <xsl:with-param name="this-p" select="1"/>
  126.         <xsl:with-param name="p" select="$p"/>
  127.         <xsl:with-param name="mo">\circ </xsl:with-param>
  128.     </xsl:call-template>
  129. </xsl:template>
  130.  
  131. <!-- 4.4.2.11 ident -->
  132. <xsl:template match="m:ident"><xsl:text>\mathrm{id}</xsl:text></xsl:template>
  133.  
  134. <!-- 4.4.2.12 domain 4.4.2.13 codomain 4.4.2.14 image 4.4.3.21 arg 4.4.3.24 lcm
  135.         4.4.5.9 grad 4.4.5.10 curl 4.4.9.4 median 4.4.9.5 mode-->
  136. <xsl:template match="m:domain | m:codomain | m:image | m:arg | m:lcm | m:grad |
  137.                                  m:curl | m:median | m:mode">
  138.     <xsl:text>\mathop{\mathrm{</xsl:text>
  139.     <xsl:value-of select="local-name()"/>
  140.     <xsl:text>}}</xsl:text>
  141. </xsl:template>
  142.  
  143. <!-- 4.4.2.15 domainofapplication -->
  144. <xsl:template match="m:domainofapplication"/>
  145.  
  146. <!-- 4.4.2.16 piecewise -->
  147. <xsl:template match="m:piecewise">
  148.     <xsl:text>\begin{cases}</xsl:text>
  149.     <xsl:apply-templates select="m:piece"/>
  150.     <xsl:apply-templates select="m:otherwise"/>
  151.     <xsl:text>\end{cases}</xsl:text>
  152. </xsl:template>
  153.  
  154. <xsl:template match="m:piece">
  155.         <xsl:apply-templates select="*[1]"/>
  156.         <xsl:text> & \text{if $</xsl:text>
  157.         <xsl:apply-templates select="*[2]"/>
  158.         <xsl:text>$}</xsl:text>
  159.         <xsl:if test="not(position()=last()) or ../m:otherwise"><xsl:text>\\  </xsl:text></xsl:if>
  160. </xsl:template>
  161.  
  162. <xsl:template match="m:otherwise">
  163.     <xsl:apply-templates select="*[1]"/>
  164.     <xsl:text> & \text{otherwise}</xsl:text>
  165. </xsl:template>
  166.  
  167. <!-- 4.4.3.1 quotient -->
  168. <xsl:template match="m:apply[*[1][self::m:quotient]]">
  169.     <xsl:text>\left\lfloor\frac{</xsl:text>
  170.     <xsl:apply-templates select="*[2]"/>
  171.     <xsl:text>}{</xsl:text>
  172.     <xsl:apply-templates select="*[3]"/>
  173.     <xsl:text>}\right\rfloor </xsl:text>
  174. </xsl:template>
  175.  
  176. <!-- 4.4.3.2 factorial -->
  177. <xsl:template match="m:apply[*[1][self::m:factorial]]">
  178.     <xsl:apply-templates select="*[2]">
  179.         <xsl:with-param name="p" select="7"/>
  180.     </xsl:apply-templates>
  181.     <xsl:text>!</xsl:text>
  182. </xsl:template>
  183.  
  184. <!-- 4.4.3.3 divide -->
  185. <xsl:template match="m:apply[*[1][self::m:divide]]">
  186.     <xsl:param name="p" select="0"/>
  187.   <xsl:param name="this-p" select="3"/>
  188.   <xsl:if test="$this-p < $p"><xsl:text>\left(</xsl:text></xsl:if>
  189.   <xsl:text>\frac{</xsl:text>
  190.     <xsl:apply-templates select="*[2]"/>
  191. <!--        <xsl:with-param name="p" select="$this-p"/>
  192.     </xsl:apply-templates>-->
  193.     <xsl:text>}{</xsl:text>
  194.     <xsl:apply-templates select="*[3]"/>
  195. <!--        <xsl:with-param name="p" select="$this-p"/>
  196.     </xsl:apply-templates>-->
  197.     <xsl:text>}</xsl:text>
  198.     <xsl:if test="$this-p < $p"><xsl:text>\right)</xsl:text></xsl:if>
  199. </xsl:template>
  200.  
  201. <!-- 4.4.3.4 max min -->
  202. <xsl:template match="m:apply[*[1][self::m:max or self::m:min]]">
  203.     <xsl:text>\</xsl:text>
  204.     <xsl:value-of select="local-name(*[1])"/>
  205.     <xsl:text>\{</xsl:text>
  206.    <xsl:choose>
  207.         <xsl:when test="m:condition">
  208.            <xsl:apply-templates select="*[last()]"/>
  209.            <xsl:text>\mid </xsl:text>
  210.             <xsl:apply-templates select="m:condition/node()"/>
  211.         </xsl:when>
  212.         <xsl:otherwise>
  213.             <xsl:for-each select="*[position() > 1]">
  214.                 <xsl:apply-templates select="."/>
  215.                 <xsl:if test="position() !=last()"><xsl:text> , </xsl:text></xsl:if>
  216.             </xsl:for-each>
  217.         </xsl:otherwise>
  218.    </xsl:choose>
  219.     <xsl:text>\}</xsl:text>
  220. </xsl:template>
  221.  
  222. <!-- 4.4.3.5  minus-->
  223. <xsl:template match="m:apply[*[1][self::m:minus] and count(*)=2]">
  224.     <xsl:text>-</xsl:text>
  225.     <xsl:apply-templates select="*[2]">
  226.         <xsl:with-param name="p" select="2"/>
  227.     </xsl:apply-templates>
  228. </xsl:template>
  229.  
  230. <xsl:template match="m:apply[*[1][self::m:minus] and count(*)>2]">
  231.     <xsl:param name="p" select="0"/>
  232.     <xsl:call-template name="binary">
  233.         <xsl:with-param name="mo">-</xsl:with-param>
  234.         <xsl:with-param name="p" select="$p"/>
  235.         <xsl:with-param name="this-p" select="2"/>
  236.     </xsl:call-template>
  237. </xsl:template> 
  238.  
  239.  
  240. <!-- 4.4.3.6  plus-->
  241. <xsl:template match="m:apply[*[1][self::m:plus]]">
  242.   <xsl:param name="p" select="0"/>
  243.   <xsl:if test="$p > 2">
  244.         <xsl:text>(</xsl:text>
  245.     </xsl:if>
  246.   <xsl:for-each select="*[position()>1]">
  247.    <xsl:if test="position() > 1">
  248.     <xsl:choose>
  249.       <xsl:when test="self::m:apply[*[1][self::m:times] and
  250.       *[2][self::m:apply/*[1][self::m:minus] or self::m:cn[not(m:sep) and
  251.       (number(.) < 0)]]]">-</xsl:when>
  252.       <xsl:otherwise>+</xsl:otherwise>
  253.     </xsl:choose>
  254.    </xsl:if>   
  255.     <xsl:choose>
  256.       <xsl:when test="self::m:apply[*[1][self::m:times] and
  257.       *[2][self::m:cn[not(m:sep) and (number(.) <0)]]]">
  258.             <xsl:value-of select="-(*[2])"/>
  259.             <xsl:apply-templates select=".">
  260.              <xsl:with-param name="first" select="2"/>
  261.              <xsl:with-param name="p" select="2"/>
  262.            </xsl:apply-templates>
  263.        </xsl:when>
  264.       <xsl:when test="self::m:apply[*[1][self::m:times] and
  265.       *[2][self::m:apply/*[1][self::m:minus]]]">
  266.                 <xsl:apply-templates select="./*[2]/*[2]"/>
  267.                 <xsl:apply-templates select=".">
  268.                     <xsl:with-param name="first" select="2"/>
  269.                     <xsl:with-param name="p" select="2"/>
  270.                 </xsl:apply-templates>
  271.             </xsl:when>
  272.             <xsl:otherwise>
  273.                 <xsl:apply-templates select=".">
  274.                     <xsl:with-param name="p" select="2"/>
  275.                 </xsl:apply-templates>
  276.             </xsl:otherwise>
  277.         </xsl:choose>
  278.     </xsl:for-each>
  279.     <xsl:if test="$p > 2">
  280.         <xsl:text>)</xsl:text>
  281.     </xsl:if>
  282. </xsl:template>
  283.  
  284. <!-- 4.4.3.7 power -->
  285. <xsl:template match="m:apply[*[1][self::m:power]]">
  286.     <xsl:apply-templates select="*[2]">
  287.         <xsl:with-param name="p" select="5"/>
  288.     </xsl:apply-templates>
  289.     <xsl:text>^{</xsl:text>
  290.     <xsl:apply-templates select="*[3]">
  291.         <xsl:with-param name="p" select="5"/>
  292.     </xsl:apply-templates>
  293.     <xsl:text>}</xsl:text>
  294. </xsl:template>
  295.  
  296. <!-- 4.4.3.8 remainder -->
  297. <xsl:template match="m:apply[*[1][self::m:rem]]">
  298.     <xsl:param name="p" select="0"/>
  299.     <xsl:call-template name="binary">
  300.         <xsl:with-param name="mo">\mod </xsl:with-param>
  301.         <xsl:with-param name="p" select="$p"/>
  302.         <xsl:with-param name="this-p" select="3"/>
  303.     </xsl:call-template>
  304. </xsl:template>
  305.  
  306. <!-- 4.4.3.9  times-->
  307. <xsl:template match="m:apply[*[1][self::m:times]]" name="times">
  308.   <xsl:param name="p" select="0"/>
  309.   <xsl:param name="first" select="1"/>
  310.   <xsl:if test="$p > 3"><xsl:text>(</xsl:text></xsl:if>
  311.   <xsl:for-each select="*[position()>1]">
  312.         <xsl:if test="position() > 1">
  313.             <xsl:choose>
  314.                 <xsl:when test="self::m:cn">\times <!-- times --></xsl:when>
  315.                 <xsl:otherwise><!--invisible times--></xsl:otherwise>
  316.             </xsl:choose>
  317.         </xsl:if> 
  318.         <xsl:if test="position()>= $first">
  319.             <xsl:apply-templates select=".">
  320.                 <xsl:with-param name="p" select="3"/>
  321.             </xsl:apply-templates>
  322.         </xsl:if>
  323.     </xsl:for-each>
  324.   <xsl:if test="$p > 3"><xsl:text>)</xsl:text></xsl:if>
  325. </xsl:template>
  326.  
  327. <!-- 4.4.3.10 root -->
  328. <xsl:template match="m:apply[*[1][self::m:root]]">
  329.     <xsl:text>\sqrt</xsl:text>
  330.     <xsl:if test="m:degree!=2">
  331.         <xsl:text>[</xsl:text>
  332.         <xsl:apply-templates select="m:degree/*"/>
  333.         <xsl:text>]</xsl:text>
  334.     </xsl:if>
  335.     <xsl:text>{</xsl:text>
  336.     <xsl:apply-templates select="*[position()>1 and not(self::m:degree)]"/>
  337.     <xsl:text>}</xsl:text>
  338. </xsl:template>
  339.  
  340. <!-- 4.4.3.11 gcd -->
  341. <xsl:template match="m:gcd"><xsl:text>\gcd </xsl:text></xsl:template>
  342.  
  343. <!-- 4.4.3.12 and -->
  344. <xsl:template match="m:apply[*[1][self::m:and]]">
  345.     <xsl:param name="p" select="0"/>
  346.     <xsl:call-template name="infix">
  347.         <xsl:with-param name="this-p" select="2"/>
  348.         <xsl:with-param name="p" select="$p"/>
  349.         <xsl:with-param name="mo">\land <!-- and --></xsl:with-param>
  350.     </xsl:call-template>
  351. </xsl:template>
  352.  
  353. <!-- 4.4.3.13 or -->
  354. <xsl:template match="m:apply[*[1][self::m:or]]">
  355.     <xsl:param name="p" select="0"/>
  356.     <xsl:call-template name="infix">
  357.         <xsl:with-param name="this-p" select="3"/>
  358.         <xsl:with-param name="p" select="$p"/>
  359.         <xsl:with-param name="mo">\lor </xsl:with-param>
  360.     </xsl:call-template>
  361. </xsl:template>
  362.  
  363. <!-- 4.4.3.14 xor -->
  364. <xsl:template match="m:apply[*[1][self::m:xor]]">
  365.     <xsl:param name="p" select="0"/>
  366.     <xsl:call-template name="infix">
  367.         <xsl:with-param name="this-p" select="3"/>
  368.         <xsl:with-param name="p" select="$p"/>
  369.         <xsl:with-param name="mo">\mathop{\mathrm{xor}}</xsl:with-param>
  370.     </xsl:call-template>
  371. </xsl:template>
  372.  
  373. <!-- 4.4.3.15 not -->
  374. <xsl:template match="m:apply[*[1][self::m:not]]">
  375.     <xsl:text>\neg </xsl:text>
  376.     <xsl:apply-templates select="*[2]">
  377.         <xsl:with-param name="p" select="7"/>
  378.     </xsl:apply-templates>
  379. </xsl:template>
  380.  
  381. <!-- 4.4.3.16 implies -->
  382. <xsl:template match="m:apply[*[1][self::m:implies]] | m:reln[*[1][self::m:implies]]">
  383.     <xsl:param name="p" select="0"/>
  384.     <xsl:call-template name="binary">
  385.         <xsl:with-param name="mo">\implies </xsl:with-param>
  386.         <xsl:with-param name="p" select="$p"/>
  387.         <xsl:with-param name="this-p" select="3"/>
  388.     </xsl:call-template>
  389. </xsl:template>
  390.  
  391. <!-- 4.4.3.17 forall 4.4.3.18 exists -->
  392. <xsl:template match="m:apply[*[1][self::m:forall or self::m:exists]]">
  393.     <xsl:text>\</xsl:text>
  394.     <xsl:value-of select="local-name(*[1])"/>
  395.     <xsl:text> </xsl:text>
  396.     <xsl:apply-templates select="m:bvar"/>
  397.     <xsl:if test="m:condition">
  398.         <xsl:text>, </xsl:text><xsl:apply-templates select="m:condition"/>
  399.     </xsl:if>
  400.     <xsl:if test="*[last()][local-name()!='condition'][local-name()!='bvar']">
  401.         <xsl:text>\colon </xsl:text>
  402.       <xsl:apply-templates select="*[last()]"/>
  403.   </xsl:if>
  404. </xsl:template>
  405.  
  406. <!-- 4.4.3.19 abs -->
  407. <xsl:template match="m:apply[*[1][self::m:abs]]">
  408.     <xsl:text>\left|</xsl:text>
  409.     <xsl:apply-templates select="*[2]"/>
  410.     <xsl:text>\right|</xsl:text>
  411. </xsl:template>
  412.  
  413. <!-- 4.4.3.20 conjugate -->
  414. <xsl:template match="m:apply[*[1][self::m:conjugate]]">
  415.     <xsl:text>\overline{</xsl:text><xsl:apply-templates select="*[2]"/><xsl:text>}</xsl:text>
  416. </xsl:template>
  417.  
  418. <!-- 4.4.3.22 real -->
  419. <xsl:template match="m:real"><xsl:text>\Re </xsl:text></xsl:template>
  420.  
  421. <!-- 4.4.3.23 imaginary -->
  422. <xsl:template match="m:imaginary"><xsl:text>\Im </xsl:text></xsl:template>
  423.  
  424. <!-- 4.4.3.25 floor -->
  425. <xsl:template match="m:apply[*[1][self::m:floor]]">
  426.     <xsl:text>\lfloor </xsl:text>
  427.     <xsl:apply-templates select="*[2]"/>
  428.     <xsl:text>\rfloor </xsl:text>
  429. </xsl:template>
  430.  
  431. <!-- 4.4.3.25 ceiling -->
  432. <xsl:template match="m:apply[*[1][self::m:ceiling]]">
  433.     <xsl:text>\lceil </xsl:text>
  434.     <xsl:apply-templates select="*[2]"/>
  435.     <xsl:text>\rceil </xsl:text>
  436. </xsl:template>
  437.  
  438. <!-- 4.4.4.1 eq -->
  439. <xsl:template match="m:apply[*[1][self::m:eq]] | m:reln[*[1][self::m:eq]]">
  440.     <xsl:param name="p" select="0"/>
  441.     <xsl:call-template name="infix">
  442.         <xsl:with-param name="this-p" select="1"/>
  443.         <xsl:with-param name="p" select="$p"/>
  444.         <xsl:with-param name="mo">=</xsl:with-param>
  445.     </xsl:call-template>
  446. </xsl:template>
  447.  
  448. <!-- 4.4.4.2 neq -->
  449. <xsl:template match="m:apply[*[1][self::m:neq]] | m:reln[*[1][self::m:neq]]">
  450.     <xsl:param name="p" select="0"/>
  451.     <xsl:call-template name="infix">
  452.         <xsl:with-param name="this-p" select="1"/>
  453.         <xsl:with-param name="p" select="$p"/>
  454.         <xsl:with-param name="mo">\neq </xsl:with-param>
  455.     </xsl:call-template>
  456. </xsl:template>
  457.  
  458. <!-- 4.4.4.3 gt -->
  459. <xsl:template match="m:apply[*[1][self::m:gt]] | m:reln[*[1][self::m:gt]]">
  460. <xsl:param name="p" select="0"/>
  461. <xsl:call-template name="infix">
  462.     <xsl:with-param name="this-p" select="1"/>
  463.     <xsl:with-param name="p" select="$p"/>
  464.     <xsl:with-param name="mo">> </xsl:with-param>
  465. </xsl:call-template>
  466. </xsl:template>
  467.  
  468. <!-- 4.4.4.4 lt -->
  469. <xsl:template match="m:apply[*[1][self::m:lt]] | m:reln[*[1][self::m:lt]]">
  470. <xsl:param name="p" select="0"/>
  471. <xsl:call-template name="infix">
  472.     <xsl:with-param name="this-p" select="1"/>
  473.     <xsl:with-param name="p" select="$p"/>
  474.     <xsl:with-param name="mo">< </xsl:with-param>
  475. </xsl:call-template>
  476. </xsl:template>
  477.  
  478. <!-- 4.4.4.5 geq -->
  479. <xsl:template match="m:apply[*[1][self::m:geq]] | m:reln[*[1][self::m:geq]]">
  480.     <xsl:param name="p" select="0"/>
  481.     <xsl:call-template name="infix">
  482.         <xsl:with-param name="this-p" select="1"/>
  483.         <xsl:with-param name="p" select="$p"/>
  484.         <xsl:with-param name="mo">\ge </xsl:with-param>
  485.     </xsl:call-template>
  486. </xsl:template>
  487.  
  488. <!-- 4.4.4.6 leq -->
  489. <xsl:template match="m:apply[*[1][self::m:leq]] | m:reln[*[1][self::m:leq]]">
  490.     <xsl:param name="p" select="0"/>
  491.     <xsl:call-template name="infix">
  492.         <xsl:with-param name="this-p" select="1"/>
  493.         <xsl:with-param name="p" select="$p"/>
  494.         <xsl:with-param name="mo">\le </xsl:with-param>
  495.     </xsl:call-template>
  496. </xsl:template>
  497.  
  498. <!-- 4.4.4.7 equivalent -->
  499. <xsl:template match="m:apply[*[1][self::m:equivalent]] | m:reln[*[1][self::m:equivalent]]">
  500.     <xsl:param name="p" select="0"/>
  501.     <xsl:call-template name="infix">
  502.         <xsl:with-param name="this-p" select="1"/>
  503.         <xsl:with-param name="p" select="$p"/>
  504.         <xsl:with-param name="mo">\equiv </xsl:with-param>
  505.     </xsl:call-template>
  506. </xsl:template>
  507.  
  508. <!-- 4.4.4.8 approx -->
  509. <xsl:template match="m:apply[*[1][self::m:approx]] | m:reln[*[1][self::m:approx]]">
  510.     <xsl:param name="p" select="0"/>
  511.     <xsl:call-template name="infix">
  512.         <xsl:with-param name="this-p" select="1"/>
  513.         <xsl:with-param name="p" select="$p"/>
  514.         <xsl:with-param name="mo">\approx </xsl:with-param>
  515.     </xsl:call-template>
  516. </xsl:template>
  517.  
  518. <!-- 4.4.4.9 factorof -->
  519. <xsl:template match="m:apply[*[1][self::m:factorof]] | m:reln[*[1][self::m:factorof]]">
  520.     <xsl:param name="p" select="0"/>
  521.     <xsl:call-template name="binary">
  522.         <xsl:with-param name="mo"> | </xsl:with-param>
  523.         <xsl:with-param name="p" select="$p"/>
  524.         <xsl:with-param name="this-p" select="3"/>
  525.     </xsl:call-template>
  526. </xsl:template>
  527.  
  528. <!-- 4.4.5.1 int -->
  529. <xsl:template match="m:apply[*[1][self::m:int]]">
  530.     <xsl:text>\int</xsl:text>
  531.     <xsl:if test="m:lowlimit/*|m:interval/*[1]|m:condition/*">
  532.         <xsl:text>_{</xsl:text>
  533.         <xsl:apply-templates select="m:lowlimit/*|m:interval/*[1]|m:condition/*"/>
  534.         <xsl:text>}</xsl:text>
  535.     </xsl:if>
  536.     <xsl:if test="m:uplimit/*|m:interval/*[2]">
  537.         <xsl:text>^{</xsl:text>
  538.         <xsl:apply-templates select="m:uplimit/*|m:interval/*[2]"/>
  539.         <xsl:text>}</xsl:text>
  540.     </xsl:if>
  541.     <xsl:text> </xsl:text>
  542.     <xsl:apply-templates select="*[last()]"/>
  543.     <xsl:text>\,d </xsl:text>
  544.     <xsl:apply-templates select="m:bvar"/>
  545. </xsl:template>
  546.  
  547. <!-- 4.4.5.2 diff -->
  548. <xsl:template match="m:apply[*[1][self::m:diff] and m:ci and count(*)=2]" priority="2">
  549.     <xsl:apply-templates select="*[2]"/>
  550.     <xsl:text>^\prime </xsl:text>
  551. </xsl:template>
  552.  
  553. <xsl:template match="m:apply[*[1][self::m:diff]]" priority="1">
  554.     <xsl:text>\frac{</xsl:text>
  555.     <xsl:choose>
  556.         <xsl:when test="m:bvar/m:degree">
  557.             <xsl:text>d^{</xsl:text>
  558.             <xsl:apply-templates select="m:bvar/m:degree/node()"/>
  559.             <xsl:text>}</xsl:text>
  560.             <xsl:apply-templates select="*[last()]"/>
  561.             <xsl:text>}{d</xsl:text>
  562.             <xsl:apply-templates select="m:bvar/node()"/>
  563.             <xsl:text>^{</xsl:text>
  564.             <xsl:apply-templates select="m:bvar/m:degree/node()"/>
  565.             <xsl:text>}</xsl:text>
  566.         </xsl:when>
  567.         <xsl:otherwise>
  568.             <xsl:text>d </xsl:text>
  569.             <xsl:apply-templates select="*[last()]"/>
  570.             <xsl:text>}{d </xsl:text>
  571.             <xsl:apply-templates select="m:bvar"/>
  572.         </xsl:otherwise>
  573.     </xsl:choose>
  574.     <xsl:text>}</xsl:text>
  575. </xsl:template>
  576.  
  577. <!-- 4.4.5.3 partialdiff -->
  578. <xsl:template match="m:apply[*[1][self::m:partialdiff] and m:list and m:ci and count(*)=3]" priority="2">
  579.     <xsl:text>D_{</xsl:text>
  580.     <xsl:for-each select="m:list[1]/*">
  581.         <xsl:apply-templates select="."/>
  582.         <xsl:if test="position()<last()"><xsl:text>, </xsl:text></xsl:if>
  583.     </xsl:for-each>
  584.     <xsl:text>}</xsl:text>
  585.     <xsl:apply-templates select="*[3]"/>
  586. </xsl:template>
  587.  
  588. <xsl:template match="m:apply[*[1][self::m:partialdiff]]" priority="1">
  589.     <xsl:text>\frac{\partial</xsl:text>
  590.     <xsl:choose>
  591.         <xsl:when test="m:degree">
  592.             <xsl:text>^{</xsl:text>    
  593.             <xsl:apply-templates select="m:degree/node()"/>
  594.             <xsl:text>}</xsl:text>        
  595.         </xsl:when>
  596.         <xsl:when test="m:bvar/m:degree[string(number(.))='NaN']">
  597.             <xsl:text>^{</xsl:text>
  598.             <xsl:for-each select="m:bvar/m:degree">
  599.                 <xsl:apply-templates select="node()"/>
  600.                 <xsl:if test="position()<last()"><xsl:text>+</xsl:text></xsl:if>
  601.             </xsl:for-each>
  602.             <xsl:if test="count(m:bvar[not(m:degree)])>0">
  603.                 <xsl:text>+</xsl:text>
  604.                 <xsl:value-of select="count(m:bvar[not(m:degree)])"/>
  605.             </xsl:if>
  606.             <xsl:text>}</xsl:text>            
  607.         </xsl:when>
  608.         <xsl:when test="sum(m:bvar/m:degree)+count(m:bvar[not(m:degree)]) > 1">
  609.                 <xsl:text>^{</xsl:text>
  610.                 <xsl:value-of select="sum(m:bvar/m:degree)+count(m:bvar[not(m:degree)])"/>
  611.                 <xsl:text>}</xsl:text>        
  612.         </xsl:when>
  613.     </xsl:choose>
  614.     <xsl:text> </xsl:text>        
  615.     <xsl:apply-templates select="*[last()]"/>
  616.     <xsl:text>}{</xsl:text>
  617.     <xsl:for-each select="m:bvar">
  618.         <xsl:text>\partial </xsl:text>
  619.         <xsl:apply-templates select="node()"/>
  620.         <xsl:if test="m:degree">
  621.             <xsl:text>^{</xsl:text>
  622.             <xsl:apply-templates select="m:degree/node()"/>
  623.             <xsl:text>}</xsl:text>
  624.         </xsl:if>
  625.     </xsl:for-each>
  626.     <xsl:text>}</xsl:text>
  627. </xsl:template>
  628.  
  629. <!-- 4.4.2.8 declare 4.4.5.4 lowlimit 4.4.5.5 uplimit 4.4.5.7 degree 4.4.9.5 momentabout -->
  630. <xsl:template match="m:declare | m:lowlimit | m:uplimit | m:degree | m:momentabout"/>
  631.  
  632. <!-- 4.4.5.6  bvar-->
  633. <xsl:template match="m:bvar">
  634.     <xsl:apply-templates/>
  635.     <xsl:if test="following-sibling::m:bvar"><xsl:text>, </xsl:text></xsl:if>
  636. </xsl:template>
  637.  
  638. <!-- 4.4.5.8 divergence-->
  639. <xsl:template match="m:divergence"><xsl:text>\mathop{\mathrm{div}}</xsl:text></xsl:template>
  640.  
  641. <!-- 4.4.5.11 laplacian-->
  642. <xsl:template match="m:laplacian"><xsl:text>\nabla^2 </xsl:text></xsl:template>
  643.  
  644. <!-- 4.4.6.1 set -->
  645. <xsl:template match="m:set">
  646.     <xsl:text>\{</xsl:text><xsl:call-template name="set"/><xsl:text>\}</xsl:text>
  647. </xsl:template>
  648.  
  649. <!-- 4.4.6.2 list -->
  650. <xsl:template match="m:list">
  651.     <xsl:text>\left[</xsl:text><xsl:call-template name="set"/><xsl:text>\right]</xsl:text>
  652. </xsl:template>
  653.  
  654. <xsl:template name="set">
  655.    <xsl:choose>
  656.         <xsl:when test="m:condition">
  657.            <xsl:apply-templates select="m:bvar/*[not(self::bvar or self::condition)]"/>
  658.            <xsl:text>\colon </xsl:text>
  659.             <xsl:apply-templates select="m:condition/node()"/>
  660.         </xsl:when>
  661.         <xsl:otherwise>
  662.             <xsl:for-each select="*">
  663.                 <xsl:apply-templates select="."/>
  664.                 <xsl:if test="position()!=last()"><xsl:text>, </xsl:text></xsl:if>
  665.             </xsl:for-each>
  666.         </xsl:otherwise>
  667.    </xsl:choose>
  668. </xsl:template>
  669.  
  670. <!-- 4.4.6.3 union -->
  671. <xsl:template match="m:apply[*[1][self::m:union]]">
  672.     <xsl:param name="p" select="0"/>
  673.     <xsl:call-template name="infix">
  674.         <xsl:with-param name="this-p" select="2"/>
  675.         <xsl:with-param name="p" select="$p"/>
  676.         <xsl:with-param name="mo">\cup </xsl:with-param>
  677.     </xsl:call-template>
  678. </xsl:template>
  679.  
  680. <!-- 4.4.6.4 intersect -->
  681. <xsl:template match="m:apply[*[1][self::m:intersect]]">
  682.     <xsl:param name="p" select="0"/>
  683.     <xsl:call-template name="infix">
  684.         <xsl:with-param name="this-p" select="3"/>
  685.         <xsl:with-param name="p" select="$p"/>
  686.         <xsl:with-param name="mo">\cap </xsl:with-param>
  687.     </xsl:call-template>
  688. </xsl:template>
  689.  
  690. <!-- 4.4.6.5 in -->
  691. <xsl:template match="m:apply[*[1][self::m:in]] | m:reln[*[1][self::m:in]]">
  692.     <xsl:param name="p" select="0"/>
  693.     <xsl:call-template name="binary">
  694.         <xsl:with-param name="mo">\in </xsl:with-param>
  695.         <xsl:with-param name="p" select="$p"/>
  696.         <xsl:with-param name="this-p" select="3"/>
  697.     </xsl:call-template>
  698. </xsl:template>
  699.  
  700. <!-- 4.4.6.6 notin -->
  701. <xsl:template match="m:apply[*[1][self::m:notin]] | m:reln[*[1][self::m:notin]]">
  702.     <xsl:param name="p" select="0"/>
  703.     <xsl:call-template name="binary">
  704.         <xsl:with-param name="mo">\notin </xsl:with-param>
  705.         <xsl:with-param name="p" select="$p"/>
  706.         <xsl:with-param name="this-p" select="3"/>
  707.     </xsl:call-template>
  708. </xsl:template>
  709.  
  710. <!-- 4.4.6.7 subset -->
  711. <xsl:template match="m:apply[*[1][self::m:subset]] | m:reln[*[1][self::m:subset]]">
  712.     <xsl:param name="p" select="0"/>
  713.     <xsl:call-template name="infix">
  714.         <xsl:with-param name="this-p" select="2"/>
  715.         <xsl:with-param name="p" select="$p"/>
  716.         <xsl:with-param name="mo">\subseteq </xsl:with-param>
  717.     </xsl:call-template>
  718. </xsl:template>
  719.  
  720. <!-- 4.4.6.8 prsubset -->
  721. <xsl:template match="m:apply[*[1][self::m:prsubset]] | m:reln[*[1][self::m:prsubset]]">
  722.     <xsl:param name="p" select="0"/>
  723.     <xsl:call-template name="infix">
  724.         <xsl:with-param name="this-p" select="2"/>
  725.         <xsl:with-param name="p" select="$p"/>
  726.         <xsl:with-param name="mo">\subset </xsl:with-param>
  727.     </xsl:call-template>
  728. </xsl:template>
  729.  
  730. <!-- 4.4.6.9 notsubset -->
  731. <xsl:template match="m:apply[*[1][self::m:notsubset]] | m:reln[*[1][self::m:notsubset]]">
  732.     <xsl:param name="p" select="0"/>
  733.     <xsl:call-template name="binary">
  734.         <xsl:with-param name="this-p" select="2"/>
  735.         <xsl:with-param name="p" select="$p"/>
  736.         <xsl:with-param name="mo">\nsubseteq </xsl:with-param>
  737.     </xsl:call-template>
  738. </xsl:template>
  739.  
  740. <!-- 4.4.6.10 notprsubset -->
  741. <xsl:template match="m:apply[*[1][self::m:notprsubset]] | m:reln[*[1][self::m:notprsubset]]">
  742.     <xsl:param name="p" select="0"/>
  743.     <xsl:call-template name="binary">
  744.         <xsl:with-param name="this-p" select="2"/>
  745.         <xsl:with-param name="p" select="$p"/>
  746.         <xsl:with-param name="mo">\not\subset </xsl:with-param>
  747.     </xsl:call-template>
  748. </xsl:template>
  749.  
  750. <!-- 4.4.6.11 setdiff -->
  751. <xsl:template match="m:apply[*[1][self::m:setdiff]]">
  752.     <xsl:param name="p" select="0"/>
  753.     <xsl:call-template name="binary">
  754.         <xsl:with-param name="this-p" select="2"/>
  755.         <xsl:with-param name="p" select="$p"/>
  756.         <xsl:with-param name="mo">\setminus </xsl:with-param>
  757.     </xsl:call-template>
  758. </xsl:template>
  759.  
  760. <!-- 4.4.6.12 card -->
  761. <xsl:template match="m:apply[*[1][self::m:card]]">
  762.     <xsl:text>|</xsl:text>
  763.     <xsl:apply-templates select="*[2]"/>
  764.     <xsl:text>|</xsl:text>
  765. </xsl:template>
  766.  
  767. <!-- 4.4.6.13 cartesianproduct 4.4.10.6 vectorproduct -->
  768. <xsl:template match="m:apply[*[1][self::m:cartesianproduct or self::m:vectorproduct]]">
  769.     <xsl:param name="p" select="0"/>
  770.     <xsl:call-template name="infix">
  771.         <xsl:with-param name="this-p" select="2"/>
  772.         <xsl:with-param name="p" select="$p"/>
  773.         <xsl:with-param name="mo">\times </xsl:with-param>
  774.     </xsl:call-template>
  775. </xsl:template>
  776.  
  777. <xsl:template
  778. match="m:apply[*[1][self::m:cartesianproduct][count(following-sibling::m:reals)=count(following-sibling::*)]]"
  779. priority="2">
  780.     <xsl:apply-templates select="*[2]">
  781.         <xsl:with-param name="p" select="5"/>
  782.     </xsl:apply-templates>
  783.     <xsl:text>^{</xsl:text>
  784.     <xsl:value-of select="count(*)-1"/>
  785.     <xsl:text>}</xsl:text>
  786. </xsl:template>
  787.  
  788. <!-- 4.4.7.1 sum -->
  789. <xsl:template match="m:apply[*[1][self::m:sum]]">
  790.     <xsl:text>\sum</xsl:text><xsl:call-template name="series"/>
  791. </xsl:template>
  792.  
  793. <!-- 4.4.7.2 product -->
  794. <xsl:template match="m:apply[*[1][self::m:product]]">
  795.     <xsl:text>\prod</xsl:text><xsl:call-template name="series"/>
  796. </xsl:template>
  797.     
  798. <xsl:template name="series">
  799.     <xsl:if test="m:lowlimit/*|m:interval/*[1]|m:condition/*">
  800.         <xsl:text>_{</xsl:text>
  801.         <xsl:if test="not(m:condition)">
  802.             <xsl:apply-templates select="m:bvar"/>
  803.             <xsl:text>=</xsl:text>
  804.         </xsl:if>
  805.         <xsl:apply-templates select="m:lowlimit/*|m:interval/*[1]|m:condition/*"/>
  806.         <xsl:text>}</xsl:text>
  807.     </xsl:if>
  808.     <xsl:if test="m:uplimit/*|m:interval/*[2]">
  809.         <xsl:text>^{</xsl:text>
  810.         <xsl:apply-templates select="m:uplimit/*|m:interval/*[2]"/>
  811.         <xsl:text>}</xsl:text>
  812.     </xsl:if>
  813.     <xsl:text> </xsl:text>
  814.     <xsl:apply-templates select="*[last()]"/>
  815. </xsl:template>
  816.  
  817. <!-- 4.4.7.3 limit -->
  818. <xsl:template match="m:apply[*[1][self::m:limit]]">
  819.     <xsl:text>\lim_{</xsl:text>
  820.     <xsl:apply-templates select="m:lowlimit|m:condition/*"/>
  821.     <xsl:text>}</xsl:text>
  822.     <xsl:apply-templates select="*[last()]"/>
  823. </xsl:template>
  824.  
  825. <xsl:template match="m:apply[m:limit]/m:lowlimit" priority="3">
  826.     <xsl:apply-templates select="../m:bvar/node()"/>
  827.     <xsl:text>\to </xsl:text>
  828.     <xsl:apply-templates/>
  829. </xsl:template>
  830.  
  831. <!-- 4.4.7.4 tendsto -->
  832. <xsl:template match="m:apply[*[1][self::m:tendsto]] | m:reln[*[1][self::m:tendsto]]">
  833.     <xsl:param name="p"/>
  834.     <xsl:call-template name="binary">
  835.         <xsl:with-param name="this-p" select="2"/>
  836.         <xsl:with-param name="p" select="$p"/>
  837.         <xsl:with-param name="mo">
  838.             <xsl:choose>
  839.                 <xsl:when test="*[1][@type='above']">\searrow </xsl:when>
  840.                 <xsl:when test="*[1][@type='below']">\nearrow </xsl:when>
  841.                 <xsl:when test="*[1][@type='two-sided']">\rightarrow </xsl:when>
  842.                 <xsl:otherwise>\to </xsl:otherwise>
  843.             </xsl:choose>
  844.         </xsl:with-param>
  845.     </xsl:call-template>
  846. </xsl:template>
  847.  
  848. <!-- 4.4.8.1 common tringonometric functions 4.4.8.3 natural logarithm -->
  849. <xsl:template match="m:apply[*[1][
  850.  self::m:sin or         self::m:cos or     self::m:tan or        self::m:sec or
  851.  self::m:csc or         self::m:cot or     self::m:sinh or         self::m:cosh or
  852.  self::m:tanh or         self::m:coth or    self::m:arcsin or     self::m:arccos or
  853.  self::m:arctan or     self::m:ln]]">
  854.     <xsl:text>\</xsl:text>
  855.     <xsl:value-of select="local-name(*[1])"/>
  856.     <xsl:text> </xsl:text>
  857.     <xsl:apply-templates select="*[2]">
  858.         <xsl:with-param name="p" select="7"/>
  859.     </xsl:apply-templates>
  860. </xsl:template>
  861.  
  862. <xsl:template match="m:sin | m:cos | m:tan | m:sec | m:csc |
  863.                                  m:cot | m:sinh | m:cosh | m:tanh | m:coth |
  864.                                  m:arcsin | m:arccos | m:arctan | m:ln">
  865.     <xsl:text>\</xsl:text>
  866.     <xsl:value-of select="local-name(.)"/>
  867.     <xsl:text> </xsl:text>
  868. </xsl:template>
  869.  
  870. <xsl:template match="m:apply[*[1][
  871.  self::m:sech or         self::m:csch or        self::m:arccosh or
  872.  self::m:arccot or     self::m:arccoth or     self::m:arccsc or
  873.  self::m:arccsch or self::m:arcsec or     self::m:arcsech or
  874.  self::m:arcsinh or self::m:arctanh]]">
  875.     <xsl:text>\mathrm{</xsl:text>
  876.     <xsl:value-of select="local-name(*[1])"/>
  877.     <xsl:text>\,}</xsl:text>
  878.     <xsl:apply-templates select="*[2]">
  879.         <xsl:with-param name="p" select="7"/>
  880.     </xsl:apply-templates>
  881. </xsl:template>
  882.  
  883. <xsl:template match="m:sech | m:csch | m:arccosh | m:arccot |
  884.                                  m:arccoth | m:arccsc |m:arccsch |m:arcsec |
  885.                                  m:arcsech | m:arcsinh | m:arctanh">
  886.     <xsl:text>\mathrm{</xsl:text>
  887.     <xsl:value-of select="local-name(.)"/>
  888.     <xsl:text>}</xsl:text>
  889. </xsl:template>
  890.  
  891. <!-- 4.4.8.2 exp -->
  892. <xsl:template match="m:apply[*[1][self::m:exp]]">
  893.     <xsl:text>e^{</xsl:text><xsl:apply-templates select="*[2]"/><xsl:text>}</xsl:text>
  894. </xsl:template>
  895.  
  896. <!-- 4.4.8.4 log -->
  897. <xsl:template match="m:apply[*[1][self::m:log]]">
  898.     <xsl:text>\lg </xsl:text>
  899.     <xsl:apply-templates select="*[last()]">
  900.         <xsl:with-param name="p" select="7"/>
  901.     </xsl:apply-templates>
  902. </xsl:template>
  903.  
  904. <xsl:template match="m:apply[*[1][self::m:log] and m:logbase != 10]">
  905.     <xsl:text>\log_{</xsl:text>
  906.     <xsl:apply-templates select="m:logbase/node()"/>
  907.     <xsl:text>}</xsl:text>
  908.     <xsl:apply-templates select="*[last()]">
  909.         <xsl:with-param name="p" select="7"/>
  910.     </xsl:apply-templates>
  911. </xsl:template>
  912.  
  913. <!-- 4.4.9.1 mean -->
  914. <xsl:template match="m:apply[*[1][self::m:mean]]">
  915.     <xsl:text>\langle </xsl:text>
  916.     <xsl:for-each select="*[position()>1]">
  917.         <xsl:apply-templates select="."/>
  918.         <xsl:if test="position() !=last()"><xsl:text>, </xsl:text></xsl:if>
  919.     </xsl:for-each>
  920.     <xsl:text>\rangle </xsl:text>
  921. </xsl:template>
  922.  
  923. <!-- 4.4.9.2 sdef -->
  924. <xsl:template match="m:sdev"><xsl:text>\sigma </xsl:text></xsl:template>
  925.  
  926. <!-- 4.4.9.3 variance -->
  927. <xsl:template match="m:apply[*[1][self::m:variance]]">
  928.     <xsl:text>\sigma(</xsl:text>
  929.     <xsl:apply-templates select="*[2]"/>
  930.     <xsl:text>)^2</xsl:text>
  931. </xsl:template>
  932.  
  933. <!-- 4.4.9.5 moment -->
  934. <xsl:template match="m:apply[*[1][self::m:moment]]">
  935.     <xsl:text>\langle </xsl:text>
  936.     <xsl:apply-templates select="*[last()]"/>
  937.     <xsl:text>^{</xsl:text>
  938.     <xsl:apply-templates select="m:degree/node()"/>
  939.     <xsl:text>}\rangle</xsl:text>
  940.     <xsl:if test="m:momentabout">
  941.         <xsl:text>_{</xsl:text>
  942.         <xsl:apply-templates select="m:momentabout/node()"/>
  943.         <xsl:text>}</xsl:text>
  944.     </xsl:if>
  945.     <xsl:text> </xsl:text>
  946. </xsl:template>
  947.  
  948. <!-- 4.4.10.1 vector  -->
  949. <xsl:template match="m:vector">
  950.     <xsl:text>\left(\begin{array}{c}</xsl:text>
  951.     <xsl:for-each select="*">
  952.         <xsl:apply-templates select="."/>
  953.         <xsl:if test="position()!=last()"><xsl:text>\\  </xsl:text></xsl:if>
  954.     </xsl:for-each>
  955.     <xsl:text>\end{array}\right)</xsl:text>
  956. </xsl:template>
  957.  
  958. <!-- 4.4.10.2 matrix  -->
  959. <xsl:template match="m:matrix">
  960.     <xsl:text>\begin{pmatrix}</xsl:text>
  961.     <xsl:apply-templates/>
  962.     <xsl:text>\end{pmatrix}</xsl:text>
  963. </xsl:template>
  964.  
  965. <!-- 4.4.10.3 matrixrow  -->
  966. <xsl:template match="m:matrixrow">
  967.     <xsl:for-each select="*">
  968.         <xsl:apply-templates select="."/>
  969.         <xsl:if test="position()!=last()"><xsl:text> & </xsl:text></xsl:if>
  970.     </xsl:for-each>
  971.     <xsl:if test="position()!=last()"><xsl:text>\\  </xsl:text></xsl:if>
  972. </xsl:template>
  973.  
  974. <!-- 4.4.10.4 determinant  -->
  975. <xsl:template match="m:apply[*[1][self::m:determinant]]">
  976.     <xsl:text>\det </xsl:text>
  977.     <xsl:apply-templates select="*[2]">
  978.         <xsl:with-param name="p" select="7"/>
  979.     </xsl:apply-templates>
  980. </xsl:template>
  981.  
  982. <xsl:template match="m:apply[*[1][self::m:determinant]][*[2][self::m:matrix]]" priority="2">
  983.     <xsl:text>\begin{vmatrix}</xsl:text>
  984.     <xsl:apply-templates select="m:matrix/*"/>
  985.     <xsl:text>\end{vmatrix}</xsl:text>
  986. </xsl:template>
  987.  
  988. <!-- 4.4.10.5 transpose -->
  989. <xsl:template match="m:apply[*[1][self::m:transpose]]">
  990.     <xsl:apply-templates select="*[2]">
  991.         <xsl:with-param name="p" select="7"/>
  992.     </xsl:apply-templates>
  993.     <xsl:text>^T</xsl:text>
  994. </xsl:template>
  995.  
  996. <!-- 4.4.10.6 selector -->
  997. <xsl:template match="m:apply[*[1][self::m:selector]]">
  998.     <xsl:apply-templates select="*[2]">
  999.         <xsl:with-param name="p" select="7"/>
  1000.     </xsl:apply-templates>
  1001.     <xsl:text>_{</xsl:text>
  1002.     <xsl:for-each select="*[position()>2]">
  1003.         <xsl:apply-templates select="."/>
  1004.         <xsl:if test="position() !=last()"><xsl:text>, </xsl:text></xsl:if>
  1005.     </xsl:for-each>
  1006.     <xsl:text>}</xsl:text>
  1007. </xsl:template>
  1008.  
  1009. <!-- 4.4.10.8 scalarproduct -->
  1010. <xsl:template match="m:apply[*[1][self::m:scalarproduct]]">
  1011.     <xsl:param name="p" select="0"/>
  1012.     <xsl:call-template name="infix">
  1013.         <xsl:with-param name="this-p" select="2"/>
  1014.         <xsl:with-param name="p" select="$p"/>
  1015.         <xsl:with-param name="mo">\cdot </xsl:with-param>
  1016.     </xsl:call-template>
  1017. </xsl:template>
  1018.  
  1019. <!-- 4.4.10.9 outerproduct -->
  1020. <xsl:template match="m:apply[*[1][self::m:outerproduct]]">
  1021.     <xsl:param name="p" select="0"/>
  1022.     <xsl:call-template name="infix">
  1023.         <xsl:with-param name="this-p" select="2"/>
  1024.         <xsl:with-param name="p" select="$p"/>
  1025.         <xsl:with-param name="mo">\otimes </xsl:with-param>
  1026.     </xsl:call-template>
  1027. </xsl:template>
  1028.  
  1029. <!-- 4.4.11.2 semantics -->
  1030. <xsl:template match="m:semantics"><xsl:apply-templates select="*[1]"/></xsl:template>
  1031.  
  1032. <xsl:template match="m:semantics[m:annotation/@encoding='TeX']">
  1033.     <xsl:apply-templates select="m:annotation[@encoding='TeX']/node()"/>
  1034. </xsl:template>
  1035.  
  1036. <!-- 4.4.12.1 integers -->
  1037. <xsl:template match="m:integers"><xsl:text>\mathbb{Z}</xsl:text></xsl:template>
  1038.  
  1039. <!-- 4.4.12.2 reals -->
  1040. <xsl:template match="m:reals"><xsl:text>\mathbb{R}</xsl:text></xsl:template>
  1041.  
  1042. <!-- 4.4.12.3 rationals -->
  1043. <xsl:template match="m:rationals"><xsl:text>\mathbb{Q}</xsl:text></xsl:template>
  1044.  
  1045. <!-- 4.4.12.4 naturalnumbers -->
  1046. <xsl:template match="m:naturalnumbers"><xsl:text>\mathbb{N}</xsl:text></xsl:template>
  1047.  
  1048. <!-- 4.4.12.5 complexes -->
  1049. <xsl:template match="m:complexes"><xsl:text>\mathbb{C}</xsl:text></xsl:template>
  1050.  
  1051. <!-- 4.4.12.6 primes -->
  1052. <xsl:template match="m:primes"><xsl:text>\mathbb{P}</xsl:text></xsl:template>
  1053.     
  1054. <!-- 4.4.12.7 exponentiale -->
  1055. <xsl:template match="m:exponentiale"><xsl:text>e</xsl:text></xsl:template>
  1056.  
  1057. <!-- 4.4.12.8 imaginaryi -->
  1058. <xsl:template match="m:imaginaryi"><xsl:text>i</xsl:text></xsl:template>
  1059.  
  1060. <!-- 4.4.12.9 notanumber -->
  1061. <xsl:template match="m:notanumber"><xsl:text>NaN</xsl:text></xsl:template>
  1062.  
  1063. <!-- 4.4.12.10 true -->
  1064. <xsl:template match="m:true"><xsl:text>\mbox{true}</xsl:text></xsl:template>
  1065.  
  1066. <!-- 4.4.12.11 false -->
  1067. <xsl:template match="m:false"><xsl:text>\mbox{false}</xsl:text></xsl:template>
  1068.  
  1069. <!-- 4.4.12.12 emptyset -->
  1070. <xsl:template match="m:emptyset"><xsl:text>\emptyset </xsl:text></xsl:template>
  1071.  
  1072. <!-- 4.4.12.13 pi -->
  1073. <xsl:template match="m:pi"><xsl:text>\pi </xsl:text></xsl:template>
  1074.  
  1075. <!-- 4.4.12.14 eulergamma -->
  1076. <xsl:template match="m:eulergamma"><xsl:text>\gamma </xsl:text></xsl:template>
  1077.  
  1078. <!-- 4.4.12.15 infinity -->
  1079. <xsl:template match="m:infinity"><xsl:text>\infty </xsl:text></xsl:template>
  1080.  
  1081. <!-- ****************************** -->
  1082. <xsl:template name="infix" >
  1083.   <xsl:param name="mo"/>
  1084.   <xsl:param name="p" select="0"/>
  1085.   <xsl:param name="this-p" select="0"/>
  1086.   <xsl:if test="$this-p < $p"><xsl:text>(</xsl:text></xsl:if>
  1087.   <xsl:for-each select="*[position()>1]">
  1088.         <xsl:if test="position() > 1">
  1089.             <xsl:copy-of select="$mo"/>
  1090.         </xsl:if>   
  1091.         <xsl:apply-templates select=".">
  1092.             <xsl:with-param name="p" select="$this-p"/>
  1093.         </xsl:apply-templates>
  1094.     </xsl:for-each>
  1095.   <xsl:if test="$this-p < $p"><xsl:text>)</xsl:text></xsl:if>
  1096. </xsl:template>
  1097.  
  1098. <xsl:template name="binary" >
  1099.   <xsl:param name="mo"/>
  1100.   <xsl:param name="p" select="0"/>
  1101.   <xsl:param name="this-p" select="0"/>
  1102.   <xsl:if test="$this-p < $p"><xsl:text>(</xsl:text></xsl:if>
  1103.     <xsl:apply-templates select="*[2]">
  1104.         <xsl:with-param name="p" select="$this-p"/>
  1105.     </xsl:apply-templates>
  1106.     <xsl:value-of select="$mo"/>
  1107.     <xsl:apply-templates select="*[3]">
  1108.         <xsl:with-param name="p" select="$this-p"/>
  1109.     </xsl:apply-templates>
  1110.     <xsl:if test="$this-p < $p"><xsl:text>)</xsl:text></xsl:if>
  1111. </xsl:template>
  1112.  
  1113. </xsl:stylesheet>
  1114.