auctex-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[AUCTeX-devel] bug and fix for problem in style/pdfsync.el


From: Matan Ninio
Subject: [AUCTeX-devel] bug and fix for problem in style/pdfsync.el
Date: Sun, 24 Feb 2008 14:46:36 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)

Hi,
There seems to be a bug with pdfsync.wl (from 2005-12-28, which was my
35th birthday BTW).  When using files "\input"-ed from the master file,
but which happen to be in a different directory, the search of the
relevant section of the MASTER.pdfsync file fails.  This is due to
pdfsync.sty writing the inputed filenames with a path relevant to the
location of the master file, while pdfsync.el-s
LaTeX-pdfsync-output-page searches for the file name only (without
either the relative path of the extension).  Here is my version of the
function, which seems to fix this problem and works well when the
inputed files are either in the same directory or in subdirectories.

(defun LaTeX-pdfsync-output-page ()
  "Return page number in output file corresponding to buffer position."
  (let* ((line (TeX-line-number-at-pos))
         (master (TeX-active-master))
         (file (file-relative-name (buffer-file-name) (file-name-directory 
master)))
         (pdfsync-file (concat master ".pdfsync"))
         (sync-record "0")
         (sync-line "-1")
         (sync-page "1")
         last-match)
    (when (file-exists-p pdfsync-file)
      (with-current-buffer (find-file-noselect pdfsync-file)
        (save-restriction
          (goto-char (point-min))
          ;; Narrow region to file in question.
          (when (not (string= (file-name-sans-extension file) master))
            (re-search-forward (concat "^(" file "$") nil t)
            (let ((beg (match-beginning 0)))
              (goto-char beg)
              (narrow-to-region (line-beginning-position 2)
                                (progn (forward-sexp) (point))))
            (goto-char (point-min)))
          ;; Look for the record number.
          (catch 'break
            (while (re-search-forward "^(\\|^l \\([0-9]+\\) \\([0-9]+\\)" nil t)
              (cond ((string= (match-string 0) "(")
                     (goto-char (match-beginning 0))
                     (forward-sexp))
                    ((> (string-to-number (match-string 2)) line)
                     (throw 'break nil))
                    (t
                     (setq sync-record (match-string 1)
                           sync-line (match-string 2)
                           last-match (match-beginning 0))))))
          ;; Look for the page number.
          (goto-char (or last-match (point-min)))
          (catch 'break
            (while (re-search-forward "^p \\([0-9]+\\)" nil t)
              (when (>= (string-to-number (match-string 1))
                        (string-to-number sync-record))
                (re-search-backward "^s \\([0-9]+\\)" nil t)
                (setq sync-page (match-string 1))
                (throw 'break nil)))))))
    sync-page))

  
-- 
Matan Ninio             
-----------------------------------------
VI VI VI - The Roman Number of The Beast




reply via email to

[Prev in Thread] Current Thread [Next in Thread]