]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/style/mmlextension.xsl
- the mathql interpreter is not helm-dependent any more
[helm.git] / helm / style / mmlextension.xsl
index 71a424d8bb52585e46c4b9aa829eee25a43e3021..4a801a65402c244e03bbe273c6a4d7a7ba1709a3 100644 (file)
@@ -40,10 +40,12 @@ which generates the toplevel element (see for instance xlink) -->
                               xmlns:xlink="http://www.w3.org/1999/xlink">
 
 <!-- OLD: <xsl:import href="mml2mmlv1_0.xsl"/> -->
-<xsl:import href="mmlctop.xsl-0.14"/>
+
+<xsl:import href="mmlnotation.xsl"/>
 
 <xsl:import href="mmltheoryextension.xsl"/>
 
+
 <xsl:param name="explodeall" select="false()"/>
 
 <!--***********************************************************************-->
@@ -179,10 +181,54 @@ which generates the toplevel element (see for instance xlink) -->
       <xsl:for-each select="Conjecture">
       <m:mtr>
        <m:mtd>
-        <m:mrow>
+        <m:mrow helm:xref="{@helm:xref}">
          <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
-         <m:mtext><xsl:value-of select="./@no"/>:</m:mtext>
-         <xsl:apply-templates select="./*[1]"/>
+         <xsl:for-each select="Decl|Def|Hidden">
+          <xsl:choose>
+           <xsl:when test="name(.)='Decl'">
+            <m:mrow helm:xref="{@helm:xref}">
+             <xsl:choose>
+              <xsl:when test="@name">
+               <m:mi><xsl:value-of select="@name"/></m:mi>
+              </xsl:when>
+              <xsl:otherwise>
+               <m:mi>_</m:mi>
+              </xsl:otherwise>
+             </xsl:choose>
+             <m:mo>:</m:mo>
+             <xsl:apply-templates select="./*[1]"/>
+            </m:mrow>
+           </xsl:when>
+           <xsl:when test="name(.)='Def'">
+            <m:mrow helm:xref="{@helm:xref}">
+             <xsl:choose>
+              <xsl:when test="@name">
+               <m:mi><xsl:value-of select="@name"/></m:mi>
+              </xsl:when>
+              <xsl:otherwise>
+               <m:mi>_</m:mi>
+              </xsl:otherwise>
+             </xsl:choose>
+             <m:mo>:=</m:mo>
+             <xsl:apply-templates select="./*[1]"/>
+            </m:mrow>
+           </xsl:when>
+           <xsl:otherwise>
+            <m:mrow helm:xref="{@helm:xref}">
+             <m:mi>_</m:mi>
+             <m:mo>:?</m:mo>
+             <m:mi>_</m:mi>
+            </m:mrow>
+           </xsl:otherwise>
+          </xsl:choose>
+          <xsl:if test="not (position() = last())">
+           <m:mo>;</m:mo>
+          </xsl:if>
+         </xsl:for-each>
+         <m:mo>|-</m:mo>
+         <m:msub><m:mi>?</m:mi><m:mn><xsl:value-of select="@no"/></m:mn></m:msub>
+         <m:mo>:</m:mo>
+         <xsl:apply-templates select="./Goal/*[1]"/>
         </m:mrow>
        </m:mtd>
       </m:mtr>
@@ -190,7 +236,7 @@ which generates the toplevel element (see for instance xlink) -->
       <m:mtr>
        <m:mtd>
         <m:mrow>
-         <m:mtext>CORRESPONDING PROOF:</m:mtext>
+         <m:mtext>PROOF:</m:mtext>
         </m:mrow>
        </m:mtd>
       </m:mtr>
@@ -358,6 +404,61 @@ which generates the toplevel element (see for instance xlink) -->
     </m:math>
 </xsl:template>
 
+<!-- SEQUENT -->
+
+<xsl:template match="Sequent">
+ <xsl:variable name="rowlines">
+  <xsl:for-each select="Decl|Def">
+   <xsl:if test="position() != last()">
+    <xsl:text>none </xsl:text>
+   </xsl:if>
+  </xsl:for-each>
+  <xsl:text>solid</xsl:text>
+ </xsl:variable>
+ <xsl:variable name="no" select="@no"/>
+    <m:math>
+     <m:mi><xsl:text>?</xsl:text><xsl:value-of select="$no"/></m:mi>
+     <m:mo>:</m:mo>
+     <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
+     <m:mtable align="baseline 1" equalrows="false" columnalign="left" helm:xref="{@helm:xref}" rowlines="{$rowlines}">
+      <xsl:for-each select="Decl|Def">
+       <m:mtr>
+        <m:mtd>
+         <m:mrow helm:xref="{@helm:xref}">
+          <m:mi><xsl:value-of select="@name"/></m:mi>
+          <xsl:choose>
+           <xsl:when test="name(.) = 'Decl'">
+            <m:mo>:</m:mo>
+           </xsl:when>
+           <xsl:otherwise>
+            <m:mo>:=</m:mo>
+           </xsl:otherwise>
+          </xsl:choose>
+          <xsl:apply-templates select="*[1]"/>
+         </m:mrow>
+        </m:mtd>
+       </m:mtr>
+      </xsl:for-each>
+      <xsl:if test="not(Decl|Def)">
+      <m:mtr>
+       <m:mtd>
+        <m:mrow>
+         <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
+        </m:mrow>
+       </m:mtd>
+      </m:mtr>
+      </xsl:if>
+      <m:mtr>
+       <m:mtd>
+        <m:mrow>
+         <xsl:apply-templates select="Goal/*[1]"/>
+        </m:mrow>
+       </m:mtd>
+      </m:mtr>
+     </m:mtable>
+    </m:math>
+</xsl:template>
+
 <!--**********************-->
 <!--        TERMS         -->
 <!--**********************-->
@@ -411,10 +512,20 @@ which generates the toplevel element (see for instance xlink) -->
     <xsl:variable name="name"><xsl:value-of select="m:csymbol"/></xsl:variable>
     <xsl:variable name="charlength"><xsl:apply-templates select="m:csymbol" mode="charcount"/></xsl:variable>
     <m:mrow>
-     <xsl:if test="@helm:xref">
-      <xsl:attribute name="m:xref"><xsl:value-of select="@id"/></xsl:attribute>
+     <xsl:if test="@id">
+      <xsl:attribute name="xref"><xsl:value-of select="@id"/></xsl:attribute>
      </xsl:if>
+     <xsl:variable name="id" select="m:csymbol/@id"/>
      <xsl:choose>
+      <!-- META -->
+      <xsl:when test="$name='meta'">
+       <m:mrow>
+        <xsl:apply-templates select="*[position()=2]"/>
+        <m:mfenced open="[" close="]" separators=";">
+         <xsl:apply-templates select="*[position()>2]"/>
+        </m:mfenced>
+       </m:mrow>
+      </xsl:when>
       <!-- FORALL -->
       <xsl:when test="$name='forall'">
        <xsl:choose>
@@ -613,7 +724,10 @@ which generates the toplevel element (see for instance xlink) -->
           <m:mtd>
            <m:mrow>
             <m:mo stretchy="false">(</m:mo>
-            <xsl:apply-templates select="*[position()=2]"/>
+<!-- added precedence to app = FUNCTION_PREC (99) -->
+            <xsl:apply-templates select="*[position()=2]">
+             <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
+            </xsl:apply-templates>
            </m:mrow>
           </m:mtd>
          </m:mtr>
@@ -622,7 +736,10 @@ which generates the toplevel element (see for instance xlink) -->
           <m:mtd>
            <m:mrow>
             <m:mphantom><m:mtext>(</m:mtext></m:mphantom>
-            <xsl:apply-templates select="."/>
+<!-- added precedence to app = FUNCTION_PREC (99) -->
+            <xsl:apply-templates select=".">
+             <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
+            </xsl:apply-templates>
            </m:mrow>
           </m:mtd>
          </m:mtr>
@@ -638,10 +755,16 @@ which generates the toplevel element (see for instance xlink) -->
        </xsl:when>
        <xsl:otherwise>
         <m:mo stretchy="false">(</m:mo>
-        <xsl:apply-templates select="*[position()=2]"/>
+<!-- added precedence to app = FUNCTION_PREC (99) -->
+        <xsl:apply-templates select="*[position()=2]">
+         <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
+        </xsl:apply-templates>
         <xsl:for-each select="*[position()>2]">
          <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
-         <xsl:apply-templates select="."/>
+<!-- added precedence to app = FUNCTION_PREC (99) -->
+         <xsl:apply-templates select=".">
+          <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
+         </xsl:apply-templates>
         </xsl:for-each>
         <m:mo stretchy="false">)</m:mo>
        </xsl:otherwise>
@@ -737,7 +860,7 @@ which generates the toplevel element (see for instance xlink) -->
            </m:mrow>
           </m:mtd>
          </m:mtr>
-         <xsl:for-each select="piecewise/piece">
+         <xsl:for-each select="m:piecewise/m:piece">
          <xsl:variable name="charlength"><xsl:apply-templates select="./*[2]" mode="charcount"><xsl:with-param name="nosibling" select="1"/></xsl:apply-templates></xsl:variable>
          <m:mtr>
           <m:mtd>
@@ -787,7 +910,7 @@ which generates the toplevel element (see for instance xlink) -->
         <xsl:apply-templates select="*[position()=3]"/>
         <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
         <m:mo>OF</m:mo>
-        <xsl:for-each select="piecewise/piece">
+        <xsl:for-each select="m:piecewise/m:piece">
          <xsl:choose>
          <xsl:when test="position() != 1">
           <m:mo stretchy="false">|</m:mo>
@@ -987,52 +1110,173 @@ which generates the toplevel element (see for instance xlink) -->
       <!-- ***************************************** -->
       <!-- PROOF -->
       <xsl:when test="$name='proof'">
-       <m:maction actiontype="toggle">
-        <!-- CSC: next if until the annotationHelper can handle mactions -->
-        <xsl:if test="not($explodeall)">
-         <!-- Details hided (default) -->
+        <!-- CSC: $explodeall until the annotationHelper can handle mactions -->
+        <xsl:variable name="test" select="(not($explodeall)) and
+          (not(preceding-sibling::*[1]/text()='letin1')) and
+          (not(preceding-sibling::*[1]/text()='rw_step')) and
+          (not(name(..)='m:lambda'))"/>
+        <xsl:variable name="hidden_details">
+         <xsl:if test="$test">
+          <!-- Details hided (default) -->
+          <m:mtable align="baseline 1" equalrows="false" columnalign="left">
+           <m:mtr>
+            <m:mtd>
+             <m:mrow>
+              <m:mtext mathcolor="Red">We&#x00a0;can&#x00a0;prove</m:mtext>
+              <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
+              <!-- the last child is either the expected type, if provided,-->
+              <!-- or the synthesized type.                                -->
+              <xsl:apply-templates select="*[position()=last()]"/>
+              <m:mrow>
+               <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
+               <m:mtext mathcolor="Green">(explain)</m:mtext>
+              </m:mrow>
+             </m:mrow>
+            </m:mtd>
+           </m:mtr>
+          </m:mtable>
+         </xsl:if>
+        </xsl:variable>
+        <xsl:variable name="shown_details">
+         <!-- Show details -->
          <m:mtable align="baseline 1" equalrows="false" columnalign="left">
           <m:mtr>
            <m:mtd>
             <m:mrow>
-             <m:mtext mathcolor="Maroon">We&#x00a0;can&#x00a0;prove</m:mtext>
+             <xsl:apply-templates select="*[position()=2]"/>
+            </m:mrow>
+           </m:mtd>
+          </m:mtr>
+          <xsl:variable name="hidedetails">
+            <m:mrow>
+             <m:mphantom>
+              <m:mtext>_</m:mtext>
+             </m:mphantom>
+             <xsl:if test="$test">
+              <m:mtext mathcolor="Green">(hide&#x00a0;details)</m:mtext>
+             </xsl:if>
+            </m:mrow>
+          </xsl:variable>
+          <m:mtr>
+           <m:mtd>
+            <m:mrow>
+             <m:mtext mathcolor="Red">we&#x00a0;proved</m:mtext>
              <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
              <xsl:apply-templates select="*[position()=3]"/>
+             <xsl:if test="not(*[4])">
+              <xsl:copy-of select="$hidedetails"/>
+             </xsl:if>
+            </m:mrow>
+           </m:mtd>
+          </m:mtr>
+          <xsl:if test="*[4]">
+           <m:mtr>
+            <m:mtd>
+             <m:mrow>
+              <m:mtext mathcolor="Red">that&#x00a0;is&#x00a0;equivalent&#x00a0;to</m:mtext>
+              <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
+              <xsl:apply-templates select="*[position()=4]"/>
+              <xsl:copy-of select="$hidedetails"/>
+             </m:mrow>
+            </m:mtd>
+           </m:mtr>
+          </xsl:if>
+         </m:mtable>
+        </xsl:variable>
+        <xsl:choose>
+         <xsl:when test="$test">
+          <m:maction actiontype="toggle">
+           <xsl:copy-of select="$hidden_details"/>
+           <xsl:copy-of select="$shown_details"/>
+          </m:maction>
+         </xsl:when>
+         <xsl:otherwise>
+          <xsl:copy-of select="$shown_details"/>
+         </xsl:otherwise>
+        </xsl:choose>
+      </xsl:when>
+      <!-- SIDE_PROOF -->
+      <xsl:when test="$name='side_proof'">
+        <xsl:variable name="test" select="(not($explodeall))"/>
+        <xsl:variable name="hidden_details">
+         <xsl:if test="$test">
+          <!-- Details hided (default) -->
+          <m:mtable align="baseline 1" equalrows="false" columnalign="left">
+           <m:mtr>
+            <m:mtd>
              <m:mrow>
+              <m:mtext mathcolor="Red">We&#x00a0;can&#x00a0;prove</m:mtext>
               <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
-              <m:mtext mathcolor="Green">(explain)</m:mtext>
+              <!-- the last child is either the expected type, if provided,-->
+              <!-- or the synthesized type.                                -->
+              <xsl:apply-templates select="*[position()=last()]"/>
+              <m:mrow>
+               <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
+               <m:mtext mathcolor="Green">(explain)</m:mtext>
+              </m:mrow>
              </m:mrow>
+            </m:mtd>
+           </m:mtr>
+          </m:mtable>
+         </xsl:if>
+        </xsl:variable>
+        <xsl:variable name="shown_details">
+         <!-- Show details -->
+         <m:mtable align="baseline 1" equalrows="false" columnalign="left">
+          <m:mtr>
+           <m:mtd>
+            <m:mrow>
+             <xsl:apply-templates select="*[position()=2]"/>
             </m:mrow>
            </m:mtd>
           </m:mtr>
-         </m:mtable>
-        </xsl:if>
-        <!-- Show details -->
-        <m:mtable align="baseline 1" equalrows="false" columnalign="left">
-         <m:mtr>
-          <m:mtd>
-           <m:mrow>
-            <xsl:apply-templates select="*[position()=2]"/>
-           </m:mrow>
-          </m:mtd>
-         </m:mtr>
-         <m:mtr>
-          <m:mtd>
-           <m:mrow>
-            <m:mtext mathcolor="Maroon">we&#x00a0;proved</m:mtext>
-            <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
-            <xsl:apply-templates select="*[position()=3]"/>
+          <xsl:variable name="hidedetails">
             <m:mrow>
              <m:mphantom>
               <m:mtext>_</m:mtext>
              </m:mphantom>
-             <m:mtext mathcolor="Green">(hide&#x00a0;details)</m:mtext>
+             <xsl:if test="$test">
+              <m:mtext mathcolor="Green">(hide&#x00a0;details)</m:mtext>
+             </xsl:if>
             </m:mrow>
-           </m:mrow>
-          </m:mtd>
-         </m:mtr>
-        </m:mtable>
-       </m:maction>
+          </xsl:variable>
+          <m:mtr>
+           <m:mtd>
+            <m:mrow>
+             <m:mtext mathcolor="Red">we&#x00a0;proved</m:mtext>
+             <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
+             <xsl:apply-templates select="*[position()=3]"/>
+             <xsl:if test="not(*[4])">
+              <xsl:copy-of select="$hidedetails"/>
+             </xsl:if>
+            </m:mrow>
+           </m:mtd>
+          </m:mtr>
+          <xsl:if test="*[4]">
+           <m:mtr>
+            <m:mtd>
+             <m:mrow>
+              <m:mtext mathcolor="Red">that&#x00a0;is&#x00a0;equivalent&#x00a0;to</m:mtext>
+              <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
+              <xsl:apply-templates select="*[position()=4]"/>
+              <xsl:copy-of select="$hidedetails"/>
+             </m:mrow>
+            </m:mtd>
+           </m:mtr>
+          </xsl:if>
+         </m:mtable>
+        </xsl:variable>
+        <xsl:choose>
+         <xsl:when test="$test">
+          <m:maction actiontype="toggle">
+           <xsl:copy-of select="$hidden_details"/>
+           <xsl:copy-of select="$shown_details"/>
+          </m:maction>
+         </xsl:when>
+         <xsl:otherwise>
+          <xsl:copy-of select="$shown_details"/>
+         </xsl:otherwise>
+        </xsl:choose>
       </xsl:when>
       <!-- LETIN1 -->
       <xsl:when test="$name='letin1'">
@@ -1040,14 +1284,14 @@ which generates the toplevel element (see for instance xlink) -->
          <m:mtr>
           <m:mtd>
            <m:mrow>
-            <xsl:apply-templates select="*[2]"/>
+            <xsl:apply-templates select="*[position()=2]"/>
            </m:mrow>
           </m:mtd>
          </m:mtr>
          <m:mtr>
           <m:mtd>
            <m:mrow>
-            <xsl:apply-templates select="*[3]"/>
+            <xsl:apply-templates select="*[position()=3]"/>
            </m:mrow>
           </m:mtd>
          </m:mtr>
@@ -1058,7 +1302,7 @@ which generates the toplevel element (see for instance xlink) -->
         <m:mtr>
          <m:mtd>
           <m:mrow>
-           <m:mtext mathcolor="red">We&#x00a0;prove</m:mtext>
+           <m:mtext mathcolor="Red">We&#x00a0;prove</m:mtext>
            <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
            <xsl:apply-templates select="../*[3]"/>
           </m:mrow>
@@ -1067,7 +1311,7 @@ which generates the toplevel element (see for instance xlink) -->
         <m:mtr>
          <m:mtd>
           <m:mrow>
-           <m:mtext mathcolor="red">by&#x00a0;induction&#x00a0;on</m:mtext>
+           <m:mtext mathcolor="Red">by&#x00a0;induction&#x00a0;on</m:mtext>
            <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
            <xsl:apply-templates 
             select="*[position()=last()]/*[position()=last()]"/>
@@ -1099,7 +1343,7 @@ which generates the toplevel element (see for instance xlink) -->
         <m:mtr>
          <m:mtd>
           <m:mrow>
-           <m:mtext mathcolor="red">Case</m:mtext>
+           <m:mtext mathcolor="Red">Case</m:mtext>
            <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
            <xsl:apply-templates select="*[2]"/>
           </m:mrow>
@@ -1114,7 +1358,7 @@ which generates the toplevel element (see for instance xlink) -->
              <m:mtr>
               <m:mtd>
                <m:mrow>
-                <m:mtext mathcolor="red">By&#x00a0;induction&#x00a0;hypothesis,&#x00a0;we&#x00a0;have:</m:mtext>
+                <m:mtext mathcolor="Red">By&#x00a0;induction&#x00a0;hypothesis,&#x00a0;we&#x00a0;have:</m:mtext>
                </m:mrow>
               </m:mtd>
              </m:mtr>
@@ -1520,32 +1764,114 @@ which generates the toplevel element (see for instance xlink) -->
          </m:mtr>
         </m:mtable>
       </xsl:when>
+      <!-- EQ_CHAIN -->
+      <xsl:when test="$name='eq_chain'">
+       <m:mtable align="baseline 1" equalrows="false" columnalign="left">
+        <m:mtr>
+         <m:mtd>
+          <m:mrow>
+           <m:mtext mathcolor="Red">We&#x00a0;have&#x00a0;the&#x00a0;following&#x00a0;equality&#x00a0;chain:</m:mtext>
+          </m:mrow>
+         </m:mtd>
+        </m:mtr>
+        <xsl:for-each select="*[position() mod 2 = 0]">
+        <xsl:variable name="pos" select="position()"/>
+        <m:mtr>
+         <m:mtd>
+          <m:mrow>
+           <xsl:choose>
+           <xsl:when test="$pos = 1">
+            <xsl:apply-templates select="."/>
+            <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
+            <m:mo>=</m:mo>
+           </xsl:when>
+           <xsl:otherwise>
+            <m:mo>=</m:mo>
+            <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
+            <xsl:apply-templates select="."/>
+           </xsl:otherwise>
+           </xsl:choose>
+          </m:mrow>
+         </m:mtd>
+        </m:mtr>
+        <xsl:if test="$pos != last()">
+        <m:mtr>
+         <m:mtd>
+          <m:mrow>
+           <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
+           <xsl:apply-templates select="../*[position()=2*$pos +1]"/>
+          </m:mrow>
+         </m:mtd>
+        </m:mtr>
+        </xsl:if>
+        </xsl:for-each>
+       </m:mtable>
+      </xsl:when>
+      <!-- DISEQ_CHAIN -->
+      <xsl:when test="$name='diseq_chain'">
+       <m:mtable align="baseline 1" equalrows="false" columnalign="left">
+        <m:mtr>
+         <m:mtd>
+          <m:mrow>
+           <m:mtext mathcolor="Red">We&#x00a0;have&#x00a0;the&#x00a0;following&#x00a0;disequality&#x00a0;chain:</m:mtext>
+          </m:mrow>
+         </m:mtd>
+        </m:mtr>
+        <xsl:for-each select="*[position() mod 3 = 2]">
+        <xsl:variable name="pos" select="position()"/>
+        <m:mtr>
+         <m:mtd>
+          <m:mrow>
+           <xsl:choose>
+           <xsl:when test="$pos = 1">
+            <xsl:apply-templates select="."/>
+            <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
+            <mo><xsl:apply-templates select="../*[position()=3*$pos]"/></mo>
+           </xsl:when>
+           <xsl:otherwise>
+            <mo><xsl:apply-templates select="../*[position()=3*($pos - 1)]"/></mo>
+            <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
+            <xsl:apply-templates select="."/>
+           </xsl:otherwise>
+           </xsl:choose>
+          </m:mrow>
+         </m:mtd>
+        </m:mtr>
+        <xsl:if test="$pos != last()">
+        <m:mtr>
+         <m:mtd>
+          <m:mrow>
+           <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
+           <xsl:apply-templates select="../*[position()=3*$pos +1]"/>
+          </m:mrow>
+         </m:mtd>
+        </m:mtr>
+        </xsl:if>
+        </xsl:for-each>
+       </m:mtable>
+      </xsl:when>
       <!-- ***************************************** -->
       <!-- *********** NOTATIONS ******************* -->
       <!-- ***************************************** -->
       <!-- subst -->
       <xsl:when test="$name='subst'">
         <xsl:apply-templates select="*[3]"/>
-        <m:mo>&#xe8a0;</m:mo>
-        <m:mrow>
-         <m:mo stretchy="false">[</m:mo>
-         <m:mrow>
-          <xsl:apply-templates select="*[4]"/>
-          <m:mo mathcolor="green">
-           <xsl:if test="$id != ''">
-            <xsl:attribute name="m:xref"><xsl:value-of select="$id"/></xsl:attribute>
-           </xsl:if>&#8592;</m:mo>
-          <xsl:apply-templates select="*[2]"/>
-         </m:mrow>
-         <m:mo stretchy="false">]</m:mo>
-        </m:mrow>
+<!-- no font for ApplyFunction: <m:mo>&#xe8a0;</m:mo> -->
+        <m:mo stretchy="false">[</m:mo>
+        <xsl:apply-templates select="*[4]"/>
+        <m:mo mathcolor="Green">
+         <xsl:if test="$id != ''">
+          <xsl:attribute name="xref"><xsl:value-of select="$id"/></xsl:attribute>
+         </xsl:if>&#8592;</m:mo>
+        <xsl:apply-templates select="*[2]"/>
+        <m:mo stretchy="false">]</m:mo>
       </xsl:when>
       <!-- lift -->
       <xsl:when test="$name='lift'">
         <m:msup>
-         <m:mo mathcolor="green">
+         <m:mo mathcolor="Green">
           <xsl:if test="$id != ''">
-           <xsl:attribute name="m:xref"><xsl:value-of select="$id"/></xsl:attribute>
+           <xsl:attribute name="xref"><xsl:value-of select="$id"/></xsl:attribute>
           </xsl:if>&#8593;</m:mo>
         <xsl:apply-templates select="*[2]"/>
         </m:msup>
@@ -1558,9 +1884,9 @@ which generates the toplevel element (see for instance xlink) -->
       <!-- lift_with_base -->
       <xsl:when test="$name='lift_with_base'">
         <m:msubsup>
-         <m:mo mathcolor="green">
+         <m:mo mathcolor="Green">
           <xsl:if test="$id != ''">
-           <xsl:attribute name="m:xref"><xsl:value-of select="$id"/></xsl:attribute>
+           <xsl:attribute name="xref"><xsl:value-of select="$id"/></xsl:attribute>
           </xsl:if>&#8593;</m:mo>
         <xsl:apply-templates select="*[3]"/>
         <xsl:apply-templates select="*[4]"/>
@@ -1575,11 +1901,11 @@ which generates the toplevel element (see for instance xlink) -->
       <xsl:when test="$name='beta_red1'">
         <xsl:apply-templates select="*[2]"/>
         <m:munder>
-         <m:mo mathcolor="green">
+         <m:mo mathcolor="Green">
           <xsl:if test="$id != ''">
-           <xsl:attribute name="m:xref"><xsl:value-of select="$id"/></xsl:attribute>
+           <xsl:attribute name="xref"><xsl:value-of select="$id"/></xsl:attribute>
           </xsl:if>&#8594;</m:mo>
-          <m:mi mathcolor="green">&#946;</m:mi>
+          <m:mi mathcolor="Green">&#946;</m:mi>
         </m:munder>
         <xsl:apply-templates select="*[3]"/>
       </xsl:when>
@@ -1587,12 +1913,12 @@ which generates the toplevel element (see for instance xlink) -->
       <xsl:when test="$name='beta_red'">
         <xsl:apply-templates select="*[2]"/>
         <m:munderover>
-         <m:mo mathcolor="green">
+         <m:mo mathcolor="Green">
           <xsl:if test="$id != ''">
-           <xsl:attribute name="m:xref"><xsl:value-of select="$id"/></xsl:attribute>
+           <xsl:attribute name="xref"><xsl:value-of select="$id"/></xsl:attribute>
           </xsl:if>&#8594;</m:mo>
-          <m:mi mathcolor="green">&#946;</m:mi>
-          <m:mi mathcolor="green">*</m:mi>
+          <m:mi mathcolor="Green">&#946;</m:mi>
+          <m:mi mathcolor="Green">*</m:mi>
         </m:munderover>
         <xsl:apply-templates select="*[3]"/>
       </xsl:when>
@@ -1600,11 +1926,11 @@ which generates the toplevel element (see for instance xlink) -->
       <xsl:when test="$name='par_beta_red1'">
         <xsl:apply-templates select="*[2]"/>
         <m:munder>
-         <m:mo mathcolor="green">
+         <m:mo mathcolor="Green">
           <xsl:if test="$id != ''">
-           <xsl:attribute name="m:xref"><xsl:value-of select="$id"/></xsl:attribute>
+           <xsl:attribute name="xref"><xsl:value-of select="$id"/></xsl:attribute>
           </xsl:if>&#8658;</m:mo>
-          <m:mi mathcolor="green">&#946;</m:mi>
+          <m:mi mathcolor="Green">&#946;</m:mi>
         </m:munder>
         <xsl:apply-templates select="*[3]"/>
       </xsl:when>
@@ -1612,12 +1938,12 @@ which generates the toplevel element (see for instance xlink) -->
       <xsl:when test="$name='par_beta_red'">
         <xsl:apply-templates select="*[2]"/>
         <m:munderover>
-         <m:mo mathcolor="green">
+         <m:mo mathcolor="Green">
           <xsl:if test="$id != ''">
-           <xsl:attribute name="m:xref"><xsl:value-of select="$id"/></xsl:attribute>
+           <xsl:attribute name="xref"><xsl:value-of select="$id"/></xsl:attribute>
           </xsl:if>&#8658;</m:mo>
-          <m:mi mathcolor="green">&#946;</m:mi>
-          <m:mi mathcolor="green">*</m:mi>
+          <m:mi mathcolor="Green">&#946;</m:mi>
+          <m:mi mathcolor="Green">*</m:mi>
         </m:munderover>
         <xsl:apply-templates select="*[3]"/>
       </xsl:when>
@@ -1625,7 +1951,7 @@ which generates the toplevel element (see for instance xlink) -->
       <xsl:when test="$name='forgetful'">
        <m:mfenced open="|" close="|">
         <xsl:if test="$id != ''">
-         <xsl:attribute name="m:xref"><xsl:value-of select="$id"/></xsl:attribute>
+         <xsl:attribute name="xref"><xsl:value-of select="$id"/></xsl:attribute>
         </xsl:if>
         <xsl:apply-templates select="*[2]"/>
        </m:mfenced>
@@ -1633,9 +1959,9 @@ which generates the toplevel element (see for instance xlink) -->
       <!-- isomorphic -->
       <xsl:when test="$name='isomorphic'">
         <xsl:apply-templates select="*[2]"/>
-        <m:mo mathcolor="green">
+        <m:mo mathcolor="Green">
          <xsl:if test="$id != ''">
-          <xsl:attribute name="m:xref"><xsl:value-of select="$id"/></xsl:attribute>
+          <xsl:attribute name="xref"><xsl:value-of select="$id"/></xsl:attribute>
          </xsl:if>&#8773;</m:mo>
         <xsl:apply-templates select="*[3]"/>
       </xsl:when>
@@ -1643,7 +1969,7 @@ which generates the toplevel element (see for instance xlink) -->
       <xsl:when test="$name='forgetful'">
        <m:mfenced open="[" close="]">
         <xsl:if test="$id != ''">
-         <xsl:attribute name="m:xref"><xsl:value-of select="$id"/></xsl:attribute>
+         <xsl:attribute name="xref"><xsl:value-of select="$id"/></xsl:attribute>
         </xsl:if>
         <xsl:apply-templates select="*[2]"/>
        </m:mfenced>
@@ -1682,7 +2008,7 @@ which generates the toplevel element (see for instance xlink) -->
          <m:mtr>
           <m:mtd>
            <m:mrow>
-            <m:mtext mathcolor="Maroon">we&#x00a0;get</m:mtext>
+            <m:mtext mathcolor="Red">we&#x00a0;get</m:mtext>
             <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
             <xsl:apply-templates select="."/>
            </m:mrow>
@@ -1700,7 +2026,7 @@ which generates the toplevel element (see for instance xlink) -->
          <m:mtr>
           <m:mtd>
            <m:mrow>
-            <m:mtext mathcolor="Maroon">we&#x00a0;get</m:mtext>
+            <m:mtext mathcolor="Red">we&#x00a0;get</m:mtext>
             <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
             <xsl:apply-templates select="."/>
            </m:mrow>
@@ -1716,7 +2042,12 @@ which generates the toplevel element (see for instance xlink) -->
 
 <xsl:template match="m:lambda">
     <xsl:variable name="charlength"><xsl:apply-templates select="*[position()=1]" mode="charcount"/></xsl:variable>
-    <m:mrow m:xref="{@id}">
+    <m:mrow>
+     <xsl:if test="@id">
+      <xsl:attribute name="xref">
+       <xsl:value-of select="@id"/>
+      </xsl:attribute>
+     </xsl:if>
      <xsl:choose>
      <xsl:when test="$charlength >= $framewidth">
       <m:mtable align="baseline 1" equalrows="false" columnalign="left">
@@ -1750,252 +2081,6 @@ which generates the toplevel element (see for instance xlink) -->
     </m:mrow>
 </xsl:template>
 
-<!-- *********************************** -->
-<!-- BASE SET OF MATHML CONTENT ELEMENTS -->
-<!-- *********************************** -->
-
-<!-- Logic -->
-
-<xsl:template match = "m:apply[m:eq[1]]">
- <xsl:variable name="charlength">
-  <xsl:apply-templates select="*[1]" mode="charcount"/>
- </xsl:variable>
- <xsl:choose>
-  <xsl:when test="$charlength >= $framewidth">
-   <m:mtable align="baseline 1" equalrows="false" columnalign="left">
-    <xsl:if test="@helm:xref">
-     <xsl:attribute name="m:xref">
-      <xsl:value-of select="@id"/>
-     </xsl:attribute>
-    </xsl:if>    
-    <m:mtr>
-     <m:mtd>
-      <m:mrow>
-       <m:mo stretchy="false">(</m:mo>
-       <xsl:apply-templates select="*[position()=2]"/>
-      </m:mrow>
-     </m:mtd>
-    </m:mtr>
-    <xsl:for-each select = "*[position()>2]">
-     <m:mtr>
-      <m:mtd>
-       <m:mrow>
-        <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
-        <m:mo m:xref="{m:in/@id}">=</m:mo>
-        <xsl:apply-templates select="."/>
-       </m:mrow>
-      </m:mtd>
-     </m:mtr>
-    </xsl:for-each>
-    <m:mtr>
-     <m:mtd>
-      <m:mrow>
-       <m:mo stretchy="false">)</m:mo>
-      </m:mrow>
-     </m:mtd>
-    </m:mtr>
-   </m:mtable>
-  </xsl:when>
-  <xsl:otherwise>
-   <xsl:apply-imports/>
-  </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-
-<xsl:template match = "m:apply[m:and[1]|m:or[1]
-          |m:geq[1]|m:leq[1]|m:gt[1]|m:lt[1]
-          |m:in[1]|m:intesect[1]|m:union[1]|m:subset[1]
-          |m:prsubset|m:setdiff[1]]">
- <xsl:variable name="symbol">
-  <xsl:choose>
-   <xsl:when test="m:and[1]">
-    <xsl:value-of select="'&#8743;'"/>
-   </xsl:when>
-   <xsl:when test="m:or[1]">
-    <xsl:value-of select="'&#8744;'"/>
-   </xsl:when>
-   <xsl:when test="m:geq[1]">
-    <xsl:value-of select="'&#8805;'"/>
-   </xsl:when>
-   <xsl:when test="m:leq[1]">
-    <xsl:value-of select="'&#8804;'"/>
-   </xsl:when>
-   <xsl:when test="m:gt[1]">
-    <xsl:value-of select="'&#62;'"/>
-   </xsl:when>
-   <xsl:when test="m:lt[1]">
-    <xsl:value-of select="'&#60;&#32;'"/>
-   </xsl:when>
-   <xsl:when test="m:eq[1]">
-    <xsl:value-of select="'&#61;'"/>
-   </xsl:when>
-   <xsl:when test="m:in[1]">
-    <xsl:value-of select="'&#x02208;'"/>
-   </xsl:when>
-   <xsl:when test="m:subset[1]">
-    <xsl:value-of select="'&#x02286;'"/>
-   </xsl:when>
-   <xsl:when test="m:prsubset[1]">
-    <xsl:value-of select="'&#x02282;'"/>
-   </xsl:when>
-   <xsl:when test="m:intersect[1]">
-    <xsl:value-of select="'&#x022C2;'"/>
-   </xsl:when>
-   <xsl:when test="m:union[1]">
-    <xsl:value-of select="'&#x022C3;'"/>
-   </xsl:when>
-   <xsl:when test="m:setdiff[1]">
-    <xsl:value-of select="'&#x02216;'"/>
-   </xsl:when>
-  </xsl:choose>
- </xsl:variable>
- <xsl:variable name="charlength">
-  <xsl:apply-templates select="*[1]" mode="charcount"/>
- </xsl:variable>
- <xsl:choose>
-  <xsl:when test="$charlength >= $framewidth">
-   <m:mtable align="baseline 1" equalrows="false" columnalign="left">
-    <xsl:if test="@helm:xref">
-     <xsl:attribute name="m:xref">
-      <xsl:value-of select="@id"/>
-     </xsl:attribute>
-    </xsl:if>    
-    <m:mtr>
-     <m:mtd>
-      <m:mrow>
-       <m:mo stretchy="false">(</m:mo>
-       <xsl:apply-templates select="*[position()=2]"/>
-      </m:mrow>
-     </m:mtd>
-    </m:mtr>
-    <xsl:for-each select = "*[position()>2]">
-     <m:mtr>
-      <m:mtd>
-       <m:mrow>
-        <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
-        <m:mo m:xref="{*[1]/@id}"><xsl:value-of select="$symbol"/></m:mo>
-        <xsl:apply-templates select="."/>
-       </m:mrow>
-      </m:mtd>
-     </m:mtr>
-    </xsl:for-each>
-    <m:mtr>
-     <m:mtd>
-      <m:mrow>
-       <m:mo stretchy="false">)</m:mo>
-      </m:mrow>
-     </m:mtd>
-    </m:mtr>
-   </m:mtable>
-  </xsl:when>
-  <xsl:otherwise>
-   <xsl:apply-imports/>
-  </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-<xsl:template match = "m:set">
- <xsl:choose>
-  <xsl:when test="count(child::*) = 0">
-   <m:mi>&#x02205;</m:mi>
-  </xsl:when>
-  <xsl:otherwise>
-   <xsl:variable name="charlength">
-    <xsl:apply-templates select="*[1]" mode="charcount"/>
-   </xsl:variable>
-   <xsl:choose>
-    <xsl:when test="$charlength >= $framewidth">
-     <xsl:choose>
-      <xsl:when test="name(*[1]) = 'm:bvar'">
-       <m:mtable align="baseline 1" equalrows="false" columnalign="left">
-        <m:mtr>
-         <m:mtd>
-          <m:mrow>
-           <m:mo stretchy="false">{</m:mo>
-           <xsl:apply-templates select="*[position()=1]"/>
-          </m:mrow>
-         </m:mtd>
-        </m:mtr>
-        <m:mtr>
-         <m:mtd>
-          <m:mrow>
-           <m:mphantom><m:mtext>{</m:mtext></m:mphantom>
-           <m:mo stretchy="false">|</m:mo>
-           <xsl:apply-templates select="m:condition/*[1]"/>
-          </m:mrow>
-         </m:mtd>
-        </m:mtr>
-        <m:mtr>
-         <m:mtd>
-          <m:mrow>
-           <m:mo stretchy="false">}</m:mo>
-          </m:mrow>
-         </m:mtd>
-        </m:mtr>
-       </m:mtable>
-      </xsl:when>
-      <xsl:otherwise>
-       <m:mtable align="baseline 1" equalrows="false" columnalign="left">
-        <m:mtr>
-         <m:mtd>
-          <m:mrow>
-           <m:mo stretchy="false">{</m:mo>
-           <xsl:apply-templates select="*[position()=1]"/>
-           <xsl:if test="position() != last()">
-            <mo>,</mo>
-           </xsl:if>
-          </m:mrow>
-         </m:mtd>
-        </m:mtr>
-        <xsl:for-each select = "*[position()>2]">
-         <m:mtr>
-          <m:mtd>
-           <m:mrow>
-            <m:mphantom><m:mtext>{</m:mtext></m:mphantom>
-            <xsl:apply-templates select="."/>
-            <xsl:if test="position() != last()">
-             <mo>,</mo>
-            </xsl:if>
-           </m:mrow>
-          </m:mtd>
-         </m:mtr>
-        </xsl:for-each>
-        <m:mtr>
-         <m:mtd>
-          <m:mrow>
-           <m:mo stretchy="false">}</m:mo>
-          </m:mrow>
-         </m:mtd>
-        </m:mtr>
-       </m:mtable>
-      </xsl:otherwise>
-     </xsl:choose>
-    </xsl:when>
-    <xsl:otherwise>
-     <xsl:apply-imports/>
-    </xsl:otherwise>
-   </xsl:choose>
-  </xsl:otherwise>
- </xsl:choose>
-</xsl:template>      
-
-<xsl:template match = "m:apply[m:card[1]]">
-  <m:mfenced open="|" close="|" stretchy="false">
-    <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
-      <xsl:attribute name="m:xref">
-        <xsl:value-of select="@id"/>
-      </xsl:attribute>
-    </xsl:if>
-  <xsl:apply-templates select="*[2]"/>
-  </m:mfenced>
-</xsl:template>
-
-<!-- *********************************** -->
-<!--          PROOF ELEMENTS             -->
-<!-- *********************************** -->
-
-
 
 <!--**********************-->
 <!--       COUNTING       -->
@@ -2053,7 +2138,16 @@ which generates the toplevel element (see for instance xlink) -->
 <xsl:param name="nosibling" select="0"/>
  <xsl:choose>
   <xsl:when test="count(child::*) = 0">
-   <xsl:value-of select="$incurrent_length"/>
+   <!-- tremendous bug fixed. An empty element can still have siblings!!! -->
+   <xsl:variable name="siblength"><xsl:apply-templates select="following-sibling::*[position()=1]" mode="charcount"><xsl:with-param name="incurrent_length" select="$incurrent_length"/></xsl:apply-templates></xsl:variable>
+   <xsl:choose>
+    <xsl:when test="string($siblength) = &quot;&quot;">
+     <xsl:value-of select="$incurrent_length"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:value-of select="number($siblength)"/>
+    </xsl:otherwise>
+   </xsl:choose>
   </xsl:when>
   <xsl:otherwise>
     <xsl:variable name="childlength"><xsl:apply-templates select="*[position()=1]" mode="charcount"><xsl:with-param name="incurrent_length" select="$incurrent_length"/><xsl:with-param name="nosibling" select="0"/></xsl:apply-templates></xsl:variable>
@@ -2078,3 +2172,4 @@ which generates the toplevel element (see for instance xlink) -->
 </xsl:template>
 
 </xsl:stylesheet> 
+