![]() |
TeXmacs style files | ![]() |
One of the fundamental strengths of TeXmacs is the possibility to write your own style files and packages. The purpose of style files is multiple:
The user may select a major style from the
Style packages, which are selected from the
When you want to add your own markup to TeXmacs or personalize the layout, then you have to choose between writing a principal style file or a style package. In most cases, you will probably prefer to write a style package, since this will allow you to combine it arbitrary other styles. However, in some cases you may prefer to create a new principal style, usually by personalizing an existing style. This is usually the case if you want to mimic the layout policy of some journal. In this chapter, we will both explain how to write your own style packages and how to customize the standard styles.
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:
Most users are used to edit source code using a conventional editor
like
In TeXmacs we have chosen to implement the second option. More
precisely, any document can be edited in “source mode”,
which is merely a mode for rendering the document in a way which makes
its tree structure particularly apparent. It may be instructive to
take an arbitrary document of yours and to take a look at it in
“source mode” by enabling
The choice between ASCII-based editing and tree-based editing is non-trivial, because TeXmacs style files and packages have a double nature: they may be seen as programs which specify how to render macros, but these programs naturally contain ordinary content. There are several reasons why users often prefer to edit source code in an ASCII-based format:
Our approach is to reproduce as much of the above advantages in a structured document environment. Although point ? will obviously be hard to meet when following this approach, we believe that the first three advantages might actually become greater in a structured environment. However, this requires a more profound understanding of how users format and edit source code.
For instance, consider a piece of manually formatted code like
if (cond) hop = 2;
else holala= 3;
Clearly, the user had a particular formatting policy when writing this code. However, this policy does not appear in the document: manual intervention will be necessary if the variable cond is renamed c, or if the variable holala is renamed hola.
At the moment, TeXmacs provides no tools for dealing with the above example in an automatic way, but a few tools are already provided. For instance, the user is given a great amount of control on how to indent source code and reasonable defaults are provided as a function of the structure. We also provide high level environments for comments and structured highlighting. Further tools will be developed later and we are open for any suggestions from our users.
In the
First of all, you may choose between the different major styles “angular”, “scheme”, “functional” and “LaTeX” for rendering source trees, as illustrated in the figure below:
Secondly, you may wish to reserve a special treatment to certain tags
like
These different options are illustrated below:
|
|||||||||||||||||||
Another thing which may be controlled by the user is whether the
presentation of tags should be compact or stretched out across several
lines. Several levels of compactification may be specified in the
The “normal” and “inline arguments” options rarely differ. The visual effect of the different options is illustrated below:
|
|||||||||||||||||||
Finally, the user may specify the way closing tags should be rendered when the tag is stretched out across several lines. The rendering may either be minimalistic, compact, long, or recall the matching opening tag. The different options are illustrated below:
|
|||||||||||||||||||
Even though TeXmacs tries hard to render source code in a nice way
following the global rendering options that you specified, the
readability of the source code often needs to be further enhanced
locally. In source mode, this can be done using the menus
First of all, for certain pieces of content the user may prefer to see them in their “activated” form instead as dead source code. This may for instance be the case for embedded images, or for mathematical symbols, like in
<assign|R|<macro|R>>
Such an active presentation may also be preferred for certain more complex macros:
<
assign
|
diag
|
<
macro
|
var
|
dim
|
(
)
>
>
var1
0
⋱
0
vardim
A piece of code can be activated by selecting it and using
Another way to customize the rendering is to override some of the
global rendering options. This is mainly interesting for controlling
more precisely which tags have to be stretched across several lines
and which tags have to be represented in a compact fashion. For
instance, the
<
assign
|
my-section
|
<
macro
|
title
|
<\concat|
<header-hook|title>
<toc-hook|title>
<my-section-title|title>
we have stretched the
<
assign
|
my-section
|
<
macro
|
title
|
<\concat|
<header-hook|title>
<toc-hook|title>
<with|font-series|bold|Section:>
title
At present, we did not implement a way to mark arguments as inline or block, but we might do this later.
A final way to customize the rendering of source code is to apply an
arbitrary macro using
In the section about writing a simple style package we already gave you a first impression about the style-sheet language of TeXmacs. In this section, we will give a more complete survey of the available features. For more detailed descriptions, we refer to the chapter about the TeXmacs primitives.
Most style-sheet primitives can be obtained from the
All user defined TeXmacs macros and style variables are stored in the
“current typesetting environment”. This environment
associates a tree value to each string variable. Variables whose
values are macros correspond to new primitives. The others are
ordinary environment variables. The primitives for operating on the
environment are available from
You may permanently change the value of an environment variable using
the
<assign|hi|<macro|Hi there!>>
You may also locally change the values of one or several environment
variables using the
<with|font-series|bold|color|red|Bold red
text>
The value of an environment variable may be retrieved using the
<assign|my-counter|<plus|my-counter|1>>
Finally, you may associate logical properties to environment variables
using the
The main interest of the TeXmacs' style-sheet language is the
possibility to define macros. These come in three flavours: ordinary
macros, macros which take an arbitrary number of arguments and
external macros, whose expansion is computed by
Ordinary macros are usually defined using
<assign|my-macro|<macro|x1|⋯|xn|body>>
After such an assignment,
<my-macro|y1|⋯|yn>
Inside the body of the macro, the
<assign|hello|<macro|name|Hello name,
you look nice today!>>
It is possible to call a macro with less or more arguments than the
expected number. Superfluous arguments are simply ignored. Missing
arguments take the nullary
<
assign
|
hey
|
<
macro
|
first
|
second
|
<\if|
<equal|second|?>
Hey first, you look
lonely today...
Hey first and second, you form a nice
couple!
We finally notice that you are allowed to compute with macros, in a similar way as in functional programming, except that our macros are not closures (yet). For instance:
<assign|my-macro-copy|my-macro>
The
<
assign
|
overloaded-hi
|
<
macro
|
name
|
<\compound|
<if|<nice-weather>|happy-hi|sad-hi>
name
This section contains some important notes on formatting primitives which are not really part of the style-sheet language, but nevertheless very related.
First of all, most TeXmacs presentation tags can be divided in two
main categories: inline tags and block tags. For instance,
<assign|my-theorem|<macro|body|<surround|<no-indent><with|font-series|bold|Theorem. >|<right-flush>|body>>>
In this example, we surrounded the body of the theorem with the bold text “Theorem.” at the left hand side and a “right-flush” at the right-hand side. Flushing to the right is important in order to make the blue visual border hints look nice when you are inside the environment.
In most cases, TeXmacs does a good job in determining which tags are
inline and which ones are not. However, you sometimes may wish to
force a tag to be a block environment. For instance, the tag
<assign|very-important|<macro|body|<with|font-series|bold|color|red|body>>>
may both be used as an inline tag and a block environment. When
placing your cursor just before the
<assign|very-important|<macro|body|<document|<with|font-series|bold|color|red|body>>>>
Since the body of the macro is now a block, your tag
Another important property of tags is whether they contain normal
textual content or tabular content. For instance, consider the
definition of the standard
<assign|eqnarray*|<macro|body|<with|par-mode|center|mode|math|math-display|true|par-sep|0.45fn|<surround|<no-page-break*><vspace*|0.5fn>|<vspace|0.5fn><no-indent*>|<tformat|<twith|table-hyphen|y>|<twith|table-width|1par>|<twith|table-min-cols|3>|<twith|table-max-cols|3>|<cwith|1|-1|1|1|cell-hpart|1>|<cwith|1|-1|-1|-1|cell-hpart|1>|body>>>>>
The use of
Finally, it is important to bear in mind that style-sheets do not
merely specify the final presentation of a document, but that they may
also contain information for the authoring phase. Above, we have
already mentioned the use of the
<
assign
|
labeled-theorem
|
<
macro
|
id
|
body
|
<\surround|
<\concat|
<no-indent>
<flag|Id:
id|blue|id>
<with|font-series|bold|Theorem. >
<right-flush>
body
More generally, the
The
<assign|new-theorem|<macro|name|text|<quasi|<assign|<unquote|name>|<macro|body|<surround|<no-indent><strong|<unquote|text>. >|<right-flush>|body>>>>>>
When calling <new-theorem|theorem|Theorem> in this example, we
first evaluate all
<assign|theorem|<macro|body|<surround|<no-indent><strong|Theorem. >|<right-flush>|body>>>
Next, this expression is evaluated, thereby defining a macro
It should be noticed that the TeXmacs conventions for evaluation are
slightly different then those from conventional functional languages
like
For instance, when TeXmacs calls a macro <macro|x1|⋯|xn|body> with arguments y1 until yn, the argument variables x1 until xn are bound to the unevaluated expressions y1 until yn, and the body is evaluated with these bindings. The evaluation of yi takes place each time we request for the argument xi. In particular, when applying the macro <macro|x|x and again x> to an expression y, the expression y is evaluated twice.
In
<assign|foo|<macro|x|<blah|x|x&