]> granicus.if.org Git - docbook-dsssl/commitdiff
Added support for TeX math in alt element. When using PassiveTeX, TeX equations can...
authorJirka Kosek <jirka@kosek.cz>
Thu, 6 Dec 2001 18:05:14 +0000 (18:05 +0000)
committerJirka Kosek <jirka@kosek.cz>
Thu, 6 Dec 2001 18:05:14 +0000 (18:05 +0000)
xsl/fo/Makefile.param
xsl/fo/math.xsl
xsl/fo/param.ent
xsl/fo/param.xweb
xsl/html/Makefile.param
xsl/html/docbook.xsl
xsl/html/math.xsl
xsl/html/param.ent
xsl/html/param.xweb
xsl/params/tex.math.file.xml [new file with mode: 0644]
xsl/params/tex.math.in.alt.xml [new file with mode: 0644]

index 04294075dfa1d045dce234d5fa2af615f78a650b..426160a036e76c8f8f3656b2ae3aa4bbafd02b48 100644 (file)
@@ -110,6 +110,7 @@ PARAMS=../params/admon.graphics.xml \
        ../params/table.entry.padding.xml \
        ../params/tablecolumns.extension.xml \
        ../params/textinsert.extension.xml \
+       ../params/tex.math.in.alt.xml \
        ../params/title.font.family.xml \
        ../params/title.margin.left.xml \
        ../params/toc.indent.width.xml \
index 23c0585cd024d5c4e57f5f1fda12d24df4011eda..9ea86c3d84d8139c00a54e2a5b17b1a0549a0377 100644 (file)
      ******************************************************************** -->
 
 <xsl:template match="inlineequation">
-  <xsl:apply-templates/>
+  <xsl:choose>
+    <xsl:when test="$passivetex.extensions != 0 and $tex.math.in.alt != ''">
+      <xsl:apply-templates select="alt"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:apply-templates/>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="equation/mediaobject | informalequation/mediaobject">
+  <xsl:if test="$passivetex.extensions = 0 or $tex.math.in.alt = ''">
+    <fo:block>
+      <xsl:call-template name="select.mediaobject"/>
+      <xsl:apply-templates select="caption"/>
+    </fo:block>
+  </xsl:if>
+</xsl:template>
+
+<xsl:template match="equation/graphic | informalequation/graphic">
+  <xsl:if test="$passivetex.extensions = 0 or $tex.math.in.alt = ''">
+    <fo:block>
+      <xsl:call-template name="process.image"/>
+    </fo:block>
+  </xsl:if>
+</xsl:template>
+
+<xsl:template match="inlineequation/alt">
+  <xsl:if test="$passivetex.extensions != 0 and $tex.math.in.alt != ''">
+    <xsl:processing-instruction name="xmltex">
+      <xsl:text>$</xsl:text>
+      <xsl:value-of select="."/>
+      <xsl:text>$</xsl:text>
+    </xsl:processing-instruction>
+  </xsl:if>
+</xsl:template>
+
+<xsl:template match="equation/alt | informalequation/alt">
+  <xsl:if test="$passivetex.extensions != 0 and $tex.math.in.alt != ''">
+    <xsl:processing-instruction name="xmltex">
+      <xsl:text>$$</xsl:text>
+      <xsl:value-of select="."/>
+      <xsl:text>$$</xsl:text>
+    </xsl:processing-instruction>
+  </xsl:if>
 </xsl:template>
 
 <xsl:template match="alt">
+  <xsl:if test="$passivetex.extensions != 0 and $tex.math.in.alt != ''">
+    <xsl:message>
+      Your equation is misplaced. It should be in inlineequation, equation or informalequation.
+    </xsl:message>
+  </xsl:if>
 </xsl:template>
 
 <!-- just send the MathML all the way through... -->
index c95d04d576a1f65827174c92df965835f666df8b..3a00625140f69d81b37a63654e83458a6c3b11d2 100644 (file)
 <!ENTITY table.entry.padding SYSTEM "../params/table.entry.padding.xml">
 <!ENTITY tablecolumns.extension SYSTEM "../params/tablecolumns.extension.xml">
 <!ENTITY textinsert.extension SYSTEM "../params/textinsert.extension.xml">
+<!ENTITY tex.math.in.alt SYSTEM "../params/tex.math.in.alt.xml">
 <!ENTITY title.font.family SYSTEM "../params/title.font.family.xml">
 <!ENTITY title.margin.left SYSTEM "../params/title.margin.left.xml">
 <!ENTITY toc.indent.width SYSTEM "../params/toc.indent.width.xml">
index 02d6de0434cd7bff5eced28ce6edc8c28514d5d4..2ebbd02a1ce8d8e60cccdabc05242d8584c026ef 100644 (file)
@@ -107,6 +107,7 @@ to be incomplete. Don't forget to read the source, too :-)</para>
 &arbortext.extensions;
 &fop.extensions;
 &passivetex.extensions;
+&tex.math.in.alt;
 &xep.extensions;
 </reference>
 
@@ -380,6 +381,7 @@ around all these parameters.</para>
 <src:fragref linkend="table.entry.padding.frag"/>
 <src:fragref linkend="tablecolumns.extension.frag"/>
 <src:fragref linkend="textinsert.extension.frag"/>
+<src:fragref linkend="tex.math.in.alt.frag"/>
 <src:fragref linkend="title.font.family.frag"/>
 <src:fragref linkend="title.margin.left.frag"/>
 <src:fragref linkend="toc.indent.width.frag"/>
index 98ab68e60db358594ceb6dc43dfa4486b93200e1..166406c05b8d9599e5fd5362b8028afc35407f0c 100644 (file)
@@ -123,6 +123,8 @@ PARAMS=../params/admon.graphics.xml \
        ../params/table.borders.with.css.xml \
        ../params/tablecolumns.extension.xml \
        ../params/textinsert.extension.xml \
+       ../params/tex.math.in.alt.xml \
+       ../params/tex.math.file.xml \
        ../params/toc.list.type.xml \
        ../params/toc.section.depth.xml \
        ../params/ulink.target.xml \
index b5b447b510686959d9a07f73cdf891fb5ec2da10..70809608a4c88ae3c16a2c4f86878e0c9895512b 100644 (file)
         </xsl:when>
         <xsl:otherwise>
           <xsl:apply-templates select="key('id',$rootid)" mode="process.root"/>
+          <xsl:if test="$tex.math.in.alt != ''">
+            <xsl:apply-templates select="key('id',$rootid)" mode="collect.tex.math"/>
+          </xsl:if>
         </xsl:otherwise>
       </xsl:choose>
     </xsl:when>
     <xsl:otherwise>
       <xsl:apply-templates select="/" mode="process.root"/>
+      <xsl:if test="$tex.math.in.alt != ''">
+        <xsl:apply-templates select="/" mode="collect.tex.math"/>
+      </xsl:if>
     </xsl:otherwise>
   </xsl:choose>
 </xsl:template>
index 502a930d8bd448dc7b7530c13d97fa34964ffe9c..c13fb8e7384f2edfbf0e916809cba3a742c95b43 100644 (file)
 <xsl:template match="alt">
 </xsl:template>
 
+<!-- Support for TeX math in alt -->
+
+<xsl:template match="*" mode="collect.tex.math">
+  <xsl:call-template name="write.text.chunk">
+    <xsl:with-param name="filename" select="$tex.math.file"/>
+    <xsl:with-param name="method" select="'text'"/>
+    <xsl:with-param name="content">
+      <xsl:choose>
+        <xsl:when test="$tex.math.in.alt = 'plain'">
+          <xsl:call-template name="tex.math.plain.head"/>
+          <xsl:apply-templates select="." mode="collect.tex.math.plain"/>
+          <xsl:call-template name="tex.math.plain.tail"/>
+        </xsl:when>
+        <xsl:when test="$tex.math.in.alt = 'latex'">
+          <xsl:call-template name="tex.math.latex.head"/>
+          <xsl:apply-templates select="." mode="collect.tex.math.latex"/>
+          <xsl:call-template name="tex.math.latex.tail"/>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:message>
+            Unsupported TeX math notation: 
+            <xsl:value-of select="$tex.math.in.alt"/>
+          </xsl:message>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:with-param>
+    <xsl:with-param name="encoding" select="$default.encoding"/>
+  </xsl:call-template>
+</xsl:template>
+
+<!-- PlainTeX -->
+
+<xsl:template name="tex.math.plain.head">
+  <xsl:text>\nopagenumbers &#xA;</xsl:text>
+</xsl:template>
+
+<xsl:template name="tex.math.plain.tail">
+  <xsl:text>\bye &#xA;</xsl:text>
+</xsl:template>
+
+<xsl:template match="inlineequation" mode="collect.tex.math.plain">
+  <xsl:variable name="filename">
+    <xsl:choose>
+      <xsl:when test="inlinegraphic">
+        <xsl:call-template name="mediaobject.filename">
+          <xsl:with-param name="object" select="inlinegraphic"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:call-template name="select.mediaobject.filename">
+          <xsl:with-param name="olist" select="inlinemediaobject/*"/>
+        </xsl:call-template>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <xsl:text>\special{dvi2bitmap outputfile </xsl:text>
+  <xsl:value-of select="$filename"/>
+  <xsl:text>} &#xA;</xsl:text>
+  <xsl:text>$</xsl:text>
+  <xsl:value-of select="alt"/>
+  <xsl:text>$ &#xA;</xsl:text>
+  <xsl:text>\vfill\eject &#xA;</xsl:text>
+</xsl:template>
+
+<xsl:template match="equation|informalequation" mode="collect.tex.math.plain">
+  <xsl:variable name="filename">
+    <xsl:choose>
+      <xsl:when test="graphic">
+        <xsl:call-template name="mediaobject.filename">
+          <xsl:with-param name="object" select="graphic"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:call-template name="select.mediaobject.filename">
+          <xsl:with-param name="olist" select="mediaobject/*"/>
+        </xsl:call-template>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <xsl:text>\special{dvi2bitmap outputfile </xsl:text>
+  <xsl:value-of select="$filename"/>
+  <xsl:text>} &#xA;</xsl:text>
+  <xsl:text>$$</xsl:text>
+  <xsl:value-of select="alt"/>
+  <xsl:text>$$ &#xA;</xsl:text>
+  <xsl:text>\vfill\eject &#xA;</xsl:text>
+</xsl:template>
+
+<xsl:template match="text()" mode="collect.tex.math.plain"/>
+
+<!-- LaTeX -->
+
+<xsl:template name="tex.math.latex.head">
+  <xsl:text>\documentclass{article} &#xA;</xsl:text>
+  <xsl:text>\pagestyle{empty} &#xA;</xsl:text>
+  <xsl:text>\begin{document} &#xA;</xsl:text>
+</xsl:template>
+
+<xsl:template name="tex.math.latex.tail">
+  <xsl:text>\end{document} &#xA;</xsl:text>
+</xsl:template>
+
+<xsl:template match="inlineequation" mode="collect.tex.math.latex">
+  <xsl:variable name="filename">
+    <xsl:choose>
+      <xsl:when test="inlinegraphic">
+        <xsl:call-template name="mediaobject.filename">
+          <xsl:with-param name="object" select="inlinegraphic"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:call-template name="select.mediaobject.filename">
+          <xsl:with-param name="olist" select="inlinemediaobject/*"/>
+        </xsl:call-template>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <xsl:text>\special{dvi2bitmap outputfile </xsl:text>
+  <xsl:value-of select="$filename"/>
+  <xsl:text>} &#xA;</xsl:text>
+  <xsl:text>$</xsl:text>
+  <xsl:value-of select="alt"/>
+  <xsl:text>$ &#xA;</xsl:text>
+  <xsl:text>\newpage &#xA;</xsl:text>
+</xsl:template>
+
+<xsl:template match="equation|informalequation" mode="collect.tex.math.latex">
+  <xsl:variable name="filename">
+    <xsl:choose>
+      <xsl:when test="graphic">
+        <xsl:call-template name="mediaobject.filename">
+          <xsl:with-param name="object" select="graphic"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:call-template name="select.mediaobject.filename">
+          <xsl:with-param name="olist" select="mediaobject/*"/>
+        </xsl:call-template>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <xsl:text>\special{dvi2bitmap outputfile </xsl:text>
+  <xsl:value-of select="$filename"/>
+  <xsl:text>} &#xA;</xsl:text>
+  <xsl:text>$$</xsl:text>
+  <xsl:value-of select="alt"/>
+  <xsl:text>$$ &#xA;</xsl:text>
+  <xsl:text>\newpage &#xA;</xsl:text>
+</xsl:template>
+
+<xsl:template match="text()" mode="collect.tex.math.latex"/>
+
+<!-- Extracting image filename from mediaobject and graphic elements -->
+
+<xsl:template name="select.mediaobject.filename">
+  <xsl:param name="olist"
+             select="imageobject|imageobjectco
+                     |videoobject|audioobject|textobject"/>
+  <xsl:param name="count">1</xsl:param>
+
+  <xsl:if test="$count &lt;= count($olist)">
+    <xsl:variable name="object" select="$olist[position()=$count]"/>
+
+    <xsl:variable name="useobject">
+      <xsl:choose>
+       <!-- The phrase is never used -->
+        <xsl:when test="name($object)='textobject' and $object/phrase">
+          <xsl:text>0</xsl:text>
+        </xsl:when>
+       <!-- The first textobject is not a reasonable fallback for equation image -->
+        <xsl:when test="name($object)='textobject'">
+          <xsl:text>0</xsl:text>
+        </xsl:when>
+       <!-- If there's only one object, use it -->
+       <xsl:when test="$count = 1 and count($olist) = 1">
+         <xsl:text>1</xsl:text>
+       </xsl:when>
+       <!-- Otherwise, see if this one is a useable graphic -->
+        <xsl:otherwise>
+          <xsl:choose>
+            <!-- peek inside imageobjectco to simplify the test -->
+            <xsl:when test="local-name($object) = 'imageobjectco'">
+              <xsl:call-template name="is.acceptable.mediaobject">
+                <xsl:with-param name="object" select="$object/imageobject"/>
+              </xsl:call-template>
+            </xsl:when>
+            <xsl:otherwise>
+              <xsl:call-template name="is.acceptable.mediaobject">
+                <xsl:with-param name="object" select="$object"/>
+              </xsl:call-template>
+            </xsl:otherwise>
+          </xsl:choose>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:variable>
+
+    <xsl:choose>
+      <xsl:when test="$useobject='1'">
+        <xsl:call-template name="mediaobject.filename">
+          <xsl:with-param name="object" select="$object"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:call-template name="select.mediaobject">
+          <xsl:with-param name="olist" select="$olist"/>
+          <xsl:with-param name="count" select="$count + 1"/>
+        </xsl:call-template>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:if>
+</xsl:template>
+
 </xsl:stylesheet>
index 1a17c34bbfb44b45b3575507fbd1b47e9bfd48a2..47d663e578a3ae79b79708d8d3cf00872efb9560 100644 (file)
 <!ENTITY table.borders.with.css SYSTEM "../params/table.borders.with.css.xml">
 <!ENTITY tablecolumns.extension SYSTEM "../params/tablecolumns.extension.xml">
 <!ENTITY textinsert.extension SYSTEM "../params/textinsert.extension.xml">
+<!ENTITY tex.math.in.alt SYSTEM "../params/tex.math.in.alt.xml">
+<!ENTITY tex.math.file SYSTEM "../params/tex.math.file.xml">
 <!ENTITY toc.list.type SYSTEM "../params/toc.list.type.xml">
 <!ENTITY toc.section.depth SYSTEM "../params/toc.section.depth.xml">
 <!ENTITY ulink.target SYSTEM "../params/ulink.target.xml">
index 31597bd6d29109830f210e766c961f9125c85217..4a963bae1d6949789251bdb6ed450190d4f33275 100644 (file)
@@ -216,6 +216,8 @@ to be incomplete. Don't forget to read the source, too :-)</para>
 &shade.verbatim.style;
 &punct.honorific;
 &segmentedlist.as.table;
+&tex.math.in.alt;
+&tex.math.file;
 </reference>
 
 <reference><title>Chunking</title>
@@ -395,6 +397,8 @@ around all these parameters.</para>
 <src:fragref linkend="table.borders.with.css.frag"/>
 <src:fragref linkend="tablecolumns.extension.frag"/>
 <src:fragref linkend="textinsert.extension.frag"/>
+<src:fragref linkend="tex.math.file.frag"/>
+<src:fragref linkend="tex.math.in.alt.frag"/>
 <src:fragref linkend="toc.list.type.frag"/>
 <src:fragref linkend="toc.section.depth.frag"/>
 <src:fragref linkend="ulink.target.frag"/>
diff --git a/xsl/params/tex.math.file.xml b/xsl/params/tex.math.file.xml
new file mode 100644 (file)
index 0000000..fd0fcf0
--- /dev/null
@@ -0,0 +1,24 @@
+<refentry id="tex.math.file">
+<refmeta>
+<refentrytitle>tex.math.file</refentrytitle>
+<refmiscinfo role="type">string</refmiscinfo>
+</refmeta>
+<refnamediv>
+<refname>tex.math.file</refname>
+<refpurpose></refpurpose>
+</refnamediv>
+
+<refsynopsisdiv>
+<src:fragment id='tex.math.file.frag'>
+<xsl:param name="tex.math.file" select="'tex-math-equations.tex'"/>
+</src:fragment>
+</refsynopsisdiv>
+
+<refsect1><title>Description</title>
+
+<para>Name of auxiliary file for TeX equations. This file can be
+processed by dvi2bitmap to get bitmap versions of equations for HTML
+output.</para>
+
+</refsect1>
+</refentry>
diff --git a/xsl/params/tex.math.in.alt.xml b/xsl/params/tex.math.in.alt.xml
new file mode 100644 (file)
index 0000000..8b2baa5
--- /dev/null
@@ -0,0 +1,36 @@
+<refentry id="tex.math.in.alt">
+<refmeta>
+<refentrytitle>tex.math.in.alt</refentrytitle>
+<refmiscinfo role="type">string</refmiscinfo>
+</refmeta>
+<refnamediv>
+<refname>tex.math.in.alt</refname>
+<refpurpose></refpurpose>
+</refnamediv>
+
+<refsynopsisdiv>
+<src:fragment id='tex.math.in.alt.frag'>
+<xsl:param name="tex.math.in.alt" select="''"/>
+</src:fragment>
+</refsynopsisdiv>
+
+<refsect1><title>Description</title>
+
+<para>If you want type math directly in TeX notation into
+<sgmltag>alt</sgmltag> element, this parameter specifies notation
+used. Currently are supported two values --
+<literal>plain</literal> and <literal>latex</literal>. Empty value
+means that you are not using TeX math.</para>
+
+<para>If you want use this feature, you should process your FO with
+PassiveTeX, which only supports TeX math notation. When calling
+stylsheet, don't forget to specify also
+passivetex.extensions=1.</para>
+
+<para>If you want equations in HTML, just process generated file
+<filename>tex-math-equations.tex</filename> by TeX or LaTeX. Then run
+dvi2bitmap program on result DVI file. You will get images for
+equations in your document.</para>
+
+</refsect1>
+</refentry>