ReST in Sage 4.1: using .. MATH:: doesn't render LaTeX in HTML

35 views
Skip to first unread message

Minh Nguyen

unread,
Jul 11, 2009, 8:12:11 AM7/11/09
to sage-...@googlegroups.com
Hi folks,

When ReSTifying the documentation, my understanding is that the tag

.. MATH::
<put your LaTeX here>

would render whatever is in

<put your LaTeX here>

as LaTeX. That's OK, I can see that the LaTeX is rendered and shows up
in the PDF version of the standard documentation (reference manual,
tutorial, etc.). The problem is that in Sage 4.1, that tag doesn't
render properly, if at all, in the HTML version of the documentation.
For example, here is a link to a screenshot of a page in the reference
manual in Sage 4.0.2:

http://sage.math.washington.edu/home/mvngu/patch/sage-ref-4.0.2.png

And here is a screenshot of the same page in Sage 4.1:

http://sage.math.washington.edu/home/mvngu/patch/sage-ref-4.1.png

This problem might be due to ticket #5799

http://trac.sagemath.org/sage_trac/ticket/5799

Can someone confirm this?

--
Regards
Minh Van Nguyen

Pat LeSmithe

unread,
Jul 11, 2009, 12:37:30 PM7/11/09
to sage-...@googlegroups.com
Minh Nguyen wrote:
> as LaTeX. That's OK, I can see that the LaTeX is rendered and shows up
> in the PDF version of the standard documentation (reference manual,
> tutorial, etc.). The problem is that in Sage 4.1, that tag doesn't
> render properly, if at all, in the HTML version of the documentation.
> For example, here is a link to a screenshot of a page in the reference
> manual in Sage 4.0.2:
>
> http://sage.math.washington.edu/home/mvngu/patch/sage-ref-4.0.2.png
>
> And here is a screenshot of the same page in Sage 4.1:
>
> http://sage.math.washington.edu/home/mvngu/patch/sage-ref-4.1.png
>
> This problem might be due to ticket #5799
>
> http://trac.sagemath.org/sage_trac/ticket/5799
>
> Can someone confirm this?

Apparently, the jsMath library hides all display equations, even if they
are images. There's a patch at

http://trac.sagemath.org/sage_trac/ticket/6512

Minh Nguyen

unread,
Jul 11, 2009, 12:52:40 PM7/11/09
to sage-...@googlegroups.com
On Sun, Jul 12, 2009 at 2:37 AM, Pat LeSmithe<qed...@gmail.com> wrote:

<SNIP>

> Apparently, the jsMath library hides all display equations, even if they
> are images.

I find this funny: I can view the rendered equations. It's just that I
have to refresh my browser every second. Even at that rate, the
equation would only be displayed for a fraction of a second :-)

Thanks for looking into the problem.

Jason Grout

unread,
Jul 11, 2009, 1:29:38 PM7/11/09
to sage-...@googlegroups.com, Davide P. Cervone
Minh Nguyen wrote:
> On Sun, Jul 12, 2009 at 2:37 AM, Pat LeSmithe<qed...@gmail.com> wrote:
>
> <SNIP>
>
>> Apparently, the jsMath library hides all display equations, even if they
>> are images.
>
> I find this funny: I can view the rendered equations. It's just that I
> have to refresh my browser every second. Even at that rate, the
> equation would only be displayed for a fraction of a second :-)


Davide,

You can see this happening at
http://sagemath.org/doc/reference/sage/numerical/knapsack.html (search
for the text "must satisfy the property")

Currently, an <img class="math" ...> displays the image, but an image
inside of a <div class="math"> is deleted.

The relevant HTML is:

<p>Let <img class="math"
src="../../_images/math/423e6d866fb7dea1490a6d84e9bd08e524a8ae74.png"
alt="L = (a_1, a_2, a_3, \dots, a_n)" /> be a non-empty sequence of
non-negative integers. Then <img class="math"
src="../../_images/math/859ccf4cd60c7bc6b8fa1afc9a42dc811a826d6f.png"
alt="L" /> is said to be super-increasing if
each <img class="math"
src="../../_images/math/412787c048e28774dc63fc27db42dc52ca858de7.png"
alt="a_i" /> is strictly greater than the sum of all previous values.
That is, for each <img class="math"
src="../../_images/math/5104cf5e4b0a4dac3d89d924244871821acf1d22.png"
alt="a_i \in L" /> the sequence <img class="math"
src="../../_images/math/859ccf4cd60c7bc6b8fa1afc9a42dc811a826d6f.png"
alt="L" /> must satisfy the property</p>

<div class="math">
<p><img
src="../../_images/math/db83da90af912a511752f6af9626076764786f3b.png"
alt="a_i &gt; \sum_{k=1}^{i-1} a_k" />
</div></p>

<p>in order to be called a super-increasing sequence, where <img
class="math"
src="../../_images/math/71b363cfed7a38259d24cb0ac71c239743efffe5.png"
alt="|L| \geq 2" />.
If <img class="math"
src="../../_images/math/859ccf4cd60c7bc6b8fa1afc9a42dc811a826d6f.png"
alt="L" /> has only one element, it is also defined to be a
super-increasing sequence.</p>

(I just noticed that the </div> and </p> tags are in the wrong order for
the <div class="math">; maybe that is part of the problem?)


Apparently, this is representative of what is now the standard python
documentation program output (so this is probably a wider concern than
just the Sage project). Is there an easy way to make jsmath look at the
alt text of images as the latex source that should be there? Ideally,
there would be a switch somewhere, maybe on the jsmath control panel,
that would tell jsmath to either leave the images alone, or to extract
and format the alt text and hide the image.

Thanks,

Jason

Jason Grout

unread,
Jul 13, 2009, 9:42:52 PM7/13/09
to sage-...@googlegroups.com
Jason Grout wrote:
> Minh Nguyen wrote:
>> On Sun, Jul 12, 2009 at 2:37 AM, Pat LeSmithe<qed...@gmail.com> wrote:
>>
>> <SNIP>
>>
>>> Apparently, the jsMath library hides all display equations, even if they
>>> are images.
>> I find this funny: I can view the rendered equations. It's just that I
>> have to refresh my browser every second. Even at that rate, the
>> equation would only be displayed for a fraction of a second :-)
>
>
> Davide,
>
> You can see this happening at
> http://sagemath.org/doc/reference/sage/numerical/knapsack.html (search
> for the text "must satisfy the property")
>


Davide sent me this extremely helpful reply. Does anyone want to take
this up as a small, but very helpful project?

Jason:

Here's what's going on: jsMath looks for DIV's and SPAN's that are
marked by CLASS="math" and treats their contents as TeX source code to
process. It replaces the original contents of the DIV or SPAN with the
typeset version of the TeX code. Because the image's are not DIV's or
SPAN's jsMath ignores them (even though they are CLASS="math"), but the
<DIV CLASS="math"> that contains an image is processed by jsMath. It
takes the text content of the DIV (empty in this case) and typesets it
(the result is blank). Thus the image disappears and is replaced by
nothing.

There are a couple of possible solutions: 1) have the python program
produce a class other than "math" for its output; 2) have jsMath look
for something other than class="math" for its trigger; 3) use a
preprocessor (in javascript) to modify the class of the DIV's that
python produces so jsMath won't modify them. It would need to run
before jsMath.js.

I suspect 3 is the best solution. You mention that you would like
jsMath to process the ALT text of the images and replace them by the
typeset output. That function could also be folded into the
preprocessor in (3) by searching for the images and changing them to
SPAN's containing the TeX. This would show up on screen as a change of
all the images then the loading of jsMath, which would be visually
apparent. You might replace

<IMG CLASS="math" ... ALT="tex-code">

by

<SPAN CLASS="math"><IMG ...><SPAN
STYLE="display:none">tex-code</SPAN></SPAN>

and

<DIV CLASS="math">
<p><IMG ... ALT="tex-code">
</DIV>

by

<DIV CLASS="math">
<p><IMG ...>
<SPAN STYLE="display:none">tex-code</SPAN>
</DIV>

This would not alter the visual display until jsMath actually processes
the SPAN. It should not be that hard to write such a preprocessor. You
would load it before loading jsMath (via easy/load.js).

Davide
Reply all
Reply to author
Forward
0 new messages