\externalcommand?
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? thanks again for help...
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
Aditya Mahajan wrote:
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. ...
good text for the wiki Hans -- ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On Fri, 5 Jan 2007, Hans Hagen wrote:
Aditya Mahajan wrote:
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. ...
good text for the wiki
Added: http://wiki.contextgarden.net/Executesystemcommand Aditya
On 2007-01-04, at 23:10.0, Aditya Mahajan wrote:
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.
I'm really grateful for your continuing help. Thanks - and I've got this working fairly easily. I'm trying to work out what ConTeXt does when it reads in the text that the external program writes to the tmp.out file... It might be that I have to output some TeX commands to the tmp.out file rather than just plain text. That will require one of the other methods, i think. plenty to do this weekend! ;-)
On Fri, 5 Jan 2007, cormullion@mac.com wrote:
On 2007-01-04, at 23:10.0, Aditya Mahajan wrote:
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.
I'm really grateful for your continuing help. Thanks - and I've got this working fairly easily. I'm trying to work out what ConTeXt does when it reads in the text that the external program writes to the tmp.out file...
basically \input reads a file and treats the material as if it were written in the tex file.
It might be that I have to output some TeX commands to the tmp.out file rather than just plain text.
That is what we do in t-vim module. The 2context.vim script writes a file that tex can understand.
That will require one of the other methods, i think.
Another option is \typefile{tmp.out} which will display the file verbatim, or \typevimfile[syntax=txt]{tmp.out} using txt.vim from http://www.vim.org/scripts/script.php?script_id=1532 Aditya
participants (3)
-
Aditya Mahajan
-
cormullion@mac.com
-
Hans Hagen