My operation system is macOS Catalina. I am using iTerm2 in order to interact with emacs and my default pdf viewer is PDF Pro Reader Light. When a pdf file is updated, PDF Pro Reader Light automatically reloads the document.

I am using following keybinding to compile the latex files.

C-c C-a (TeX-command-run-all) will do the job in AUCTeX 11.89.

After compilation is completed the keyboard focus is switch into the default pdf viewer and also the pdf view pops up in front of my terminal.

[Q] Is there any way to keep the focus on the terminal after compiling the tex and prevent pdf viewer to pop-up?

  • It may depend on the system; e.g., on an older version of OSX there are arguments to open external programs in the background when calling open ...; or, when using Skim's displayline program it has an optional argument of -g to open it in the background, whereas -o causes it to acquire focus and be brought to the foreground. – lawlist May 25 at 20:04
  • I forget to mention the system, I am using macOS Catalina. As terminal its iTerm – alper May 25 at 20:08

I have add following to my .emacs file by following this answer @lucky1928:

  1. Change (setq TeX-PDF-mode nil) to (setq TeX-PDF-mode t) will get pdf output.
  2. Add below configuration to remove the compile prompt:

    (setq TeX-command-force "LaTeX") (setq TeX-clean-confirm t)

When I do C-c C-c compiles the latex file and focus remains on the terminal.

  1. Set the PATH variable in .profile as:

export PATH=$PATH:/Library/TeX/texbin

  1. Afterwards, I added following to force latex to compiled.
(setq TeX-PDF-mode t)
(setq TeX-command-force "LaTeX") 
(setq TeX-clean-confirm t)
| improve this answer | |
  • Sorry for the confusion. I improved my questions and updated PATH part where I also get from (emacs.stackexchange.com/a/40882/18414). I just wanted to compile the tex document and on my system, pdf viewer will already automatically detects the changes. I don't know why focus was changing when I do C-c C-a. – alper May 26 at 17:24
  • I removed my comment above because it contained a partial misstatement ... I was previously unaware setenv had an optional second argument for SUBSTITUTE-ENV-VARS ... so I just learned something new. Thank you for adding details regarding which external program is being used to view the PDF. – lawlist May 26 at 21:02
  • C-c C-c seems like compiles only the related .tex file that is open in the .emacs and seems like references file (.bib) is not take place during compiling (which actually considred when I do C-c C-a). @lawlist – alper May 26 at 21:11

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.