2

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

1
  • 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, 2019 at 16:37

3 Answers 3

1

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")))
3
  • If that is necessary, I feel there is something wrong with AUCTeX.
    – Toothrot
    May 20, 2019 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, 2019 at 16:49
  • The option TeX-view-evince-keep-focus doesn't work with Okular unfortunately.
    – StarBug
    May 21, 2019 at 9:05
1

does

(add-hook 'TeX-after-compilation-finished-functions
        #'TeX-revert-document-buffer))

do the trick ?

0

I had the exact same problem. It turned out that adding the -g option to the Skim command invoked in TeX-view-program-list solved it for me for Skim+MacOS. Maybe there are similar options for other PDF viewers.

;; DOOM-EMACS snippet
(after! tex
  :config
  (dolist (viewer (reverse +latex-viewers))
  (pcase viewer
    (`skim
     (when-let
         (app-path
          (and IS-MAC
               (file-exists-p! (or "/Applications/Skim.app"
                                   "~/Applications/Skim.app"))))
       (add-to-list 'TeX-view-program-selection '(output-pdf "Skim"))
       (add-to-list 'TeX-view-program-list
                    (list "Skim" (format "%s/Contents/SharedSupport/displayline -r -b -g %%n %%o %%b"
                                         app-path)))))))
  )

Note: I edited the code from https://github.com/doomemacs/doomemacs/blob/master/modules/lang/latex/%2Bviewers.el to ensure that it only affects Skim if Skim was selected in the doom config.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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