UP | HOME

使用Org mode画图

Table of Contents

设置 Org-babel

ditaa的相关代码已经由org-mode提供,你需要在系统中安装 graphviz 和 PlantUML 。graphviz 的安装参见笔记:http://wiki.manan.org/data/graphviz.html

然后将下面代码更改路径后添加到emacs的init file中。

(setq org-ditaa-jar-path "~/git/org-mode/contrib/scripts/ditaa.jar")
(setq org-plantuml-jar-path "~/java/plantuml.jar")

(add-hook 'org-babel-after-execute-hook 'bh/display-inline-images 'append)

; Make babel results blocks lowercase
(setq org-babel-results-keyword "results")

(defun bh/display-inline-images ()
  (condition-case nil
      (org-display-inline-images)
    (error nil)))

(org-babel-do-load-languages
 (quote org-babel-load-languages)
 (quote ((emacs-lisp . t)
         (dot . t)
         (ditaa . t)
         (R . t)
         (python . t)
         (ruby . t)
         (gnuplot . t)
         (clojure . t)
         (sh . t)
         (ledger . t)
         (org . t)
         (plantuml . t)
         (latex . t))))

; Do not prompt to confirm evaluation
; This may be dangerous - make sure you understand the consequences
; of setting this -- see the docstring for details
(setq org-confirm-babel-evaluate nil)

; Use fundamental mode when editing plantuml blocks with C-c '
(add-to-list 'org-src-lang-modes (quote ("plantuml" . fundamental)))

ditaa

在org文件中输入:

#+begin_src ditaa :file d.png :cmdline -r -s 1.0
    +-----------+        +---------+
    |    PLC    |        |         |
    |  Network  +<------>+   PLC   +<---=---------+
    |    cYEL   |        |  cYEL   |              |
    +-----------+        +----+----+              |
#+end_src

执行 C-c C-c 可以在 file 指定的路径中生成图片,或者直接查看生成的html结果: C-c C-e h o ,生成的图片如下:

d.png

Graphviz

在org文件中输入:

#+begin_src dot :file g.svg :cmdline -Kdot -Tsvg
digraph G {
  size="8,6"
  ratio=expand
  edge [dir=both]
  plcnet [shape=box, label="PLC Network"]
  subgraph cluster_wrapline {
    label="Wrapline Control System"
    color=purple
    subgraph {
    rank=same
    exec
    sharedmem [style=filled, fillcolor=lightgrey, shape=box]
    }
    edge[style=dotted, dir=none]
    exec -> opserver
    exec -> db
    plc -> exec
    edge [style=line, dir=both]
    exec -> sharedmem
    sharedmem -> db
    plc -> sharedmem
    sharedmem -> opserver
  }
  plcnet -> plc [constraint=false]
  millwide [shape=box, label="Millwide System"]
  db -> millwide

  subgraph cluster_opclients {
    color=blue
    label="Operator Clients"
    rankdir=LR
    labelloc=b
    node[label=client]
    opserver -> client1
    opserver -> client2
    opserver -> client3
  }
}
#+end_src

执行 C-c C-c 可以在 file 指定的路径中生成图片,或者直接查看生成的html结果: C-c C-e h o ,生成的图片如下:

g.svg

Emacs插件

Graphviz dot mode for emacs 插件提供了在Emacs中快速编写、编译Graphviz图片的方法。

graphviz-dot-mode.png

  • 地址:
  • 使用方法
    • 添加 (load-file "PATH_TO_FILE/graphviz-dot-mode.el") 到init file中;
  • 缩进 tab, M-j and C-M-q
  • 插入注释 M-;
  • 编译 C-c c
  • 查错 M-x next-error
  • 图片预览 C-c p (我没有试成功)

PlantUML

在org文件中输入:

#+begin_src plantuml :file p.png
@startuml
Alice->Alice: This is a signal to self.\nIt also demonstrates\nmultiline \ntext
@enduml
#+end_src

执行 C-c C-c 可以在 file 指定的路径中生成图片,或者直接查看生成的html结果: C-c C-e h o ,生成的图片如下:

p.png

参考:

Date: 2014-12-20

Author: 马楠

Created: 2014-12-22 一 21:49

Emacs 24.3.1 (Org mode 8.2.10)

Validate