I understand that you can write (?highlighted-as:numbers,math-delimiter,math-keyword)
before your trigger and TexStudio will execute the macro only in Math mode. I already tested that in "scripts type" and "normal type" and it works fine as expected. Somewhere I forgot where I read that (?highlighted-as:normal)
works in a comparable way in normal/text mode type, i.e. if written before a trigger, it will restrict/limit the scope of the macro to only normal/text mode. I was trying to implement this in a script, but it does not work. It basically runs the Javascript in both math and normal/text mode, not what I want.
Example of what I have been trying to do:
Name: foobar replacement
Trigger (?highlighted-as:normal) foo
type: script
%SCRIPT
replace = {' foo ':' bar '}
trigger=triggerMatches
if (trigger in replace) {trigger=replace[trigger]}
editor.write(trigger)
This script will run in both math and normal mode. I need it to only run in text/normal mode. What am I doing wrong? Of course I could do each replacement without the script type, just normal type, but it will be very tedious to write a macro for each replacement one by one. Is there anyway to tell TexStudio to execute this script in normal mode only? Or is there anyway while writing a script to get the current mode (whether it's math/normal text, true/false?) and then write an IF statement to execute a certain set of commands if in one mode and a different set of commands if in a different mode?
Sorry for these questions if they are simple or "basics" for some of you. I am newbie to LaTeX and TexStudio and I am just trying to write some scripts in TexStudio to make my life a bit easier, no intention at the moment to delve deeper "under the hood" into LaTeX like a pro and use \ifmmode
and such.
Thanks very much in advance!