[Tex/LaTex] Error when trying to open pdf file from AUCTeX

auctexemacs

I'm new to Emacs and AUCTeX. On my home computer (with Windows XP) I can successfully compile .tex files and then, using C-c C-c again, launch a pdf viewer (Adobe Reader or Sumatra) to view the file.

However, on my work computer (Windows 7), I can successfully compile a .tex file to pdf using C-c C-c, but when I do C-c C-c again to view, the default view command that appears is start "" "a.pdf". Pressing Enter brings up the Windows error message Windows cannot find 'a.pdf'. Make sure you typed the name correctly, and then try again. If I change the command so that it includes the full location of the file, e.g. start "" "//servername/mark/a.pdf", then the pdf viewer opens. At home, there is no need to change the default command start "" "a.pdf".

I'd appreciate if anyone can tell me how to get the pdf viewer to open without having to edit the command each time. At work I have AUCTeX version 11.86.

Best Answer

Your default PDF-viewer is controlled by two variables called TeX-view-program-list and TeX-view-program-selection. There are several ways of modifying these:

Through the Emacs's interface

M-x customize-group <RET>
AUCTeX

Select the group called: Tex Command then find TeX View. Under TeX View Program List is all the list of known commands for viewing your generated pdf. In my case I use SumatraPDF.exe which I also have in my global PATH variable. Insert following:

Name: SumatraPDF
Command: SumatraPDF.exe %o

Under TeX View Program Selection the default viewer for pdf and dvi can be selected. Select the previously defined SumatraPDF.

Inserting setup in .emacs

Just insert following code in your .emacs configuration file:

(setq TeX-output-view-style '("^pdf$" "." "SumatraPDF.exe %o"))

(setq TeX-view-program-list
      '(("SumatraPDF" "SumatraPDF.exe %o")
        ))
(cond
 ((eq system-type 'windows-nt)
  (add-hook 'LaTeX-mode-hook
            (lambda ()
              (setq TeX-view-program-selection '((output-pdf "SumatraPDF")
                                                 (output-dvi "Yap"))))))

 ((eq system-type 'gnu/linux)
  (add-hook 'LaTeX-mode-hook
            (lambda ()
              (setq TeX-view-program-selection '((output-pdf "Okular")
                                                 (output-dvi "Okular")))))))

If you don't use SumatraPDF (I really recommend you do), then change the name and command. Remember to have your pdf-viewer in your PATH or refer directly to it through the full path.

Related Question