This question already has an answer here:

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.

[edit] 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 Menke Jun 5 '16 at 9:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


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{@})

enter image description here

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

For more information check out this: Texmaker Documentation: User Tags


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

txt = cursor.selectedText()

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.

Send ^c
Send \textbf{{}{}}{LEFT}
Send ^v
  • 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
  • 1
    Well, there is Autokey under Linux, Textexpander under Mac OS, Emacs can do it as well... – Uwe Ziegenhagen Jul 6 '17 at 19:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.