# Do TeXStudio Macros allow for conditionals?

I am trying to get a conditional to work within a TeXStudio script macro. Specifically, this is what I have:

%SCRIPT
txt = cursor.selectedText()
editor.write("\\left\\langle "+txt+" \\right\\rangle")
cursor.clearSelection()
if (cursor.hasSelection() == false) {
cursor.shift(-14)
}


The above macro, basically wraps the selected text in \left\langle and \right\rangle. The second part is meant to move the cursor inside, if there is no selection. If there is a selection, I want the cursor to be where it would normally be (outside, to the right of \rangle).

The above macro works fine, except it always moves the cursor inside, regardless of whether I have a selection. If I remove the conditional statement, then the macro is always outside. Is this not how conditionals work in TeXStudio?

• I think if you define a LaTeX new command on preamble of you tex file it will work as you expect. TXS will be able to recognize it and autocomplete it. – Sigur Apr 2 at 1:26
• Possibly need to use TeXstudio macro directive %| see tex.stackexchange.com/questions/298808/… – user170109 Apr 2 at 23:31
• @KJO That doesn’t work in script macros, unfortunately – jackson5 Apr 2 at 23:36
• OK, I am puzzled by the line cursor.clearSelection before IF has ... – user170109 Apr 2 at 23:40
• Oh wow! I don't know how I missed that (it was from an earlier version of the macro), removed it and it works perfectly, thanks so much! – jackson5 Apr 3 at 1:13