Macro expansion

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 Scheme or a plug-in. The macro-related primitives are available from the Source→Macro menu. Below, we will only describe the ordinary macros. For more details, we refer to the section about macro primitives.

Ordinary macros are usually defined using

<assign|my-macro|<macro|x1|⋯|xn|body>>

After such an assignment, my-macro becomes a new primitive with n arguments, which may be called using

<my-macro|y1|⋯|yn>

Inside the body of the macro, the arg primitive may be used to retrieve the values of the arguments to the macro.

<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 uninit primitive as value:

< 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 compound tag may be used to apply macros which are the result of a computation:

< assign | overloaded-hi | < macro | name |

<\compound|

<if|<nice-weather>|happy-hi|sad-hi>

|

name

>

> >

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".