[racket] About rendering to PDF under Scribble but from DrRacket IDE
On Jan 19, 2015, at 9:00 PM, E Comer <kernel at matikai.com> wrote:
> Hi friends:
>
> Could someone share a basic example of how to render to PDF a document under Scribble, but not using the command line, but from a program under DrRacket IDE?
>
> Thank you very much in advance for your support, and congratulations to the Scribble designers: its really a great environment to work with.
This is how I run a draft or a release version of HtDP/2e:
#! /bin/sh
#|
exec /Users/matthias/plt/racket/bin/racket -tm "$0" ${1+"$@"}
|#
#lang racket/gui
;; ---------------------------------------------------------------------------------------------------
;; runs scribble and opens preview for section, draft, release
(provide
;; String -> Void
;; ./xhtml [release | draft | file[.scrbl]]
;; renders the stable version of HtDP2e, its draft version, or just the specified part or chapter
;; when a plain file name f is given, xhtml looks for f.scrbl
main)
;; ---------------------------------------------------------------------------------------------------
(require net/sendurl scribble/render scribble/html-render scribble/xref setup/xref)
(define (main arg)
(cond
[(string=? "release" arg)
(process-whole "HtDP2e" "/Users/matthias/0Unison/0Web/" #f)]
[(string=? "draft" arg)
(when (file-exists? "Draft.scrbl") (delete-file "Draft.scrbl"))
(copy-file "HtDP2e.scrbl" "Draft.scrbl")
(process-whole "Draft" "/Users/matthias/0Unison/0Web/HtDP2e" #t)]
[(file-exists? arg)
(define match (regexp-match "(.*)\\.scrbl" arg))
(if match
(process (second match))
(error 'xhtml "not a scribble file: ~a" arg))]
[else
(define stem.scrbl (string-append arg ".scrbl"))
(if (file-exists? stem.scrbl)
(process arg)
(error 'xhtml "no such file: ~a" stem.scrbl))]))
;; String String Boolean -> Void
;; create a renderer and a path for the documentation, then scribble the desired document
(define (process-whole stem destination draft?)
(define renderer (compose render-multi-mixin render-mixin))
(define redirect (if draft?
"http://plt.eecs.northwestern.edu/snapshots/current/doc/" ;
; http://pre.racket-lang.org/docs/html/"
"http://docs.racket-lang.org/"))
(scribble-it stem destination draft? redirect renderer))
;; String -> Void
;; create a destination directory, then scribble the desired document
(define (process stem)
(define destination (string-append "HTML/" stem))
(unless (directory-exists? destination) (make-directory destination))
(scribble-it stem destination #f #f))
;; String String Boolean [Maybe String] { [Class -> Class] } -> Void
;; render stem.scrbl in destination/stem.html, using the redirect? url as source of documentation
;; initialize the is-draft parameter in shared.ss with the draft? flag
;; use renderer, which implements render<%>, to scribble
;; open browser on stem.html
(define (scribble-it stem destination draft? redirect? (renderer render-mixin))
(define stem.scrbl (string-append stem ".scrbl"))
(define stem.html (string-append stem ".html"))
(displayln `(rendering ,stem.scrbl draft: ,draft?))
((dynamic-require "Shared/shared.rkt" 'is-draft?) draft?)
(define stem.doc (dynamic-require stem.scrbl 'doc))
(render (list stem.doc) (list stem)
#:render-mixin renderer
#:dest-dir destination
#:xrefs (list (load-collections-xref))
#:quiet? #false
#:redirect-main redirect?)
(displayln `(done rendering))
;; ---
(parameterize ([current-directory destination])
(displayln `(cleaning up ,stem))
(cleanup)
(displayln `(opening browser at ,destination ,stem.html))
(send-url/file (if (file-exists? stem.html) stem.html (build-path stem "index.html")))))
;; -----------------------------------------------------------------------------
;; the code below used to be a standalone script
;; -> Void
(define (cleanup)
(void))