Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sync Emacs AUCTeX with Sumatra PDF

With these lines in my init.el I am able to sync the Emacs LaTeX buffer with Sumatra:

(setq TeX-source-correlate-mode t)
(setq TeX-source-correlate-method 'synctex)
(setq TeX-view-program-list 
  '(("Sumatra PDF" ("\"C:/bin86/SumatraPDF/SumatraPDF.exe\" -reuse-instance" 
                      (mode-io-correlate " -forward-search %b %n ") " %o"))))
(setq TeX-view-program-selection  
      '(((output-dvi style-pstricks) "dvips and start") (output-dvi "Yap") 
       (output-pdf "Sumatra PDF") (output-html "start")))

To set a double click on the PDF to get me to the related LaTeX code, I also set in Sumatra options Set inverse search command line to:

"c:\bin86\GNU Emacs 24.2\bin\emacsclient.exe" --no-wait +%l "%f" 

Despite the sync works, I’d like to code it differently.

If I didn’t set the last expression, (setq TeX-view-program-selection..., I would get the default values, which are the same as above, apart from the value for the PDF output that would be: (output-pdf "start"). I’d like to change this one to "Sumatra PDF" and leave the other values to their default, that is, I’d like to ask Emacs the default values for the viewers and change only the PDF value.

It is mostly an ELisp question concerning the manipulation of the variable TeX-view-program-selection. Thanks for helping.

P.S. Please tell me if this question is best fit on tex.stackexchange

Update based on lunaryorn comments/answer

To update TeX-view-program-selection I could use:

(assq-delete-all 'output-pdf  TeX-view-program-selection)
(add-to-list 'TeX-view-program-selection   '(output-pdf "Sumatra PDF"))

The first line is optional, but it makes the list look "cleaner".

In both cases (with or without assq-delete-all) I now need to insert the code in the proper hook, since TeX-view-program-selection is void in init.el.

like image 533
antonio Avatar asked Jan 21 '13 22:01

antonio


3 Answers

My credits to lunaryorn for suggestions! I am repackaging the steps involved to the benefits of the others.

Emacs side

Add to your init.el:

(setq TeX-PDF-mode t)
(setq TeX-source-correlate-mode t)
(setq TeX-source-correlate-method 'synctex)
(setq TeX-view-program-list
   '(("Sumatra PDF" ("\"path/to/SumatraPDF/SumatraPDF.exe\" -reuse-instance"
                      (mode-io-correlate " -forward-search %b %n ") " %o"))))

(eval-after-load 'tex
  '(progn
     (assq-delete-all 'output-pdf TeX-view-program-selection)
     (add-to-list 'TeX-view-program-selection '(output-pdf "Sumatra PDF"))))

Sumatra side

In Settings->Options dialog set Set inverse search command line to:

"path\to\GNU Emacs ver\bin\emacsclient.exe" --no-wait +%l "%f" 

How to use

In your LaTeX document in Emacs type C-c C-v or double click the related PDF in Sumatra and ... enjoy))

like image 97
antonio Avatar answered Sep 22 '22 13:09

antonio


Use add-to-list instead of setq. See C-h f add-to-list for more information.

TeX-view-program-selection is defined in tex.el, so you'll need to execute this code after this library is loaded:

(eval-after-load 'tex
  '(progn
     (assq-delete-all 'output-pdf TeX-view-program-selection)
     (add-to-list 'TeX-view-program-selection '(output-pdf "Sumatra PDF"))))
like image 26
lunaryorn Avatar answered Sep 22 '22 13:09

lunaryorn


I was driven nearly mad by the quoting conventions for windows ->emacs If you install SumatraPDF in the default place, then this works on windows 8.1

(setq TeX-view-program-list
   '(("Sumatra PDF" ("\"C:/Program Files (x86)/SumatraPDF/SumatraPDF.exe\" -reuse-instance"
          (mode-io-correlate " -forward-search %b %n ") " %o")))))

That's an hour or so I'll never get back :)

like image 23
user2162871 Avatar answered Sep 22 '22 13:09

user2162871