[racket] Scribble + dynamically entering a file

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Wed Sep 29 09:40:57 EDT 2010

On Sep 29, 2010, at 7:24 AM, Matthew Flatt wrote:

> At Wed, 29 Sep 2010 14:40:17 +0530, Ishaan Singh wrote:
>> I'm new here, but went through the documentation and couldn't find an answer
>> to this so was wondering:
>> If I want to write a scribble file and somehow 'include' a text file by just
>> referencing the name of that text file, is it possible?
>> I want to do this to set up an example and add scheme codes '.ss' but want
>> to make it such that if i make changes to the scheme code in the .ss files,
>> and then re-execute scribble --html, the updated code should be embedded in
>> the generated html file.
> See "collects/scribblings/guide/modfile.rkt".
> The "modfile.rkt" module defines a `racketmodfile' form that is like
> `racketmod', but `racketmodfile' takes the content to typeset from a
> file.
> Something like that is probably what you want. In fact, let me know how
> what you wanted differs, because I should add a suitably general form
> of `racketmodfile' in the Scribble libraries.

If you don't want it type set you may wish to write a function like this: 

  ;; read count lines from file f and label it 'name' in the scribble document
  (-> natural-number/c (and/c string? file-exists?) string? 

(define (file-is count f name)
  (define prefix (map tt (append (take (read-lines f) count) '("..."))))
  (define newln* (add-between prefix nl))
   (tabular (list (list "file name:" sp (italic name))))
   (tabular (list (list newln*)))))

Posted on the users mailing list.