I am syncing AUCTeX with Sumatra PDF on MSWindows. I used the instructions in https://www.barik.net/archive/2012/07/18/154432/ (I write here the setqs instead of customization)

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

However, when there is a space in the file name (e.g. "example 1.tex"), the syncing has problems: when from Emacs I do CRTL-c CRTL-v, it opens both the the file "example 1.pdf" and a dummy "123" file, where 123 is the line number in the source file.

Any suggestions on how to solve this problem?

  • 1
    The tutorial you link to is quite old. You can find the current instructions for your version of AucTeX from Emacs: C-h i to open the info system, m Auctex <return> to pick the AucTeX manual, m viewing <return> to open the chapter on viewers. It looks like your value for TeX-source-correlate-method is not in the right format. It should be (setq TeX-source-correlate-method '((dvi . source-specials) (pdf . synctex))) – Tyler Feb 1 '19 at 18:45
  • Code that manipulates file and directory names should use the Elisp functions provided for that. It should not use just string-manipulation functions. IOW, tell Emacs that these are file names by using filename-manipulation functions. – Drew Feb 1 '19 at 18:55
  • @Tyler - TeX-source-correlate-method can be set to the symbol synctex. Check the docstring with C-h v TeX-source-correlate-method RET. – Arash Esbati Feb 2 '19 at 12:31
  • The tutorial I used is the one recommend by the AUCTeX documentation emacswiki.org/emacs/AUCTeX#toc26 – Antongiulio Fornasiero Feb 2 '19 at 19:27

With a recent AUCTeX, you can reduce the required customization if you have SumatraPDF in your PATH env. variable. You can check if Emacs finds the executable with ESC-: (executable-find "sumatrapdf") RET. If the executable is found, you only need to customize TeX-view-program-selection and add the following line:

(output-pdf "SumatraPDF")

Note the missing blank.

If you have to hardcode the path, you have to quote the %b expander with \":

(setq TeX-view-program-list 
      '(("Sumatra PDF"
         ("\"C:/bin86/SumatraPDF/SumatraPDF.exe\" -reuse-instance" 
          (mode-io-correlate " -forward-search \"%b\" %n ") " %o"))))
  • Thanks, the suggestion of adding the \" worked perfectly. – Antongiulio Fornasiero Feb 4 '19 at 15:25
  • On the other hand, the line (output-pdf "SumatraPDF") should be added to the variable TeX-view-program-selection. Moreover, in the builtin variable TeX-view-program-list-builtin there is the same bug I had in my customization: if I view a file with a space inside its name, it also opens a dummy page with the pagenumber. – Antongiulio Fornasiero Feb 4 '19 at 15:52
  • @AntongiulioFornasiero - Thanks for catching the typo, I meant TeX-view-program-selection, answer edited. Reg. TeX-view-program-list-builtin, you're right, this issue was fixed in AUCTeX sources in April 2018, but the last ELPA release was in March 2018. It is time for a new ELPA release :-) – Arash Esbati Feb 4 '19 at 16:56

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.