Diagram related Org Mode Settings

My configures

NOTE: PlantUML depends on graphviz, download it from its official web site.

;; enable ditaa
(org-babel-do-load-languages 'org-babel-load-languages '((ditaa . t)))
;; don't ask before evaluating ditaa blocks
(defun my-org-confirm-babel-evaluate (lang body)
  (not (string= lang "ditaa")))
(setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate
      org-ditaa-jar-path (concat my-extension-path
                                 "org/contrib/scripts/ditaa.jar"))

Make them work in Cygwin

The issue

  • There is no native java for Cygwin.
  • In Cygwin, we use java for windows.
  • Java for windows does not recognize file paths in the Cygwin style.
  • Java fails to run ditaa.jar and plantuml.jar.
  • No "nice" pictures generated.

The solution

It is simple and straight forward: convert the paths before passing them to java.

Put generated images to publish directories

The issue

  1. Unlike html files, the PNG files generated by ditaa are put under current directory instead of designated publish directory.
  2. That implies, after publishing current file/project, I will have to "manually" move the ditaa pictures to the publish directory.

Solution

After some googling and code reading, I did not find an elegant way. So, here is my dirty-but-work solution.

  1. Save "tmp-pub-dir", which is the real publish destination.
  2. Before assembling the ditaa command, modify the "out-file" accordingly.

Note that setting property "dir" does work. This way, the links to images will be changed as well. Consequently, links are broken.

My patches

NOTE: writing a wrapper script of java might be a better design. But now that I am already here …

*** ox-publish.el.8.2.10    2015-02-27 14:26:36.827628700 +0800
--- ox-publish.el   2015-02-27 14:28:28.014746300 +0800
***************
*** 647,652 ****
--- 647,653 ----
       (concat pub-dir
           (and (string-match (regexp-quote base-dir) ftname)
            (substring ftname (match-end 0))))))
+     (setq lgf-tmp-pub-dir tmp-pub-dir)
      (if (listp publishing-function)
    ;; allow chain of publishing functions
    (mapc (lambda (f)
***************
*** 662,667 ****
--- 663,675 ----
     filename pub-dir publishing-function base-dir)))
      (unless no-cache (org-publish-write-cache-file))))

+ (defun lgf-get-tmp-pub-dir (file)
+   "I want the generated picture in tmp-pub-dir."
+   ;; Refer to [[file:~/mynotes/emacs/org-graph.blog]]"
+   (if (and lgf-tmp-pub-dir (not (string-prefix-p "/" file)))
+       (concat lgf-tmp-pub-dir file)
+     file))
+ 
  (defun org-publish-projects (projects)
    "Publish all files belonging to the PROJECTS alist.
  If `:auto-sitemap' is set, publish the sitemap too.  If
*** ob-ditaa.el.8.2.10  2015-03-03 13:43:37.246318300 +0800
--- ob-ditaa.el 2015-03-03 13:46:45.692387300 +0800
***************
*** 92,103 ****
     (eps (cdr (assoc :eps params)))
     (cmd (concat org-babel-ditaa-java-cmd
              " " java " " org-ditaa-jar-option " "
              (shell-quote-argument
               (expand-file-name
!           (if eps org-ditaa-eps-jar-path org-ditaa-jar-path)))
              " " cmdline
!             " " (org-babel-process-file-name in-file)
!             " " (org-babel-process-file-name out-file)))
     (pdf-cmd (when (and (or (string= (file-name-extension out-file) "pdf")
                 (cdr (assoc :pdf params))))
            (concat
--- 92,105 ----
     (eps (cdr (assoc :eps params)))
     (cmd (concat org-babel-ditaa-java-cmd
              " " java " " org-ditaa-jar-option " "
+                       (cygpath
                         (shell-quote-argument
                          (expand-file-name
!                          (if eps org-ditaa-eps-jar-path org-ditaa-jar-path))))
              " " cmdline
!             " " (cygpath (org-babel-process-file-name in-file))
!             " " (cygpath (org-babel-process-file-name
!                                     (lgf-get-tmp-pub-dir out-file)))))
     (pdf-cmd (when (and (or (string= (file-name-extension out-file) "pdf")
                 (cdr (assoc :pdf params))))
            (concat
*** /home/lungangf/.emacs.d/emacs-extensions/org/lisp/ob-plantuml.el.orig   2014-03-10 17:04:43.598032200 +0800
--- /home/lungangf/.emacs.d/emacs-extensions/org/lisp/ob-plantuml.el    2014-03-10 17:03:28.260413500 +0800
***************
*** 58,73 ****
     (cmd (if (string= "" org-plantuml-jar-path)
          (error "`org-plantuml-jar-path' is not set")
        (concat "java " java " -jar "
            (shell-quote-argument
!            (expand-file-name org-plantuml-jar-path))
            (if (string= (file-name-extension out-file) "svg")
                " -tsvg" "")
            (if (string= (file-name-extension out-file) "eps")
                " -teps" "")
            " -p " cmdline " < "
!           (org-babel-process-file-name in-file)
            " > "
!           (org-babel-process-file-name out-file)))))
      (unless (file-exists-p org-plantuml-jar-path)
        (error "Could not find plantuml.jar at %s" org-plantuml-jar-path))
      (with-temp-file in-file (insert (concat "@startuml\n" body "\n@enduml")))
--- 58,75 ----
     (cmd (if (string= "" org-plantuml-jar-path)
          (error "`org-plantuml-jar-path' is not set")
        (concat "java " java " -jar "
+                 (cygpath
            (shell-quote-argument
!            (expand-file-name org-plantuml-jar-path)))
            (if (string= (file-name-extension out-file) "svg")
                " -tsvg" "")
            (if (string= (file-name-extension out-file) "eps")
                " -teps" "")
            " -p " cmdline " < "
!           (cygpath (org-babel-process-file-name in-file))
            " > "
!           (cygpath (org-babel-process-file-name
!                       (lgf-get-tmp-pub-dir out-file)))))))
      (unless (file-exists-p org-plantuml-jar-path)
        (error "Could not find plantuml.jar at %s" org-plantuml-jar-path))
      (with-temp-file in-file (insert (concat "@startuml\n" body "\n@enduml")))

Created: 2015-12-11 Fri 16:07 by Emacs 24.5.1 (Org mode 8.2.10)

comments powered by Disqus