Equation box

Hi Flavio,

On an unrelated note, you will be happy to know that wxagg will be
included in the next release, probably early next week. It's
currently in CVS if you want to get started right away. font support
has been thoroughly revised and improved by Paul Barrett, and these
changes are not currently documented, so be don't be surprised if you
get some unexpected font warnings in the CVS version.

    > Hi john , I was doing a pure TeX plot (a bunch of
    > equations inside a box) and I noticed that the
    > \sqrt{}command does not work even though it listed in the
    > help page for mathtext.

    > \frac and \dfrac would be a nice addition too...

Agreed. And I guess asking for &=& array layout will be coming soon
:slight_smile:

    > feel free to used this little script as an example of
    > another use of mathtext...

I will - they look nice! If you add more to it, be sure to send me
the updated version.

John Gill has written a Cell class for his Table class which is
basically a rectangular box with a text instance inside. It might be
nice to generalize that code to allow multiple lines of text to be
added

  cell.add_line(t1)
  cell.add_line(t2)

Cell already handles autosizing of the box to surround the text, and
you wouldn't have to mess with turning off the ticks, etc.... John
might be willing to do this, and it could be wrapped in a nice
interface command textbox.

    > Flavio """ This script create a box with a series of
    > equations

Your code revealed one bug unrelated to the sqrt problem you
described, but you need to make the change below to have your example
render properly. In mathtext.py, in the function math_parse_s, change

    maxoy = max(oys)

to
    maxoy = abs(max(oys))

Now on to your script. A couple of minor comments first

  text(1,9,r'$dx/dt = \alpha y^{2}$', fontsize=15)
  
the brackets for superscripts are not required; eg, the following is
ok

  text(1,9,r'$dx/dt = \alpha y^2$', fontsize=15)

Normally math functions like sin, cos, exp are in roman type, so I
would use

  text(1,7,r'$dz/dt = \gamma x^2+\rm{sin}(2\pi y+\phi)$', fontsize=15)

As for sqrt, the mathtext syntax differs from TeX. The main reason is
that I don't draw an overbar with the sqrt symbol group, though this
is something I can add (probably when I get around to dealing with
frac, etc, all of which require some additional drawing and layout).
The point is, you can't use the curly brackets with sqrt or you get a
(silent) parse error. I'll try and amend the parser to allow the
group.

In the meantime, just do

  text(1,5,r'$\phi = zy + \Sqrt\alpha\beta $', fontsize=15)

I noticed there is a small clipping bug with sqrt. There are still
some hacks in the way I layout the cmex fonts which are discussed in
the mathtext documentation - the clipping problem likely arises from
this hack.

Also, note that spaces are respected in font mode, so a hackish way to
include them is \rm{ }. I've put adding the TeX small space command
\/ on the (growing at an alarming rate) TODO list. So if you want a
space after zy, you can do

  text(1,5,r'$\phi = zy\rm{ } + \sqrt\alpha\beta $', fontsize=15)

That's it; here is the modified script that looks great!

from matplotlib.matlab import *
figure(1, figsize=(5,5), dpi=100)
subplot(111)
plot([0])

a=axis([0,10,0,10])
title('Equation Box')
set(gca(),'xticklabels',[])
set(gca(),'yticklabels',[])
set(gca(),'xticks',[])
set(gca(),'yticks',[])

text(1,9,r'$dx/dt = \alpha y^2$', fontsize=15)
text(1,8,r'$dy/dt = \beta x^2$', fontsize=15)
text(1,7,r'$dz/dt = \gamma x^2+\rm{sin}(2\pi y+\phi)$', fontsize=15)
text(1,5,r'$\phi = zy\rm{ } + \sqrt\alpha\beta $', fontsize=15)

show()

Hi John,

*

Hi Flavio,
On an unrelated note, you will be happy to know that wxagg will be
included in the next release, probably early next week.*

That’s great news! I really need to include that equation box in my wx app.

*
> \frac and \dfrac would be a nice addition too...
Agreed. And I guess asking for &=& array layout will be coming soon
:-)*

That would be great too!!

*I will - they look nice! If you add more to it, be sure to send me
the updated version.*

I surely will since this was just a simple draft, to see if it worked.

*
  John Gill has written a Cell class for his Table class which is
basically a rectangular box with a text instance inside. It might be
nice to generalize that code to allow multiple lines of text to be
added
cell.add_line(t1)
cell.add_line(t2)
Cell already handles autosizing of the box to surround the text, and
you wouldn't have to mess with turning off the ticks, etc.... John
might be willing to do this, and it could be wrapped in a nice
interface command textbox.*

Is this code already in the 0.52 release? if So, I’ll take a look at it!

*    Flavio> Flavio """ This script create a box with a series of
> equations
Your code revealed one bug unrelated to the sqrt problem you
described, but you need to make the change below to have your example
render properly. In mathtext.py, in the function math_parse_s, change
maxoy = max(oys)
to maxoy = abs(max(oys))
Now on to your script. A couple of minor comments first
text(1,9,r'$dx/dt = \alpha y^{2}$', fontsize=15)
the brackets for superscripts are not required; eg, the following is
ok
  text(1,9,r'$dx/dt = \alpha y^2$', fontsize=15)*

In TeX, the curly brackets are necessary when you want more than one character in the subscript or subscript. That’s why I had them there since I was, at first tryin to do a more complex example.

*
  Normally math functions like sin, cos, exp are in roman type, so I
would use
text(1,7,r'$dz/dt = \gamma x^2+\rm{sin}(2\pi y+\phi)$', fontsize=15)*

You are right, thanks.

*As for sqrt, the mathtext syntax differs from TeX. The main reason is
that I don't draw an overbar with the sqrt symbol group, though this
is something I can add (probably when I get around to dealing with
frac, etc, all of which require some additional drawing and layout).
The point is, you can't use the curly brackets with sqrt or you get a
(silent) parse error. I'll try and amend the parser to allow the
group.*

That would be a nice idea not to move away from standard TeX syntax…

*
  In the meantime, just do
text(1,5,r'$\phi = zy + \Sqrt\alpha\beta $', fontsize=15)
I noticed there is a small clipping bug with sqrt. There are still
some hacks in the way I layout the cmex fonts which are discussed in
the mathtext documentation - the clipping problem likely arises from
this hack.
Also, note that spaces are respected in font mode, so a hackish way to
include them is \rm{ }. I've put adding the TeX small space command
\/ on the (growing at an alarming rate) TODO list. So if you want a
space after zy, you can do*

Ok, TeX has a whole range of space commands that are import to tweak the layout of math expressions.

Does mathtext support formatting multiline strings? waht about TeX’s line break command ‘\’?

*
text(1,5,r'$\phi = zy\rm{ } + \sqrt\alpha\beta $', fontsize=15)
That's it; here is the modified script that looks great!*

Thanks again John, mathtext is a great piece of software, and a life saver for people like me that need to include math symbols in their software. I wish I could use it on other parts of my GUI such as menus, window titles and etc.

_
from matplotlib.matlab import *
figure(1, figsize=(5,5), dpi=100)
subplot(111)
plot([0])
a=axis([0,10,0,10])
title('Equation Box')
set(gca(),'xticklabels',[])
set(gca(),'yticklabels',[])
set(gca(),'xticks',[])
set(gca(),'yticks',[])
text(1,9,r'$dx/dt = \alpha y^2$', fontsize=15)
text(1,8,r'$dy/dt = \beta x^2$', fontsize=15)
text(1,7,r'$dz/dt = \gamma x^2+\rm{sin}(2\pi y+\phi)$', fontsize=15)
text(1,5,r'$\phi = zy\rm{ } + \sqrt\alpha\beta $', fontsize=15)
show()_

···

On Wed, 2004-04-07 at 13:16, John Hunter wrote:

*
I will - they look nice! If you add more to it, be sure to send me
the updated version.
John Gill has written a Cell class for his Table class which is
basically a rectangular box with a text instance inside. It might be
nice to generalize that code to allow multiple lines of text to be
added
cell.add_line(t1)
cell.add_line(t2)
Cell already handles autosizing of the box to surround the text, and
you wouldn't have to mess with turning off the ticks, etc.... John
might be willing to do this, and it could be wrapped in a nice
interface command textbox.*

I will take a look at this when i get some time.

It might be a week or two though – i do this stuff commuting on the train, but unfortunately my laptop recently had a hard drive failure, so I’m out of action for a while.

Looking forward to getting the latest matplotlib stuff up and running and trying out all this Agg stuff.

John