Latex and wxpython

Hi everybody!

I'm very new to python and wxpython (one month of experience with python and
one week with wxpython). However, I managed to put together all the pieces of
info I need to write and run my script, except for one:

Can you use latex in wxpython? Can I set the window frame or a StaticText bot
to, let's say, r'$\gamma_{max}$'?

If I do something like this:

self.lblname = wx.StaticText(self, -1, r'$\gamma_{max}$',wx.Point(20,60))

I get $\gamma_{max}$ and not its latex equivalent.

Cheers!

Andrea

Andrea Canidio wrote:

I'm very new to python and wxpython (one month of experience with python and
one week with wxpython). However, I managed to put together all the pieces of
info I need to write and run my script, except for one:

Can you use latex in wxpython? Can I set the window frame or a StaticText bot
to, let's say, r'$\gamma_{max}$'?

If I do something like this:

self.lblname = wx.StaticText(self, -1, r'$\gamma_{max}$',wx.Point(20,60))

I get $\gamma_{max}$ and not its latex equivalent.
  
No, of course not. The only application that understands LaTeX code is
a LaTeX compiler.

The Greek lower case "gamma" is Unicode U+03B3. You should be able to use
    self.lblname = wx.StaticText( self, -1, u"\u03B3max", wx.Point(20,60) )
assuming your dialog font supports that glyph.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Andrea Canidio wrote:

Hi everybody!

I'm very new to python and wxpython (one month of experience with python and one week with wxpython). However, I managed to put together all the pieces of info I need to write and run my script, except for one:

Can you use latex in wxpython? Can I set the window frame or a StaticText bot to, let's say, r'$\gamma_{max}$'?

If I do something like this:

self.lblname = wx.StaticText(self, -1, r'$\gamma_{max}$',wx.Point(20,60))

I get $\gamma_{max}$ and not its latex equivalent.

You can combine a edit box with an image,
on every character you type,
call mimetex with a fixed image name
and then load the image.
I've done this in Delphi,
and it works quit well.

cheers,
Stef

···

Cheers!

Andrea
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

I don't think that deserves an "of course" -- Python seems to have modules for everything including the kitchen sink; I'm somewhat surprised myself that there isn't a LeTeX module that can draw arbitrary TeX into any graphics context.

Best,
- Joe

···

On Dec 5, 2008, at 10:54 AM, Tim Roberts wrote:

No, of course not. The only application that understands LaTeX code is
a LaTeX compiler.

Hi Andrea,

I have an unfinished project that used mathtext fom matplotlib with
some success. I vaguely remember a Google summer of code project
related to this but I cannot provide any more details, you may want to
explore that further.

This is how I did it:
Generated images then painted them on a DC. Not quite StaticText but
could be useful!

Example:

import wx
import mathtext

class LaTex:
    def __init__(self, rawText, pos = (0, 0), size = 72):
        self.laTexParser = mathtext.MathTextParser('Bitmap')
        self.rawText = rawText
        self.pos = pos
        self.size = size
        self.setImage()

    def setImage(self):
        img = self.laTexParser.parse(self.rawText, self.size)
        img = wx.ImageFromData(img.get_width(), img.get_height(),
img.as_rgb_str())
        self.img = wx.BitmapFromImage(img)

    def draw(self, dc):
        dc.DrawBitmap(self.img, self.pos[0], self.pos[1])

s = r"$\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!"
test = LaTex(s)
test.draw(your_DC_here)

Regards,

Fahri Basegmez

···

On Fri, Dec 5, 2008 at 10:46 AM, Andrea Canidio <acanidio@gmail.com> wrote:

Hi everybody!

I'm very new to python and wxpython (one month of experience with python and
one week with wxpython). However, I managed to put together all the pieces of
info I need to write and run my script, except for one:

Can you use latex in wxpython? Can I set the window frame or a StaticText bot
to, let's say, r'$\gamma_{max}$'?

If I do something like this:

self.lblname = wx.StaticText(self, -1, r'$\gamma_{max}$',wx.Point(20,60))

I get $\gamma_{max}$ and not its latex equivalent.

Cheers!

Andrea
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Hi Everybody,

thank you for your answers! In fact, I asked because I was expecting wxpython
to be able to handle latex more or less like matplotlib, but I couldn't make
it work.

For now I'll probably stay with the 'easy' method: combine an image and an
edit box, as suggested by Stef. But as soon as I have some time I'll try to
look into Fahri suggestion.

Cheers

Andrea

···

On Friday 05 December 2008 01:14:05 pm Stef Mientki wrote:

Andrea Canidio wrote:
> Hi everybody!
>
> I'm very new to python and wxpython (one month of experience with python
> and one week with wxpython). However, I managed to put together all the
> pieces of info I need to write and run my script, except for one:
>
> Can you use latex in wxpython? Can I set the window frame or a StaticText
> bot to, let's say, r'$\gamma_{max}$'?
>
> If I do something like this:
>
> self.lblname = wx.StaticText(self, -1, r'$\gamma_{max}$',wx.Point(20,60))
>
> I get $\gamma_{max}$ and not its latex equivalent.

You can combine a edit box with an image,
on every character you type,
call mimetex with a fixed image name
and then load the image.
I've done this in Delphi,
and it works quit well.

cheers,
Stef

> Cheers!
>
> Andrea
> _______________________________________________
> wxpython-users mailing list
> wxpython-users@lists.wxwidgets.org
> http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Andrea Canidio wrote:

Can you use latex in wxpython? Can I set the window frame or a StaticText bot to, let's say, r'$\gamma_{max}$'?

the short answer in no.

However there are a few options:

Matplotlib (MPL) can optionally render TeX, and MPL can be embedded in wx (google wxmpl for a good way to do that). With MPL there are two options:
  1) having MPL call LaTeX itself, which means you need a working TeX installaion, but get full LaTeX support.
  2) using the built in, written in python, TeX implimentation, which is massibly more limted but will do basic simple math.

MPL is really a plotting package, and the TeX stuff is designed to support putting simple equations on a plot, so it's probably not going to do well if you want a lot of support.

Ideally, you could pull code out of MPL to do the same thing directly on a wxWindow.

PyX might be worth looking at:
http://pyx.sourceforge.net/
though it looks like it's really only designed for generating PS, which wont' help you much.

TeX ultimately produced DVI. It wouldn't be all that hard to write a DVI renderer for wx (and I think I've seen some mention of such a thing somewhere...), which would let you use TeX as a layout engine for a wxPython app -- it could be really nice. It would require a working TeX install, which is a major dependency, but TeX really isn't designed to be embedded.

Similarly, dvipng is a utility that comes with many TeX distributions that turns a dvi file into a PNG, that could then be rendered by wxPython. I think this is how MPL does it.

tkDVI looks promising -- it's for TCL/Tk, but the author appears to have written the core DVI handling code in C, with the idea that it could be wrapped for other languages:

http://ctan.binkerton.com/ctan.php?filename=dviware/tkdvi/tkdvi-etcl2K.pdf

pyTex:
http://www.pytex.org/

this looks like it hasn't been updated since 2005, but you might want to get in touch with the author and see what's up with it.

-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