1

I know in Texstudio the embedding PDF viewer can be closed using Esc and will appear again if I hit F7 key and it can also be expanded. Is it possible to write a macro script for which whenever I start writing in the editor the PDF viewer will be automatically closed and will appear in the extended view after the compilation?

1
  • I would also like to have this. However, I could not find an option for it. I believe though that just having to hit ESC is not so bad. Alternatively, you could have the previewer open in a window. – basseur Oct 13 '17 at 7:04
1

It's possible to use macro script to close the pdf viewer automatically, following a keypress trigger. The pdf viewer opening after compilation can be set as part of your build sequence.

To close PDF viewer automatically

Create a new script with the following:

%SCRIPT
editor.insertText(triggerMatches);
if (pdfs.length > 0) 
{
    pdfs[0].close();
}

with the trigger set to whatever you like. Suppose you want the viewer to be closed after typing one of the 26 (small) letters in the English alphabet, then set trigger to [a-z].

pdf closer

Some Disclaimer:

  • I'm not sure whether this introduces any lag/latency when typing large files (since the script is checking whether the viewer is open almost every keypress you make).
  • This does not work when the completer is open. For example, if you are typing \sect, then the completer pops up to suggest \section, then the trigger will not be active and thus the script will not run. This is well documented in the User Manual Section 4.5.4.1. Just continue typing until the autocompleter closes, then the trigger will work as per normal after that.
  • And honestly, I think this behaviour is extremely jarring and distracting, but if that's what you want. :)

Note: The trigger can take other values also, so suppose you have:

[a-zA-Z0-9:.,?!] % Set as the trigger

then the script will trigger for all 26 letters of the English alphabet (capitalized and non-capitalized), all numbers, and some of the punctuation symbols. Look up 'Regular Expression', or 'regex' for more information.

To Open PDF viewer automatically

This should be the default behaviour of TeXstudio, so just click the shortcut for Build & View (F5).

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.