![]() |
Example of a plug-in with C++ code | ![]() |
Consider the example of the minimal plug-in in the directory
$TEXMACS_PATH/examples/plugins
It consists of the following files:
minimal/Makefile
minimal/progs/init-minimal.scm
minimal/src/minimal.cpp
In order to try the plug-in, you first have to recursively copy the directory
$TEXMACS_PATH/examples/plugins/minimal
to $TEXMACS_PATH/plugins or $TEXMACS_HOME_PATH/plugins. Next, running the Makefile in the copied directory using
make
will compile the program
minimal.cpp
and create a binary
minimal/bin/minimal.bin
The Makefile simply runs g++ on each file in src and expects the directory bin to exist (create it using mkdir bin if necessary). When relaunching TeXmacs, the plug-in should now be automatically recognized. Notice that TeXmacs has to be restarted after the compilation: the bin directories of plug-ins are only added to the PATH at startup, and the result of the :require test is cached (use Tools\(\rightarrow\)Update\(\rightarrow\)Plugins if the plug-in is still not recognized).
The minimal plug-in demonstrates a minimal interface between TeXmacs and an extern program; the program
minimal.cpp
is explained in more detail in the chapter about writing interfaces. The initialization file
init-minimal.scm
essentially contains the following code:
(plugin-configure minimal
(:require (url-exists-in-path? "minimal.bin"))
(:launch "minimal.bin")
(:session "Minimal")) |
The :require option checks whether minimal.bin indeed exists in the path (so this will fail if you forgot to run the Makefile). The :launch option specifies how to launch the extern program. The :session option indicates that it will be possible to create sessions for the minimal plug-in using Insert\(\rightarrow\)Session\(\rightarrow\)Minimal.