0

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?

jackson5
  • 101
  • 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 02 '19 at 01:26
  • Possibly need to use TeXstudio macro directive %| see https://tex.stackexchange.com/questions/298808/math-mode-macro-in-texstudio –  Apr 02 '19 at 23:31
  • 1
    @KJO That doesn’t work in script macros, unfortunately – jackson5 Apr 02 '19 at 23:36
  • 1
    OK, I am puzzled by the line cursor.clearSelection before IF has ... –  Apr 02 '19 at 23:40
  • 1
    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 03 '19 at 01:13

0 Answers0