[racket] Images in Scribble?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Jul 2 00:43:48 EDT 2011

At Fri, 1 Jul 2011 17:59:04 -0500, Don Blaheta wrote:
> I was just Scribble-ing and needed a (small) image, so I thought, hey
> this is DrRacket, I'll just paste it in.  DrRacket can handle it, and
> the WXME format is readable by scribble, but I do get this message:
> 
> regexp-match: non-character in an unsupported context, from port: 
> #<input-port:/Users/blahedo/courses/comp160/s11/code/0114-image.scrbl>

This is a limitation of the current `at-exp' reader. Even when `@'
shifts to S-expression mode in the `at-exp' reader, the reader assumes
only characters for the S-expression part. I tried to fix the reader
once, but it wasn't easy, so I left it as future work.


One workaround is to put the image in its own file with normal
S-expression notation:

 ; img.rkt:
 #lang racket
 (provide img)
 (define img <image>)

and then use it from a Scribble document:

 #lang scribble/base
 @(require "img.rkt")
 @img


But mostly I use the style that Matthias and others suggested, which is
to write expression that generate images. I usually use
`slideshow/pict', so if the image is in the file "img.png", then I'd
write

  #lang scribble/base
  @(require slideshow/pict)
  @(bitmap "img.png")

where `bitmap' is the function from `slideshow/pict' that takes a
filename and returns an image.



Posted on the users mailing list.