Below code will draw a tree graph with dot, it works fine but the output graph has been included in "".

#+NAME: nodes
| From | To | Weight |
| A    | B  |      3 |
| A    | C  |      2 |
| B    | D  |      4 |
| B    | E  |      5 |
| C    | F  |     10 |

#+BEGIN_SRC elisp :results output :wrap image :var nodes=nodes
    (defun rowfun(x)
      (format "%s -> %s [label=%s];" (nth 0 x) (nth 1 x) (nth 2 x))
    (defun dotgen(nodes)
      (let ((dotbegin "digraph {\nnode [shape=circle]\n")
            (dotend "\n}"))
        (concat dotbegin
                (mapconcat #'rowfun nodes "\n")
    (setq dotname "test.dot")
  (setq pngname (format "%s.png"
                        (replace-regexp-in-string "\.dot" "" dotname)))
  (with-temp-file dotname (insert (dotgen nodes)))
  (shell-command-to-string (format "dot -Tpng %s -o %s" dotname pngname))
  (delete-file dotname)
  (print (format "[[./%s]]" pngname))



The output:

enter image description here

How can I get a clean image without the extra "" printed before and end of the picture?

  • What happens if you remove each double-quote from the second to the last line of your example code? I.e., change "[[./test.png]]" to [[./test.png]]
    – lawlist
    Apr 8 '17 at 20:45
  • it's from print output.
    – lucky1928
    Apr 8 '17 at 22:03
  • FWIW: one very kludgy solution I've used for this issue is printing a symbol since elisp allows most characters in symbol names ((print (make-symbol "my-unquoted-string"))). Unfortunately that doesn't work for your circumstance with square brackets.
    – ebpa
    Apr 8 '17 at 22:58

Change (print (format "[[./%s]]" pngname)) to (princ (format "[[./%s]]" pngname))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.