Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to set Emacs/AUCTeX to invoke an external PDF viewer so I can view the document output, preferably with source correlation via SyncTeX. AUCTeX, by default, suggested evince file.pdf; however, I don't have Evince installed and I figure Skim is a better option.

I searched around for how to go about this and found the following modifications to the .emacs file that should allow me to do this:

(add-hook 'LaTeX-mode-hook 'TeX-source-correlate-mode)

(setq TeX-source-correlate-method 'synctex)

(add-hook 'LaTeX-mode-hook
      (lambda()
        (add-to-list 'TeX-expand-list
             '("%q" skim-make-url))))

(defun skim-make-url () (concat
        (TeX-current-line)
        " "
        (expand-file-name (funcall file (TeX-output-extension) t)
            (file-name-directory (TeX-master-file)))
        " "
        (buffer-file-name)))

(setq TeX-view-program-list
      '(("Skim" "/Applications/Skim.app/Contents/SharedSupport/displayline %q")))

(setq TeX-view-program-selection '((output-pdf "Skim")))

Source: http://www.bleedingmind.com/index.php/2010/06/17/synctex-on-linux-and-mac-os-x-with-emacs/

The hooks load without complaints. I tested on a filed named sandbox.tex, which produced the output sandbox.pdf and the C-c C-c view command attempts to invoke Skim as follows:

 /Applications/Skim.app/Contents/SharedSupport/displayline 1 /path-to-sandbox.pdf /path-to-sandbox.tex

but nothing happens: Skim does not launch nor does AUCTeX complain. I'm stumped here.

I'm using GNU Emacs 23.2.1 (x86_64-apple-darwin10.4.0, NS apple-appkit-1038.32) and AUCTeX v.11.86 on OSX 10.6.6.

share|improve this question
    
I have more or less the same configuration and it works just fine here. What happens if you run the displayline command (exactly as it is invoked by Emacs) through the Terminal? –  cefstat Feb 21 '11 at 9:00
    
Running the display command through the Terminal opens the PDF with Skim. It complains some as follows, but seems to work things out by itself. –  Ricardo Feb 21 '11 at 13:06
    
2011-02-21 09:05:23.459 osascript[62878:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osascript: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers. –  Ricardo Feb 21 '11 at 13:08
    
Try installing evince and see if that works. Does skim work on the PDF if you open it manually? If you open it from inside emacs with M-! skim file.pdf ? –  Seamus Feb 21 '11 at 13:15
3  
shouldn't you set skim as your default PDF viewer, then in emacs, the command to open it should be open foo.pdf -- or that always worked for me with carbon emacs. –  Mica Feb 21 '11 at 17:24

4 Answers 4

Not exactly an answer to your question but a work-around. I use skim too and a tool called latexmk that I just found today. It's like a MakeFile for LateX only better. If you call it as: latexmk yourfile.tex -pvc it will look for changes and rerun whenever you save your files. And skim will see that the file has changed and reload. Seems to work nicely (only lately the auto reload function of my skim is messing up but that is beside the point). By default it outputs dvi though so you probably want to run it as:

$ latexmk yourfile.tex -pvc -pdf
share|improve this answer
    
I get the same auto-reload behavior with the Mac's Preview.app when I open it manually. If it weren't for that I would have probably gone insane opening files upon each modification! How do you get Skim to launch? –  Ricardo Feb 21 '11 at 20:08
    
I launch Skim (once) the same way as I launch any mac application. Then I load the pdf I want to view. Once I have done that skim notices whenever the file has changed and asks whether to reload or not reload. In that dialog window there is an auto button which sets skim to reload automatically whenever there is a change. Was that what you were asking? –  jonalv Feb 22 '11 at 12:58
    
Yes, that was my question. Unfortunately I was hoping you would tell me you launched it from Emacs with C-c C-v or C-c C-c View. I can live with launching Skim or Preview once and having it auto-reload, but it would be nice to get Emacs to do it for me. –  Ricardo Feb 22 '11 at 18:55
up vote 6 down vote accepted

Got it to work. A hard wrap happened in the following function after formatting it with M-q, separating the %q from the rest of the command.

(setq TeX-view-program-list
      '(("Skim" "/Applications/Skim.app/Contents/SharedSupport/displayline 
              %q")))

I couldn't catch it initially because it looked OK (even though it was not). I also must have fixed it when I pasted it in the question. At any rate, the proper form is:

(setq TeX-view-program-list
  '(("Skim" "/Applications/Skim.app/Contents/SharedSupport/displayline %q")))

and now things work as they should.

share|improve this answer
1  
Thank you very much -- greatly appreciated!!!!!!!!!!! Just in case I didn't put in enough exclamation points, here are a few more !!!!!!!! :) –  lawlist Apr 24 '13 at 5:00
    
Do you know what should I write if I want to use Mac's preview instead of skim? –  LWZ Oct 30 '13 at 1:41
    
You would be better served by asking a new question. That being said, tex.stackexchange.com/a/70409/3731 suggests using open -a/Applications/Preview.app/Contents/MacOS/Preview %.pdf if one is already using a different viewer. If Preview.app is your default, adding this to your .emacs should work: (add-to-list 'TeX-command-list (list "View" "/Applications/Preview.app/Contents/MacOS/Preview %o" 'TeX-run-discard t t :help "Run Viewer")). Finally, this does the same thing: tex.stackexchange.com/a/119649/3731. –  Ricardo Oct 30 '13 at 5:03

skim-make-url doesn't work with paths with spaces (at least for me) so I had to double quote the paths, like this:

(defun skim-make-url ()
  (concat
   (TeX-current-line)
   " \""
   (expand-file-name (funcall file (TeX-output-extension) t)
             (file-name-directory (TeX-master-file)))
   "\" \""
   (buffer-file-name)
   "\""))
share|improve this answer

I'm not sure whether this is exactly related to the same issue experienced by the original poster, but I recently experienced a similar issue when trying to automatically launch any pdf previewer following a latex build when using the terminal (or comparable Shell utility) on a couple of my Macs running OSX 10.6.8. I discovered that setting the $preview_mode = 1 within latexmkrc fixes this issue. If using -pvc or $preview_continuous_mode = 1, then $preview_mode = 1 would need to be turned off so as to avoid a conflict. The command line equivalent for $preview_mode= is -pv.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.