<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html 
    PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
           "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd"
>
<?xml-stylesheet type="text/xsl" href="mathml.xsl"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Using CPT Embedded in a Page</title>
</head>
<body>
<h2>Using Content Pseudo-TeX Embedded in an XHTML Page</h2>
<p>
Here is a short, complete example XHTML file, <kbd>in-page-ex.xml</kbd>,
demonstrating basic use of Content Pseudo-TeX embedded within the XHTML -- the
relevant parts of the file are highlighted:</p>
<pre><![CDATA[
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html 
    PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
           "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
<?xml-stylesheet type="text/xsl" 
  href="http://cs.jsu.edu/~leathrum/mathtrans/mathml.xsl"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CPT -- In-Page Test</title>
</head>
<body>]]><strong style="color:blue"><![CDATA[
<p style="height:0px;"><script type="text/javascript" src="cpt-inpage.js"/>
<object codebase="http://cs.jsu.edu/~leathrum/mathtrans/"
        classid="java:MathTransApplet.class" 
        type="application/x-java-applet"
	archive="mathtrans.jar" height="1" width="1"/></p>
]]></strong><![CDATA[<p>
Testing in-page CPT mark-up:]]><strong style="color:blue"><![CDATA[
<span class="math"><![CDATA[
\int[v:x][l:0][u:\pi;]{\sin{x}}=2
]]]]>&gt;<![CDATA[</span>
]]></strong><![CDATA[after text
</p>
</body>
</html>
]]>
</pre>
<p>(<a href="in-page-ex.xml">View page</a> locally, with relative URLs.
There is also a page with <a href="in-page-samp.xml">more complicated examples</a>.)
</p>
<p>
The <kbd>&lt;script/&gt;</kbd> and <kbd>&lt;object/&gt;</kbd> tags are necessary
to load the JavaScript for handling the embedded content, and the
Java applet for translating the Content Pseudo-TeX into Content MathML.
The surrounding <kbd>&lt;p&gt;...&lt;/p&gt;</kbd> tags help keep XHTML formatting
valid and also help hide the applet.
These tags need to appear <em>exactly</em> as shown, immediately after
the opening <kbd>&lt;body&gt;</kbd> tag of the XHTML document
(<em>not</em> within the <kbd>&lt;head&gt;...&lt;/head&gt;</kbd> environment).
</p>
<p>
In the example, the Content Pseudo-TeX is enclosed within the
<kbd>&lt;span class="math"&gt;...&lt;/span&gt;</kbd> environment.
Note also the <kbd>&lt;![CDATA[...]]&gt;</kbd> environment -- the Content
Pseudo-TeX <em>must</em> be protected from the XHTML parser by telling the
parser that it is raw character data (<kbd>CDATA</kbd>).
The enclosed text, <kbd>\int[v:x][l:0][u:\pi;]{\sin{x}}=2</kbd>, is the
actual Content Pseudo-TeX mark-up -- for details of the syntax, see the
<a href="mathtransdoc.xml">documentation page</a>.
Use <kbd>&lt;span class="math"&gt;...&lt;/span&gt;</kbd> for in-line math
expressions (as in the example file), 
<kbd>&lt;div class="math"&gt;...&lt;/div&gt;</kbd> for displayed math expressions.
The <kbd>class="math"</kbd> attribute is the flag which indicates 
(to the JavaScript routines) that the
environment contains Content Pseudo-TeX mark-up (which is then sent to the
embedded Java applet for translation, then placed within the document again
by the JavaScript, <em>inside</em> the <kbd>&lt;span&gt;</kbd> or
<kbd>&lt;div&gt;</kbd> tag, which is <em>not</em> removed).
The placement and presentation of the mathematics can be further configured by 
applying a <kbd>style="..."</kbd> attribute to the <kbd>&lt;span&gt;</kbd>
or <kbd>&lt;div&gt;</kbd> tag.
</p>
<p>
See the <a href="index.xml">list of tools and materials</a>.
</p>
<p>
By way of acknowledgement, I should point out that this technique of embedding
Content Pseudo-TeX within a page is based, in theory at least, upon the mechanism used by 
<a href="http://www.math.union.edu/~dpvc/jsmath/">jsMath</a> to 
embed its TeX-like mark-up in HTML pages.  The main
visible difference between jsMath and Content Pseudo-TeX is in the syntax of the
embedded mark-up.  In particular, since jsMath attempts to mimic LaTeX
mathematics closely, its mark-up is presentation-oriented, whereas
Content Pseudo-TeX is built around Content MathML and is therefore
heavily semantic.  Internally, jsMath also uses a different mechanism for placing
the mathematics within the page, using either small images for math symbols placed
using CSS or special browser fonts.  Content Pseudo-TeX, on the other hand, relies
on the (Firefox) browser's native MathML capabilities, placing the MathML within
the page using JavaScript methods to manipulate the Document Object Model (DOM).
</p>
</body>
</html>

