MathJax on iPad

524 views
Skip to first unread message

Kumar Thiagarajan

unread,
Mar 7, 2012, 5:10:59 PM3/7/12
to MathJax Users, srikanth....@npcompete.com
We are trying to test rendering TeX on iPad using MathJax. We have
this html on the iPad and we are trying to display this using the UI
Kit. But it displays the TeX as simple text. Any thoughts?

Thanks,
Kumar

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head>
<title>MathML's Hello Square</title>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/2.0-
latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js">
</script>
</head>

<body>

\[P(E) = {n \choose k} p^k (1-p)^{ n-k} \]

</body>
</html>

Thomas Leathrum

unread,
Mar 7, 2012, 5:19:50 PM3/7/12
to mathja...@googlegroups.com, srikanth....@npcompete.com
First of all, why are you trying to load MathJax twice?  You have two different <script> tags both loading MathJax.js, one with a config file and the other without.  (The versions should be the same now that version 2.0 is on the .../latest/... link at the CDN.)  Try deleting the second <script> tag (since the first one has the config file reference), and deleting the "2.0-" from the src URL in the first tag.  Then let us know if you still have the problem.  (You shouldn't.)

Kumar Thiagarajan

unread,
Mar 9, 2012, 3:15:28 PM3/9/12
to MathJax Users
Thomas, did both and the problem still exists.

Any other thoughts?

On Mar 7, 5:19 pm, Thomas Leathrum <leath...@jsu.edu> wrote:
> First of all, why are you trying to load MathJax twice?  You have two
> different <script> tags both loading MathJax.js, one with a config file and
> the other without.  (The versions should be the same now that version 2.0
> is on the .../latest/... link at the CDN.)  Try deleting the second
> <script> tag (since the first one has the config file reference), and
> deleting the "2.0-" from the src URL in the first tag.  Then let us know if
> you still have the problem.  (You shouldn't.)
>
>
>
>
>
>
>
> On Wednesday, March 7, 2012 4:10:59 PM UTC-6, Kumar Thiagarajan wrote:
>
> > We are trying to test rendering TeX on iPad using MathJax. We have
> > this html on the iPad and we are trying to display this using the UI
> > Kit. But it displays the TeX as simple text. Any thoughts?
>
> > Thanks,
> > Kumar
>
> > <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
>
> > <head>
> > <title>MathML's Hello Square</title>
> > <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/2.0-
> > latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML<http://cdn.mathjax.org/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-M...>"></script>

Davide P. Cervone

unread,
Mar 11, 2012, 4:31:49 PM3/11/12
to mathja...@googlegroups.com
> We are trying to test rendering TeX on iPad using MathJax. We have
> this html on the iPad and we are trying to display this using the UI
> Kit. But it displays the TeX as simple text. Any thoughts?

Can you be more specific about your setup? When you say on the iPad,
are you viewing this in a web browser, or are you writing an App in
which you want to display the math? I don't know UI Kit, but I
googled it and don't really see the connection to MathJax. Can you
say how you are using it with MathJax? Finally, have you read the
documentation at

http://www.mathjax.org/docs/2.0/typeset.html

?

Davide

Kumar Thiagarajan

unread,
Mar 12, 2012, 4:34:58 PM3/12/12
to MathJax Users
Davide, we have written an app to display the Math.

Davide P. Cervone

unread,
Mar 12, 2012, 4:41:32 PM3/12/12
to mathja...@googlegroups.com
Can you be more specific about what you are doing to display the page?

When you say you are using UI Kit do you really mean UIWebKit? If so,
you might want to check how it gets configured, as I think that you
may need to ask it to enable javascript.

Have you tested that javascript is actually being processed (e.g., but
adding

<script> alert("Javascript working!") </script>

to the page and looking for the alert)?

These are the first things I'd look at.

Davide

Kumar Thiagarajan

unread,
Mar 13, 2012, 12:14:42 PM3/13/12
to MathJax Users
Davide, we are using UIWebKit. Javascript is enabled and the alert
works fine.

Kumar

Thomas Leathrum

unread,
Mar 13, 2012, 1:10:53 PM3/13/12
to mathja...@googlegroups.com
I did some more poking around on Google -- I'm pretty sure you mean "iWebKit" not "UIWebKit", but please correct me if I'm wrong.

Anyway, I'm not sure how iWebKit feels about off-site script files, but I will keep poking around to see what I can find out.

(iWebKit is a platform to use HTML/CSS/JavaScript to build native iPhone/iPad apps.  Since these are supposed to run natively, you may need to use a local copy of the MathJax JavaScript files and fonts rather than linking to the CDN.)

Davide P. Cervone

unread,
Mar 13, 2012, 3:11:39 PM3/13/12
to mathja...@googlegroups.com
OK, good that javascript is working. Tom points out that there may be
an issue loading external URLs. Can you check that by putting the
alert into a separate javascript file on a server somewhere and see if
that works?

You may need to use a local copy of MathJax, in which case you may
want to slim it down a bit first. See

http://new2objectivec.blogspot.com/2012/03/tutorial-how-to-setup-mathjax-locally.html

for some details about what can be removed. See in particular my
response to the post for some additional reductions that can be made.

Davide

Kumar Thiagarajan

unread,
Mar 13, 2012, 10:24:15 PM3/13/12
to MathJax Users
Davide,

I added 3 alerts in the onload method - one directly in the onload
method, one from a method within the html file and one from another js
file in the same directory. The first two worked and the third did
not.

I do have a local copy of MathJax now. If I open the html on Safari it
shows up fine. But struggling to make it work from within the app.

Kumar

On Mar 13, 3:11 pm, "Davide P. Cervone" <d...@union.edu> wrote:
> OK, good that javascript is working.  Tom points out that there may be
> an issue loading external URLs.  Can you check that by putting the
> alert into a separate javascript file on a server somewhere and see if
> that works?
>
> You may need to use a local copy of MathJax, in which case you may
> want to slim it down a bit first.  See
>
>        http://new2objectivec.blogspot.com/2012/03/tutorial-how-to-setup-math...

Kumar Thiagarajan

unread,
Mar 13, 2012, 10:30:01 PM3/13/12
to MathJax Users
Davide, I replied too soon. There was a typo. All three alerts are
working.

Davide P. Cervone

unread,
Mar 14, 2012, 9:06:38 AM3/14/12
to mathja...@googlegroups.com
OK, then it looks like MathJax stands a good chance of working in the
App.

The next thing to do is insert

<script>
alert("MathJax = "+window.MathJax);
</script>

in the file after MathJax.js is loaded and see if the alert shows that
the MathJax object has been defined. If yes, then try

<script>
MathJax.Hub.Queue(function () {alert(MathJax.Message.Log())});
</script>

to see if what messages are being produced.

You could also try adding

<script type="text/x-mathjax-config">
alert("Processing Config");
var mj_output = "";
MathJax.Hub.Startup.signal.Interest(function (message) {mj_output +=
"Startup: "+message+"\n"});
MathJax.Hub.signal.Interest(function (message) {mj_output += "Hub:
"+message+"\n"});
MathJax.Hub.Queue(function () {alert(mj_output)});
</script>

BEFORE the script that loads MathJax.js. This should get you a long
list of actions that MathJax has taken.

Send me the results and we'll see what we can figure out.

Davide

Thomas Leathrum

unread,
Mar 14, 2012, 10:34:26 AM3/14/12
to mathja...@googlegroups.com
I would suggest one more test:  that you put the alert() call into a Javascript file in a *different* directory from your HTML file, with an appropriate URL in the src attribute for the script tag, and make sure it still works.  If it doesn't, then you may need the copy of the MathJax directory to reside in the same place as the HTML and other stuff for the purposes of iWebKit.  This would be a bit of a nuisance in the long run, because it means that if you are developing several apps, each one would need its own copy of MathJax.  This is where Davide's suggestions for minimizing the MathJax directory could become really important.  So run the test and let us know what happens.

Kumar Thiagarajan

unread,
Mar 14, 2012, 11:29:43 PM3/14/12
to MathJax Users
The first alert showed MathJax = [object Object]
The second and the third ones that were added before the script that
loads MathJax.js don't seem to work.

Kumar

Kumar Thiagarajan

unread,
Mar 14, 2012, 11:42:00 PM3/14/12
to MathJax Users
Having multiple copies of slimmed down version of MathJax is not a
viable solution. I still put the alert call into a js file in a
different directory and it worked fine.

Davide P. Cervone

unread,
Mar 15, 2012, 8:58:22 AM3/15/12
to mathja...@googlegroups.com
OK. For the second and third, will you wait 15 seconds before giving
up on them? It may be that MathJax timing out trying to load the
configuration file and that takes 15 seconds (it will seem like
forever).

Are you loading a configuration file with config=filename, or do you
do inline configuration?

Try the following:

<script type="text/x-mathjax-config">
alert("Processing Config");

</script>
<script src="path-to-mathjax/MathJax.js"></script>

where "path-to-mathjax" is the location of your copy of MathJax. You
should get the alert, and also a warning message that no configuration
was specified.

I'm wondering if MathJax's method of loading external files is not
working. Can you do the following: create a file called alert.js (in
the same directory as the HTML file) containing the line

alert("External file loaded");

and then put

<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "alert.js";
document.getElementsByTagName("head")[0].appendChild(script);
})()
</script>

in the main HTML file and see if you get the alert from the external
file.

Do you get an error console anywhere that you can check for javascript
errors? If so, when you use MathJax do you get any errors?

kum...@gmail.com

unread,
Mar 15, 2012, 10:21:20 PM3/15/12
to mathja...@googlegroups.com
I did wait for more than 15 seconds. No luck.

The "External file loaded!" message comes up. I, in fact, had this file in a different directory. The Processing Config alert is, however, not displayed.

MathJax seems to be getting loaded. That is why the alert is seeing that as an object. If I misspell the directory name, for example, I get an "undefined" message.

I have tried both config=TeX-AMS_HTML-full and inline configuration.

Davide P. Cervone

unread,
Mar 16, 2012, 9:42:59 AM3/16/12
to mathja...@googlegroups.com
OK, it looks like something must be going wrong with MathJax itself, then.  That is going to be harder to diagnose.  

Do you have any kind of error console where javascript errors are reported?   If not, you can add

<script>
window.onerror = function(message, url, linenumber) {
  alert("JavaScript error: " + message + " on line " + linenumber + " for " + url);
}
</script>

so that javascript errors will cause alerts reporting the error.  See if there is anything reported for MathJax.js.

Did you keep the unpacked directory, or did you delete it?  If it is still there, then switching to unpacked/MathJax.js rather than MathJax.js will give better line numbers.

Let me know if this shows anything.  If not, then we'll have to try editing MathJax.js to do some debug reporting.

Davide

kum...@gmail.com

unread,
Mar 16, 2012, 5:51:36 PM3/16/12
to mathja...@googlegroups.com
I added this script and I got the following error:

SECURITY_ERR: DOM Exception 18: An attempt was made to break through the security policy of the user agent on line 0 for undefined.

I did delete the unpacked directory.

Davide P. Cervone

unread,
Mar 19, 2012, 6:52:11 AM3/19/12
to mathja...@googlegroups.com
OK, that error is frequently associated with cross-domain security issues.  Are you getting MathJax from the same domain as the web page you are using it from?  Perhaps at this point it would be reasonable to describe the setup in more detail.  What is the directory structure you are using, and what does the page you are using look like?  Are you loading MathJax as part of the page, or injecting it later?  

Davide

Thomas Leathrum

unread,
Mar 19, 2012, 3:03:23 PM3/19/12
to mathja...@googlegroups.com
That error is an indication of a violation of the browser's same-domain security policy, as Davide suggests (and as I have been afraid all along would turn out to be the case).  This can also be triggered by using "file://" URL's -- in particular, if you use a "file://" URL to load a script, and the script loads another script, even if the two scripts are in the same directory, the browser often triggers a violation of this policy (depending on the browser).  MathJax loads several components from the main script, so if you are using a "file://" URL to load MathJax.js, you will get this violation.  You can probably turn off this particular security setting in your browser, but that is something that must be done on the user end, not something a script can do for you.  There are two other options:  1) if you can rely on having an internet connection, use the CDN; or 2) if you can't rely on having an internet connection, install local server software (something like XAMPP) and install MathJax in the server's directories -- then you can use URLs with "http://localhost/..." or "http://127.0.0.1:8080/...".  If you use the second option, you just need to remember to turn the server on before you start using the pages with MathJax.  If you are building to standalone apps, you may be able to get the app to launch the local server as needed.  I use this second option quite a bit on my Android tablet (with the PAW server app), albeit for reasons that go far beyond just MathJax (I do a lot with PHP, too).

Davide P. Cervone

unread,
Mar 20, 2012, 3:19:49 PM3/20/12
to mathja...@googlegroups.com
I'm wondering if this discussion 


is related to your issue?  In particular setting the base URL seems to have an effect on whether MathJax can be loaded.  It may be the local v. server issue that Tom mentioned.

Davide



On Mar 16, 2012, at 5:51 PM, kum...@prazas.com wrote:

Reply all
Reply to author
Forward
0 new messages