From 0e9a359c1d5e8f67c20066533171fb1edc11ba61 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Mon, 16 Nov 2009 16:53:34 -0700 Subject: [PATCH] latex fragment images cached using sha1 hash keys Latex fragment images are now saved in files named by the sha1 hash of the latex text used to create the image. By checking if files exist before images generation the regeneration of identical latex images is avoided. --- lisp/ChangeLog | 6 ++++++ lisp/org.el | 22 +++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 5f83aaa..b581931 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2009-11-17 Eric Schulte + + * org.el (org-format-latex): Latex images are now saved to files + named by the sha1 hash of the latex source text avoiding + regeneration of identical images. + 2009-11-16 Carsten Dominik * org-html.el (org-export-html-home/up-format): Add an ID to the diff --git a/lisp/org.el b/lisp/org.el index bf6573b..15a8f9e 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -14550,15 +14550,9 @@ Some of the options can be changed using the variable (opt org-format-latex-options) (matchers (plist-get opt :matchers)) (re-list org-latex-regexps) - (cnt 0) txt link beg end re e checkdir + (cnt 0) txt hash link beg end re e checkdir executables-checked m n block linkfile movefile ov) - ;; Check if there are old images files with this prefix, and remove them - (when (file-directory-p todir) - (mapc 'delete-file - (directory-files - todir 'full - (concat (regexp-quote prefixnodir) "_[0-9]+\\.png$")))) ;; Check the different regular expressions (while (setq e (pop re-list)) (setq m (car e) re (nth 1 e) n (nth 2 e) @@ -14576,9 +14570,14 @@ Some of the options can be changed using the variable (setq txt (match-string n) beg (match-beginning n) end (match-end n) cnt (1+ cnt) - linkfile (format "%s_%04d.png" prefix cnt) - movefile (format "%s_%04d.png" absprefix cnt) link (concat block "[[file:" linkfile "]]" block)) + (setq hash (sha1 (prin1-to-string + (list org-format-latex-header + (if (boundp 'org-export-latex-package-alist) + org-export-latex-package-alist) + forbuffer txt))) + linkfile (format "%s_%s.png" prefix hash) + movefile (format "%s_%s.png" absprefix hash)) (if msg (message msg cnt)) (goto-char beg) (unless checkdir ; make sure the directory exists @@ -14592,8 +14591,9 @@ Some of the options can be changed using the variable "dvipng" "needed to convert LaTeX fragments to images") (setq executables-checked t)) - (org-create-formula-image - txt movefile opt forbuffer) + (unless (file-exists-p movefile) + (org-create-formula-image + txt movefile opt forbuffer)) (if overlays (progn (mapc (lambda (o) -- 1.6.4.73.gc144