From mboxrd@z Thu Jan 1 00:00:00 1970 From: Aaron Ecay Subject: [PATCH 3/3] Add synctex modification based on concordance Date: Sun, 31 Mar 2013 23:15:01 -0400 Message-ID: <1364786101-16603-4-git-send-email-aaronecay@gmail.com> References: <1364786101-16603-1-git-send-email-aaronecay@gmail.com> Return-path: Received: from eggs.gnu.org ([208.118.235.92]:44175) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMVDK-0002Rk-Pl for emacs-orgmode@gnu.org; Sun, 31 Mar 2013 23:15:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMVDH-0003hO-SP for emacs-orgmode@gnu.org; Sun, 31 Mar 2013 23:15:18 -0400 Received: from mail-qc0-x22f.google.com ([2607:f8b0:400d:c01::22f]:48540) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMVDH-0003hI-OH for emacs-orgmode@gnu.org; Sun, 31 Mar 2013 23:15:15 -0400 Received: by mail-qc0-f175.google.com with SMTP id j3so892113qcs.20 for ; Sun, 31 Mar 2013 20:15:15 -0700 (PDT) In-Reply-To: <1364786101-16603-1-git-send-email-aaronecay@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org * lisp/ox-latex.el (org-latex-patch-synctex): New function (org-latex-export-to-pdf): Call it, if appropriate This teaches the latex backend how to patch synctex files. The patch will be done automatically if exporting directly to pdf. If not, the user must call the org-latex-patch-synctex function (because it relies on the synctex file, which will only be generated when pdflatex is run) Touch the file after modifying the synctex, to trigger the pdf viewer to re-read it. --- lisp/ox-latex.el | 64 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 8727adc..43c5fde 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -115,6 +115,7 @@ (eval-when-compile (require 'cl)) (require 'ox) (require 'ox-publish) +(require 'dired) ; for dired-touch-program (defvar org-latex-default-packages-alist) (defvar org-latex-packages-alist) @@ -1150,6 +1151,43 @@ just outside of it." (funcall search-refs element)) "")) +(defun org-latex-patch-synctex (&optional subtreep) + (cond + ((not org-export-concordance) + (message "No concordance, not patching.")) + ((not (file-exists-p + (org-export-output-file-name ".synctex.gz" subtreep))) + (message "No synctex file found, not patching.")) + (t + (let* ((conc org-export-concordance) + (file-base (org-export-output-file-name "." subtreep)) + (buf (find-file-noselect (concat file-base "synctex.gz")))) + (with-current-buffer buf + (let ((max-index 0) + the-index extra-path) + (goto-char (point-min)) + (while (re-search-forward "^Input:\\([0-9]+\\):" nil t) + (setq max-index (max max-index (string-to-int (match-string 1))))) + (goto-char (point-min)) + (when (re-search-forward (concat "^Input:\\([0-9]+\\):\\(.*\\)" + (regexp-quote file-base) "tex$") + nil t) + (setq the-index (string-to-int (match-string 1))) + (setq extra-path (match-string 2)) + (goto-char (line-end-position)) + (insert (format "\nInput:%s:%s%sorg" (1+ max-index) extra-path file-base))) + (goto-char (point-min)) + (while (re-search-forward (format "^[vhxkgr$[)]\\(%s\\),\\([0-9]+\\):" + the-index) + nil t) + (replace-match (int-to-string (1+ max-index)) nil t nil 1) + (replace-match + (int-to-string + (org-export--read-concordance conc (string-to-int (match-string 2)))) + nil t nil 2)) + (save-buffer))) + (kill-buffer buf))))) + ;;; Template @@ -2918,14 +2956,24 @@ Return PDF file's name." (let ((outfile (org-export-output-file-name ".tex" subtreep))) (org-export-async-start (lambda (f) (org-export-add-to-stack f 'latex)) - `(expand-file-name - (org-latex-compile - (org-export-to-file - 'latex ,outfile ,subtreep ,visible-only ,body-only - ',ext-plist))))) - (org-latex-compile - (org-latex-export-to-latex - nil subtreep visible-only body-only ext-plist)))) + `(let ((pdf-file + (expand-file-name + (org-latex-compile + (org-export-to-file + 'latex ,outfile ,subtreep ,visible-only ,body-only + ',ext-plist))))) + (when org-export-with-concordance + (org-latex-patch-synctex subtreep) + (call-process dired-touch-program nil nil nil pdf-file)) + pdf-file))) + (let ((pdf-file + (org-latex-compile + (org-latex-export-to-latex + nil subtreep visible-only body-only ext-plist)))) + (when org-export-with-concordance + (org-latex-patch-synctex subtreep) + (call-process dired-touch-program nil nil nil pdf-file)) + pdf-file))) (defun org-latex-compile (texfile &optional snippet) "Compile a TeX file. -- 1.8.2