[racket] Installing a reader macro in Scribble

From: Grant Rettke (grettke at acm.org)
Date: Tue Jan 8 17:02:28 EST 2013

Hi,

I have a first goal of loading a file into an @interaction block in
side of Scribble.

The language to evaluate those values is another story, I just want to
get the contents of a file in there. Here is what I have done:

; the file to load
; cat 04-02.clp
(watch all)
(reset)
(defrule do-anything
  "A rule for anything."
  ?ne <- (anything)
  =>
  (printout t "Someone did something.")
  (retract ?ne))
(assert (anything))
(run)

; the reader macro
; cat 06-04.rkt
#lang racket

(require racket/port)

(provide read read-syntax)

(define (read in) (work in))
(define (read-syntax src in) (work in))

(define (work in)
  (let* ((path (first (port->lines in)))
         (in (open-input-file path #:mode 'text)))
    (port->string in)))

; a sample program that works
cat 06-04a.rkt
#lang racket

#reader"06-04.rkt"/home/gcr/racket-external-eval/04-02.clp

; a scribble that does not work
cat 06-05.scrbl
#lang scribble/manual

@title{Basic Scribble External Eval}

@(require scribble/eval
          racket/sandbox)

@(define my-evaluator
   (parameterize ([sandbox-output 'string]
                  [sandbox-error-output 'string])
     (make-evaluator 'racket)))

@interaction[#:eval
             my-evaluator
             (display "Hello, world.")]

#reader"06-04.rkt"/home/gcr/racket-external-eval/04-02.clp

;; end

I do need to load that file into the @interaction block, but didn't
set it up yet not to lose the closing square paren.

Scribble just renders
"#reader"06-04.rkt"/home/gcr/racket-external-eval/04-02.clp" instead
of doing what it did in Racket.

I suppose Scribble has it's own reader macros (or read table?) to work
how it does.

How may I get this macro working inside of Scribble?

Posted on the users mailing list.