emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Aaron Ecay <aaronecay@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH 3/3] Add synctex modification based on concordance
Date: Sun, 31 Mar 2013 23:15:01 -0400	[thread overview]
Message-ID: <1364786101-16603-4-git-send-email-aaronecay@gmail.com> (raw)
In-Reply-To: <1364786101-16603-1-git-send-email-aaronecay@gmail.com>

* 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)))))
+
 
 \f
 ;;; 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

  parent reply	other threads:[~2013-04-01  3:15 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-01  3:14 [PATCH 0/3] synctex support for pdf export Aaron Ecay
2013-04-01  3:14 ` [PATCH 1/3] Add :begin-line and :end-line to parser results Aaron Ecay
2013-04-01  3:15 ` [PATCH 2/3] Introduce machinery to ox.el for concordance generation Aaron Ecay
2013-04-01  3:15 ` Aaron Ecay [this message]
2013-04-01  9:15 ` [PATCH 0/3] synctex support for pdf export Nicolas Goaziou
2013-04-01 15:33   ` Aaron Ecay
2013-04-04 13:19     ` Nicolas Goaziou
2013-04-18  8:29       ` Aaron Ecay
2013-04-18 16:27         ` Rasmus
2013-04-15  9:33   ` Andreas Leha
2013-04-15 11:50     ` Alan Schmitt
2013-04-15 15:37       ` Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1364786101-16603-4-git-send-email-aaronecay@gmail.com \
    --to=aaronecay@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).