[racket] Scribble experience

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Sun Jan 16 11:44:40 EST 2011

2011/1/10 Matthew Flatt <mflatt at cs.utah.edu>:
> At Mon, 10 Jan 2011 10:38:55 +0100, Jens Axel Søgaard wrote:
>> Another small issue (for me): Since Asymptote is used to produce the
>> geometric figures, I can produce both a pdf and a png version of each image.
>> I was expecting/hoping that the Scribble would pick the pdf version
>> when the output format is pdf and png when the output format is html,
>> but Scribble AFAIR just picks one.
> Did you try
>  @image[#:suffixes '(".pdf" ".png") filename-without-suffix]
> ?

Now I remember the problem with the suffix less version.

Although the source of html-renderer suggests that it calls
install-file on the correct file, something goes wrong.

Using the code below I get the following error:

copy-file: source file does not exist; cannot copy:
to: /Users/soegaard/Dropbox/matematikbog/geometri/geometribogen/3baed4ae12c212682cdd916559546fe1

 === context ===
v5.0.99.6/collects/scribble/base-render.rkt:692:4: core
v5.0.99.6/collects/scribble/html-render.rkt:946:4: render-content
method in ...bble/html-render.rkt:178:2
v5.0.99.6/collects/scribble/base-render.rkt:658:4: render-content
method in render%
v5.0.99.6/collects/scribble/html-render.rkt:905:4: do-render-paragraph
method in ...bble/html-render.rkt:178:2
v5.0.99.6/collects/racket/private/map.rkt:18:11: map
v5.0.99.6/collects/racket/list.rkt:312:2: append-map
v5.0.99.6/collects/scribble/html-render.rkt:1255:4: render-nested-flow
method in ...bble/html-render.rkt:178:2
render-intrapara-block method in ...bble/html-render.rkt:178:2
render-compound-paragraph method in render%
render-compound-paragraph method in ...bble/html-render.rkt:178:2
v5.0.99.6/collects/scribble/html-render.rkt:892:6: loop

Here the images are
all are generated the subdirectory asymptote-images.

And the source is:

(define (asymptote  s . strs)
  (define asymptote-dir "asymptote-images")
  (let* ([strs (apply string-append (cons s strs))]
         [md (bytes->string/utf-8 (md5 strs))]
         [asy-name (string-append md ".asy")]
         [asy-path (build-path asymptote-dir asy-name)]
         [png-name (string-append md ".png")]
         [png-path (build-path asymptote-dir png-name)]
         [pdf-name (string-append md ".pdf")]
         [pdf-path (build-path asymptote-dir pdf-name)]
         [svg-name (string-append md ".svg")]
         [svg-path (build-path asymptote-dir svg-name)])
    ;; create directory if neccessary
    (unless (directory-exists? asymptote-dir)
      (make-directory asymptote-dir))
    ;; save asymptote code to <md5-of-input>.asy
    (with-output-to-file asy-path
      (lambda () (display strs) (newline))
      #:exists 'replace)
    (parameterize ([current-directory (build-path (current-directory)
      (unless (file-exists? svg-name)
          (system (format "asy  -f svg ~a" asy-name)))
      (unless (file-exists? pdf-name)
        (system (format "asy -v -f pdf ~a" asy-name)))
      (unless (file-exists? png-name)
        (system (format "asy -v -f png ~a" asy-name)))
      (image (build-path md) #:suffixes (list ".pdf" ".svg" ".png"))  ; 1.
    ; (image svg-path #:suffixes (list ".svg" #;".pdf" ))             ; 2.

If I use the line 2 instead of 1, everything works.
Furthermore if I after using line 2 switch back to line 1, it
too works (since the image file now was installed by line 2).

Jens Axel Søgaard

Posted on the users mailing list.