Parametrized macros

Hello,

I’d like to create a small set of macros in a .ts package file for writing vectors in two different styles: either as bold italic letters or as letters with arrows above .

I could define two separate macros — for example, vec for bold italic vectors and vecarrow for arrowed vectors.

image

However, I’d prefer to use a single macro name , like vec , and control the style via a parameter or a global setting to be specified when using the package. For example style=bold_italic or style=arrow.

Is it possible in TeXmacs to define such a macro where the vector style (bold italic vs. arrow) can be selected through an argument or a configurable option? Do you have an idea of how I could write these macros?

Best regards,
Diog

Hi @Diog
One way is with environment variables and conditional macros. See manual 11.3.5. Flow control, for a description and a warning of which I do not understand how important it is (how widely it applies).

Here is an example.

<assign|vecshape|bold>

<assign|vc|<macro|body|<case|<equal|<value|vecshape>|bold>|<with|font-series|bold|font-shape|italic|<arg|body>>|<equal|<value|vecshape>|arrow>|<wide|<arg|body>|\<vect\>>>>>

I don’t like in my example that you don’t get the typeset vector while you are typing but maybe there is a way to do that too.

One might also get conditional formatting through Scheme. Here is a forum thread where environment variables and Scheme—and possibly other ways of controlling the behaviour of a TeXmacs document—are discussed: Reproducible Research "Plugin"

I did not re-read it before posting, this said I have the feeling it may help.