From d3689276ec7f4db7199c7f7759fbb09045dc9928 Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Thu, 30 Apr 2009 22:50:47 +0200 Subject: [PATCH] LaTeX fragments: Better error message when latex/dvipng unavailable Thomas Morgan writes: > I just tried exporting an Org file with LaTeX fragments to HTML > on a computer that doesn't have dvipng. There were error messages > in *Messages* ("Failed to create png file..."), but this wasn't > obvious to me at first glance because those messages were replaced > in the echo area by "Exporting... done" before I could see them. > > So I was wondering, is there a good way to make the user aware of > those errors? Maybe by printing "Exporting... done (with errors)"? There is now a better error message when either the latex or the dvipng program does not exist. --- lisp/ChangeLog | 4 ++++ lisp/org-exp.el | 5 ++++- lisp/org-macs.el | 12 ++++++++++++ lisp/org.el | 9 +++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 22aa6d256..1c8da8c30 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,6 +1,10 @@ 2009-04-30 Carsten Dominik + * org-macs.el (org-check-external-command): New defsubst. + * org.el (org-mode-map): New key for reload. + (org-format-latex): Better error message when external programs + are not available. * org-agenda.el (org-agenda-mode-map): Bind `org-reload'. diff --git a/lisp/org-exp.el b/lisp/org-exp.el index a72b601bd..da016c3af 100644 --- a/lisp/org-exp.el +++ b/lisp/org-exp.el @@ -425,7 +425,10 @@ the first non-white thing on a line. It will also find the math delimiters like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for display math. -This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"." +This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\". + +The default is nil, because this option needs the `dvipng' program which +is not available on all systems." :group 'org-export-translation :group 'org-export-latex :type 'boolean) diff --git a/lisp/org-macs.el b/lisp/org-macs.el index 4e9de17ef..cce886747 100644 --- a/lisp/org-macs.el +++ b/lisp/org-macs.el @@ -165,6 +165,18 @@ We use a macro so that the test can happen at compilation time." ((assoc key option) (cdr (assoc key option))) (t (cdr (assq 'default option))))) +(defsubst org-check-external-command (cmd &optional use no-error) + "Check if external progam CMD for USE exists, error if not. +When the program does exist, return it's path. +When it does not exist and NO-ERROR is set, return nil. +Otherwise, throw an error. The optional argument USE can describe what this +program is needed for, so that the error message can be more informative." + (or (executable-find cmd) + (if no-error + nil + (error "Can't find `%s'%s" cmd + (if use (format " (%s)" use) ""))))) + (defsubst org-inhibit-invisibility () "Modified `buffer-invisibility-spec' for Emacs 21. Some ops with invisible text do not work correctly on Emacs 21. For these diff --git a/lisp/org.el b/lisp/org.el index 1eec5bac8..69fc139e1 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -13521,6 +13521,7 @@ The images can be removed again with \\[org-ctrl-c-ctrl-c]." (matchers (plist-get opt :matchers)) (re-list org-latex-regexps) (cnt 0) txt 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) @@ -13549,6 +13550,14 @@ The images can be removed again with \\[org-ctrl-c-ctrl-c]." (unless checkdir ; make sure the directory exists (setq checkdir t) (or (file-directory-p todir) (make-directory todir))) + + (unless executables-checked + (org-check-external-command + "latex" "needed to convert LaTeX fragments to images") + (org-check-external-command + "dvipng" "needed to convert LaTeX fragments to images") + (setq executables-checked t)) + (org-create-formula-image txt movefile opt forbuffer) (if overlays