I am using TexStudio 2.6.6 and what I need is to create a custom keyboard shortcut macro that will insert _{%|}
whenever I type _
in math code only. Or a macro that will insert ^{%|}
whenever I type ^
in math code. But these macros should not work in text mode. So that in text mode I can type _
.
So I needed to know how to tell the macro to activate only when I am writing math code.
Best Answer
In the TexStudio user mannual I have found the answer of the question. I am sharing it with the hope that it will help others.
Trigger
write(?highlighted-as:numbers,math-delimiter,math-keyword)_
Type
isNormal
Latex Content
is_{%|}
Although replacing
^
with^{%|}
is little bit more tricky, because^
has special meanings in a regular expression. For that change the third bullet above byTrigger
write(?highlighted-as:numbers,math-delimiter,math-keyword)\^
And change fifth bullet above by
Latex Content
is^{%|}
The only drawback of this method is that the macro will also activated by pressing the trigger if the cursor is touching any math code even if it is outside the math code. For example:
A$ some math code $B
here you can trigger the macro even if the cursor is in betweenA
and$
or in betweenB
and$
because$
is a math code and the cursor is touching$
. However, if the cursor is not touching any math code the macro will not be executed by trigger.