OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

docbook message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: Re: [docbook] LaTeX math inside docbook, on-the-fly MathML conversion?



On 01/29/2015 11:20 PM, Justus-bulk@Piater.name wrote:
Alexey Neyman <stilor@att.net> wrote on Thu, 29 Jan 2015 12:34:05 -0800:

I found this quite useful for PDF output:

http://pmml2svg.sourceforge.net/

This XSL stylesheet converts MathML to SVG. SVG can be then inserted
into the XSL-FO for PDF output or converted to PNG for HTML.
I'm the person behind pmml2svg.  I think its output is clearly superior
to JEuclid in most cases, mostly because JEclid literally handles
stretchy characters by anisotropic scaling of glyphs.
Indeed, and in addition to that, it looks like JEuclid just attempts to draw some symbols using line art (e.g., the root symbol). The result is ugly. The quality of JEuclid's output was the primary reason we switched to pmml2svg.

Thanks for this stylesheet, by the way!

If you want to use inline formulas, you'd need a small hack to pass
the baseline shift generated by pMML2SVG (which is stored in the
generated SVG) into the XSL-FO attribute. I have a patch for that
somewhere; I'll dig it up if you're interested.
I am :-)
Well, it's sort of trivial. In a common stylesheet (include in both HTML and FO outputs), I have:

[[[
 <xsl:template match="inlinemediaobject">
  <xsl:variable name="generated.content">
   <xsl:apply-imports/>
  </xsl:variable>

  <xsl:variable name="baseline.adjustment">
   <xsl:if test="imageobject/imagedata[@format='SVG']">
<xsl:value-of select="document(imageobject/imagedata[@format='SVG']/@fileref)/svg:svg/svg:metadata/pmml2svg:baseline-shift"/>
   </xsl:if>
  </xsl:variable>

  <xsl:choose>
<xsl:when test="$baseline.adjustment = ''"><xsl:copy-of select="$generated.content"/></xsl:when>
   <xsl:otherwise>
<xsl:apply-templates select="exsl:node-set($generated.content)" mode="inlinemediaobject.adjust.baseline"> <!-- We secretly know SVGs were generated with 'pt' (points) master unit --> <xsl:with-param name="adj" select="concat('-',$baseline.adjustment,'pt')"/>
    </xsl:apply-templates>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>
]]]

Then, in HTML stylesheet:

[[[
 <xsl:template match="img" mode="inlinemediaobject.adjust.baseline">
  <xsl:param name="adj" select="'0pt'"/>
  <xsl:if test="@style">
   <!--
We don't expect a style attribute... If XSLs start to generate it, we need to selectively merge it - i.e., copy all but 'vertical-align' attributes and add the vertical align. Defer until it is actually needed - hope I'll be able to persuade DocBook XSL maintainers to allow for customization hook in process.image
   templates.
   -->
<xsl:message terminate="yes">Not implemented: merging @style attributes for inlinemediaobject processing.</xsl:message>
  </xsl:if>
  <xsl:copy>
<xsl:attribute name="style">vertical-align: <xsl:value-of select="$adj"/></xsl:attribute> <xsl:apply-templates select="@*[local-name() != 'alignment-adjust'] | node() | text() | processing-instruction() | comment()" mode="inlinemediaobject.adjust.baseline"/>
  </xsl:copy>
 </xsl:template>

<xsl:template match="@* | node() | text() | processing-instruction() | comment()" mode="inlinemediaobject.adjust.baseline">
  <xsl:param name="adj" select="'0pt'"/>

  <xsl:copy>
<xsl:apply-templates select="@* | node() | text() | processing-instruction() | comment()" mode="inlinemediaobject.adjust.baseline">
    <xsl:with-param name="adj" select="$adj"/>
   </xsl:apply-templates>
  </xsl:copy>
 </xsl:template>
]]]

And in the FO stylesheet:

[[[
 <!--
For this postprocessing, we only expect a single fo:external-graphic tag. Copy attributes, add alignment-adjust
 -->
<xsl:template match="fo:external-graphic" mode="inlinemediaobject.adjust.baseline">
  <xsl:param name="adj" select="'0pt'"/>
  <xsl:copy>
<xsl:attribute name="alignment-adjust"><xsl:value-of select="$adj"/></xsl:attribute> <xsl:apply-templates select="@*[local-name() != 'alignment-adjust'] | node() | text() | processing-instruction() | comment()" mode="inlinemediaobject.adjust.baseline"/>
  </xsl:copy>
 </xsl:template>

<xsl:template match="@* | text() | processing-instruction() | comment()" mode="inlinemediaobject.adjust.baseline">
  <xsl:copy/>
 </xsl:template>

 <xsl:template match="*" mode="inlinemediaobject.adjust.baseline">
<xsl:message terminate="yes">Unexpected element for inline media object postprocessing: <xsl:value-of select="name(.)"/></xsl:message>
 </xsl:template>
]]]

Regards,
Alexey.


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]