This whole post deals with Python 2.7 on Windows. Your mileage may vary in other environments.
I’m doing some writing on the topic of hybrid automata, and it looks like the best way to generate figures of the automata in LaTeX is with GraphViz and the dot2texi package, which works with the very nice dot2tex tool to generate figures from GraphViz dot formatted code embedded directly in LaTeX.
One of the issues, however, is that it expects an executable called “dot2tex” to be available on the shell. This means that, first and foremost, shell escape needs to be enabled when compiling the document (–shell-escape in many distributions, and –enable-write18 in MiKTeX, which I use). Adding this line to the beginning of the LaTeX source will handle it:
%& --shell-escape --enable-write18
Next, since the executable file that’s installed (in Windows on Python 2.7 it goes, by default, to C:\Python27\Scripts\dot2tex) is made executable by a shebang on its first line, even if this file is on your path in Windows, it won’t do anything. So you need to use ExeMaker, which creates a very lightweight exe file to call a Python script. I put it in a directory that’s in my PATH (I made C:\Users\george\bin for this purpose) ran it like this:
C:\Users\george> rename C:\Python27\Scripts\dot2tex dot2tex.py C:\Users\george> exemaker C:\Python27\Scripts\dot2tex.py
In my case, this created dot2tex.exe and dot2tex.py in C:\Users\george\bin. However, running dot2tex.exe causes an error:
C:\Users\george>dot2tex
Traceback (most recent call last):
File "C:\Users\george\bin\dot2tex.py", line 6, in <module>
from dot2tex.dot2tex import main
File "C:\Users\george\bin\dot2tex.py", line 6, in <module>
from dot2tex.dot2tex import main
ImportError: No module named dot2tex
A bit of poking around reveals that this is due to the way that Python searches paths in import statements: the script, dot2tex.py, conflicts in its name with the module that we want to import, and the first directory that Python searches when looking for a file to import is the directory containing the executing script (or, in interactive mode, the working directory). The workaround I came up with, which seems to work well, is just to add two lines to dot2tex.py:
import sys del sys.path[0]
Now my dot2tex.py file (the one in C:\Users\george\bin) looks like this:
#!C:\Python27\python.exe
import site
import sys
del sys.path[0]
#!C:\Python27\python.exe
from dot2tex.dot2tex import main
if __name__ == '__main__':
main()
So far, this seems to have fixed all of my problems.