# User Tags using selection multiple times

I will be using a lot of subsections and intend to label it the same name.

\subsection{Name}
\label{Name}


I would like to use a user Tag so i only have to type "Name" out once select it and the macro does the rest.

This question is about using a selected text represented by a @ multiple times in the same macro.

A small graphic to illustrate my problem:

If this actually is explained in this post i hope someone can explain it in easier words.

• The TeXmaker documentation states "(if some text has been selected in the editor before, the first "•" field will be replaced automatically by the selected text)." That is, subsequent • will not be filled in. So the functionality you desire does not seem to be built in to Texmaker – Troy Sep 18 '17 at 16:48
• Would a solution using TeXstudio be acceptable? – Troy Sep 18 '17 at 16:56
• @Troy if it works yes – Eumel Sep 18 '17 at 16:59

The TeXmaker documentation states

...(if some text has been selected in the editor before, the first "•" field will be replaced automatically by the selected text).

That is, subsequent "•" will not be filled in. So the functionality you desire does not seem to be built in to Texmaker.

Here's an alternative solution using TeXstudio, a fork of TeXmaker. (Solution here is an adaptation from: https://tex.stackexchange.com/a/294698/117534)

What you are trying to achieve is replacing multiple placeholders with the same argument, which can be achieved in TeXstudio using the nifty "Mirrored Placeholders". From within TeXstudio, you can set up user macros similar to user tags in TeXmaker:

Macros -> Edit Macros -> Add


Make the macro a Normal type, and paste the following into the LaTeX content box:

\subsection{%<%:id:1%>}
\label{%<%:mirror,id:1%>}


Finally, give the macro a name, in the Name entry, for e.g. subsection.

The final result should look like this:

If your settings are default, you will be able to access this macro via Shift + F1 (or the other Fn keys if this is not your first macro).

If you are not sure, go to the Macros menu and you should see your macro there.

A quick test:

I had the same problem. I managed to fix it by using a script instead of user tags. You can check out what I did over here:

Is TeXMaker capable of using a .js script made to work for TeXWorks? If not, how do I go about turning a .js into a .tms?

toggleHyperref.tms

// TeXworksScript
// Shortcut: Ctrl+Shift+H
// Description: Converts the current selection to be a hyperlink.
// Author: Robo
// Version: 0.1
// Date: 2018-01-06
// Script-Type: standalone
// Context: TeXDocument

var txt = TM.selection;
var len = txt.length;
var wrapped = prefix + txt + midfix + txt + suffix;
var pos = TM.selectionStart;
if (pos >= prefix.length) {
TM.selectRange(pos - prefix.length, wrapped.length);
if (TM.selection == wrapped) {
TM.insertText(txt);
TM.selectRange(pos - prefix.length, len);
return;
}
TM.selectRange(pos, len);
}
TM.insertText(wrapped);
TM.selectRange(pos + prefix.length, len);
return;
};