LyXPython-generated diagram as "external material"

Information and discussion about LyX, a WYSIWYM editor, available for Linux, Windows and Mac OS X systems.
Post Reply
del
Posts: 1
Joined: Mon Mar 08, 2010 2:59 pm

Python-generated diagram as "external material"

Post by del »

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:

Code: Select all

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". 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:

Code: Select all

\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).

Any ideas what I am doing wrong? I am running Lyx 1.6.3 on Windows XP.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Post Reply