Displaying \frac{a}{b} in xlabel

Hi all,

How do I use \frac{a}{b} within labels ?

from pylab import *
from scipy import *
x = linspace(0,pi,20)
plot(x,sin(x))
title(r'\frac{\Theta}{2\pi}')
xlabel(r'\frac{\Theta}{2\pi}') # The output is not o.k.
show()

Am I missing something or is it a bug ?

matplotlib data path /usr/lib64/python2.4/site-packages/matplotlib/mpl-data
$HOME=/home/nwagner
CONFIGDIR=/home/nwagner/.matplotlib
ghostscript-8.15 found. ghostscript-8.16 or later is recommended for use
with the text.usetex option.
loaded rc file /home/nwagner/.matplotlib/matplotlibrc
matplotlib version 0.87.1
verbose.level helpful
interactive is False
platform is linux2
numerix numpy 0.9.6.2206
font search path ['/usr/lib64/python2.4/site-packages/matplotlib/mpl-data']
loaded ttfcache file /home/nwagner/.matplotlib/ttffont.cache
backend GTKAgg version 2.8.0

Nils

Hoi,

···

On Wednesday 08 March 2006 11:06, Nils Wagner wrote:

title(r'\frac{\Theta}{2\pi}')
xlabel(r'\frac{\Theta}{2\pi}') # The output is not o.k.

And the writing the title is working? Try
xlabel(r'\\frac\{\\Theta\}\{2\\pi\}')
instead.

Hope this helps.

Christian

This is not a bug. Please keep in mind that usetex is really only an interface
to latex. For problems specific to LaTeX, it would be best to consult the
appropriate sources or lists. As it happens, \frac is only allowed in math
mode. That it produced any output at outside of mathmode is a case of failing
silently.

Does anyone know how to catch exit status using os.popen and friends? LaTeX
would have returned an exit status of 1 for this example, which could be used
to raise a warning.

Darren

···

On Wednesday 08 March 2006 5:06 am, Nils Wagner wrote:

Hi all,

How do I use \frac{a}{b} within labels ?

from pylab import *
from scipy import *
x = linspace(0,pi,20)
plot(x,sin(x))
title(r'\frac{\Theta}{2\pi}')
xlabel(r'\frac{\Theta}{2\pi}') # The output is not o.k.
show()

Am I missing something or is it a bug ?

What does "The output is not o.k." mean?

The output is somewhat like \Theta \frac{}{2\pi}
If I use
xlabel(r'\\frac\{\\Theta\}\{2\\pi\}')

it works fine.

I think I got it. I had to play around a bit with a couple different
approaches. Part of the trick is that you have to run latex with
-interaction=nonstopmode, otherwise the child process never completes
and it seems like most of python's tools for capturing the errors and
outputs just hang.

Here is what I did:
import popen2
In [8]: latexcmd3=popen2.Popen3('latex -interaction=nonstopmode bad.tex')

In [9]: latexcmd3.wait()
Out[9]: 256

In [10]: latexcmd4=popen2.Popen3('latex -interaction=nonstopmode good.tex')

In [11]: latexcmd4.wait()
Out[11]: 0

where bad.tex and good.tex basically have just headers and
\frac{1}{\theta} with and without $$ around it. If I just use
os.popen3, the stderr object returned is empty in both cases:

In [14]: r,w,e=os.popen3('latex -interaction=nonstopmode good.tex')

In [15]: e.readlines()
Out[15]:

In [16]: r,w,e=os.popen3('latex -interaction=nonstopmode bad.tex')

In [17]: e.readlines()
Out[17]:

and to know there was a problem, you would have to parse w.readlines()
- and in this case it doesn't even say there is an error, it mentions
something about a missing $.

But it seems like creating your own Popen3 object and executing it
through the wait() command, returns 0 on a clean exit or 256 on the
bad ones (at least for this error). I have compiled one other good
file from my hard drive and it also returns 0.

Hope this helps,

Ryan

···

On 3/8/06, Darren Dale <dd55@...163...> wrote:

>> On Wednesday 08 March 2006 5:06 am, Nils Wagner wrote:
>>
>>> Hi all,
>>>
>>> How do I use \frac{a}{b} within labels ?
>>>
>>> from pylab import *
>>> from scipy import *
>>> x = linspace(0,pi,20)
>>> plot(x,sin(x))
>>> title(r'\frac{\Theta}{2\pi}')
>>> xlabel(r'\frac{\Theta}{2\pi}') # The output is not o.k.
>>> show()
>>>
>>> Am I missing something or is it a bug ?
>>>
>>
>> What does "The output is not o.k." mean?
>>
> The output is somewhat like \Theta \frac{}{2\pi}
> If I use
> xlabel(r'\\frac\{\\Theta\}\{2\\pi\}')
>
> it works fine.

This is not a bug. Please keep in mind that usetex is really only an interface
to latex. For problems specific to LaTeX, it would be best to consult the
appropriate sources or lists. As it happens, \frac is only allowed in math
mode. That it produced any output at outside of mathmode is a case of failing
silently.

Does anyone know how to catch exit status using os.popen and friends? LaTeX
would have returned an exit status of 1 for this example, which could be used
to raise a warning.

Darren

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmdlnk&kid0944&bid$1720&dat1642
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Hi Darren,

Does anyone know how to catch exit status using os.popen and friends?

You may want to switch to subprocess.py. It comes with Python 2.4, but
it's backwards compatible with Python2.3 (maybe older). We could just
include it alongside the modules that want to use it. It's pretty easy
to use and is meant to unify all the various ways of executing a subprocess.

Here's an example from some other code of mine (a recursive build tool
that seeks out directories with setup.py and builds them with
setuptools). It should be a good example of using subprocess.

    args = [sys.executable,'-c',"import setuptools; execfile('setup.py')"]
    args.extend(commands)
           
    print dir,':',' '.join(args)
    sub = subprocess.Popen(args,
                           cwd=dir,
                           stdout=subprocess.PIPE,
                           stderr=subprocess.PIPE,
                           )
    sub.wait()
    if sub.returncode != 0:
        print '-='*20
        print '*** The following call failed:'
        print args
        stdout = sub.stdout.read()
        if len(stdout):
            print '*** stdout was:'
            print stdout
        stderr = sub.stderr.read()
        if len(stderr):
            print '*** stderr was:'
            print stderr
        print '-='*20
        sys.exit( sub.returncode )

Thank you for the suggestion. How is it compatible with Python-2.3? Do you
mean we would include the source for that module in mpl?

···

On Wednesday 08 March 2006 12:07, you wrote:

Hi Darren,

>Does anyone know how to catch exit status using os.popen and friends?

You may want to switch to subprocess.py. It comes with Python 2.4, but
it's backwards compatible with Python2.3 (maybe older).

Darren Dale wrote:

···

On Wednesday 08 March 2006 12:07, you wrote:

Hi Darren,

Does anyone know how to catch exit status using os.popen and friends?
     

You may want to switch to subprocess.py. It comes with Python 2.4, but
it's backwards compatible with Python2.3 (maybe older).
   
Thank you for the suggestion. How is it compatible with Python-2.3? Do you
mean we would include the source for that module in mpl?

Yes, exactly.