I want to run a TeXstudio command (namely, "Tab or indent selection") from inside a macro. The reason is that I would like to make the Tab key act as follows:

  • If there is a placeholder, move to it;

  • If there is no placeholder, then execute the command "Tab or indent selection"

Is there a way to do that?


  • yes, it's editor.tabOrIndentSelection(). or do you need help writing the rest of the script? – Troy Mar 14 '18 at 17:52
  • Thanks for your comment. I was going to try to write my first macro in TeXstudio... any help will be much appreciated. (also: where is the full API documentation?) – Biel Cardona Mar 14 '18 at 18:26
  • I don't really have time to write a full script right now, sorry. I'll come back to this again later if it hasn't been attempted by anyone else. The documentation for macros is just the TXS user manual here; The scripting language is ECMAscript. Quite a number of the commands are not made explicit to the user. – Troy Mar 14 '18 at 19:02
  • @Troy Thanks! Would also be great to have the full set of available commands – Biel Cardona Mar 14 '18 at 20:48

If I understand your requirements, it's just a two-line code. Go to Edit Macros -> Add, give it whatever name you want, and paste the following under LaTeX content:

if (!editor.nextPlaceHolder()){

enter image description here

Then set this shortcut to the Tab key under the Shorcuts settings.

enter image description here



A note of warning. This does not (cannot?) replicate the functionality of the Tab key entirely. The Tab key serves more roles than just indenting: it also accepts the autocomplete suggestions when the autocompleter menu is open. Cf. TeXstudio tab to accept autocomplete

I'm not too confident that this functionality is accessible via scripting, so you're going to have to live without this if you choose to implement the Tab macro like that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.