2

I would like to define a customized function to open the complied pdf file of the current tex file in the default pdf viewer of the system (say SumatraPDF.exe).

I am primarily interested to a solution without AUCTeX/LateX mode facilities, though such a solution would be also useful.

Name
  • 7,689
  • 4
  • 38
  • 84
  • 1
    Here is a link to some AUCTeX solutions for Windows and OSX, and some non-AUCTeX solutions for each OS. I normally like to build and display, rather than just display; however, AUCTeX is already set up to handle a view-only so long as you define the default viewer correctly. See my notes, and then just look for the built-in AUCTeX view command after you have defined the default viewer: http://tex.stackexchange.com/a/156617/26911 I have already set it up for SumatraPDF.exe when using a Windows version of Emacs -- just adjust the absolute path to wherever you have installed the executable. – lawlist Feb 03 '15 at 09:11
  • @lawlist, (+1) your code is very complete. I asked about a tree you gave a forest. Thank you. A simple solution just to open the pdf file is still interests me. – Name Feb 03 '15 at 09:30
  • Your precise question is somewhat user-specific because the location and name of your `*.pdf` file may be different than other users, and most people like the `find-executable` instead of using the absolute path (which I personally prefer). I generally open the `*.pdf` that I send to the temporary folder, instead of the one copied to the working folder. You may be interested in using `dired-mode` to open a buffer and then select the `*.pdf` file (wherever it is) and then open it using SumatraPDF.exe -- some people seem to like the `open-with` library, but I haven't tried it with Windows. – lawlist Feb 03 '15 at 17:08
  • You can take the `xp-latexmk` example in the link above and dissect it -- keeping only what you want -- e.g., `(w32-shell-execute "open" latexmk-sumatra latexmk-w32-document)` is what opens the `*.pdf` file. **NOTE**: The code assumes you have built using synctex. You will probably want to remove everything relating to building and cleaning, and also remove the process sentinel stuff. – lawlist Feb 03 '15 at 17:20
  • @lawlist many thanks for you detailed comments. By the way, the code on TeX SE that you have given is one of the most comprehensive customization that I have seen. – Name Feb 03 '15 at 18:43

1 Answers1

1

Finding the default pdf viewer for your system will depend on your operating system I think. On some Linux systems xdg-open would work for this. It might be easier to hard-code the viewer into the code:

(defun my-view-pdf ()
  (interactive)
  (async-shell-command
    (concat "SumatraPDF " (file-name-base (buffer-file-name)) ".pdf")))

Of course, if you're using AucTex you can just call C-c C-v and you're done. Why not use AucTeX?

Tyler
  • 21,719
  • 1
  • 52
  • 92
  • @Name corrected, thanks. I don't understand how 'shell-commands' work in Windows, so I can't explain about the .exe suffix – Tyler Feb 03 '15 at 20:32