I cannot provide a detailed solution right now, but here are some hints.
My solution relies on my filter
module, which provides a generic interface for running an external program on the content of an environment. To implement the same in LaTeX you need to
Write the contents on an environment to an external file. In LaTeX, the filecontents
package does that. In the filter module I do some book-keeping to automatically et the name of the output file.
Run the external program on the file. This step uses \write18
, which also works in LaTeX.
Read the result back, using a user supplied command.
Basically, the filter module provides the pluming to automate these steps. It also provides some goodies rerunning the external program only if the file has changed, storing all intermediate files in a subdirectory, and so on, but those are not essential.
For a one off solution, you should be able to use the filecontents package and \write18
.