iOS implementation - short list of steps

1,935 views
Skip to first unread message

Joel

unread,
Jul 31, 2011, 5:27:11 PM7/31/11
to MathJax Users
Hi, I was able to incorporate MathJax successfully in my iOS app
(www.touchyMath.com).

Background: my math typesetting needs are: parenthesis, fractions,
exponents, numbers, and variables. Pretty simple.

Here is a short list of the things I did:

1- Remove the PNG fonts... all of it. Delete.

2- Setup a template html file configured to use the slimed down
version of MathJax. I basically made a normal website and tested it on
a browser. In the initial setup and troubleshooting phases, the
template html had equations in latex so I could quickly see if it was
working or not.

3- Packaged the template html, css, and MathJax into a folder, then I
added this folder to the Xcode project as a “Create folder references
for any added folders” (this is an option you get when adding files to
an Xcode project, some refer to it as the ‘blue folder” approach) and
then made sure that it was copied into the resource bundle (target/
Build Phases/Copy Bundle Resources, if you do not see the MathJax
folder on the list, drag and drop it).

4- Setup a web view. To do this, I used the “TransWeb” sample code
from the iOS 4.3 Documentation Library.

5- Many iterations of CSS, html, and MathJax fine tuning until it
looked like I wanted on iOS.

Bugs:
- MathJax would try to load the image fonts in portrait mode but would
not do so in landscape mode. I decided not to jump into MathJax code
but to trick MathJax into thinking that it did not need to load the
image fonts: in portrait mode the Web View is 480 pt wide for a short
period of time (~0.5s) and then silently animate it to 320 pt. It
worked.

Davide P. Cervone

unread,
Aug 1, 2011, 9:19:44 AM8/1/11
to mathja...@googlegroups.com
Thanks for the details about how to load MathJax in an iOS app. I
know this is something that a number of people have been asking about.

A couple of comments below:

> 1- Remove the PNG fonts... all of it. Delete.

Just to be clear, this is the MathJax/fonts/HTML-CSS/TeX/png directory
and its contents.

If you do this, you should be sure to set

imageFont: null

in your configuration, to let MathJax know it should not try to use
them. See the MathJax documentation at

http://www.mathjax.org/docs/1.1/configuration.html#configuring-mathjax

for details about how to specify the configuration.

> Bugs:
> - MathJax would try to load the image fonts in portrait mode but would
> not do so in landscape mode. I decided not to jump into MathJax code
> but to trick MathJax into thinking that it did not need to load the
> image fonts: in portrait mode the Web View is 480 pt wide for a short
> period of time (~0.5s) and then silently animate it to 320 pt. It
> worked.

Setting imageFont to null will prevent the attempt to use image fonts,
but probably wouldn't solve the problem, since then it would default
to generic unicode fonts. I'm glad you worked out a solution, but I
don't understand why there is a problem. MathJax's detection of fonts
is a bit fragile, so it may be that something in the landscape mode
was interfering with that initially. Something for me to look into in
the future.

Davide

Joel Esli Martinez

unread,
Aug 1, 2011, 11:16:11 AM8/1/11
to mathja...@googlegroups.com
Hi Davide,

the imageFont: null is something I will try out and see if it solves the apparent bug I say.

About the bug: note that the landscape iPhone version had no problem at all, it was the portrait that ran into a problem. If you want more details, just ask and I will be happy to send them over (screenshots of the error messages or a screen recording of the error).

Would be happy to help.

Best - Joel

Davide P. Cervone

unread,
Aug 2, 2011, 2:13:18 PM8/2/11
to mathja...@googlegroups.com
> About the bug: note that the landscape iPhone version had no problem
> at all, it was the portrait that ran into a problem.

Right. I read your page too quickly. Sorry about that.

The font testing is a bit fragile. MathJax uses large versions of the
fonts, so perhaps the test strings are too wide to fit in the small
portrait screen. I will have to do some testing.

> If you want more details, just ask and I will be happy to send them
> over (screenshots of the error messages or a screen recording of the
> error).

Thanks for your offer to help. I may send you some things to try out,
when I get the chance to figure out what to try.

Davide

Joel Esli Martinez

unread,
Aug 3, 2011, 7:16:09 AM8/3/11
to mathja...@googlegroups.com

That is the folder that really inflates the size of MathJax from ~5 MB to over 100 MB.
> 1- Remove the PNG fonts... all of it. Delete. Just to be clear, this is the MathJax/fonts/HTML-CSS/TeX/png directory and its contents.

In the configuration file that I am using (TeX-AMS_HTML-full) I added
imageFont:null

but this had no impact on Mathjax trying to load imageFont.js after I turned my re-sizing workaround out.


Clarification about the Bug: it is not only about trying to load the image fonts.


> Bugs:
> - MathJax would try to load the image fonts in portrait mode but would
> not do so in landscape mode. I decided not to jump into MathJax code
> but to trick MathJax into thinking that it did not need to load the
> image fonts: in portrait mode the Web View is 480 pt wide for a short
> period of time (~0.5s) and then silently animate it to 320 pt. It
> worked.


Error messages
1- Loading \WebFont TeX/Main/Regular
2- Loading /[MathJax]jax/output/HTML-CSS/imageFonts.js
3- All equations on the page display [Math Processing Error] in red.

This problem is not encountered when opening the view in the landscape orientation.


IMG_1117.PNG
IMG_1118.PNG
IMG_1119.PNG

Davide P. Cervone

unread,
Aug 8, 2011, 8:16:41 AM8/8/11
to mathja...@googlegroups.com
> In the configuration file that I am using (TeX-AMS_HTML-full) I added
> imageFont:null

This must be in the "HTML-CSS" block of your configuration. So it
would be something like

MathJax.Hub.Config({
"HTML-CSS": {
imageFont: null
}
});

> but this had no impact on Mathjax trying to load imageFont.js after
> I turned my re-sizing workaround out.

This should prevent that (but it will just default to a generic
unicode configuration, which isn't what you want, either).

> Clarification about the Bug: it is not only about trying to load the
> image fonts.

Yes, but I was just trying to be clear about how one should handle not
installing the image fonts in general (since others will read this
thread in the future).


>> Bugs:
>> - MathJax would try to load the image fonts in portrait mode but
>> would
>> not do so in landscape mode. I decided not to jump into MathJax code
>> but to trick MathJax into thinking that it did not need to load the
>> image fonts: in portrait mode the Web View is 480 pt wide for a short
>> period of time (~0.5s) and then silently animate it to 320 pt. It
>> worked.
>
>
> Error messages
> 1- Loading \WebFont TeX/Main/Regular
> 2- Loading /[MathJax]jax/output/HTML-CSS/imageFonts.js
> 3- All equations on the page display [Math Processing Error] in red.
>
> This problem is not encountered when opening the view in the
> landscape orientation.

I think it may be that some of the tests for the fonts use large font
sizes and wide texts, and it might be that they are wrapping, which is
causing the font detection to fail. I'll have to look into it further.

Davide

Reply all
Reply to author
Forward
0 new messages