all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Odd constrained failure mode in org-format-latex
@ 2010-07-31 22:35 Alexandre Passos
  2010-08-01  8:08 ` Bastien
  0 siblings, 1 reply; 2+ messages in thread
From: Alexandre Passos @ 2010-07-31 22:35 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

I was editing an org document on a server earlier today, remotely
using tramp, and continuously exporting it to html. When I added
LaTeX, it exported once and then not anymore, failing because it
couldn't create a directory anymore. So I found out that patching
org-export-latex to pass a "t" parameter to org-make-directory fixes
this, and it continues to work perfectly. This is the modified version
of that function, if anyone else is interested in this constrained
case. The only change I made was right under the "make sure directory
exists" comment.

(defun org-format-latex (prefix &optional dir overlays msg at forbuffer)
  "Replace LaTeX fragments with links to an image, and produce images."
  (if (and overlays (fboundp 'clear-image-cache)) (clear-image-cache))
  (let* ((prefixnodir (file-name-nondirectory prefix))
	 (absprefix (expand-file-name prefix dir))
	 (todir (file-name-directory absprefix))
	 (opt org-format-latex-options)
	 (matchers (plist-get opt :matchers))
	 (re-list org-latex-regexps)
	 (cnt 0) txt link beg end re e checkdir
	 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)
	    block (if (nth 3 e) "\n\n" ""))
      (when (member m matchers)
	(goto-char (point-min))
	(while (re-search-forward re nil t)
	  (when (and (or (not at) (equal (cdr at) (match-beginning n)))
		     (not (get-text-property (match-beginning n)
					     'org-protected)))
	    (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))
	    (if msg (message msg cnt))
	    (goto-char beg)
	    (unless checkdir ; make sure the directory exists
	      (setq checkdir t)
	      (or (file-directory-p todir) (make-directory todir t)))
	    (org-create-formula-image
	     txt movefile opt forbuffer)
	    (if overlays
		(progn
		  (setq ov (org-make-overlay beg end))
		  (if (featurep 'xemacs)
		      (progn
			(org-overlay-put ov 'invisible t)
			(org-overlay-put
			 ov 'end-glyph
			 (make-glyph (vector 'png :file movefile))))
		    (org-overlay-put
		     ov 'display
		     (list 'image :type 'png :file movefile :ascent 'center)))
		  (push ov org-latex-fragment-image-overlays)
		  (goto-char end))
	      (delete-region beg end)
	      (insert link))))))))


-- 
 - Alexandre

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-08-01 16:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-31 22:35 Odd constrained failure mode in org-format-latex Alexandre Passos
2010-08-01  8:08 ` Bastien

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.