i wrote a package which provides a new command called \QJinclude. This command is to be used instead of \includegraphics when i actually do not want to include the original eps-graphic but the new eps graphic which is created by the script. This python script takes the original pic picname, edits it and creates a new pic called picname-QJ.eps . Then the command \includegraphics{picname-QJ.eps} follows. But when i run pdflatex an error appears from the package epstopdf that claims that there would not be that file picname-QJ.eps. However when i look in the directory i can see that the file exists. If i run pdflatex again there are no more problems and the eps gets converted to pdf.
My guess is that latex calls the script and heads to the next command instead of waiting for the script to be finished. That way the file would not yet be created and creates an error.
As the data given to the python script is dynamic, pdflatex would probably be to run many times. Besides it is not very nice to get errors all the time. Can anyone help me with this?

edit: Oh and i almost forgot: You can see that i call the script by \write18{python QJchem.py}. This of course will only work on Linux. Does anybody know how to put this for a windows user?
Code: Select all
\newcommand{\QJinclude}[3][]{%
\newwrite\myfile%
\immediate\openout\myfile=pythonjob.out%
\write\myfile{#3}% Data for the script to edit the pic
\closeout\myfile%
\newwrite\myfile%
\immediate\openout\myfile=QJfile.out%
\write\myfile{#2}% Tells the script which pic to edit
\closeout\myfile%
\write18{python QJchem.py}%
\includegraphics[#1]{#2-QJ.eps}%
}%
Code: Select all
#!/usr/local/bin/python
import os,re,sys,time,tempfile
sys.path.append(os.getcwd())
fileext = ".eps"
arr = []
c = open("pythonjob.out", "r")
text = c.read()
text = text.replace(";", "")
text = text.replace("\n", "")
for B in text.split():
arr.append(B)
c.close()
d = open("QJfile.out", "r")
text = d.read()
file = text.replace("\n", "")
d.close()
f = open(file + fileext, "r")
text = f.read()
f.close()
counter = 0
while counter <= len(arr)-1:
m = re.search(r"QJ\d{1,}", text)
text = text.replace(m.group(0), arr[counter])
counter = counter + 1
ff = open(file + "-QJ" + fileext, "w")
ff.write(text)
ff.close()
exit()