<script type="text/x-mathjax-config">
MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
MathJax.InputJax.TeX.prefilterHooks.Add(function (data) {
data.math = data.math.replace(/^\s*<!\[CDATA\[\s*(.*)\s*\]\]>
\s*$/m,"$1");
});
});
</script>
before the script that loads MathJax.js in order to filter out the
comments.
Davide
The fact that you are seeing the CDATA comment suggests that you are
not viewing XHTML but HTML. Do they insert this comment in HTML
documents as well? That seems ill-advised. But if that is the case,
then you can use<script type="text/x-mathjax-config">
MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
MathJax.InputJax.TeX.prefilterHooks.Add(function (data) {
data.math = data.math.replace(/^\s*<!\[CDATA\[\s*(.*)\s*\]\]>
\s*$/m,"$1");
});
});
</script>before the script that loads MathJax.js in order to filter out the
comments.
Then I think the file is being handled as HTML rather than XHTML. In
XHTML the DATA delimiters will be removed by the browser (leaving the
data they contain), and will not be available to MathJax, so will not
appear in the output. If you are seeing the CDATA in the output, then
that suggests that it is not being handled as XHTML. You have to make
sure your server is sending it with the proper MIME-type, or if you
are loading from a local file, that it is properly interpreted as XHTML.
Can you point to a URL with the expected behavior? Or send a test
file that you are using?
> By looking through the source code of MathJax I found that CDATA
> sections inside \[...\] and \(...\) are automatically removed.
Note that in HTML documents, this is not a standard CDATA segment, but
an actual comment (note that it is for <!--[CDATA[...]]--> not <!
[CDATA[...]]>). MathJax uses this "fake" CDATA comment as a means of
allowing people to avoid some problems with <, >, and & that would
otherwise be embedded in the body of the document where they would
have to be escaped. Since these are not real CDATA (and since HTML
doesn't handle CDATA comments anyway), MathJax is forced to handle
them itself.
> Why is this not done for script tags too?
Because in HTML, <script> tags are automatically CDATA, so it is not
needed there, and in XHTML, the browser handles CDATA itself, so
MathJax doesn't have to.
> There seems to be no reason not to do this...
The reason is that is is not needed. If you want to include unneeded
CDATA in your HTML script tags, then you can use the code I gave you
in my previous answer to handle that.
> Is there any way to create an XHTML and HTML compatible MathJax
> document that uses script tags?
XHTML and HTML are different formats with different requirements
(though they are very similar). The same file will not work for both,
in general. But if you want to put CDATA comments in your HTML
scripts, use the code from my previous message.
Davide
<SNIP />
> Is there any way to create an XHTML and HTML compatible MathJax
> document that uses script tags?XHTML and HTML are different formats with different requirements
(though they are very similar). The same file will not work for both,
in general. But if you want to put CDATA comments in your HTML
scripts, use the code from my previous message.
Davide
On Apr 22, 2012, at 3:01 AM, <thomas....@gmail.com> <thomas....@gmail.com