Removing typesetting - opposite of MathJax.Hub.Typeset()

505 views
Skip to first unread message

Enrico

unread,
Nov 7, 2011, 12:19:12 AM11/7/11
to MathJax Users
Hi,

I'm a newbie and I couldn't find any info on the possibility of
removing the typesetting from the entire page. Saying it in a
different way, is there any method that does the exact opposite of
MathJax.Hub.Typeset()?

Thanks,

Enrico

leathrum

unread,
Nov 7, 2011, 12:06:32 PM11/7/11
to MathJax Users
I'm afraid you need to give more context for your question. What are
you trying to do? If you are just trying to see source LaTeX that was
used to generate MathJax output, the right-click context menu on the
typeset output has a "show source" option which will show you the
LaTeX (or MathML, if it was generated that way). If you want to see
the source HTML for the whole page, with the LaTeX still in it, just
use your browser's "view page source" menu option.

That's at the easy end of the problem, though. At the other extreme,
if you are looking for a way to take a previously typeset expression
from some other source and generate LaTeX, then you will need to know
what format the previously typeset expression is stored in. If it is
a GIF or JPEG image, that is way outside the scope of MathJax -- you
need something like math-enabled OCR software. Such software does
exist, but it is not easy to come by, and the format of the output
generated may not be LaTeX. That is the very hardest case. If you
are looking to convert MathML to LaTeX, that is somewhat easier, and
there does exist software for that, too, but that is not the direction
MathJax is designed to go.

Enrico

unread,
Nov 7, 2011, 2:07:17 PM11/7/11
to MathJax Users
Thank you for the detailed reply leathrum.
I'm trying save in Latex source code a content rendered in MathJax;
basically I'd like to do what "show source" does via javascript.
Here are the steps:
!) The equation is written in the html page as a Latex and is rendered
on the screen in MathJax format
   <div id="equation">      $$ \hbar $$   </div>
2) If I try to get the content of by
document.getElementById("equation").innerHTML I don't get the clean
source code in Latex but I get the Mathjax scripts:
<span class="MathJax_Preview" style="display: none; "></span><div
class="MathJax_Display" style="width: 100%; position: relative; text-
align: center; " role="textbox" aria-readonly="true"><span
class="MathJax" style=""><nobr><span class="math" id="MathJax-
Span-10"><span style="display: inline-block; position: relative;
height: 0px; font-size: 121%; width: 0.573em; "><span style="position:
absolute; top: -2.527em; left: 0em; clip: rect(1.653em 1000em 2.728em
-0.526em); "><span class="mrow" id="MathJax-Span-11"><span class="mi"
id="MathJax-Span-12" style="font-family: STIXVariants; ">ℏ</span></
span><span style="display: inline-block; width: 0px; height: 2.527em;
"></span></span></span><span style="border-left-width: 0em; border-
left-style: solid; border-left-color: initial; display: inline-block;
overflow-x: hidden; overflow-y: hidden; width: 0px; height: 0.838em;
vertical-align: -0.012em; "></span></span></nobr></span></div><script
type="math/tex; mode=display" id="MathJax-Element-1"> \hbar </script>

So basically if there would be a way of 'undoing' the rendering before
trying to get the html code it would solve the problem.Is the
SourceCode method supposed to do something similar? If so is there any
simple example on how to use it?
Thanks again!
Enrico

leathrum

unread,
Nov 7, 2011, 7:10:23 PM11/7/11
to MathJax Users
OK, so you are trying to catch the LaTeX dynamically inside a script.
That's a different kind of problem (roughly midway between the easy
and hard extremes). I would suggest instead that you make sure your
script runs before MathJax, then wrap the LaTeX in a <span
id="foo">...</span> so that you can grab the LaTeX with
document.getElementById("foo").innerHTML or something similar. The
point is that undoing MathJax once it has processed the LaTeX is
pretty much not going to happen, so you should try to catch the LaTeX
before it is processed. If that is not an option, you will need to go
into the MathJax API to find where the original LaTeX is stored (it is
stored, since it is displayed in the context menu) -- look for example
at the ElementJax object's originalText field.

Davide P. Cervone

unread,
Nov 7, 2011, 8:23:40 PM11/7/11
to mathja...@googlegroups.com
You might look at my response at

http://groups.google.com/group/mathjax-users/browse_thread/thread/41519b69408fe9f6

which could help you get the original TeX source. It is also possible
to use jax.originalText one you have the ElementJax, as @leathrum
suggests, though I have been considering changes to how the original
text is stored.

Davide

Enrico

unread,
Nov 7, 2011, 10:54:24 PM11/7/11
to MathJax Users
leathrum and Davide, your answers already helped me and I made some
progess, but I have to check more carefully to see if they can solve
my problem entirely.
In the meantime I just wanted to thank you both for the help, it's
very much appreciated.
Best,
Enrico
On Nov 7, 8:23 pm, "Davide P. Cervone" <d...@union.edu> wrote:
> You might look at my response at
>
>        http://groups.google.com/group/mathjax-users/browse_thread/thread/415...
Reply all
Reply to author
Forward
0 new messages