Expand | Collapse

◀ 20. Site maps22. User customizations ▶

21. Math formulas in TEX

This stylesheet provides rudimentary support for mathematical formulae written in TEX. The formulae are displayed as raster images in the final HTML rendition. For example: \phi = (1 + \sqrt{5})/2.

This support is useful for documents with a few occasional formulae. For documents with heavy use of TEX, a non-XSLT implementation that does caching will be faster and more robust.

    \frac{dX_t}{X_t} = r_t \, dt + \sigma_t \, dW_t 
    \quad \Leftrightarrow \quad
    X_t = X_0 \, \exp \left( \int_0^t (r_s - \frac12 \sigma_s^2) \, ds + 
                             \int_0^t \sigma_s \, dW_s \right) \,.
xsl:stylesheet id="stylesheet" exclude-result-prefixes="x2 lit xs exslt" extension-element-prefixes="exslt" version="1.0" xml:lang="en"
  
  xsl:template match="tex:s"
    <img>
      xsl:attribute name="src"
        xsl:call-template name="id"
        xsl:text.tex.png
      
      xsl:attribute name="alt"
        xsl:value-of select="."
      
    </img>

    xsl:variable name="tex-file"
      xsl:call-template name="id"
      xsl:text.tex
    

    <exslt:document method="text" encoding="utf-8" href="{$tex-file}">\documentclass{minimal}
\begin{document}
$ xsl:value-of select="." $
\end{document}</exslt:document>
  

  xsl:template match="tex:b"
    <div>
      <img>
        xsl:attribute name="src"
          xsl:call-template name="id"
          xsl:text.tex.png
        
        xsl:attribute name="alt"
          xsl:value-of select="."
        
      </img>
    </div>

    xsl:variable name="tex-file"
      xsl:call-template name="id"
      xsl:text.tex
    

    <exslt:document method="text" encoding="utf-8" href="{$tex-file}">\documentclass{minimal}
\begin{document}
\[
xsl:value-of select="."
\]
\end{document}</exslt:document>
  

  

Formatted using xhtml2to1 by Steve Cheng.