Rendering LaTeX in a wxPython application

Hi,

Short version:
I have documentation (which includes mathematical and technical text) in the form of a LaTeX source, and I need to present selected portions of this to my users as context sensitive help. The solution that comes to mind for me is to render the appropriate sections on some variety of Frame on demand.
For this approach to be meaningful it’s pretty much necessary for the text to wrap naturally as most sections would cover from a few lines to about half a page on A4 paper ( i.e. circa 20 cm wide, circa 30 cm high ).
There has been discussions about doing things similar to this, but it’s a while ago and the material I have found so far can basically be divided into
1.) suggestions for hacks that provide some pretty limited functionality,
and
2.) old ideas and plans about writing ‘official’ code for wxPython to do this task well.

Is there now a good way to render LaTeX in a wxPython? If not, could you suggest alternative approaches for my particular task?

A bit more background:
The software in question is a somewhat complicated beast for physics simulations. (I’m writing some pieces of GUI for what has up until now been a pure command line application). Since the learning curve is high, we want to help new users out by giving them the option of viewing a Frame with the relevant piece of documentation when they select a field for editing. Since updating manuals can be discouraging enough to do once, it’s pretty much a requirement that the descriptions displayed in this help function should be pulled from the manual source, which is the place that will be updated as the software is developed; hence the format. Some of the sections also contain mathematical expressions that look better and are much more readable if some symbols are used rather than being described in pure text, and this is another reason something like LaTeX would be useful.

I am currently trying to show the help using the capabilities of wxmpl, following Christopher Barker 's
suggestion in the thread “Latex and wxpython”
( https://groups.google.com/group/wxpython-users/browse_thread/thread/bd56870c64c840b9?hl=en&noredirect=true&pli=1 ),
but as far as I can tell this does not seem to be suitable for more than one-liners, and adds the complications of placing the text in the right place on what is basically a plotting canvas. Notably, I have not found any way to make text wrap or otherwise fit itself to the frame without using a lot of ugly manual workarounds.

The discussion in “TeX/PDF. Was: ideas for Andrea” (https://groups.google.com/group/wxpython-users/browse_thread/thread/708579f63de00167?hl=en&noredirect=true ) seems somewhat relevant as well, but it doesn’t really offer anything I could turn in to a solution. What is the situation on viewing pdf in wxPython today?

Again, I need some help here. Do you have suggestions for handling LaTeX in wxPython? Or ideas for how to turn LaTex source into something that’s better to handle in wxPython?

Here’s a hack thread: https://groups.google.com/forum/?fromgroups=#!topic/wxpython-users/M74UiYhxxfo

It talks about using matplotlib to generate pngs or render straight to the screen, but it only uses a subset of LaTeX. Here’s the link that one of the fellows pointed to: http://matplotlib.sourceforge.net/users/usetex.html#usetex-tutorial

  • Mike
···

On Wednesday, August 29, 2012 7:19:26 AM UTC-5, mirari wrote:

Hi,

Short version:
I have documentation (which includes mathematical and technical text) in the form of a LaTeX source, and I need to present selected portions of this to my users as context sensitive help. The solution that comes to mind for me is to render the appropriate sections on some variety of Frame on demand.
For this approach to be meaningful it’s pretty much necessary for the text to wrap naturally as most sections would cover from a few lines to about half a page on A4 paper ( i.e. circa 20 cm wide, circa 30 cm high ).
There has been discussions about doing things similar to this, but it’s a while ago and the material I have found so far can basically be divided into
1.) suggestions for hacks that provide some pretty limited functionality,
and
2.) old ideas and plans about writing ‘official’ code for wxPython to do this task well.

A quick google of “latex to html” shows a number of free tools for doing this conversion. So, run a cron job once a day, at 3am or something that converts your manual to html, and display that in a wx.htmlwindow.

···


Best Regards,
Michael Moriarity

On Wed, Aug 29, 2012 at 5:19 AM, mirari

Is there now a good way to render LaTeX in a wxPython?

full featured? no.

following Christopher Barker's suggestion in the thread "Latex and wxpython"

being quoted means I kind of have to reply, yes :wink:

but as far as I can tell this does not seem to be suitable for more than
one-liners,

Indeed -- the TeX implementation in MPL is very limited, and designed
for putting small equations on a plot, and the like. In fact, it
doesn't support paragraph formatting and the like at all.

HOnestly, I doubt you'd ever be able to get a ful featured TeX system,
other than TeX itself, so if you want to support full-on LaTeX, you're
going to need TeX one way or another. There has been some noise about
an embedable TeX system, but last I looked, it was only noise. So you
need to either:

pre-render the LaTex to PDF or html -- pdf will look nicer, but you'll
pretty much have to rely on the system pdf renderer to show it -- I
don't hink there is a good embedded PDF render for wx. It's possible
that tex2html will produce old-fashioned enough html to render with
wxHTML -- that would be a nice controllable option for online help. If
not, you can embed the system browser, or use wxWebKit, which is
getting pretty mature:

https://gitorious.org/+wxwebkit-developers/webkit/wxwebkit

Another cool option would be to write a DVI renderer in wx -- not
trivial, but not impossible, either. And maybe someone has done a DVI
renderer in Python somewhere.

If you can rely on a system TeX installation, you can use tex2png or
dvipng, or???

archlinux.ca Tex2png

Then render the Pngs in wx on the fly.

Now that I think about it -- you could pre-render them, and then show
the pages that way -- each page of the doc could be a PNg file --
that could be pretty easy and look great.

HTH,

-Chris

···

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Thank you for a wealth of information and suggestions! That should do it.
For this task I don't think I'll need anything close to the full powers of TeX -- it's probably enough if the solution supports some definitions of custom commands and renders the math and symbols correctly (in addition to sensible handling of paragraphs, etc, as we have already mentioned).
At a first look I'm most inclined to go with conversion to HTML and displaying in wxHTML or wxWebKit. It seem to me that would require the least assumptions about the system and be nicely embeddable. The PNG option could be good as well.
It'll be a few days until I get the time to do this. I'll get back to you about how.

All the best until then!