GNU TeXmacsUser manualReferenceAboutEnglish
Plug-ins as scripting languages

TeXmacs provides a few other kinds of additional interfaces to external systems in addition to shell-like interfaces. First of all, it is possible to insert a so called “executable switch” anywhere in the document using Insert\(\rightarrow\)Fold\(\rightarrow\)Executable.

For instance, if Maxima is installed on your system, then Insert\(\rightarrow\)Fold\(\rightarrow\)Executable\(\rightarrow\)Maxima should yield something like

Maxima
. You may enter a Maxima expression in the yellow part of this markup, say
Maxima diff(x^x,x)
. Using ↩, you may now switch back and forth between the unevaluated input and the evaluated output \(x^x (\log (x) + 1)\). Using ⇧↩, you enable multi-line input. This kind of executable switches are very useful for plug-ins such as DraTeX, Eukleides, Feynmf, etc., which are mainly used for the efficient computation and insertion of special graphics inside TeXmacs documents.

Some plug-ins such as Maxima can even be selected as a scripting language using Document\(\rightarrow\)Scripts\(\rightarrow\)Maxima. When doing so, a special Maxima menu will appear, which allows for many useful operations directly on formulas. For instance, when putting the cursor inside the formula \(1 + 1\) and pressing ? or Evaluate, the formula gets evaluated automatically to yield \(2\).

If a plug-in can be used as a scripting language, then it is possible to create executable switches with links between them. More precisely, assuming that you selected a scripting language from Document\(\rightarrow\)Scripts, you may insert a new executable input field using \! or Insert\(\rightarrow\)Link\(\rightarrow\)Executable input field. As before, when pressing ↩, the current input is evaluated and you will see the corresponding output; you may switch back to the input by pressing ↩ once more.

Contrary to executable switches, you may attach an identifier to the executable input field by deactivating the field or by editing the Ref field in the focus bar. Inside other executable input fields, you may then refer to the value of the field by inserting a field reference using \? or Insert\(\rightarrow\)Link\(\rightarrow\)Field reference. As a variant to executable input fields, you may sometimes prefer to insert plain input fields using \\ or Insert\(\rightarrow\)Link\(\rightarrow\)Input field. These fields can only be used as inputs and pressing ↩ inside such a field will only recompute those other fields which depend on it.

Example 1. The executable input fields may for instance be nice in pedagogic documents in which parts of the document may be modified and recomputed by the reader. For instance, evaluation of the input fragment

The derivative of \(x^x\) equals diff(function,x).

The second derivative is given by diff(derivative,x).

yields

The derivative of \(x^x\) equals \(x^x (\log (x) + 1)\).

The second derivative is given by \(x^x (\log (x) + 1)^2 + x^{x - 1}\).

Of course, if the reader changes the input function \(x^x\) into something else and presses ↩, then the first and second derivatives will be updated automatically.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".