On Thu, 4 Jan 2007, cormullion@mac.com wrote:
I think there's something in ConTeXt called \externalcommand. Can this be used to hand over a section of source text for processing by an external program during the ConTeXt-ing of a document? How does it work, exactly?
There are two ways, \executesystemcommand and \installprogram. \executesystemcommand is equal to \immediate\write18 while \installprogram defines a program in the tui file which is then run before the next execution of texexec. I do not know what is the best source of their documenentation. \write is explained in the texbook, \write18 executes its argument on shell. luatex will have a better model for executing commands on the shell, and some of it is explained in the luatex manual. (But luatex is still pre-alpha, so the interface can change). \installprogram is not documented, you need to read cont-uti.tex and texutil.rb to understand how it works. I found ConTeXt sources to be the best way to understand how these things are working. See t-lilypond, which checks if write18 is enabled or not, and then uses \executesystemcommand or \installprogram. The module writes stuff to a temporary file, and then uses lilypond to get a ps/pdf which is included back in the document. Another example is m-r.tex which writes things to a temp file and runs them through R (a statistical program) and types the output. It also shows how you can capture the contents of an evironment to a temp file. I copied this idea in the t-vim module. Of course, the ConTeXt sources have plenty of examples. There is also core-buf where the buffer handling is implemented, and the sources related to metapost handling, which are perhaps the best example of how to go back and forth between tex and an external program. Perhaps the R module is easiest to understand. That method will work for most cases where you simply want to capture part of tex source and write it verbatim to a file, and then read the output back into tex. Aditya