How to make a macro that works globally?

I define a macro to make red colors in a preamble of a file as follows (in TeXmacs scheme format):

(assign "red-color" (macro "body" (with "color" "red" (arg "body"))))

Then I define a keyboard shorctcut in my-init-texmacs.scm for this macro as follows.

("M-1" (make 'red-color))

This works as expected for that specific document. However, I would like to make this work globally for any document. One option is to create a style file or package and apply it when needed, but I prefer a global solution. I tried placing the macro definition in my-init-texmacs.scm or my-init-buffer.scm , but it was unsuccessful.

Additionally, I have a related question: how can I define a “temporary” shortcut that works only for a specific document or style? This would be useful in situations like composing a paper on electromagnetics where I want EE to expand to <b-up-E> for that particular paper but have a different expansion for other papers.

You could put your macro in a style file and then load that style file in my-init-buffer.scm. See this post for an example:

1 Like

For shortcuts in specific types of documents, you could define mode-dependent shortcuts.

You’d need to create a Scheme function that determines whether you are in an electromagnetics paper, for example by checking (has-style-package? "electromagnetics").

Have a look at how the education, graphics and math modes are defined and how these are used to define their shortcuts.

You don’t need that for red env. A tm macro called red is already bundled. Press \ r e d enter then you get it.

Yes. This is a good option! I could define my own base style and load it by default.