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