There are many ways in which TeXmacs can be customized or extended: users may define their own style files, customize the user interface, or write links with extern programs. The plug-in system provides a universal mechanism to combine one or several such extensions in a single package. Plug-ins are both easy to install by other users and easy to write and maintain.
From the user's point of view, a plug-in myplugin will usually be distributed on some web-site as a binary tarball with the name
myplugin-version-architecture.tar.gz
If you installed TeXmacs yourself in the directory $TEXMACS_PATH, then you should unpack this tarball in the directory $TEXMACS_PATH/plugins, using
tar -zxvf myplugin-version-architecture.tar.gz
This will create a myplugin subdirectory in
$TEXMACS_PATH/plugins. As soon as you restart TeXmacs,
the plug-in should be automatically recognized. If not, then click on
cd myplugin; make
or
cd myplugin; ./configure; make
rm -rf myplugin
and reinstall as explained above.
In order to write a plug-in myplugin, you should start by creating a directory
$TEXMACS_HOME_PATH/plugins/myplugin
where to put all your files (recall that $TEXMACS_HOME_PATH defaults to $HOME/.TeXmacs). In addition, you may create the following subdirectories (when needed):
For binary files.
For documentation.
For language related files, such as dictionaries (not yet supported).
For libraries.
For style packages.
For
For source files.
For style files.
As a general rule, files which are present in these subdirectories will be automatically recognized by TeXmacs at startup. For instance, if you provide a bin subdirectory, then
$TEXMACS_HOME_PATH/plugins/myplugin/bin
will be automatically added to the PATH environment variable at startup. Notice that the subdirectory structure of a plug-in is very similar to the subdirectory structure of $TEXMACS_PATH.
Similarly, plugin documentation is intended to be automatically added
to the
myplugin.en.tm myplugin-abstract.en.tm
The first file is the main entry point to the plugin's documentation and should follow the general conventions for structuring TeXmacs documentation. The -abstract file provides a short description of the plugin's functionality.
$TEXMACS_HOME_PATH/plugins/myplugin $TEXMACS_HOME_PATH/plugins/myplugin/styles $TEXMACS_HOME_PATH/plugins/myplugin/packages
and to put your style files and packages in the last two directories.
After restarting TeXmacs, your style files and packages will
automatically appear in the
For more complex plug-ins, such as plug-ins with additional
$TEXMACS_HOME_PATH/plugins/myplugin/progs/init-myplugin.scm
This configuration file should contain an instruction of the following form
(plugin-configure myplugin configuration-options)
Here the configuration-options describe the principal actions which have to be undertaken at startup, including sanity checks for the plug-in. In the next sections, we will describe some simple examples of plug-ins and their configuration. Many other examples can be found in the directories
$TEXMACS_PATH/examples/plugins $TEXMACS_PATH/plugins
Some of these are described in more detail in the chapter about writing new interfaces.
Consider the world plug-in in the directory
$TEXMACS_PATH/examples/plugins
This plug-in shows how to extend TeXmacs with some additional
world/progs/init-world.scm
In order to test the world plug-in, you should recursively copy the directory
$TEXMACS_PATH/examples/plugins/world
to $TEXMACS_PATH/plugins or $TEXMACS_HOME_PATH/plugins.
When relaunching TeXmacs, the plug-in should now be automatically
recognized (a
The file init-world.scm essentially contains the following code:
(plugin-configure world (:require #t)) (when (supports-world?) (display* "Using world plug-in!\n"))
The configuration option
Assuming that the configuration succeeds, the supports-world?
predicate will evaluate to #t. In our example, the
body of the
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/progs or $TEXMACS_HOME_PATH/progs. Next, running the Makefile using
make
will compile the program minimal.cpp and create a binary
minimal/bin/minimal.bin
When relaunching TeXmacs, the plug-in should now be automatically 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
Consider the example of the pyminimal plug-in in the directory
$TEXMACS_PATH/examples/plugins
It consists of the following files:
pyminimal/progs/init-pyminimal.scm pyminimal/src/minimal.py
In order to try the plug-in, you first have to recursively copy the directory
$TEXMACS_PATH/examples/plugins/pyminimal
to $TEXMACS_PATH/progs or $TEXMACS_HOME_PATH/progs.
When relaunching TeXmacs, the plug-in should now be automatically recognized.
The pyminimal plug-in demonstrates a minimal interface between TeXmacs and an extern program in python. The initialization file init-pyminimal.scm essentially contains the following code:
(define (python-launcher) (if (url-exists? "$TEXMACS_HOME_PATH/plugins/pyminimal") (string-append "python \"" (getenv "TEXMACS_HOME_PATH") "/plugins/pyminimal/src/minimal.py\"") (string-append "python \"" (getenv "TEXMACS_PATH") "/plugins/pyminimal/src/minimal.py\""))) (plugin-configure pyminimal (:require (url-exists-in-path? "python")) (:launch ,(python-launcher)) (:session "PyMinimal"))
The
The
python "$TEXMACS_HOME_PATH/plugins/pyminimal/src/minimal.py"
otherwise,
python "$TEXMACS_PATH/plugins/pyminimal/src/minimal.py"
The environment variables will be replaced in runtime. Sometimes,
Using the Python interpreter, we do not need to compile the code. And most of the time, python code can be interpreted without any modification under multiple platforms. The built-in python libraries are really helpful and handy.
Many TeXmacs built-in plugins are written in Python, and we have
carefully organized the code and reused the common part named
import os import sys from os.path import exists tmpy_home_path = os.environ.get("TEXMACS_HOME_PATH") + "/plugins/tmpy" if (exists (tmpy_home_path)): sys.path.append(os.environ.get("TEXMACS_HOME_PATH") + "/plugins/") else: sys.path.append(os.environ.get("TEXMACS_PATH") + "/plugins/")
The first part of the code just add
from tmpy.protocol import * from tmpy.compat import * flush_verbatim ("Hi there!") while True: line = tm_input() if not line: pass else: flush_verbatim ("You typed " + line)
This demo plugin is a Python implementation of the well-documented minimal plugin written in
pyminimal requires the
pyminimal is easier to install than minimal
pyminimal reuses the common part related to TeXmacs
pyminimal has better compatibility for
As explained before, the
(plugin-configure myplugin configuration-options)
Here follows a list of the available configuration-options:
Specify where to search for the plug-in under windows. The package-path is the usual place where the plug-in is installed. The inner-bin-path is the place where to look for the binary executable corresponding to the plug-in, relative to the package-path.
Analogous to :winpath, but under
This option specifies a sanity condition which needs to be satisfied by the plug-in. Usually, it is checked that certain binaries or libraries are present on your system. If the condition fails, then TeXmacs will continue as whether your plug-in did not exist. In that case, further configuration is aborted. The :require option usually occurs first in the list of configuration options.
This option specifies a
This command is only executed when the version of the plug-in changed from one execution of TeXmacs to another one. This occurs mainly when installing new versions of TeXmacs or helper applications.
This option specifies that the plug-in is able to evaluate expressions over a pipe, using a helper application which is launched using the shell-command shell-cmd.
This option is similar to :launch, except that the extern application is now linked dynamically. For more information, see the section about dynamic linking.
This option indicates that the plug-in supports an evaluator for
interactive shell sessions. An item menu-item
will be inserted to the
If the plug-in can be used as an evaluator, then this option
specifies the
This command is similar to the :serializer option except that it is used to transform special commands to strings.
This command indicates that the plug-in supports tab-completion.
This command indicates that the plug-in provides a routine for testing whether the input is complete.
It should be noticed that the configuration of the plug-in myplugin automatically creates a few predicates:
Test whether the plug-in is fully operational (all requirements are met).
Test whether myplugin is the current programming language.
Test whether myplugin is the current scripting language.