Discussion:
[Matplotlib-users] Efficient matplotlib use on iOS and Android apps
asiga
2015-07-09 12:03:44 UTC
Permalink
Hi,

I need to render LaTeX math formulas on mobile apps (iOS/Android), with high
quality, and as efficiently as possible.

I'm considering matplotlib as the best candidate at the moment. Maybe it
might be a bit overkill because I don't need plotting, just math formulas
rendering, but it has a "copycenter" license (very welcome when you target
iOS), and it seems to render LaTeX math with high quality. So I think it
beats other options I found (MathGL: copyleft license; and MathJax: setting
a complete Javascript engine just for rendering math does seem overkill to
me).

However, I still have some doubts before choosing matplotlib:

1) Can I redirect the output of math rendering to OpenGL calls, or convert
it into a 2D triangle mesh for example? (if the drawing commands issued by
matplotlib when rendering math are a relatively small set, I can translate
them to OpenGL myself, but I need to know where should I do that translation
(I've zero idea about matplotlib internals, and I'm a Python newbie -I'm
here because I need math rendering, not because I use Python).

(note that I wish to render through OpenGL because I want to be able to
interactively pan and zoom math very efficiently: the best approach would be
to cache the matplotlib output as a -for example- 2D triangle mesh, and then
just send the triangles to OpenGL, without having to call matplotlib on each
screen redraw, which would kill performance)

2) In order to get matplotlib running as efficient as possible on mobile
devices, would you recommend that I translate matplotlib to C/C++ using any
of the translators available? If affirmative, what translator would you
suggest me to use?

Thanks a lot!!





--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Efficient-matplotlib-use-on-iOS-and-Android-apps-tp45901.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
Benjamin Root
2015-07-09 14:46:15 UTC
Permalink
why not use MathJax?
Post by asiga
Hi,
I need to render LaTeX math formulas on mobile apps (iOS/Android), with high
quality, and as efficiently as possible.
I'm considering matplotlib as the best candidate at the moment. Maybe it
might be a bit overkill because I don't need plotting, just math formulas
rendering, but it has a "copycenter" license (very welcome when you target
iOS), and it seems to render LaTeX math with high quality. So I think it
beats other options I found (MathGL: copyleft license; and MathJax: setting
a complete Javascript engine just for rendering math does seem overkill to
me).
1) Can I redirect the output of math rendering to OpenGL calls, or convert
it into a 2D triangle mesh for example? (if the drawing commands issued by
matplotlib when rendering math are a relatively small set, I can translate
them to OpenGL myself, but I need to know where should I do that translation
(I've zero idea about matplotlib internals, and I'm a Python newbie -I'm
here because I need math rendering, not because I use Python).
(note that I wish to render through OpenGL because I want to be able to
interactively pan and zoom math very efficiently: the best approach would be
to cache the matplotlib output as a -for example- 2D triangle mesh, and then
just send the triangles to OpenGL, without having to call matplotlib on each
screen redraw, which would kill performance)
2) In order to get matplotlib running as efficient as possible on mobile
devices, would you recommend that I translate matplotlib to C/C++ using any
of the translators available? If affirmative, what translator would you
suggest me to use?
Thanks a lot!!
--
http://matplotlib.1069221.n5.nabble.com/Efficient-matplotlib-use-on-iOS-and-Android-apps-tp45901.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Matplotlib-users mailing list
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
asiga
2015-07-10 08:37:46 UTC
Permalink
Why do you suggest MathJax? I assume Javascript will be less efficient than
Python. Moreover, I'm not sure I can get the MathJax output as polygonal
primitives that I can send to OpenGL. And, to complicate things, you cannot
use JIT Javascript engines on iOS such as V8, due to sandboxing.

In fact, I'm considering to build myself a minimal LaTeX distro. Maybe that
would be the best option.





--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Efficient-matplotlib-use-on-iOS-and-Android-apps-tp45901p45914.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
Benjamin Root
2015-07-10 15:01:47 UTC
Permalink
The way matplotlib does its MathText rendering is 1) incomplete (we don't
support all of MathTex), and 2) has *massive* overhead (relatively
speaking). Matplotlib is intended for producing figures with many disparate
components. The amount of code it takes to just generate a simple plot is
fairly significant (along with also firing up a python interpreter).
Meanwhile, MathJax is much lighter in the sense that all it needs to do is
parse a string and render out font characters.

As for matplotlib vs. MathJax, you will likely sending bitmaps to OpenGL
(if possible) anyway because that is pretty much what you will need to do
with matplotlib as well as MathJax. It is technically possible to obtain
the stroke data to send the font lines to OpenGL, but it will not look the
same as it would if you let a font renderer generate the bitmap. There are
a few reasons why matplotlib does not have an OpenGL backend yet, one of
them is because OpenGL does a terrible job in rendering text.

This is not to say that what you are thinking of doing is impossible to do.
It may be quite possible, but given that no one (that I am aware of) have
managed to get matplotlib running on a mobile OS, you have a huge
undertaking ahead of you just to get started. And, once you get there, it
is quite likely that the performance won't be what you need. In addition,
you might not like the resulting render. More power to you if you can get
it working, and I know many people who are interested in getting that stack
working on tablets and such.

On the other hand, there are plenty of documentation on how to build mobile
apps that take advantage of javascript-based technologies. Your startup
cost is very low here. And given that you will likely going to need to use
bitmaps anyway, it might not be all that bad of an option. I have no clue
what the performance penalty of firing up a javascript renderer on a mobile
OS, but in the face of the unknown, I avoid guessing. Don't fall victim to
premature optimization. I have been very surprised at how fast certain
(slow) technologies can be.

A minimalist LaTeX distro is an intriguing idea. I have no clue how much
effort it would take to do that, but that may be quite feasible.

Best of luck to you, and I look forward to finding out what you manage to
get working.

Cheers!
Ben Root
Post by asiga
Why do you suggest MathJax? I assume Javascript will be less efficient than
Python. Moreover, I'm not sure I can get the MathJax output as polygonal
primitives that I can send to OpenGL. And, to complicate things, you cannot
use JIT Javascript engines on iOS such as V8, due to sandboxing.
In fact, I'm considering to build myself a minimal LaTeX distro. Maybe that
would be the best option.
--
http://matplotlib.1069221.n5.nabble.com/Efficient-matplotlib-use-on-iOS-and-Android-apps-tp45901p45914.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Matplotlib-users mailing list
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Loading...