The following functions use Windows' DDE messaging protocol to control Adobe Acrobat Reader. Additionally, they define an extra expansion pattern for calling Acrobat with the full, quoted pathname of the PDF file.
The DDE functions work much more effectively when Acrobat has been opened by emacs, rather than being a pre-existing process. The code currently does no checking for whether Acrobat is used by emacs; that would be a useful robustness check.
;; LaTeX (load "auctex.el" nil t t) (require 'reftex) (defun acrobat-close-file (file) "Close file in Acrobat" (save-excursion (set-buffer (get-buffer-create " *ddeclient*")) (erase-buffer) (insert "[DocOpen(\"" file "\")]\n" ) (insert "[DocClose(\"" file "\")]\n" ) (call-process-region (point-min) (point-max) "ddeclient" t t nil "acroview" "control") (if (= 0 (string-to-int (buffer-string))) t nil))) (defun acrobat-open-file (file) "Open file in Acrobat" (save-excursion (set-buffer (get-buffer-create " *ddeclient*")) (erase-buffer) (insert "[DocOpen(\"" file "\")]\n" ) (insert "[FileOpen(\"" file "\")]\n" ) (call-process-region (point-min) (point-max) "ddeclient" t t nil "acroview" "control") (if (= 0 (string-to-int (buffer-string))) t nil))) (defadvice TeX-run-TeX (before cleanup-acrobat (name command file)) "Wrapped version that closes pdfs first" (let* ((fullfile (expand-file-name (concat file ".pdf") (TeX-master-directory))) (filestats (file-attributes fullfile)) (filesize (nth 7 filestats))) (if (and (file-exists-p fullfile) (> filesize 0)) ; simple case for degenerate files ; that cause Adobe to be upset (progn (acrobat-close-file fullfile) (raise-frame (car (car (cdr (current-frame-configuration))))))) ) ) (add-hook 'TeX-mode-hook (lambda () (add-to-list 'TeX-expand-list '("%(OutFullPath)" (lambda nil (expand-file-name (TeX-active-master (TeX-output-extension) t) (TeX-master-directory)))))) ) ; Add to custom-set-variables section (custom-set-variables '(TeX-output-view-style '(("^pdf$" "." "\"path/to/AcroRd32.exe\" \"%(OutFullPath)\""))))
Contact
- Email (essential):
- (first initial + last name) {at} ccs.neu.edu
- Location (likely):
- West Village H, Office 326
- Post (possible):
-
Northeastern University
Khoury College of Computer Sciences
360 Huntington Ave, 2nd floor
Boston, MA 02115


