[racket] Texinfo-like Racket Evaluation Results in Scribble

From: Neil Van Dyke (neil at neilvandyke.org)
Date: Mon Sep 5 20:42:54 EDT 2011

For typesetting nit-pickers like me...

[This is a paste of a blog post.  Here, I've replaced the Unicode 
double-arrow character with ASCII "=>".  The whitespace in code examples 
might get garbled a little.  If you want to see the Unicode character 
and whitespace properly, 
"http://www.neilvandyke.org/weblog/2011/09/#2011-09-05".]

Using Racket Scribble, but miss Texinfo-like evaluation results?

Eventually, either we'll get this added to Scribble, or I'll make a tiny 
PLaneT package that does this in a nicer way. But for now, you can 
kludge it up like:

@(define => (larger (italic "\u21d2")))

@(racketblock (+ 1 2 3) #,=> #,(racketresult 6)
              (+ 1 3 3) #,=> #,(racketresult 7))

This formats like:

(+ 1 2 3) ==> 6
(+ 1 3 3) ==> 7
(+ 1 4 3) ==> 8

The double-arrows used to look quite nice in Texinfo-generated DVI, PS, 
and PDF output; Web browsers and putting it in fixed-pitch font don't do 
the character justice right now.

Compare to one of the usual Racket ways:

@(racketinput (+ 1 2 3)           
              #,(racketresult 6))
@(racketinput (+ 1 3 3)           
              #,(racketresult 7))
@(racketinput (+ 1 4 3)           
              #,(racketresult 8))

Which formats like:

 > (+ 1 2 3)
  6

 > (+ 1 3 3)
  7

 > (+ 1 4 3)
  8

The usual Scribble format uses much more space, and also does not permit 
a columnar layout that would help show symmetries among more complicated 
expressions and results. Less importantly, this format can also be 
harder to read without color. As for the ">" prompt, I don't have a 
strong argument against it, but I don't think it's necessary.

Aside: This was a pressing question for me because I'm almost ready to 
release the McFly package, which lets you embed API documentation within 
Racket files. Just now, I considered simply adding => to McFly, but I 
think I'll wait.

-- 
http://www.neilvandyke.org/



Posted on the users mailing list.