> <\body> plug-in> Consider the example of the plug-in in the directory <\verbatim> \ \ \ \ $TEXMACS_PATH/examples/plugins It consists of the following files: <\verbatim> \ \ \ \ \ \ \ \ In order to try the plug-in, you first have to recursively copy the directory <\verbatim> \ \ \ \ $TEXMACS_PATH/examples/plugins/pyminimal to or . When relaunching , the plug-in should now be automatically recognized. The plug-in demonstrates a minimal interface between and an extern program in python. The initialization file essentially contains the following code: <\scm-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 option checks whether indeed exists in the path (so this will fail if you did not have python installed). The option specifies how to launch the extern program. The option indicates that it will be possible to create sessions for the plug-in using . The function will be evaluated and return the proper command to launcher the extern program. If exists, it would be <\shell-code> python "$TEXMACS_HOME_PATH/plugins/pyminimal/src/minimal.py" otherwise, <\shell-code> python "$TEXMACS_PATH/plugins/pyminimal/src/minimal.py" The environment variables will be replaced in runtime. Sometimes, and may contain spaces, as a result, we quote the path using the double quotes. 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 built-in plugins are written in Python, and we have carefully organized the code and reused the common part named . <\python-code> 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 or to the python path for importing the package. <\python-code> 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) is provided by which is a subpackage for interaction with server in Python. is provided by which is a subpackage for compatibility within Python 2 and 3. For built-in plugins written in Python, it would be better to support more Python version. For example, in some desktop environments, the command may redirect to . > This demo plugin is a Python implementation of the well-documented written in . Here is the summary of the differences: <\itemize> requires the interpreter, needs to be compiled and linked is easier to install than reuses the common part related to has better compatibility for , and >