Could I suggest an alternative approach?... Since you're already taking the trouble to prepare entire tests using LaTeX, maybe an extra minute or two of manual work afterwards is acceptable. Here's the idea.
First step: use the latexrender procedure (see http://www.mayer.dial.pipex.com/tex.htm#latexrender
for more info) to create a gif as follows. Suppose your test is in quiz.tex. Then latex quiz.tex as usual. After that run dvips as dvips -E quiz.dvi -o quiz.ps to create quiz.ps postscript. Finally, use ImageMagick's convert utility as convert -density 120 -trim -transparent "#FFFFFF" quiz.ps quiz.gif to create a gif image of your quiz. (Note that you can produce many other graphic output formats, too, but we'll want gif.)
Second step (this is the tricky part): Suppose you'd like to "access" this quiz.gif file by typing the latex expression Quiz1 in moodle. Just find the md5 hash value of the string Quiz1 and rename your quiz.gif file as xxxxxx.gif where xxxxxx is the md5 hash. Now move that file into your moodle cache database
directory. Then, everytime you write Quiz1 as a LaTeX expression, Zig's scripts will get fooled into grabbing your file containing the entire quiz.
It's a bit kludgey, but maybe also a bit more convenient than what you're currently trying to implement. And, if you do find it convenient, I suppose you could write a short script to automate most of the required steps.