emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] exporting Racket images


From: Lawrence Bottorff
Subject: [O] exporting Racket images
Date: Mon, 23 Oct 2017 21:43:50 -0400

I'm using a nice package from a Racket user called MetaPict, however, I don't know how to export the image produced. Here's some Racket code calling MetaPict:

#+begin_src scheme :session mainsession :exports both
(require racket/draw metapict metapict/graph)
         
(set-curve-pict-size 300 300)  ; width and height of image
(ahlength  1.0)                ; size of arrow head 

(define (f x) (sin x))

(define p
  (with-window (window -12 12 -12 12)             ; xmin, xmax, ymin, ymax
    (draw (draw-arrow (curve (pt -10   0) -- (pt 10  0)))  ; x-axis
          (draw-arrow (curve (pt   0 -10) -- (pt  0 10)))  ; y-axis
          (label-rt  "x" (pt 10.2 0))                      ; label for x axis
          (label-top "y" (pt 0 10.2))                      ; label for y axis
          (color "blue" (draw (circle (pt 2 1) 3)))        ; center (2,1) radius 3
          (color "red"  (draw (graph f -10 10 #:samples 50))))))

(define (save-pict-as-svg p width height filename [exists 'replace])
  (define dc (new svg-dc%
                  [width width]
                  [height height]
                  [output filename]
                  [exists exists]))
  (send dc start-doc "An SVG Test")  ; a message
  (send dc start-page)
  (draw-pict p dc 0 0)
  (send dc end-page)
  (send dc end-doc))
  
(save-pict-as-svg p 300 300 "images/outtestmetapict1.svg")
#+end_src

No surprise, but orgmode doesn't know that the image output

(save-pict-as-svg p 300 300 "images/outtestmetapict1.svg")

should be the code block's results. And adding #+RESULTS: over a hand-added [[file:images/outtestmetapict1.svg]] link makes it not display. I'm guessing this means orgmode does things internally with, say, gnuplot to make the generated image the results and obey the :exports both . . . Any ideas how I can get this gnuplot-like behavior with Racket MetaPict? I'm guessing a customization of the underlying babel code is necessary. . . .

LB

reply via email to

[Prev in Thread] Current Thread [Next in Thread]