# Macro in texstudio/texmaker to surround selected text with tags [duplicate]

When you use some of the predefined shortcuts in texstudio on selected text, it wraps the text with the appropriate tags(is that the proper term?). For instance, suppose i highlight Hello Worldand press Ctrl+i it becomes \textit{Hello World}.

That is pretty handy as you dont't have to move the end tags around. I was wondering whether there a way to program macro to have similar behavior too. Many thanks in advanced.

 found a similar answered question: Cross out the selected text using macro script in TexStudio

## marked as duplicate by Johannes_B, Zarko, Paul Gaborit, Claudio Fiandrino, Henri MenkeJun 5 '16 at 9:09

In Texmaker you can use user tags to achieve this.

1. Go to the Menu User > User Tags > Edit User Tags
2. On the left hand side select a free slot (e.g. Menu 1:)
3. On the right hand side enter any name for the macro in the Menu Item Textbox (e.g. Bold)
4. In the Latex Content box enter your code (e.g. \textbf{@})

The @-symbols are placeholders. The first @-symbol is replaced by the currently selected text when inserting the user tag.

Now i can just select the text i want to be surrounded and press Shift+F1 or select the appropriate tag from the menu. (F1 because it is the first entry in my case, shortcuts are shown in the menu.)

Thanks for the suggestion! I managed to find a similar question and answer here For reference, here is how the script would look like.

%SCRIPT
txt = cursor.selectedText()
editor.write("\\underline{"+txt+"}")
cursor.clearSelection()


I am not familiar with the macro programming functions of the mentioned editors but I use Autohotkey-Scripts for this, which should work in all editors. The following is just one example.

F2::
Send ^c
Send \textbf{{}{}}{LEFT}
Send ^v
Return

• Ok for Windows users... but... me and many many people do not want to pay something so expensive and so buggy to M\$ anymore. – ThierryB Jul 5 '17 at 19:56
• Well, there is Autokey under Linux, Textexpander under Mac OS, Emacs can do it as well... – Uwe Ziegenhagen Jul 6 '17 at 19:50