It seems that TeX-command-run-all shifts focus to the pdf window, which is quite annoying. Is there a way to prevent that?

  • I think that this is not the standard behaviour with pdf-tools. At least on my system with emacs 27.0.5, latest AUCTeX and pdf-tools from melpa, the focus is kept in the window with the tex file. I have tested it with emacs -Q and minimal config.
    – andrej
    May 20 '19 at 16:37

I use xdotool to shift focus back to Emacs after Tex-command-run-all. Works on an X system (Linux/Unix) with xdotool installed. I use Okular as pdf-viewer and the following settings:

(setq TeX-view-program-selection '((output-pdf "Okular")))

(setq TeX-view-program-list 
'(("Okular" "emacswinno=`xdotool getwindowfocus` \; okular --unique %o\#src:%n`pwd`/./%b \; sleep 0.1\; xdotool windowactivate $emacswinno")))

The xdotool solution will work with any pdf viewer, but it is actually an overkill if you use Okular. I just realized you can call Okular with the option --noraise to prevent it from taking focus. So if you use Okular, the following setting will work:

(setq TeX-view-program-list
  '(("Okular" ("okular --noraise --unique %o"  (mode-io-correlate "#src:%n%a")) "okular")))
  • If that is necessary, I feel there is something wrong with AUCTeX.
    – Toothrot
    May 20 '19 at 15:58
  • There is a user option: TeX-view-evince-keep-focus When this option is non-nil and the viewer is compatible with evince, the focus is pulled back to Emacs immediately after the viewer is invoked or refreshed from within AUCTeX. from here gnu.org/software/auctex/manual/auctex/Starting-Viewers.html This option as well as xdotools should not affect pdf-tools.
    – andrej
    May 20 '19 at 16:49
  • The option TeX-view-evince-keep-focus doesn't work with Okular unfortunately.
    – StarBug
    May 21 '19 at 9:05


(add-hook 'TeX-after-compilation-finished-functions

do the trick ?

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.