From 8e30cbca79c1290a1a680d4ed91d2faa00122c1d Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Mon, 16 Nov 2009 17:11:03 -0700 Subject: [PATCH] Sha1 hash of latex fragments to avoid regeneration Patch by Eric Schulte, with amends by Carsten --- lisp/ChangeLog | 11 +++++++++++ lisp/org-latex.el | 9 --------- lisp/org.el | 35 +++++++++++++++++++++++------------ 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 5f83aaaa5..f7935c000 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,14 @@ +2009-11-17 Carsten Dominik + + * org.el (org-export-latex-packages-alist): Option definition + moved here from org-latex.el. + +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-latex.el b/lisp/org-latex.el index d89ce2c5a..85a6684cd 100644 --- a/lisp/org-latex.el +++ b/lisp/org-latex.el @@ -256,15 +256,6 @@ When nil, grouping causes only separation lines between groups." :group 'org-export-latex :type 'boolean) -(defcustom org-export-latex-packages-alist nil - "Alist of packages to be inserted in the header. -Each cell is of the format \( \"option\" . \"package\" \)." - :group 'org-export-latex - :type '(repeat - (list - (string :tag "option") - (string :tag "package")))) - (defcustom org-export-latex-low-levels 'itemize "How to convert sections below the current level of sectioning. This is specified by the `org-export-headline-levels' option or the diff --git a/lisp/org.el b/lisp/org.el index bf6573bc8..74540276d 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -2858,6 +2858,17 @@ appears on the page." :group 'org-latex :type 'string) +;; The following variable is defined here because is it also used +;; when formatting latex fragments. Originally it was part of the +;; LaTeX exporter, which is why the name includes "export". +(defcustom org-export-latex-packages-alist nil + "Alist of packages to be inserted in the header. +Each cell is of the format \( \"option\" . \"package\" \)." + :group 'org-export-latex + :type '(repeat + (list + (string :tag "option") + (string :tag "package")))) (defgroup org-font-lock nil "Font-lock settings for highlighting in Org-mode." @@ -14550,15 +14561,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 +14581,15 @@ 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)) + (let (print-length print-level) ; make sure full list is printed + (setq hash (sha1 (prin1-to-string + (list org-format-latex-header + org-export-latex-packages-alist + org-format-latex-options + 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 +14603,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) @@ -14617,7 +14629,6 @@ Some of the options can be changed using the variable (delete-region beg end) (insert link)))))))) -(defvar org-export-latex-packages-alist) ;; defined in org-latex.el ;; This function borrows from Ganesh Swami's latex2png.el (defun org-create-formula-image (string tofile options buffer) "This calls dvipng." -- 2.11.4.GIT