<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">% $Id: tex4ht-html-speech-xtpipes.tex 740 2020-06-13 22:35:32Z karl $
% htlatex tex4ht-html-speech-xtpipes "html,next,3" "" "-d./"
%
% Copyright 2009-2020 TeX Users Group
% Copyright 2006-2009 Eitan M. Gurari
% Released under LPPL 1.3c+.
% See tex4ht-cpright.tex for license text.
\documentclass{article}
    \Configure{ProTex}{log,&lt;&lt;&lt;&gt;&gt;&gt;,title,list,`,[[]]}
\begin{document}

\input{common}
\input{tex4ht-dir}
\input{tex4ht-cpright}

%%%%%%%%%%%%%%%%%%
\part{Script for xtpipes}
%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%
\section{Outline}
%%%%%%%%%%%%%%%%%%



\AtEndDocument{\OutputCodE\&lt;htspk.4xt\&gt;}


\Needs{"xmllint --valid --noout htspk.4xt"} 


\&lt;htspk.4xt\&gt;&lt;&lt;&lt;
&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
&lt;!DOCTYPE xtpipes SYSTEM "xtpipes.dtd" &gt;
&lt;!-- htspk.4xt (`version), generated from `jobname.tex
     Copyright (C) 2009-2010 TeX Users Group
     Copyright (C) `CopyYear.2002. Eitan M. Gurari
`&lt;TeX4ht copyright`&gt; --&gt;
&lt;xtpipes&gt;
   &lt;sax content-handler="xtpipes.util.ScriptsManager"
        lexical-handler="xtpipes.util.ScriptsManagerLH" &gt;
     `&lt;non short tag br elements`&gt;     
     `&lt;undo empty scripts`&gt; 
     `&lt;span frac elements`&gt;
     `&lt;short cut modifiers`&gt;
     `&lt;over and under scripts`&gt;
     `&lt;bold math`&gt;
     `&lt;capital math letters`&gt;
     `&lt;remove multline eqnum cell`&gt; 
     `&lt;inline math`&gt;
     `&lt;display math`&gt;
     `&lt;measure tables`&gt;
     `&lt;remove empty split entries`&gt;
     `&lt;boundaries on theorems`&gt;
   &lt;/sax&gt;
&lt;/xtpipes&gt;
&gt;&gt;&gt;



\&lt;inline math\&gt;&lt;&lt;&lt;
&lt;script element="span::inline-math" &gt;
  `&lt;compress numeric subscripts`&gt;
  `&lt;set levels for hyper complex fracs`&gt;
  `&lt;set levels for sub and sup scripts`&gt;
  `&lt;set levels for roots`&gt;
  &lt;set name="inline-math" &gt;
     `&lt;open xslt script`&gt;
     `&lt;shared display and inline math 1`&gt;
     `&lt;eliminate inline math narrative`&gt;
     `&lt;close xslt script`&gt;
  &lt;/set&gt;
  &lt;xslt name="." xml="." xsl="inline-math" /&gt;
  &lt;set name="inline-math-2" &gt;
     `&lt;open xslt script`&gt;
     `&lt;shared display and inline math 2`&gt;
     `&lt;eliminate inline math narrative 2`&gt;
     `&lt;close xslt script`&gt;
  &lt;/set&gt;
  &lt;xslt name="." xml="." xsl="inline-math-2" /&gt;
  `&lt;set empty elements for the w3 browser`&gt;
&lt;/script&gt; 
&gt;&gt;&gt;




\&lt;display math\&gt;&lt;&lt;&lt;
&lt;script element="div::display-math" &gt;
  `&lt;compress numeric subscripts`&gt;
  `&lt;set levels for hyper complex fracs`&gt;
  `&lt;set levels for sub and sup scripts`&gt;
  `&lt;set levels for roots`&gt;
  &lt;set name="display-math" &gt;
     `&lt;open xslt script`&gt;
     `&lt;shared display and inline math 1`&gt;
     `&lt;close xslt script`&gt;
  &lt;/set&gt;
  &lt;xslt name="." xml="." xsl="display-math" /&gt;
  &lt;set name="display-math-2" &gt;
     `&lt;open xslt script`&gt;
     `&lt;shared display and inline math 2`&gt;
     `&lt;close xslt script`&gt;
  &lt;/set&gt;
  &lt;xslt name="." xml="." xsl="display-math-2" /&gt;
  `&lt;set empty elements for the w3 browser`&gt;
&lt;/script&gt; 
&gt;&gt;&gt;

\&lt;shared display and inline math 1\&gt;&lt;&lt;&lt;
`&lt;get content template`&gt;
`&lt;eliminate baseline script marks`&gt; 
`&lt;fraction 'and' prefix`&gt; 
`&lt;'minus' into 'negative'`&gt; 
`&lt;compress limit script`&gt;
`&lt;remove scrip indicators from primes`&gt; 
&gt;&gt;&gt;


\&lt;shared display and inline math 2\&gt;&lt;&lt;&lt;
`&lt;get content template`&gt;
`&lt;replace nested baseline script marks`&gt;
`&lt;insert pre mi spaces`&gt;
`&lt;eliminate begin script marks`&gt; 
&gt;&gt;&gt;


\marginpar{Can dom be prevented from creating an xml declaration in
  the output? The xslt part is there just to remove the undesirable
  declaration.}


\&lt;remove xml declaration\&gt;&lt;&lt;&lt;
&lt;set name="rmXmlDecl" &gt;
  `&lt;open xslt script`&gt;
  `&lt;close xslt script`&gt;
&lt;/set&gt;
&lt;xslt name="." xml="." xsl="rmXmlDecl" /&gt;
&gt;&gt;&gt;







\AtEndDocument{\OutputCodE\&lt;HtSpk.java\&gt;}
\ifdojava
  \Needs{"
    javac HtSpk.java      -d \XTPIPES . 
"}
\fi

\&lt;HtSpk.java\&gt;&lt;&lt;&lt;
package tex4ht;
/* HtSpk.java (`version), generated from `jobname.tex
   Copyright (C) 2009-2010 TeX Users Group
   Copyright (C) `CopyYear.2006. Eitan M. Gurari
`&lt;TeX4ht copyright`&gt; */
import org.w3c.dom.*;
public class HtSpk {
  `&lt;static void fracLevel(dom)`&gt;
  `&lt;static void scriptLevel(dom)`&gt;
  `&lt;static void rootLevel(dom)`&gt;
}
&gt;&gt;&gt;


%%%%%%%%%%%%%%%%%%
\section{Line Break Elements}
%%%%%%%%%%%%%%%%%%

Avoid short versions \verb+&lt;br /&gt;+.

\&lt;non short tag br elements\&gt;&lt;&lt;&lt;
&lt;script element="br" &gt;
  &lt;set name="br" &gt;
    &lt;![CDATA[ 
       &lt;xsl:stylesheet version="1.0"
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       &gt;
          &lt;xsl:output omit-xml-declaration = "yes" /&gt;
          &lt;xsl:template match="br" &gt;
            &lt;xsl:copy&gt;
              &lt;xsl:apply-templates select="@*" /&gt;
              &lt;xsl:comment&gt;`&lt;comment`&gt;&lt;/xsl:comment&gt;
            &lt;/xsl:copy&gt;
          &lt;/xsl:template&gt; 
          &lt;xsl:template match="*|@*|text()|comment()" &gt;
            &lt;xsl:copy&gt;
              &lt;xsl:apply-templates select="*|@*|text()|comment()" /&gt;
            &lt;/xsl:copy&gt;
          &lt;/xsl:template&gt;
       &lt;/xsl:stylesheet&gt; 
    ]]&gt;
  &lt;/set&gt;
  &lt;xslt name="." xml="." xsl="br" /&gt;
&lt;/script&gt; 
&gt;&gt;&gt;

%%%%%%%%%%%%%%%%%%
\section{Capital Letters in Math}
%%%%%%%%%%%%%%%%%%

\&lt;capital math letters\&gt;&lt;&lt;&lt;
&lt;script element="span::mi" &gt;
  &lt;set name="math-cap" &gt;
     `&lt;open xslt script`&gt;
     `&lt;span.mi cap letters`&gt; 
     `&lt;close xslt script`&gt;
  &lt;/set&gt;
  &lt;xslt name="." xml="." xsl="math-cap" /&gt;
&lt;/script&gt; 
&gt;&gt;&gt;

%                     (translate(.,'abcdefghijklmnopqrstuvwxyz',
%                                  'ABCDEFGHIJKLMNOPQRSTUVWXYZ') = . )
%                    and

\&lt;span.mi cap letters\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[ @class = 'mi' ]" &gt;
  &lt;xsl:copy&gt;
    &lt;xsl:apply-templates select="@*" /&gt;
      &lt;xsl:if test=" string-length(.) = 1 " &gt;      
         &lt;xsl:if test="
                     (translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
                                  '') = '' )
                  " &gt;      
            &lt;span class="capital-description" 
                  title="speech-extra" &gt;
               &lt;xsl:text&gt; capital &lt;/xsl:text&gt;
            &lt;/span&gt;
         &lt;/xsl:if&gt;      
      &lt;/xsl:if&gt;      
    &lt;xsl:apply-templates select="*|text()|comment()" /&gt;
  &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;

%%%%%%%%%%%%%%%%%%
\section{Superscripts and Subscripts}
%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%
\subsection{Insert Sub-Levels Info}
%%%%%%%%%%%%%




\&lt;set levels for sub and sup scripts\&gt;&lt;&lt;&lt;
&lt;dom name="." xml="." method="scriptLevel" class="tex4ht.HtSpk" /&gt;
`&lt;remove xml declaration`&gt;
&gt;&gt;&gt;



\&lt;static void scriptLevel(dom)\&gt;&lt;&lt;&lt;
public static void scriptLevel(Node dom) {
   setScriptLevel(dom.getFirstChild(), "");
}
private static void setScriptLevel(Node node, String prefix) {
  String clName = null;
  if (node.hasChildNodes()) {
    if (node.hasAttributes()) {
      Node cl = node.getAttributes().getNamedItem("class");
      if (cl != null) {
        clName = cl.getNodeValue();
        if( clName.equals("mrow-sub")
            ||
            clName.equals("mrow-super")
        ){
          `&lt;append script prefix`&gt;
        } else if( 
           clName.equals("msqrt")
        ){  prefix = ""; }
    } }
    `&lt;script invoke children`&gt;
} }
&gt;&gt;&gt;

\&lt;script invoke children\&gt;&lt;&lt;&lt;
NodeList children = node.getChildNodes();
for (int i = 0; i &lt; children.getLength(); i++) {
   Node child = children.item(i);
   if (child.getNodeType() == Node.ELEMENT_NODE) {
      setScriptLevel(child, prefix);
}  }
&gt;&gt;&gt;

\&lt;append script prefix\&gt;&lt;&lt;&lt;
if( !prefix.equals("") ){
  `&lt;use current script prefix`&gt;
}
if( clName.equals( "mrow-sub" ) ){ prefix += " sub "; }
else
if( clName.equals( "mrow-super" ) ){ prefix += " super "; }
&gt;&gt;&gt;


\&lt;use current script prefix\&gt;&lt;&lt;&lt;
Node child = node.getFirstChild();
if( (child.getNodeType() == Node.ELEMENT_NODE) 
    &amp;&amp;
    child.hasAttributes()
){
   Node cls = child.getAttributes().getNamedItem("class");
   if (cls != null) {
      String clsName = cls.getNodeValue();
      if ( clsName.equals("begin-script")
           ||
           clsName.equals("mid-script")
      ) {
         child = child.getFirstChild();
         String s = child.getNodeValue();
         ((org.w3c.dom.Text) child).setData( prefix + s );
}  }  }
&gt;&gt;&gt;
 


%%%%%%%%%%%%%
\subsection{Eliminate  End Script Marks}
%%%%%%%%%%%%%


The following takes care of end-scripts that semantically can be
merged into other end markers.

\&lt;eliminate baseline script marks\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[
   (@class = 'end-script')
   and
   ancestor::* [ following-sibling::* [
                         not( @class = 'content-less' )
                      ] 
               ][1]
           / following-sibling::* [
                         not( @class = 'content-less' )
                     ][1] 
           / self::*
    [
       (@class = 'end-math') 
       or
       (@class = 'end-script') 
       or
       (@class = 'end-root') 
       or
       (@class = 'end-stack') 
       or
       (@class = 'mid-stack') 
       or
       (@class = 'end-array') 
       or
       (@class = 'tr') 
       or
       (@title = 'implicit-baseline') 
    ]
]"  &gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;



%%%%%%%%%%%%%
\subsection{Replace Nested Baseline Script Marks}
%%%%%%%%%%%%%


\&lt;replace nested baseline script marks\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[
     (@class = 'end-script')
   and
     ancestor::*[ preceding-sibling::* [
       ((@class = 'begin-script') or (@class = 'mid-script')) ]]
`%   and
     ( normalize-space(.) = 'baseline' )     REMOVE `%
]" &gt;
  &lt;xsl:copy&gt;
     &lt;xsl:apply-templates select="*|@*|comment()" /&gt;
     &lt;xsl:value-of select="
            ancestor::*[ preceding-sibling::* [
                           ((@class = 'begin-script') or 
                            (@class = 'mid-script'))     ]]  [1]
            / preceding-sibling::* [
                           ((@class = 'begin-script') or 
                            (@class = 'mid-script'))  ][1]
      " /&gt;
  &lt;/xsl:copy&gt;
&lt;/xsl:template&gt;   
&gt;&gt;&gt;


%%%%%%%%%%%%%
\subsection{Eliminate  Begin Script Marks}
%%%%%%%%%%%%%



\&lt;eliminate begin script marks\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[
     (@class = 'begin-script')
   and
     following-sibling::* [1] / child::*[  
       (position() = 1)
       and 
       (@class = 'mrow-base')
       and
       ( normalize-space(.) = '' )
     ]
]"  &gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;



%%%%%%%%%%%%%
\subsection{Undo Empty Scripts}
%%%%%%%%%%%%%




\&lt;undo empty scripts\&gt;&lt;&lt;&lt;
&lt;script element="span::msup" &gt;
   &lt;set name="m-sub-sup" &gt;
     `&lt;open xslt script`&gt;
     `&lt;undo if empty su`&gt; 
     `&lt;close xslt script`&gt;
   &lt;/set&gt;
   &lt;xslt name="." xml="." xsl="m-sub-sup" /&gt;
   `&lt;superscript 2 and 3 into verbose`&gt;
&lt;/script&gt; 
&lt;script element="span::msub" &gt;
  `&lt;sub sup script`&gt;
&lt;/script&gt; 
&lt;script element="span::msubsup" &gt;
  `&lt;subsup prime`&gt;
  `&lt;sub sup script`&gt;
  `&lt;sub superscript 2 and 3 into verbose`&gt;
&lt;/script&gt; 
&gt;&gt;&gt;

\&lt;sub sup script\&gt;&lt;&lt;&lt;
&lt;set name="m-sub-sup" &gt;
  `&lt;open xslt script`&gt;
  `&lt;undo if empty su`&gt; 
  `&lt;close xslt script`&gt;
&lt;/set&gt;
&lt;xslt name="." xml="." xsl="m-sub-sup" /&gt;
&gt;&gt;&gt;

\&lt;undo if empty su\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[
    ((@class = 'msup') or (@class = 'msub')
                       or (@class = 'msubsup'))
  and
    not(
      child::span[ (@class = 'mrow-sub') ] 
        / child::span[ (@class != 'begin-script')
                       and
                       (@class != 'end-script')
                       and
                       (@class != 'mid-script')
                     ]
    )
  and
    not(
      child::span[ (@class = 'mrow-super') ] 
        / child::span[ (@class != 'begin-script')
                       and
                       (@class != 'end-script')
                       and
                       (@class != 'mid-script')
                     ]
    )
]" &gt;
   &lt;xsl:apply-templates select="child::span[ 
                          @class = 'mrow-base' ]/*" /&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;



\begin{verbatim}
&lt;span class="msup"&gt;
   &lt;span class="mrow-base"&gt;
     .........
   &lt;/span&gt;
   &lt;span class="mrow-super"&gt;
     &lt;span class="begin-script"&gt; superscript &lt;/span&gt;
     &lt;span class="end-script"&gt; baseline &lt;/span&gt;
   &lt;/span&gt;
&lt;/span&gt;
\end{verbatim}




%%%%%%%%%%%%%
\subsection{Squared}
%%%%%%%%%%%%%

\&lt;superscript 2 and 3 into verbose\&gt;&lt;&lt;&lt;
&lt;set name="m-sup-2-3" &gt;
  `&lt;open xslt script`&gt;
  `&lt;superscript into squared abd cube`&gt; 
  `&lt;close xslt script`&gt;
&lt;/set&gt;
&lt;xslt name="." xml="." xsl="m-sup-2-3" /&gt;
&gt;&gt;&gt;

\&lt;superscript into squared abd cube\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[
    (@class = 'msup') 
  and
    (normalize-space(
      child::span[ (@class = 'mrow-super') ] 
        / child::span[ (@class != 'begin-script')
                       and
                       (@class != 'end-script')
                     ]
     ) = '2')
  and `&lt;su verbose not on op`&gt;
]" &gt;
   &lt;xsl:copy&gt;
      &lt;xsl:apply-templates select="*|@*|text()|comment()" 
                           mode="squared" /&gt;
   &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;


\&lt;su verbose not on op\&gt;&lt;&lt;&lt;
not(
  child::span[ (@class = 'mrow-base') ] 
    / child::span[ not( @title = 'speech-extra' ) ]
                 [ position() = last() ]
    / self::* [ @class = 'mo-op' ]    
)
&gt;&gt;&gt;




\&lt;superscript into squared abd cube\&gt;&lt;&lt;&lt;
&lt;xsl:template match="*|@*|text()|comment()" 
                           mode="squared" &gt;
   &lt;xsl:copy&gt;
     &lt;xsl:choose&gt;
        &lt;xsl:when test=" @class = 'mrow-super' "&gt;
           &lt;xsl:apply-templates select="@*" /&gt;
           &lt;span class="mo-op"&gt;
             &lt;xsl:text&gt; squared &lt;/xsl:text&gt;
           &lt;/span&gt;
        &lt;/xsl:when&gt;  
        &lt;xsl:otherwise&gt;
           &lt;xsl:apply-templates select="*|@*|text()|comment()" /&gt;
        &lt;/xsl:otherwise&gt;
     &lt;/xsl:choose&gt;
   &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;






\begin{verbatim}
&lt;span class="msup"&gt;
  &lt;span class="mrow-base"&gt;
    &lt;span class="mo-op"&gt;cos&lt;/span&gt;
  &lt;/span&gt;
  &lt;span class="mrow-super"&gt;
    &lt;span class="begin-script"&gt; superscript &lt;/span&gt;
    &lt;span class="mn"&gt;2&lt;/span&gt;
    &lt;span class="end-script"&gt; baseline &lt;/span&gt;
  &lt;/span&gt;
&lt;/span&gt;
\end{verbatim}




\&lt;superscript into squared abd cube\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[
    (@class = 'msup') 
  and
    (normalize-space(
      child::span[ (@class = 'mrow-super') ] 
        / child::span[ (@class != 'begin-script')
                       and
                       (@class != 'end-script')
                     ]
     ) = '3')
  and `&lt;su verbose not on op`&gt;
]" &gt;
   &lt;xsl:copy&gt;
      &lt;xsl:apply-templates select="*|@*|text()|comment()" 
                           mode="cube" /&gt;
   &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;



\&lt;superscript into squared abd cube\&gt;&lt;&lt;&lt;
&lt;xsl:template match="*|@*|text()|comment()" 
                           mode="cube" &gt;
   &lt;xsl:copy&gt;
     &lt;xsl:choose&gt;
        &lt;xsl:when test=" @class = 'mrow-super' "&gt;
           &lt;xsl:apply-templates select="@*" /&gt;
           &lt;span class="mo-op"&gt;
             &lt;xsl:text&gt; cube &lt;/xsl:text&gt;
           &lt;/span&gt;
        &lt;/xsl:when&gt;  
        &lt;xsl:otherwise&gt;
           &lt;xsl:apply-templates select="*|@*|text()|comment()" /&gt;
        &lt;/xsl:otherwise&gt;
     &lt;/xsl:choose&gt;
   &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;


\&lt;sub superscript 2 and 3 into verbose\&gt;&lt;&lt;&lt;
&lt;set name="m-subsup-2-3" &gt;
  `&lt;open xslt script`&gt;
  `&lt;subsup into sub squared and cube`&gt; 
  `&lt;close xslt script`&gt;
&lt;/set&gt;
&lt;xslt name="." xml="." xsl="m-subsup-2-3" /&gt;
&gt;&gt;&gt;





\&lt;subsup into sub squared and cube\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[
    (@class = 'msubsup') 
  and
    (normalize-space(
      child::span[ (@class = 'mrow-super') ] 
        / child::span[ (@class != 'mid-script')
                       and
                       (@class != 'end-script')
                     ]
     ) = '2')
  and `&lt;su verbose not on op`&gt;
]" &gt;
   &lt;xsl:copy&gt;
      &lt;xsl:attribute name="class" &gt;
         &lt;xsl:text&gt;msub&lt;/xsl:text&gt;
      &lt;/xsl:attribute&gt;
      &lt;xsl:apply-templates select="*|text()|comment()" 
                           mode="sub-squared" /&gt;
   &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;



\&lt;subsup into sub squared and cube\&gt;&lt;&lt;&lt;
&lt;xsl:template match="*|@*|text()|comment()" 
                           mode="sub-squared" &gt;
   &lt;xsl:copy&gt;
     &lt;xsl:choose&gt;
        &lt;xsl:when test=" @class = 'mrow-sub' "&gt;
           &lt;xsl:apply-templates select="*[
                       not( @class = 'end-script' )
                     ]
                           |@*|text()|comment()" /&gt;
           &lt;xsl:apply-templates select="
               following-sibling::*[1] / *[
                        @class = 'end-script' 
                  ] " /&gt;
        &lt;/xsl:when&gt;  
        &lt;xsl:when test=" @class = 'mrow-super' "&gt;
           &lt;xsl:attribute name="class" &gt;
               &lt;xsl:text&gt;squared-super&lt;/xsl:text&gt;
           &lt;/xsl:attribute&gt;
           &lt;span class="mo-op"&gt;
             &lt;xsl:text&gt; squared &lt;/xsl:text&gt;
           &lt;/span&gt;
        &lt;/xsl:when&gt;  
        &lt;xsl:otherwise&gt;
           &lt;xsl:apply-templates select="*|@*|text()|comment()" /&gt;
        &lt;/xsl:otherwise&gt;
     &lt;/xsl:choose&gt;
   &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;


\&lt;subsup into sub squared and cube\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[
    (@class = 'msubsup') 
  and
    (normalize-space(
      child::span[ (@class = 'mrow-super') ] 
        / child::span[ (@class != 'mid-script')
                       and
                       (@class != 'end-script')
                     ]
     ) = '3')
  and `&lt;su verbose not on op`&gt;
]" &gt;
   &lt;xsl:copy&gt;
      &lt;xsl:attribute name="class" &gt;
         &lt;xsl:text&gt;msub&lt;/xsl:text&gt;
      &lt;/xsl:attribute&gt;
      &lt;xsl:apply-templates select="*|text()|comment()" 
                           mode="sub-cube" /&gt;
   &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;



\&lt;subsup into sub squared and cube\&gt;&lt;&lt;&lt;
&lt;xsl:template match="*|@*|text()|comment()" 
                           mode="sub-cube" &gt;
   &lt;xsl:copy&gt;
     &lt;xsl:choose&gt;
        &lt;xsl:when test=" @class = 'mrow-sub' "&gt;
           &lt;xsl:apply-templates select="*[
                       not( @class = 'end-script' )
                     ]
                           |@*|text()|comment()" /&gt;
           &lt;xsl:apply-templates select="
               following-sibling::*[1] / *[
                        @class = 'end-script' 
                  ] " /&gt;
        &lt;/xsl:when&gt;  
        &lt;xsl:when test=" @class = 'mrow-super' "&gt;
           &lt;xsl:attribute name="class" &gt;
               &lt;xsl:text&gt;cube-super&lt;/xsl:text&gt;
           &lt;/xsl:attribute&gt;
           &lt;span class="mo-op"&gt;
             &lt;xsl:text&gt; cube &lt;/xsl:text&gt;
           &lt;/span&gt;
        &lt;/xsl:when&gt;  
        &lt;xsl:otherwise&gt;
           &lt;xsl:apply-templates select="*|@*|text()|comment()" /&gt;
        &lt;/xsl:otherwise&gt;
     &lt;/xsl:choose&gt;
   &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;



%%%%%%%%%%%%%
\subsection{Numeric Subscripts (Rule 77)}
%%%%%%%%%%%%%

\&lt;compress numeric subscripts\&gt;&lt;&lt;&lt;
  &lt;set name="num-sub" &gt;
     `&lt;open xslt script`&gt;
     `&lt;num sub`&gt; 
     `&lt;close xslt script`&gt;
  &lt;/set&gt;
  &lt;xslt name="." xml="." xsl="num-sub" /&gt;
&gt;&gt;&gt;



\&lt;num sub\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[
    (@class = 'msub')
  and
    (count( child::span[ @class = 'mrow-base' ] 
           / child::* ) = 1 )
  and not( ancestor::*[
      (@class = 'msub')
    or
      (@class = 'msup')
    or
      (@class = 'msubsup')
    ] )
  and
    not( child::span[ @class = 'mrow-sub' ] 
           / child::* [
                not( @title = 'speech-extra' )
              and
                not( @class = 'mn' )
              and
                not( 
                  (@class = 'mo-punc')
                  and
                  ( . = ',' )
                  and
                  preceding-sibling::*[1][ @class = 'mn' ]
                  and
                  following-sibling::*[1][ @class = 'mn' ]
                  and
                  following-sibling::*[2][ @class = 'mn' ]
                  and
                  following-sibling::*[3][ @class = 'mn' ]
                  and
                  (  not(following-sibling::*[4])
                     or
                     not(following-sibling::*[4][ @class = 'mn' ])
                  )
                )
              and
                not( 
                  (@class = 'mo-punc')
                  and
                  ( . = '.' )
                  and
                  following-sibling::*[1][ @class = 'mn' ]
                  and
                  not(
                    following-sibling::*[ 
                       (@class = 'mo-punc')
                     and
                       (. = '.')
                    ]
                  )
                )
          ]) 
]" &gt;
  &lt;xsl:copy&gt;
     &lt;xsl:apply-templates select="@*" /&gt;     
     &lt;xsl:apply-templates select="*[1]" /&gt;
     &lt;span class="mrow-sub"&gt;
        &lt;span class="space" title="speech-extra"&gt;
           &lt;xsl:text&gt; &lt;/xsl:text&gt; 
        &lt;/span&gt;
        &lt;xsl:apply-templates
           select="*[2] / *[ 
                    not(@title = 'speech-extra')  
                 and
                    not(
                      (@class = 'mo-punc')
                      and (. = ',')
                    )  
          ]" /&gt;
     &lt;/span&gt;
  &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;

Emacspeak doesn't read fluently numbers with commas. For instance `10,000' is 
treated as `ten comma zero zero zero'.

\begin{verbatim}
&lt;span class="msub"&gt;
  &lt;span class="mrow-base"&gt;
    &lt;span class="mi"&gt;x&lt;/span&gt;
  &lt;/span&gt;
  &lt;span class="mrow-sub"&gt;
    &lt;span class="begin-script" title="speech-extra"&gt; subscript &lt;/span&gt;
    &lt;span class="mn"&gt;1&lt;/span&gt;
    &lt;span class="end-script" title="speech-extra"&gt; baseline &lt;/span&gt;
  &lt;/span&gt;
&lt;/span&gt;
\end{verbatim}

%%%%%%%%%%%%%
\subsection{Primes}
%%%%%%%%%%%%%

\&lt;remove scrip indicators from primes\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[
    (@class = 'begin-script')
  and
    following-sibling::*[
         child::span / child::span[ 
            (@class = 'ch 2032') or (@class = 'ch 2033')
                                 or (@class = 'ch 2034')
    ]    ]
]" &gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;



\&lt;remove scrip indicators from primes\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[
    (@class = 'end-script')
  and
    preceding-sibling::*[
         child::span / child::span[ 
            (@class = 'ch 2032') or (@class = 'ch 2033') 
                                 or (@class = 'ch 2034')
    ]    ]
]" &gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;



\begin{verbatim}
&lt;span class="msup"&gt;
  &lt;span class="mrow-base"&gt;
    &lt;span class="mi"&gt;x&lt;/span&gt;
  &lt;/span&gt;
  &lt;span class="mrow-super"&gt;
    &lt;span class="begin-script"&gt; superscript &lt;/span&gt;
    &lt;span class="mo-op"&gt;
      &lt;span class="char"&gt;
        &lt;span class="ch 2033"&gt;double prime&lt;/span&gt;
      &lt;/span&gt;
    &lt;/span&gt;
    &lt;span class="end-script"&gt; baseline &lt;/span&gt;
  &lt;/span&gt;
&lt;/span&gt;
\end{verbatim}

\&lt;subsup prime\&gt;&lt;&lt;&lt;
&lt;set name="subsup-prime" &gt;
   `&lt;open xslt script`&gt;
   `&lt;compress subsup prime`&gt; 
   `&lt;close xslt script`&gt;
&lt;/set&gt;
&lt;xslt name="." xml="." xsl="subsup-prime" /&gt;
&gt;&gt;&gt;


\&lt;compress subsup prime\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[ 
    (@class = 'msubsup')
  and
    (count(
        child::* [ @class='mrow-super' ]
       / child::span [ not(@title = 'speech-extra') ] ) = 1)
  and
    (count(
       child::* [ @class='mrow-super' ]
          / child::span [ not(@title = 'speech-extra') ] 
          / child::span) = 1)
  and
    child::* [ @class='mrow-super' ]
       / child::span [ not(@title = 'speech-extra') ] 
       / child::span[ @class='char' ]
       / child::span[
            (@class = 'ch 2032') or (@class = 'ch 2033') 
                                 or (@class = 'ch 2034') 
         ]  
]" &gt;  
  &lt;xsl:copy&gt;
    &lt;xsl:attribute name="class" &gt;
       &lt;xsl:text&gt;msub&lt;/xsl:text&gt;
    &lt;/xsl:attribute&gt;
    &lt;span class="mrow-base"&gt; 
       &lt;xsl:apply-templates select="
             *[@class = 'mrow-base'] / *
          " /&gt;    
       &lt;xsl:apply-templates select="
             *[@class = 'mrow-super']
             / child::span [ not(@title = 'speech-extra') ] 
          " /&gt;    
    &lt;/span&gt; 
    &lt;xsl:apply-templates select="*[@class = 'mrow-sub']" /&gt;
  &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;



\begin{verbatim}
&lt;span class="msubsup"&gt; 
  &lt;span class="mrow-base"&gt; 
    &lt;span class="mi"&gt;x&lt;/span&gt; 
  &lt;/span&gt; 
  &lt;span class="mrow-sub"&gt; 
    ......
  &lt;/span&gt; 
  &lt;span class="mrow-super"&gt; 
    &lt;span class="mid-script" title="speech-extra"&gt; superscript &lt;/span&gt; 
    &lt;span class="mi"&gt; 
      &lt;span class="char" title="ch-verbose"&gt; 
        &lt;span class="ch 2032" title="ch-verbose"&gt;prime&lt;/span&gt; 
      &lt;/span&gt; 
    &lt;/span&gt; 
  &lt;/span&gt; 
&lt;/span&gt; 
\end{verbatim}


%%%%%%%%%%%%%%%%%%
\section{Over and Under Limit Scripts}
%%%%%%%%%%%%%%%%%%


\&lt;over and under scripts\&gt;&lt;&lt;&lt;
&lt;script element="span::limits-msub-msup" &gt;
  &lt;set name="smash" &gt;
     `&lt;open xslt script`&gt;
     `&lt;smash over and under scripts`&gt;
     `&lt;close xslt script`&gt;
  &lt;/set&gt;
  &lt;xslt name="." xml="." xsl="smash" /&gt;
&lt;/script&gt; 
&gt;&gt;&gt;

\&lt;smash over and under scripts\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[
       (@class = 'limits-msub-msup')
     and
       child::*[ (position() = 1) 
                 and (@class = 'limits-mrow-base')
                 and child::*[ (position() = 1) 
                         and (@class = 'limits-msub-msup')
       ]             ]
]" &gt;
  &lt;xsl:copy&gt;
     &lt;xsl:apply-templates select="@*" /&gt;
     &lt;xsl:apply-templates select="
                   *[1]
                   / *[1] 
                   / *[ not(@class='limits-mrow-super') ]  " /&gt;
     &lt;xsl:apply-templates select=" *[
                   preceding-sibling::* 
                 and
                   not(@class='limits-mrow-super') ]" /&gt;
     &lt;xsl:apply-templates select="
                   *[1]
                   / *[1]
                   / *[@class='limits-mrow-super' ]  " /&gt;
     &lt;xsl:apply-templates select=" *[
                   preceding-sibling::* 
                 and
                   (@class='limits-mrow-super') ]" /&gt;
  &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;


\&lt;compress limit script\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[ @class = 'end-limits-script' ]" &gt;
  &lt;xsl:if test=" parent::*[ not(following-sibling::*) ] "&gt;
    &lt;xsl:copy&gt;
       &lt;xsl:apply-templates select=" @* " /&gt;
       &lt;xsl:choose&gt;
          &lt;xsl:when test="  
                parent::*[ preceding-sibling::span[
                                  @class != 'limits-mrow-base'
                         ]  ]
            " &gt;
            &lt;xsl:text&gt; end scripts &lt;/xsl:text&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:otherwise&gt;
            &lt;xsl:text&gt; end script &lt;/xsl:text&gt;
          &lt;/xsl:otherwise&gt;
       &lt;/xsl:choose&gt;
    &lt;/xsl:copy&gt;
  &lt;/xsl:if&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;


\&lt;compress limit script\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[ @class = 'begin-limits-script' ]" &gt;
    &lt;xsl:copy&gt;
       &lt;xsl:apply-templates select=" @* " /&gt;
       &lt;xsl:choose&gt;
          &lt;xsl:when test="  
                parent::*[ @class = 'limits-mrow-super'  ]
          " &gt;
              &lt;xsl:apply-templates 
                  select=" parent::* 
                           / preceding-sibling::*[1] " 
                  mode = "extra-over" /&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:when test="  
                parent::*[ @class = 'limits-mrow-sub'  ]
          " &gt;
              &lt;xsl:apply-templates 
                  select=" parent::* 
                           / preceding-sibling::*[1] " 
                  mode = "extra-under" /&gt;
          &lt;/xsl:when&gt;
       &lt;/xsl:choose&gt;
       &lt;xsl:apply-templates select="*|text()|comment()" /&gt;
    &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;



\&lt;compress limit script\&gt;&lt;&lt;&lt;
&lt;xsl:template match="*" mode="extra-over" &gt;
   &lt;xsl:if   test = " self::span[ @class = 'limits-mrow-super' ] " &gt;
     &lt;xsl:text&gt; over &lt;/xsl:text&gt;
     &lt;xsl:apply-templates select=" preceding-sibling::*[1] " 
                    mode = "extra-over" /&gt;
   &lt;/xsl:if&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;


\&lt;compress limit script\&gt;&lt;&lt;&lt;
&lt;xsl:template match="*" mode="extra-under" &gt;
   &lt;xsl:if   test = " self::span[ @class = 'limits-mrow-sub' ] " &gt;
     &lt;xsl:text&gt; under &lt;/xsl:text&gt;
     &lt;xsl:apply-templates select=" preceding-sibling::*[1] " 
                    mode = "extra-under" /&gt;
   &lt;/xsl:if&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;






%%%%%%%%%%%%%%%%%%
\section{Fractions}
%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%
\subsection{Outline}
%%%%%%%%%%%%%



\&lt;span frac elements\&gt;&lt;&lt;&lt;
&lt;script element="span::mfrac" &gt;
  &lt;set name="mfrac" &gt;
     `&lt;open xslt script`&gt;
     `&lt;frac templates`&gt; 
     `&lt;close xslt script`&gt;
  &lt;/set&gt;
  &lt;xslt name="." xml="." xsl="mfrac" /&gt;
&lt;/script&gt; 
&gt;&gt;&gt;

\&lt;frac templates\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[ @class = 'mfrac' ]" &gt;
  &lt;xsl:copy&gt;
    &lt;xsl:choose&gt;
       `&lt;constant fracs`&gt;
       `&lt;prepend continuos fractions`&gt;
       `&lt;tail continuos fractions`&gt;
       &lt;xsl:otherwise&gt;
         &lt;xsl:apply-templates select="*|@*|text()|comment()" /&gt;
       &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
  &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;

%%%%%%%%%%%%%
\subsection{Continuos Fractions}
%%%%%%%%%%%%%

%%%%%%%%%%%%%
\subsubsection{Get Three Bottom Levels}
%%%%%%%%%%%%%



\&lt;tail continuos fractions\&gt;&lt;&lt;&lt;
&lt;xsl:when test="          `%check numeral numerator`%
   (translate(
      normalize-space(
      child::span[ @class = 'mrow-numerator' ]),
                              '0123456789','')= '')
   and `&lt;check equality of numerators`&gt;
   and `&lt;check ops before two top fracs`&gt;
"&gt;
  `&lt;a,b := top 2 pre op values`&gt;
  &lt;xsl:choose&gt;
     &lt;xsl:when test="
         ( translate($a,'0123456789 ','') = '')
         and (normalize-space($a)=normalize-space($b)) 
         and starts-with( $c, normalize-space( $a )) 
         and starts-with(
               normalize-space(
                 substring-after( $c, normalize-space( $a )) )
               , 
               normalize-space(
                    child::span[ @class = 'mrow-enumerator' ] /
                    child::span[ @class = 'mfrac' ] /
                    preceding-sibling::*[1]                  )
             )
     " &gt;
         &lt;xsl:attribute name="class"&gt;
            &lt;xsl:value-of select=" 'continuous-mfrac' " /&gt;
         &lt;/xsl:attribute&gt;         
         &lt;xsl:apply-templates select="*|text()|comment()" /&gt;
     &lt;/xsl:when&gt;
     &lt;xsl:otherwise&gt;
         &lt;xsl:apply-templates select="*|@*|text()|comment()" /&gt;
     &lt;/xsl:otherwise&gt;
  &lt;/xsl:choose&gt;
&lt;/xsl:when&gt;
&gt;&gt;&gt;


\&lt;check equality of numerators\&gt;&lt;&lt;&lt;
(  normalize-space(
   child::span[ @class = 'mrow-numerator' ])
  and
   normalize-space(
   child::span[ @class = 'mrow-enumerator' ] /
   child::span[ @class = 'mfrac' ] /
   child::span[ @class = 'mrow-numerator' ])
)
and
(  normalize-space(
   child::span[ @class = 'mrow-enumerator' ] /
   child::span[ @class = 'mfrac' ] /
   child::span[ @class = 'mrow-numerator' ])
  and
   normalize-space(
   child::span[ @class = 'mrow-enumerator' ] /
   child::span[ @class = 'mfrac' ] /
   child::span[ @class = 'mrow-enumerator' ] /
   child::span[ @class = 'mfrac' ] /
   child::span[ @class = 'mrow-numerator' ])
)
&gt;&gt;&gt;



\&lt;check ops before two top fracs\&gt;&lt;&lt;&lt;
(  child::span[ @class = 'mrow-enumerator' ] /
   child::span[ @class = 'mfrac' ] /
   preceding-sibling::*[1][@class = 'mo-bin']
)
and  
(  normalize-space(
   child::span[ @class = 'mrow-enumerator' ] /
   child::span[ @class = 'mfrac' ] /
   preceding-sibling::*[1] )
   =
   normalize-space(
   child::span[ @class = 'mrow-enumerator' ] /
   child::span[ @class = 'mfrac' ] /
   child::span[ @class = 'mrow-enumerator' ] /
   child::span[ @class = 'mfrac' ] /
   preceding-sibling::*[1] )
)
&gt;&gt;&gt;



\&lt;a,b := top 2 pre op values\&gt;&lt;&lt;&lt;
&lt;xsl:variable name="a"&gt;
   &lt;xsl:apply-templates select="
         child::span[ @class = 'mrow-enumerator' ] /
         child::span[ @class = 'mfrac' ] /
         preceding-sibling::*[2] 
   "  mode="enum-op" /&gt;  
&lt;/xsl:variable&gt;
&lt;xsl:variable name="b"&gt;
   &lt;xsl:apply-templates select="
         child::span[ @class = 'mrow-enumerator' ] /
         child::span[ @class = 'mfrac' ] /
         child::span[ @class = 'mrow-enumerator' ] /
         child::span[ @class = 'mfrac' ] /
         preceding-sibling::*[2] 
   "  mode="enum-op" /&gt;  
&lt;/xsl:variable&gt;
&lt;xsl:variable name="c"&gt;
   &lt;xsl:value-of select="
    normalize-space(
      child::span[ @class = 'mrow-enumerator' ] /
      child::span[ @class = 'mfrac' ] /
      child::span[ @class = 'mrow-enumerator' ] /
      child::span[ @class = 'mfrac' ] /
      child::span[ @class = 'mrow-enumerator' ] )
   "  /&gt;  
&lt;/xsl:variable&gt;
&gt;&gt;&gt;


\&lt;frac templates\&gt;&lt;&lt;&lt;
&lt;xsl:template match="*" mode="enum-op"&gt;
   &lt;xsl:if test="preceding-sibling::*" &gt;
      &lt;xsl:apply-templates select=" preceding-sibling::*[1] " /&gt;
   &lt;/xsl:if&gt;
   &lt;xsl:value-of select="." /&gt;
&lt;/xsl:template&gt;
&gt;&gt;&gt;




%%%%%%%%%%%%%
\subsubsection{Prepend Existing one}
%%%%%%%%%%%%%



\&lt;prepend continuos fractions\&gt;&lt;&lt;&lt;
&lt;xsl:when test="
      (@class = 'mfrac')
    and
      child::span[ @class = 'mrow-enumerator' ]
        / child::span[ @class = 'continuous-mfrac' ]
    and
      ( normalize-space(
          child::span[ @class = 'mrow-numerator' ]
        )
        =
        normalize-space(
          child::span[ @class = 'mrow-enumerator' ]
           / child::span[ @class = 'continuous-mfrac' ]
           / child::span[ @class = 'mrow-numerator' ]  
        )
      ) 
    and `&lt;check equality of op with cont frac`&gt;
" &gt;
  `&lt;a,b := cont top 2 pre op values`&gt;
  &lt;xsl:choose&gt;
     &lt;xsl:when test="
         normalize-space($a)=normalize-space($b)
     " &gt;
         &lt;xsl:attribute name="class"&gt;
            &lt;xsl:value-of select=" 'continuous-mfrac' " /&gt;
         &lt;/xsl:attribute&gt;         
         &lt;xsl:apply-templates select="*|text()|comment()" /&gt;
     &lt;/xsl:when&gt;
     &lt;xsl:otherwise&gt;
         &lt;xsl:apply-templates select="*|@*|text()|comment()" /&gt;
     &lt;/xsl:otherwise&gt;
  &lt;/xsl:choose&gt;
&lt;/xsl:when&gt; 
&gt;&gt;&gt;

\&lt;check equality of op with cont frac\&gt;&lt;&lt;&lt;
(
   normalize-space(
   child::span[ @class = 'mrow-enumerator' ] /
   child::span[ @class = 'mfrac' ] /
   preceding-sibling::*[1] )
   =
   normalize-space(
   child::span[ @class = 'mrow-enumerator' ] /
   child::span[ @class = 'mfrac' ] /
   child::span[ @class = 'mrow-enumerator' ] /
   child::span[ @class = 'continuous-mfrac' ] /
   preceding-sibling::*[1] )
)
&gt;&gt;&gt;


\&lt;a,b := cont top 2 pre op values\&gt;&lt;&lt;&lt;
&lt;xsl:variable name="a"&gt;
   &lt;xsl:apply-templates select="
         child::span[ @class = 'mrow-enumerator' ] /
         child::span[ @class = 'mcontinuous-mfrac' ] /
         preceding-sibling::*[2] 
   "  mode="enum-op" /&gt;  
&lt;/xsl:variable&gt;
&lt;xsl:variable name="b"&gt;
   &lt;xsl:apply-templates select="
         child::span[ @class = 'mrow-enumerator' ] /
         child::span[ @class = 'mcontinuous-mfrac' ] /
         child::span[ @class = 'mrow-enumerator' ] /
         child::span[ 
           (@class = 'mfrac') or (@class = 'mcontinuous-mfrac')
         ] /
         preceding-sibling::*[2] 
   "  mode="enum-op" /&gt;  
&lt;/xsl:variable&gt;
&gt;&gt;&gt;

%%%%%%%%%%%%%
\subsection{Word Fractions}
%%%%%%%%%%%%%



\&lt;constant fracs\&gt;&lt;&lt;&lt;
&lt;xsl:when test=" 
   (string-length(
      normalize-space(child::span[ @class = 'mrow-numerator' ][1])
     ) = 1)
   and
   (string-length(
     normalize-space(child::span[ @class = 'mrow-enumerator' ][1])
     ) = 1)
"&gt;
   `&lt;a := numerator; b := enumerator`&gt;
   &lt;xsl:choose&gt;
      &lt;xsl:when test=" 
           (translate($a,'123456789','') != '')
           or
           (translate($b,'123456789','') != '')
       " &gt;
         &lt;xsl:apply-templates select="*|@*|text()|comment()" /&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:when test=" $a &amp;lt; $b "&gt;
         &lt;xsl:attribute  name="class"&gt;
             &lt;xsl:text&gt;word-frac&lt;/xsl:text&gt;
         &lt;/xsl:attribute&gt;
         `&lt;word numerator`&gt;
         `&lt;word enumerator`&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:otherwise&gt;
         &lt;xsl:apply-templates select="*|@*|text()|comment()" /&gt;
      &lt;/xsl:otherwise&gt;
   &lt;/xsl:choose&gt;    
&lt;/xsl:when&gt;
&gt;&gt;&gt;


\&lt;a := numerator; b := enumerator\&gt;&lt;&lt;&lt;
&lt;xsl:variable name="a"&gt;
   &lt;xsl:value-of select="
      normalize-space(child::span[ @class = 'mrow-numerator' ][1])
   " /&gt;
&lt;/xsl:variable&gt;
&lt;xsl:variable name="b"&gt;
   &lt;xsl:value-of select="
      normalize-space(child::span[ @class = 'mrow-enumerator' ][1])
   " /&gt;
&lt;/xsl:variable&gt;
&gt;&gt;&gt;


\&lt;word numerator\&gt;&lt;&lt;&lt;
&lt;xsl:choose&gt;
   &lt;xsl:when test=" $a = 1 "&gt;&lt;xsl:text&gt; one &lt;/xsl:text&gt;&lt;/xsl:when&gt;
   &lt;xsl:when test=" $a = 2 "&gt;&lt;xsl:text&gt; two &lt;/xsl:text&gt;&lt;/xsl:when&gt;
   &lt;xsl:when test=" $a = 3 "&gt;&lt;xsl:text&gt; three &lt;/xsl:text&gt;&lt;/xsl:when&gt;
   &lt;xsl:when test=" $a = 4 "&gt;&lt;xsl:text&gt; four &lt;/xsl:text&gt;&lt;/xsl:when&gt;
   &lt;xsl:when test=" $a = 5 "&gt;&lt;xsl:text&gt; five &lt;/xsl:text&gt;&lt;/xsl:when&gt;
   &lt;xsl:when test=" $a = 6 "&gt;&lt;xsl:text&gt; six &lt;/xsl:text&gt;&lt;/xsl:when&gt;
   &lt;xsl:when test=" $a = 7 "&gt;&lt;xsl:text&gt; seven &lt;/xsl:text&gt;&lt;/xsl:when&gt;
   &lt;xsl:when test=" $a = 8 "&gt;&lt;xsl:text&gt; eight &lt;/xsl:text&gt;&lt;/xsl:when&gt;
   &lt;xsl:when test=" $a = 9 "&gt;&lt;xsl:text&gt; nine &lt;/xsl:text&gt;&lt;/xsl:when&gt;
&lt;/xsl:choose&gt;
&gt;&gt;&gt;


\&lt;word enumerator\&gt;&lt;&lt;&lt;
&lt;xsl:choose&gt;
   &lt;xsl:when test=" $b = 2 "&gt;&lt;xsl:text&gt; half&lt;/xsl:text&gt;&lt;/xsl:when&gt;
   &lt;xsl:when test=" $b = 3 "&gt;&lt;xsl:text&gt; third&lt;/xsl:text&gt;&lt;/xsl:when&gt;
   &lt;xsl:when test=" $b = 4 "&gt;&lt;xsl:text&gt; fourth&lt;/xsl:text&gt;&lt;/xsl:when&gt;
   &lt;xsl:when test=" $b = 5 "&gt;&lt;xsl:text&gt; fifth&lt;/xsl:text&gt;&lt;/xsl:when&gt;
   &lt;xsl:when test=" $b = 6 "&gt;&lt;xsl:text&gt; sixth&lt;/xsl:text&gt;&lt;/xsl:when&gt;
   &lt;xsl:when test=" $b = 7 "&gt;&lt;xsl:text&gt; seventh&lt;/xsl:text&gt;&lt;/xsl:when&gt;
   &lt;xsl:when test=" $b = 8 "&gt;&lt;xsl:text&gt; eighth&lt;/xsl:text&gt;&lt;/xsl:when&gt;
   &lt;xsl:when test=" $b = 9 "&gt;&lt;xsl:text&gt; nineth&lt;/xsl:text&gt;&lt;/xsl:when&gt;
&lt;/xsl:choose&gt;
&lt;xsl:if test=" $a &amp;gt; 1 "&gt;&lt;xsl:text&gt;s&lt;/xsl:text&gt;&lt;/xsl:if&gt;
&lt;xsl:text&gt; &lt;/xsl:text&gt;
&gt;&gt;&gt;


%%%%%%%%%%%%%
\subsection{Prefix `and' Connectors}
%%%%%%%%%%%%%

\&lt;fraction 'and' prefix\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[
   ((@class = 'mfrac') and 
                       (translate(
                          concat(
                            span[ (@class = 'mrow-numerator')],
                            span[ (@class = 'mrow-enumerator')] 
                          )  ,'0123456789','') = '')
                       and
                       not(descendant::*/descendant::*/descendant::*)
    or 
    (@class = 'word-frac'))
   and 
   preceding-sibling::*[1]
       / self::span[ @class = 'mn']
 ]" &gt;
  &lt;xsl:text&gt; and &lt;/xsl:text&gt;
  &lt;xsl:copy&gt;
    &lt;xsl:apply-templates select="*|@*|text()|comment()" /&gt;
  &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;

%%%%%%%%%%%%%
\subsection{Hyper Complex Fractions}
%%%%%%%%%%%%%


\&lt;set levels for hyper complex fracs\&gt;&lt;&lt;&lt;
&lt;dom name="." xml="." method="fracLevel" class="tex4ht.HtSpk" /&gt;
`&lt;remove xml declaration`&gt;
&gt;&gt;&gt;



\&lt;static void fracLevel(dom)\&gt;&lt;&lt;&lt;
public static void fracLevel(Node dom) {
   setFracLevel(dom.getFirstChild(), 0);
}
private static int setFracLevel(Node node, int cont) {
  int level = 0;
  String clName = null;
  if (node.hasChildNodes()) {
    if (node.hasAttributes()) {
      Node cl = node.getAttributes().getNamedItem("class");
      if (cl != null) { clName = cl.getNodeValue(); }
    }
    `&lt;count levels inherited from children`&gt;
    if( clName != null ){
      `&lt;block on sub and super scripts`&gt;
      `&lt;deal with continuou fracs`&gt;
      if (clName.equals("mfrac")) {
        if( cont &gt; 0 ){
          `&lt;remove end of nested continuous frac`&gt; 
        } else if( level &gt; 0 ){
          `&lt;set extra levels for frac`&gt;
        }
        level++;
  } } }
  return level;
}
&gt;&gt;&gt;


\&lt;count levels inherited from children\&gt;&lt;&lt;&lt;
NodeList children = node.getChildNodes();
int max = 0;
for (int i = 0; i &lt; children.getLength(); i++) {
   Node child = children.item(i);
   if (child.getNodeType() == Node.ELEMENT_NODE) {
      int d = setFracLevel(child, 
           (clName != null) &amp;&amp;
            clName.equals("continuous-mfrac")? 
            2 : 
            ((clName != null) &amp;&amp;
              clName.equals("continuous-mfrac")?
                (cont-1) : cont)
        );
      if (d &gt; max) { max = d; }
}  }
level += max;
&gt;&gt;&gt;




The `cont' parameter is for determining whether the parent and the
grandparent are frac elements marked as continuous.


\&lt;block on sub and super scripts\&gt;&lt;&lt;&lt;
if( clName.equals("msub") || clName.equals("msup") ||
    clName.equals("msubsup") 
) {
   return 0;
}
&gt;&gt;&gt;


\&lt;deal with continuou fracs\&gt;&lt;&lt;&lt;
if( clName.equals("continuous-mfrac") ) {
   if( cont &gt; 0 ){   
     `&lt;remove end of nested continuous frac`&gt;
   } else { `&lt;set continuous frac`&gt; } `%root of continuous chain`%
   return 0;
}
&gt;&gt;&gt;



\&lt;set extra levels for frac\&gt;&lt;&lt;&lt;
for (int i = 0; i &lt; children.getLength(); i++) {
  Node child = children.item(i);
  if (child.getNodeType() == Node.ELEMENT_NODE) {
    Node cls = child.getAttributes()
                    .getNamedItem("class");
    if (cls != null) {
      String clsName = cls.getNodeValue();
      if (clsName.equals("begin-end")) {
         child = child.getFirstChild();
         String s = child.getNodeValue();
         String bg = "", ov = "", en = "";
         for(int j=0; j&lt;level; j++){ 
            bg += " begin "; ov += " over "; en += " end ";
         }
         s = s.replaceFirst("begin", bg + "begin");
         s = s.replaceFirst("over", ov + "over");
         s = s.replaceFirst("end", en + "end");
         ((org.w3c.dom.Text) child).setData(s);
} } } }
&gt;&gt;&gt;


\&lt;set continuous frac\&gt;&lt;&lt;&lt;
for (int i = 0; i &lt; children.getLength(); i++) {
  Node child = children.item(i);
  if (child.getNodeType() == Node.ELEMENT_NODE) {
    Node cls = child.getAttributes()
                   .getNamedItem("class");
    if (cls != null) {
       String clsName = cls.getNodeValue();
       if ( clsName.equals("begin-end")) {
          child = child.getFirstChild();
          String s = child.getNodeValue();
          s = s.replaceFirst("begin", "begin continued");
          s = s.replaceFirst("end", "end continued");
          ((org.w3c.dom.Text) child).setData(s);
} } } }
&gt;&gt;&gt;

\&lt;remove end of nested continuous frac\&gt;&lt;&lt;&lt;
Node child = node.getLastChild();
if (child.getNodeType() == Node.ELEMENT_NODE) {
   Node cls = child.getAttributes() .getNamedItem("class");
   if (cls != null) {
      String clsName = cls.getNodeValue();
      if ( clsName.equals("begin-end")) {
         node.removeChild( child  );
}  }  }
&gt;&gt;&gt;




%%%%%%%%%%%%%
\subsection{Set Levels on Roots}
%%%%%%%%%%%%%

\&lt;set levels for roots\&gt;&lt;&lt;&lt;
&lt;dom name="." xml="." method="rootLevel" class="tex4ht.HtSpk" /&gt;
`&lt;remove xml declaration`&gt;
&gt;&gt;&gt;

\&lt;static void rootLevel(dom)\&gt;&lt;&lt;&lt;
public static void rootLevel(Node dom) {
   setRootLevel(dom.getFirstChild());
}
private static int setRootLevel( Node node ){
  int level = 0;
  String clName = null;
  if (node.hasChildNodes()) {
    if (node.hasAttributes()) {
      Node cl = node.getAttributes().getNamedItem("class");
      if (cl != null) { clName = cl.getNodeValue(); }
    }
    `&lt;count root levels inherited from children`&gt;
    if( clName != null ){
      `&lt;block for roots`&gt;
      if( clName.equals("msqrt") || clName.equals("root") ){
        `&lt;set extra levels for roots`&gt;
        level++;
  } } }
  return level;
}
&gt;&gt;&gt;


\&lt;count root levels inherited from children\&gt;&lt;&lt;&lt;
NodeList children = node.getChildNodes();
int max = 0;
for (int i = 0; i &lt; children.getLength(); i++) {
  Node child = children.item(i);
  if (child.getNodeType() == Node.ELEMENT_NODE) {
    int d = setRootLevel(child);
    if( d &gt; max ){ max = d; }
} }
level += max;
&gt;&gt;&gt;


\&lt;block for roots\&gt;&lt;&lt;&lt;
if( clName.equals("msub") || clName.equals("msup") ||
    clName.equals("msubsup") 
) {
   return 0;
}
&gt;&gt;&gt;




\&lt;set extra levels for roots\&gt;&lt;&lt;&lt;
for (int i = 0; i &lt; children.getLength(); i++) {
  Node child = children.item(i);
  if (child.getNodeType() == Node.ELEMENT_NODE) {
    Node cls = child.getAttributes()
                    .getNamedItem("class");
    if (cls != null) {
      String clsName = cls.getNodeValue();
      if( clsName.equals("begin-root") 
          || clsName.equals("mid-root") 
          || clsName.equals("end-root") 
      ){
         child = child.getFirstChild();
         String s = child.getNodeValue();
         String nested = "";
         for(int j=0; j&lt;level; j++){ 
            nested += " nested ";
         }
         ((org.w3c.dom.Text) child).setData( nested + s);
} } } }
&gt;&gt;&gt;



%%%%%%%%%%%%%%%%%%
\section{Odd Ends}
%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%
\subsection{Remove Empty Array Cells}
%%%%%%%%%%%%%

Empty array celles at end of rows can make it more difficult to 
detect deletable baseline indicators.



\&lt;remove multline eqnum cell\&gt;&lt;&lt;&lt;
&lt;script element="div::tr" &gt;
  &lt;set name="bold" &gt;
     `&lt;open xslt script`&gt;
     `&lt;remove empty cells from rows`&gt; 
     `&lt;close xslt script`&gt;
  &lt;/set&gt;
  &lt;xslt name="." xml="." xsl="bold" /&gt;
&lt;/script&gt; 
&gt;&gt;&gt;

\&lt;remove empty cells from rows\&gt;&lt;&lt;&lt;
&lt;xsl:template match="div[ 
    parent::div[ @class = 'tr' ]
    and ( normalize-space(.) = '' )
    and not( normalize-space(following-sibling::*) != '' )
]" &gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;





%%%%%%%%%%%%%
\subsection{'minus' into 'negative'}
%%%%%%%%%%%%%



\&lt;'minus' into 'negative'\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[
    (@class = 'mo-bin')
  and
    (   preceding-sibling::*[
           (position()=1) 
           and 
           ( (@title='speech-extra') 
             or (@class='mo-bin') 
             or (@class='mo-rel')  )
        ]
        and 
        (
           following-sibling::*[ (@class='mn') or (@class='mi') ]
          or
           (count(following-sibling::*[
               not(@title = 'speech-extra')
            ]) = 1)
        )
      or
        not(preceding-sibling::*)
    )
  and
    (normalize-space(.)='minus')
]" &gt;
  &lt;xsl:copy&gt;
    &lt;xsl:attribute name="class"&gt;
       &lt;xsl:text&gt;mo-unary&lt;/xsl:text&gt;
    &lt;/xsl:attribute&gt;
    &lt;xsl:apply-templates select="*|text()|comment()" 
                         mode="minus-neg" /&gt;
  &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;


\&lt;'minus' into 'negative'\&gt;&lt;&lt;&lt;
&lt;xsl:template match="*|@*|text()|comment()" mode="minus-neg" &gt;
  &lt;xsl:copy&gt;
    &lt;xsl:apply-templates select="*|@*|text()|comment()" 
                         mode="minus-neg" /&gt;
  &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;

\begin{verbatim}
&lt;span class="begin-script"&gt; subscript &lt;/span&gt;
&lt;span class="mo-bin"&gt;
  &lt;span class="char"&gt;
    &lt;span class="ch 2212"&gt;minus&lt;/span&gt;
  &lt;/span&gt;
&lt;/Span&gt;
&lt;span class="mn"&gt;2&lt;/span&gt;
\end{verbatim}




\&lt;'minus' into 'negative'\&gt;&lt;&lt;&lt;
&lt;xsl:template match="text()" mode="minus-neg" &gt;
  &lt;xsl:choose&gt;
    &lt;xsl:when test=" . = 'minus' " &gt;
      &lt;xsl:text&gt;negative&lt;/xsl:text&gt;
    &lt;/xsl:when&gt;
    &lt;xsl:otherwise&gt;
      &lt;xsl:value-of select="." /&gt;
    &lt;/xsl:otherwise&gt;
  &lt;/xsl:choose&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;

%%%%%%%%%%%%%
\subsection{Short-Cuts for Modifiers}
%%%%%%%%%%%%%

\&lt;short cut modifiers\&gt;&lt;&lt;&lt;
&lt;script element="span::munder-underline" &gt;
  &lt;set name="munder" &gt;
     `&lt;open xslt script`&gt;
     `&lt;get content template`&gt;
     `&lt;under modifier templates`&gt; 
     `&lt;close xslt script`&gt;
  &lt;/set&gt;
  &lt;xslt name="." xml="." xsl="munder" /&gt;
&lt;/script&gt; 
&gt;&gt;&gt;




\&lt;short cut modifiers\&gt;&lt;&lt;&lt;
&lt;script element="span::mover-overline" &gt;
  &lt;set name="mover" &gt;
     `&lt;open xslt script`&gt;
     `&lt;get content template`&gt;
     `&lt;over modifier templates`&gt; 
     `&lt;close xslt script`&gt;
  &lt;/set&gt;
  &lt;xslt name="." xml="." xsl="mover" /&gt;
&lt;/script&gt; 
&gt;&gt;&gt;









\&lt;under modifier templates\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[
    (@class = 'munder-underline')
   and
    child::span[ 
       (@class = 'mo-0332')
       and
       descendant::span[ @class = 'mi' ]
   ]
]" &gt;
  &lt;xsl:copy&gt;
    &lt;xsl:apply-templates select="@*" /&gt;
    &lt;xsl:variable name="content"&gt;
       &lt;xsl:apply-templates select="*" mode="content" /&gt;
    &lt;/xsl:variable&gt;
    &lt;xsl:choose&gt;
       &lt;xsl:when test=" 
          string-length( normalize-space( $content )) = 1
       " &gt;       
           &lt;xsl:apply-templates
              select=" *[ @class != 'begin-end' ] " /&gt;
           &lt;span class="begin-end" title="speech-extra" &gt; 
              &lt;xsl:text&gt; under bar &lt;/xsl:text&gt;
           &lt;/span&gt;
       &lt;/xsl:when&gt;
       &lt;xsl:otherwise&gt;
          &lt;xsl:apply-templates select="*|text()|comment()" /&gt;
       &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
  &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;








\&lt;over modifier templates\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[
    (@class = 'mover-overline')
   and
    child::span[ 
       (@class = 'mo-00AF')
       and
       descendant::span[ @class = 'mi' ]
   ]
]" &gt;
  &lt;xsl:copy&gt;
    &lt;xsl:apply-templates select="@*" /&gt;
    &lt;xsl:variable name="content"&gt;
       &lt;xsl:apply-templates select="*" mode="content" /&gt;
    &lt;/xsl:variable&gt;
    &lt;xsl:choose&gt;
       &lt;xsl:when test=" 
          string-length( normalize-space( $content )) = 1
       " &gt;       
           &lt;xsl:apply-templates
              select=" *[ @class != 'begin-end' ] " /&gt;
           &lt;span class="begin-end" title="speech-extra" &gt; 
              &lt;xsl:text&gt; over bar &lt;/xsl:text&gt;
           &lt;/span&gt;
       &lt;/xsl:when&gt;
       &lt;xsl:otherwise&gt;
          &lt;xsl:apply-templates select="*|text()|comment()" /&gt;
       &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
  &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;



\begin{verbatim}
&lt;span class="mover-overline"&gt;
  &lt;span class="begin-end" title="speech-extra"&gt; modified above &lt;/span&gt;
  &lt;span class="mo-00AF"&gt;
    &lt;span class="mathvariant-bold"&gt;
      &lt;span title="speech-extra" class="begin-end"&gt; bold &lt;/span&gt;
      &lt;span class="mi"&gt;
          &lt;span title="speech-extra" 
                class="capital-description"&gt; capital &lt;/span&gt;
          Z
      &lt;/span&gt;
    &lt;/span&gt;
  &lt;/span&gt;
  &lt;span class="begin-end" title="speech-extra"&gt; with bar &lt;/span&gt;
&lt;/span&gt;
\end{verbatim}



\begin{verbatim}
&lt;span class="munder-underline"&gt;
  &lt;span class="begin-end" title="speech-extra" &gt; modified under &lt;/span&gt;
  &lt;span class="mo-0332"&gt;
    &lt;span class="mi"&gt;x&lt;/span&gt;
  &lt;/span&gt;
  &lt;span class="begin-end" title="speech-extra" &gt; with bar &lt;/span&gt;
&lt;/span&gt;
\end{verbatim}

%%%%%%%%%%%%%
\subsection{Font Decorations}
%%%%%%%%%%%%%





\&lt;bold math\&gt;&lt;&lt;&lt;
&lt;script element="span::mathvariant-bold" &gt;
  &lt;set name="bold" &gt;
     `&lt;open xslt script`&gt;
     `&lt;get content template`&gt;
     `&lt;math bold templates`&gt; 
     `&lt;close xslt script`&gt;
  &lt;/set&gt;
  &lt;xslt name="." xml="." xsl="bold" /&gt;
&lt;/script&gt; 
&gt;&gt;&gt;



\&lt;math bold templates\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[ @class = 'mathvariant-bold' ]" &gt;
  &lt;xsl:copy&gt;
    &lt;xsl:apply-templates select="@*" /&gt;
    &lt;xsl:variable name="content"&gt;
       &lt;xsl:apply-templates select="*" mode="content" /&gt;
    &lt;/xsl:variable&gt;
    &lt;xsl:choose&gt;
       &lt;xsl:when test=" 
          string-length( normalize-space( $content )) = 1
       " &gt;
          &lt;span class="begin-end" title="speech-extra" &gt; 
             &lt;xsl:text&gt; bold &lt;/xsl:text&gt;
          &lt;/span&gt;
          &lt;xsl:apply-templates select="*|text()|comment()" /&gt;
       &lt;/xsl:when&gt;
       &lt;xsl:otherwise&gt;
          &lt;span class="begin-end" title="speech-extra" &gt; 
             &lt;xsl:text&gt; begin bold &lt;/xsl:text&gt;
          &lt;/span&gt;
          &lt;xsl:apply-templates select="*|text()|comment()" /&gt;
          &lt;span class="begin-end" title="speech-extra" &gt; 
             &lt;xsl:text&gt; end bold &lt;/xsl:text&gt;
          &lt;/span&gt;
       &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
  &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;


%%%%%%%%%%%%%
\section{Eliminate Inline Math Narrative}
%%%%%%%%%%%%%


%%%%%%%%%%%%%
\subsection{Simple Sub-Sup (Core Content of Length One)}
%%%%%%%%%%%%%




\&lt;eliminate inline math narrative\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[
    (@class = 'inline-math')
  and
    (count( `&lt;math content element`&gt; ) = 1)
]" &gt;
  &lt;xsl:copy&gt;
    &lt;xsl:variable name="content"&gt;
       &lt;xsl:apply-templates
           select="`&lt;math content element`&gt;"
             mode="content" /&gt;
    &lt;/xsl:variable&gt;
    &lt;xsl:choose&gt;
       &lt;xsl:when test=" 
          string-length( normalize-space( $content )) = 1
       " &gt;
          &lt;xsl:attribute name="class"&gt;
             &lt;xsl:text&gt;semi-math&lt;/xsl:text&gt;
          &lt;/xsl:attribute&gt;
          &lt;xsl:apply-templates select="`&lt;math content element`&gt;" /&gt;
       &lt;/xsl:when&gt;
       `&lt;simple sub or sup`&gt;
       &lt;xsl:otherwise&gt;
          &lt;xsl:apply-templates select="*|@*|comment()|text()" /&gt;
       &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
  &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;


\&lt;math content element\&gt;&lt;&lt;&lt;
child::*[ not(@title) or (@title != 'speech-extra') ]
&gt;&gt;&gt;


\&lt;simple sub or sup\&gt;&lt;&lt;&lt;
&lt;xsl:when test="  child::*[
     (position() = 2)
   and
     ((@class = 'msub') or (@class = 'msup') or (@class = 'msubsup'))
]" &gt;
    &lt;xsl:variable name="content"&gt;
       &lt;xsl:apply-templates select="child::*[2] / child::*[
                                       @class = 'mrow-base' ]" 
                            mode="content" /&gt;
    &lt;/xsl:variable&gt;
    &lt;xsl:choose&gt;
       &lt;xsl:when test=" 
          string-length( normalize-space( $content )) = 1
       " &gt;
          &lt;xsl:attribute name="class"&gt;
             &lt;xsl:text&gt;semi-math&lt;/xsl:text&gt;
          &lt;/xsl:attribute&gt;
          &lt;xsl:apply-templates select="*[2]" /&gt;
`%
          &lt;span class="end-script" title="speech-extra"&gt;
             &lt;xsl:text&gt; baseline &lt;/xsl:text&gt;
          &lt;/span&gt; 
`%
      &lt;/xsl:when&gt;
       &lt;xsl:otherwise&gt;
          &lt;xsl:apply-templates select="*|@*|comment()|text()" /&gt;
       &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
&lt;/xsl:when&gt;
&gt;&gt;&gt;


\begin{verbatim}
&lt;span class="inline-math"&gt;
  &lt;span class="msub"&gt;
    &lt;span class="mrow-base"&gt;
      &lt;span class="mi"&gt;C&lt;/span&gt;
    &lt;/span&gt;
    &lt;span class="mrow-sub"&gt;
      &lt;span class="mi"&gt;i&lt;/span&gt;
    &lt;/span&gt;
  &lt;/span&gt;
&lt;/span&gt;
\end{verbatim}




%%%%%%%%%%%%%
\subsection{Unary Op on Core Content of Length One}
%%%%%%%%%%%%%

The `mo-unary' is established in the first pass over inline-math,
so we need to wait for the second pass with the following.


\&lt;eliminate inline math narrative 2\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[
    (@class = 'inline-math')
  and
    (count( `&lt;math content element`&gt; ) = 2)
  and
    child::span[ 
        (@class = 'mo-unary')
      and
        following-sibling::*[1]
        / descendant::span[ @class = 'mi' ]
    ]    
]" &gt;
  &lt;xsl:copy&gt;
    &lt;xsl:variable name="content"&gt;
       &lt;xsl:apply-templates
           select="child::*[ 
               (not(@title) or (@title != 'speech-extra'))
               and not( @class = 'mo-unary' )
             ]"
             mode="content" /&gt;
    &lt;/xsl:variable&gt;
    &lt;xsl:choose&gt;
       &lt;xsl:when test=" 
          string-length( normalize-space( $content )) = 1
       " &gt;
          &lt;xsl:attribute name="class"&gt;
             &lt;xsl:text&gt;semi-math&lt;/xsl:text&gt;
          &lt;/xsl:attribute&gt;
          &lt;xsl:apply-templates select="`&lt;math content element`&gt;" /&gt;
       &lt;/xsl:when&gt;
       &lt;xsl:otherwise&gt;
          &lt;xsl:apply-templates select="*|@*|comment()|text()" /&gt;
       &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
  &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;



\begin{verbatim}
&lt;span class="inline-math"&gt;
  &lt;span class="begin-math" title="speech-extra"&gt; begin math &lt;/span&gt;
  &lt;span name="mo-unary"&gt;
    &lt;span class="char" title="ch-verbose"&gt;
      &lt;span class="ch 2212" title="ch-verbose"&gt;negative&lt;/span&gt;
    &lt;/span&gt;
  &lt;/span&gt;
  &lt;span class="mathvariant-bold"&gt;
    &lt;span title="speech-extra" class="begin-end"&gt; bold &lt;/span&gt;
    &lt;span title="speech-extra" class="space"&gt;&lt;!----&gt;          &lt;/span&gt;
    &lt;span class="mi"&gt;
       &lt;span title="speech-extra" class="capital-description"&gt; 
         capital
       &lt;/span&gt;
       A
    &lt;/span&gt;
  &lt;/span&gt;
  &lt;span class="end-math" title="speech-extra"&gt;end math&lt;/span&gt;
&lt;/span&gt;
\end{verbatim}

%%%%%%%%%%%%%%%%%%
\section{Empty Elements}
%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%
\subsection{Set for W3}
%%%%%%%%%%%%%



\&lt;set empty elements for the w3 browser\&gt;&lt;&lt;&lt;
&lt;set name="empty-el" &gt;
   `&lt;open xslt script`&gt;
   `&lt;tags for empty templates`&gt; 
   `&lt;close xslt script`&gt;
&lt;/set&gt;
&lt;xslt name="." xml="." xsl="empty-el" /&gt;
&gt;&gt;&gt;

\&lt;tags for empty templates\&gt;&lt;&lt;&lt;
&lt;xsl:template match="*[ not(child::*) ]" &gt;
  &lt;xsl:copy&gt;
    &lt;xsl:apply-templates select="@*|comment()|text()" /&gt;
    &lt;xsl:if test=" normalize-space(.) = '' " &gt;      
       &lt;xsl:comment&gt;`&lt;comment`&gt;&lt;/xsl:comment&gt;
    &lt;/xsl:if&gt;
  &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;

Note: Java 5 complains when comments contain just white spaced.


\&lt;comment\&gt;&lt;&lt;&lt;
.&gt;&gt;&gt;

%%%%%%%%%%%%%
\subsection{Remove Split Arrays}
%%%%%%%%%%%%%

\&lt;remove empty split entries\&gt;&lt;&lt;&lt;
&lt;script element="div::split-side" &gt;
  &lt;set name="clean-split" &gt;
     `&lt;open xslt script`&gt;
     `&lt;get content template`&gt;
     `&lt;clean math split`&gt; 
     `&lt;close xslt script`&gt;
  &lt;/set&gt;
  &lt;xslt name="." xml="." xsl="clean-split" /&gt;
&lt;/script&gt; 
&gt;&gt;&gt;


\&lt;clean math split\&gt;&lt;&lt;&lt;
&lt;xsl:template match=" div[ @class='split-side' ] 
" &gt;
    &lt;xsl:variable name="content"&gt;
       &lt;xsl:apply-templates select="*" mode="content" /&gt;
    &lt;/xsl:variable&gt;
    &lt;xsl:if test=" 
       string-length( normalize-space( $content )) != 0
    " &gt;       
       &lt;xsl:copy&gt;
          &lt;xsl:apply-templates select=" *|@*|text()|comment() " /&gt;
       &lt;/xsl:copy&gt;
    &lt;/xsl:if&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;


%%%%%%%%%%%%%%%%%%
\section{Spaces around Math Identifiers}
%%%%%%%%%%%%%%%%%%

The following is to cause a pause.  For instance, between the
variables in \verb+&lt;mi&gt;i&lt;/mi&gt;&lt;mi&gt;j&lt;/mi&gt;+.


\&lt;insert pre mi spaces\&gt;&lt;&lt;&lt;
&lt;xsl:template match="span[ @class = 'mi' ]" &gt;
  &lt;span class="space" title="speech-extra"&gt;
     &lt;xsl:text&gt; &lt;/xsl:text&gt; 
  &lt;/span&gt;
  &lt;xsl:copy&gt;
     &lt;xsl:apply-templates select="*|@*|text()|comment()" /&gt;
  &lt;/xsl:copy&gt;
&lt;/xsl:template&gt;   
&gt;&gt;&gt;



%%%%%%%%%%%%%%%%%%
\section{Prose}
%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%
\subsection{Tables}
%%%%%%%%%%%%%

\&lt;measure tablesREMOVE\&gt;&lt;&lt;&lt;
&lt;script element="div::table" &gt;
  &lt;set name="rows" &gt;
     `&lt;open xslt script`&gt;
     `&lt;record number of rows`&gt; 
     `&lt;close xslt script`&gt;
  &lt;/set&gt;
  &lt;xslt name="." xml="." xsl="rows" /&gt;
&lt;/script&gt; 
&gt;&gt;&gt;


\&lt;record number of rowsREMOVE\&gt;&lt;&lt;&lt;
&lt;xsl:template match=" 
   div[ (@class='table') 
        and 
        ((@title='tabular') or (@title='array'))
   ] 
" &gt;
   &lt;xsl:copy&gt;
     &lt;xsl:apply-templates select="@*" /&gt;
     &lt;div class="begin-end" title="speech-extra"&gt; 
        &lt;xsl:value-of select=" 
           concat( child::*[1] /self::div[
             (@class = 'begin-end') and (@title = 'speech-extra')
                   ],
                   ' with ',
                   count(child::*) - 2 ,
                   ' rows '
           ) " /&gt;
     &lt;/div&gt;
     &lt;xsl:apply-templates select=" *[position() &amp;gt; 1]
                                  | @* | text() | comment() " /&gt;
   &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;





%%%%%%%%%%%%%
\subsection{New Theorems}
%%%%%%%%%%%%%

\&lt;boundaries on theorems\&gt;&lt;&lt;&lt;
&lt;script element="div::newtheorem" &gt;
  &lt;set name="newtheorem" &gt;
     `&lt;open xslt script`&gt;
     `&lt;annotate bounderies of theorems`&gt; 
     `&lt;tags for empty templates`&gt;
     `&lt;close xslt script`&gt;
  &lt;/set&gt;
  &lt;xslt name="." xml="." xsl="newtheorem" /&gt;
&lt;/script&gt; 
&gt;&gt;&gt;


\&lt;annotate bounderies of theorems\&gt;&lt;&lt;&lt;
&lt;xsl:template match=" 
    div[   (@class='newtheorem') 
         and
           child::*[1] / child::span[ @class = 'theorem-head' ]
    ]
" &gt;
   &lt;xsl:copy&gt;
     &lt;xsl:apply-templates select="*|@*|text()|comment()" /&gt;
     &lt;div class="begin-end" title="speech-extra"&gt; 
        &lt;xsl:value-of select=" 
           concat( ' end ',
                   string( child::*[1] / 
                           child::span[ @class = 'theorem-head' ] )
           ) " /&gt;
     &lt;/div&gt;
   &lt;/xsl:copy&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;









%%%%%%%%%%%%%%%%%%
\section{Shared}
%%%%%%%%%%%%%%%%%%



\&lt;open xslt script\&gt;&lt;&lt;&lt;
&lt;![CDATA[ 
   &lt;xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   &gt;
      &lt;xsl:output omit-xml-declaration = "yes" /&gt;
&gt;&gt;&gt;

\&lt;close xslt script\&gt;&lt;&lt;&lt;
      &lt;xsl:template match="*|@*|text()|comment()" &gt;
        &lt;xsl:copy&gt;
          &lt;xsl:apply-templates select="*|@*|text()|comment()" /&gt;
        &lt;/xsl:copy&gt;
      &lt;/xsl:template&gt;
   &lt;/xsl:stylesheet&gt; 
]]&gt;
&gt;&gt;&gt;


\&lt;get content template\&gt;&lt;&lt;&lt;
&lt;xsl:template match="*" mode="content" &gt;
  &lt;xsl:choose&gt;
     &lt;xsl:when test=" @class = 'char' " &gt;   
       &lt;xsl:text&gt;x&lt;/xsl:text&gt;
     &lt;/xsl:when&gt;
     &lt;xsl:when test=" not( 
            (@title = 'speech-extra') or (@class = 'accent-char')
         ) " &gt;
       &lt;xsl:apply-templates select="*|text()" mode="content" /&gt;
     &lt;/xsl:when&gt;
  &lt;/xsl:choose&gt;
&lt;/xsl:template&gt; 
&gt;&gt;&gt;


%%%%%%%%%%%%%%%%%%
\section{To Do}
%%%%%%%%%%%%%%%%%%

\begin{itemize}
\item
Left subscripts and tensors.
\end{itemize}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\ifdojava
\AtEndDocument{\Needs{%
    "pushd \XTPIPES || exit 1
     ;  
     jar cf tex4ht.jar *
     ;
     popd
     ;
     mkdir -p \TEXMFTEXivBIN || exit 1
     ;
     mv \XTPIPES tex4ht.jar \TEXMFTEXivBIN . 
"}}
\fi



\end{document}





</pre></body></html>