LaTeX and PDFView

PDFView offers powerful integration with LaTeX:

Setting up your editor

With the use of PDFSync, you can have PDFView load the document, and jump to the corresponding page of the line you are editing in your editor. To do it, all you have to do is set up your editor to call this script:

PDFView.app/Contents/MacOS/gotoline.sh %line "%pdffile"

One thing is to be noticed: %pdffile must be the full path of the PDF document - e.g. /Users/andry/work/test.pdf is fine, where ~/job.pdf is not.

Setting up TextMate

For TextMate, you can open up the Bundle Editor (Control+Option+Command+B), select LaTeX and create (or replace the TeXniscope one) a new item, calling it (for example) "Show in PDFView (pdfsync)". Insert the following as the commands:

# If TM_LATEX_MASTER is not set use TM_FILEPATH
: ${TM_LATEX_MASTER:=$TM_FILEPATH}

# Switch to the right directory
cd "${TM_PROJECT_DIRECTORY:-$TM_DIRECTORY}"
cd "$(dirname "$TM_LATEX_MASTER")"

FILE="$TM_LATEX_MASTER"
SCRIPT="$(find_app PDFView.app)/Contents/MacOS/gotoline.sh"

if [[ -x "$SCRIPT" ]]; then
	"$SCRIPT" &>/dev/console "$TM_LINE_NUMBER" "${FILE%.tex}.pdf"
	open -a PDFView.app
else
	echo "Unable to locate PDFView."
fi

Your new command should look similar to this screenshot:

TextMate setup

Setting up Emacs

The following code may require a newer version of Emacs and AUCTeX, it was tested using Emacs version 22.0.97.1 and AUCTeX 11.84, all contained in Carbon Emacs build from Spring 2007

Inverse search

You need to put the following code in your .emacs

		;; Starts the Emacs server
		(server-start)
		

In addition, most people would want to make Emacs auto-raise when a CMD + Click is executed in PDFView. Carbon Emacs does not seem to respond to raise-frame, so we do it using Applescript.

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

The ampersand after activate makes the command slightly more robust, but also opens up an *Async Shell Command*. You may experiment with removing it.

Forward Search

To make PDFView jump to the relevant line of the LaTeX source, you can add the following to your .emacs

		;; The following only works with AUCTeX loaded
		(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-active-master (TeX-output-extension) t)
		                                  (TeX-master-directory))))))
		)
		

Please note: this section is based on the suggestions of Kasper Daniel Hansen.