[macemacsjp-english 830] PDF previewing of TeX code and forward search

Back to archive index

Kasper Daniel Hansen khans****@stat*****
Sat Jan 13 07:49:19 JST 2007


Hi

There were quite a few posts in December on getting a good preview  
program to work for editing LaTeX documents, since Preview.app  
(amongst other things) do not automatically reload the pdf document  
when it is changed because of a recompilation of the latex code.  
Suggestions of other programs were Acrobat Reader and Texniscope.

I have looked at a new application based in part on Texniscope:  
PDFView ( http://pdfview.sourceforge.net/index.html ).

Amongst other things I like is
- Automatic reload of the page when the pdf source changes
- I like the keyboard navigation better (space jumps one viewing unit  
at a time)
- Automatic maximization for better readability (after having tried  
this for a few days, this is a killer feature in my opinion: I read  
quite a lot of pdf documents, and this has just made it so much better)

I have managed to get PDFView to work with AUCTeX, providing both  
forward search (when doing C-c C-c View in AUCTeX, PDFView changes to  
the line in the pdf document corresponding to the line I was editing)  
and inverse search (When you CTRL+click in the pdf document, Emacs  
jumps to the relevant place in the source code).

My preference is to have the PDF opening (from Emacs) to be done in  
the background, but I want Emacs to get the focus when I CTRL+click  
in PDFView.

So here are the steps you need to take (assuming Emacs.app and  
PDFVIew.app is installed in /Applications):

1) Customizing PDFView: in the LaTeX pref. panel, choose "custom"  
under pdfsync preset. The command is
   /Applications/Emacs.app/Contents/MacOS/bin/emacsclient
and the argument is
   --no-wait +%line %file

(I have emailed the author to ask him to include this as a standard  
preset in next version)

Note: I had to click around a bit in the pref. panel before I got  
PDFView to accept my entries. I think there is a small bug regarding  
the automatic saving of preferences (also reported to the author)

2) Customizing Emacs. Add the following to your .emacs

(server-start)

(defun raise-emacs-on-aqua()
   (shell-command
    "osascript -e 'tell application \"Emacs\" to activate'"))
(add-hook 'server-switch-hook 'raise-emacs-on-aqua)

(require 'tex-site)
(add-hook 'TeX-mode-hook
	  (lambda ()
	    (add-to-list 'TeX-output-view-style
			 '("^pdf$" "."
			   "/Applications/PDFView.app/Contents/MacOS/gotoline.sh %n % 
(OutFullPath)"))
	    (add-to-list 'TeX-expand-list
			 '("%(OutFullPath)" (lambda nil
					      (expand-file-name
					       (TeX-view-output-file)
					       (TeX-master-directory)))))
))

The first line is to get inverse search to work. The next group of  
lines is to make Emacs gain focus when you do inverse search, and the  
last group of lines (beginning with (require 'tex-site) is to get  
forward search to work with AUCTeX.

3) Add
\usepackage{pdfsync}
to your LaTeX code and use pdflatex to compile it (on my systems the  
latex command is just an alias for pdflatex)

Cheers, Kasper



More information about the macemacsjp-english mailing list
Back to archive index