#lang racket
(require racket/pretty)
(define (output-ex-1 ex-name file-name)
  (let ((contents (file->string file-name)))
       (section ,ex-name)
       (subsection "source code in " ,ex-name ".rkt")
       (codeblock ,contents)
       (subsection "the result of " ,ex-name)
       (display (string-append "generating " ,ex-name "\n"))
       (examples #:eval e 
                 (require ,file-name)
                 (make-figure ,ex-name main)))))
(define (output-ex-0 ex-name)
  (let* ((file-name (string-append "examples/" ex-name ".rkt")))
    (if (file-exists? file-name)
        (output-ex-1 ex-name file-name)
(define (output-ex i)
  (let* ((ex-name (string-append "ex-" (number->string i))))
       ,@(filter (compose not empty?)
                 (for/list ((x (list "" "-b")))
                           (output-ex-0 (string-append ex-name x)))))))
(define doc
  `((require scribble/manual)
    (require scribble/core)
    (require scribble/eval)
    (require scribble/decode)
    (require racket/file)
    (require racket/list)
    (require (for-syntax racket))
    (require (for-label racket))
    (require (for-label racket/base))
    (define e (make-base-eval))
    (title "Welcome to mpost-wrapper.")
    "Many examples are listed as below. In order to run these examples, we need first require the snip module to show figures."
    (examples #:eval e (require (planet wcy/mpost-wrapper/snip)))
    ,@(for/list ((i (in-range 1 400)))
                (output-ex i))))
 #:exists 'replace
 (lambda (out)
   (parameterize ([current-output-port out])
     (display "#lang scribble/manual")
     (display "@(begin ")
     (for-each pretty-write doc)
     (display ")\n"))))