Feeds:
Posts

## Emacs Tip: Using Macros

Yesterday I started to edit an old $\LaTeX$  file, and it happened that in my set of definitions I changed a bold math-operator with no arguments `\df`, by a math-operator with one argument (which happens to by the following word) `\de{#1}`.

## The problem

The issue now is that I should go all over the text finding the `\df` command and replaced by `\de{#1}`. But note that the is a delimiter with the curly bracket!

## The solution

A while ago I found a page called , and I learn about emacs’ macro, i.e., a set of rules you define and then can be applied recursively.

### How is it done?

A short explanation is given at .

In my case I follow that rules below:

• Press `F3` to start recording the macro.
• Look for the initial command and change it by the other using `M-% \df` (press enter) `\de{` (press enter)
• Move the cursor forward until the end of the next word using the command `M-f`
• In that cursor place close the curly bracket `}`
• Finish the recording of the macro by pressing `F4`.

Finally, to apply the macro use `F4` to apply it once, `M-4 F4` to apply it 4 times or `M-0 F4` to apply it until it fails.