6

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.

antonio
  • 10,629
  • 13
  • 68
  • 136
  • The question is o.k. here, but you should really accept some answers to your questions. – Martin Schröder Jan 22 '13 at 08:44
  • @antonio I have updated my answer to explain how your code is executed at the right place, i.e. after `TeX-view-program-selection` has been defined. –  Jan 24 '13 at 02:03
  • @MartinSchröder: I suppose I understand what you observed. I prepared a step by step solution to my own answer which should be easily used by all Emacs-Sumatra users and checked the green mark. – antonio Feb 11 '13 at 07:44

5 Answers5

12

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))

antonio
  • 10,629
  • 13
  • 68
  • 136
  • I had to also create an environment variable `ALTERNATE_EDITOR` pointing to my runemacs.exe, and `EMACS_SERVER` to point to my emacs server file (in the `.emacs.d\server` directory) – Ryan May 05 '14 at 15:39
  • Since official SumatraPDF does not include a dialog for inverse search, one can supply necessary stuff from within emacs: `(add-to-list 'TeX-view-program-list '("Sumatra PDF" ("sumatrapdf -reuse-instance" (mode-io-correlate " -forward-search %b %n -inverse-search \"emacsclientw --no-wait +%%l \"\"%%f\"\"\" ") " %o")))` – mlt Jun 01 '14 at 06:12
  • Here is the correct quotation: `(add-to-list 'TeX-view-program-list '("Sumatra PDF" ("sumatrapdf -reuse-instance" (mode-io-correlate " -forward-search %b %n -inverse-search \"emacsclientw --no-wait +%%l \\\"%%f\\\"\" ") " %o")))` as *"* is expanded according to *TeX-expand-list*. Also note that if you are using [Chocolatey](http://chocolatey.org) for Emacs and SumatraPDF installs, beware of [#372](https://github.com/chocolatey/chocolatey/issues/372). – mlt Jun 02 '14 at 16:27
1

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"))))
  • There is already the element `(output-pdf "start")` in `TeX-view-program-selection`. If I use: `(add-to-list 'TeX-view-program-selection '(output-pdf "Sumatra PDF"))`, I get twice the pair with the key `output-pdf`. – antonio Jan 23 '13 at 13:50
  • 1
    @antonio `add-to-list` adds the new element at the beginning of the list, and AUCTeX will use the first `output-pdf` element in `TeX-view-program-selection`. –  Jan 23 '13 at 14:05
  • Given the formatting constraints I commented editing the question. – antonio Jan 23 '13 at 14:25
  • +1 Sorry I haven't noticed your question edit. It works as intended now, thanks – antonio Jan 31 '13 at 15:35
1

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 :)

user2162871
  • 409
  • 3
  • 10
0

I have prepared a batch file, Emacs_SumatraPDF.bat.

It works perfect with sumatra-forward.el to realize forward and backward search.

For example:

Download

http://www.ai.soc.i.kyoto-u.ac.jp/~shi/files/Emacs_SumatraPDF.bat

http:/william.famille-blum.org/software/sumatra/sumatra-forward.el


Prepare

put Emacs_SumatraPDF.bat and SumatraPDF.exe --> %Emacs_Home%/bin.

put sumatra-forward.el --> %Emacs_Home%/site-lisp


Usage

;Emacs_Home=C:/Program Files (x86)/GNU Emacs 23.4
;~\.emacs add following information


;;; Emacs_SumatraPDF.bat
;;  @info: pdf viewer 
;   @refer: 
(setq TeX-view-program-list '(
      ("Sumatra" "C:/Program Files (x86)/GNU Emacs 23.4/bin/Emacs_SumatraPDF.bat 
                   %o %t %n") ))         

(setq TeX-view-program-selection '(
     (output-pdf "Sumatra") 
     (output-dvi "Yap") 
     ((output-dvi style-pstricks) "dvips and start") 
     (output-html "start"))) 

 ;;; sumatra-forward.el
 ;;  @info: forward search. 
 ;   @refer: http:/william.famille-blum.org/blog/static.php?page=static081010-000413
 (require 'sumatra-forward)

That is all.


Besides

Emacs 4 Latex Support under Windows 7 for newcomer for Emacs.

http://chunqishi.github.io/emacs4ls/


Jeff
  • 119
  • 1
  • 3
0

It's worth mentioning that Set inverse search command line is invisible in the Settings->Options dialog by default. To show this option field, go to Settings->Advanced options or open SumatraPDF-settings.txt and turn on EnableTeXEnhancements = true.

hanli8
  • 1
  • 3