> John K wrote:
>> 
>> 
>> I am trying to auto-generate a diagram from a Python script in my Lyx 
>> document using the "External Material" function. I have created a Python 
>> script called "myscript.py" which generates a diagram and saves it to 
>> "myscript.pdf". I am trying to make Lyx run my script to generate the 
>> diagram when I export my document to PDF.
>> 
>> I added the following to the Lyx external_templates file:
>> 
>> Template Python
>> GuiName "Python: $$AbsOrRelPathParent$$Basename"
>> HelpText
>> Python diagram.
>> HelpTextEnd
>> InputFormat "*"
>> FileFilter "*.py"
>> AutomaticProduction true
>> Preview Graphics
>> Format PDFLaTeX
>> Product "\\includegraphics{$$AbsPath$$Basename.pdf}"
>> Requirement "graphicx"
>> UpdateCommand "python $$AbsPath$$Basename.py"
>> UpdateFormat pdf
>> UpdateResult "$$AbsPath$$Basename.pdf"
>> Requirement "graphicx"
>> ReferencedFile pdflatex "$$AbsPath$$Basename.pdf"
>> FormatEnd
>> TemplateEnd
>> 
>> However, when I insert the Python script in Lyx, it draws a box that says 
>> "Error converting to loadable format".
> This isn't critical, it merely means you won't get a preview within LyX 
> because of a failure to convert to something displayable. (png, I believe.)
> 
> Of course, this may also be a symptom of what's wrong with the main 
> conversion.
> 
>> If I try exporting to PDF using pdflatex, I get the following error:
>> 
>> "Missing $ inserted. Missing { inserted. I've inserted a begin-math/end-math 
>> symbol since I think you left one out. Proceed, with fingers crossed."
>> 
>> If I export to Latex using pdflatex, it seems to export correctly, and my 
>> text file contains something like this:
>> 
>> begin{document}
>> \includegraphics{C:/Documents and Settings/MyUsername/Desktop/myscript.pdf}
>> \end{document}
>> 
>> However, it doesn't run my update command, i.e. doesn't run the Python 
>> script. (I've even tried changing my update command to things like "echo 
>> test> output.txt" but I can't seem to get any commands to run at all.)
>> 
> That is the problem, and I guess it explains why everything else goes 
> wrong too.
> 
> First thing to check: is python in the path? I.e. can you give the 
> command "python filename.py" on the command line - will that work?
> 
> If python isn't in the path, then LyX won't find it.

Yes, Python is on the path. I tried putting the full path to Python in the 
UpdateCommand as well but that didn't work either. I don't think it's a path 
issue because even a command like "echo test> output.txt" does not work.

> If this succeed, will the latex export then work, as long as  the 
> manually converted file is present?

If I first run the Python script manually and then try exporting the Lyx 
document to PDF (pdflatex), I still get this error:

"Missing $ inserted. Missing { inserted. I've inserted a
begin-math/end-math symbol since I think you left one out. Proceed,
with fingers crossed."

However, if I export to LaTeX (pdflatex), and then open this LaTeX file in 
TeXnicCenter, I can export to PDF with no problems and the Python-generated 
figure shows up correctly.

>> Any ideas what I am doing wrong? I've tried on Lyx 1.6.3 and 1.6.5-1 on 
>> Windows XP.
> 
> Another wild guess: You have a path with spaces in it, e.g. "Documents 
> and Settings". Some versions of LyX can't deal with that. Some can, but 
> you have to take care when a path is passed to external utilities (such 
> as python) Otherwise, you risk that:
> 
> python "C:\documents and settings\folder\file.py"
> becomes
> python "C:\documents" "and" "settings\folder\file.py"
> and the latter just won't work.
> 
> To check if you have space problems, copy the document and all files
> to some space-free path such as C:\test\
> See if that changes anything.

I tried putting everything in to the root directory C:\ but had the same 
problem.

J
                                          
_________________________________________________________________
Link all your email accounts and social updates with Hotmail. Find out now.
http://windowslive.ninemsn.com.au/oneinbox?ocid=T162MSN05A0710G

Reply via email to