Writing a simple style package |
Let us explain on an example how to write a simple style package.
First of all, you have to create a new buffer using
$HOME/.TeXmacs/packages
Notice that the button
$HOME/.TeXmacs/texts
Consequently, you can go to the style package directory from there, by double clicking on .. and next on packages. Similarly, the directory
$HOME/.TeXmacs/styles
contains your personal style files. After saving your empty style
package, it should automatically appear in the
Let us now create a simple macro
<assign||>
Now enter “hi” as the first argument and type A-m inside the second argument in order to create a macro. You should now see something like
<assign|hi|<macro|>>
Finally, type the text “Hello world” in the body of the macro. Your document should now consist of the following line:
<assign|hi|<macro|Hello world>>
After saving your style package, opening a new document and selecting
your package in the
In a similar way, you may create macros with arguments. For instance,
assume that we started entering a macro
<assign|hello|<macro|name|>>
In the second argument of the body, we now type “Hello ”, A-#, “name”, right and “, how are you today?”. After this you should see
<assign|hello|<macro|name|Hello name, how
are you today?>>
The A-# shortcut is used to retrieve the macro argument name. Instead of typing A-#, “name” and right, you may also use the hybrid \-key and type \ n a m e followed by return. After saving your style package, you may again use the macro in any document which uses your package by typing \ h e l l o and hitting return.
From the internal point of view, all macro definitions are stored in
the environment of the TeXmacs typesetter. Besides macros, the
environment also contains normal environment variables, such as
section counters or the font size. The environment variables can
either be globally changed using the
<assign|section-nr|-1>
in your package, and using article as your major style, then the first section will be numbered 0. Similarly, the variant
<assign|hello|<macro|name|Hello <with|font-shape|small-caps|name>!>>
of the
<assign|hello|<macro|name|Hello <person|name>!>>
In order to produce the macro application <person|name>,
you first have to start a compound tag using A-c, type
the name “person”, insert an argument
A-right, and enter the argument name
as before. When you are done, you may press return in
order to change the
By combining the above constructs, an ordinary user should already be able to produce style packages for all frequently used notations. An interesting technique for writing macros which involve complex formulas with some subformulas which may change goes as follows:
Create the skeleton of your macro in your style package:
<assign|n-tuple|<macro|a|>>
Copy the formula and paste it into the body of your macro:
<assign|n-tuple|<macro|a|(a<rsub|1>,…,a<rsub|n>)>>
Replace the subformulas you want to parameterize by macro arguments:
<assign|n-tuple|<macro|a|(a<rsub|1>,…,a<rsub|n>)>>
You may now use the macro in documents which use your package: