1#lang racket/base
2(require scribble/doclang
3         (except-in scribble/base author)
4         scribble/jfp
5         setup/collects
6         "../private/defaults.rkt"
7         net/ftp
8         racket/file
9         scribble/latex-prefix
10         (for-syntax racket/base))
11(provide (except-out (all-from-out scribble/doclang) #%module-begin)
12         (all-from-out scribble/jfp)
13         (all-from-out scribble/base)
14         (rename-out [module-begin #%module-begin]))
15
16(module test racket/base)
17
18;; No options, currently, but keep in case we want to support some:
19(define-syntax (module-begin stx)
20  (syntax-case* stx () (lambda (a b) (eq? (syntax-e a) (syntax-e b)))
21    [(_ id ws . body)
22     ;; Skip intraline whitespace to find options:
23     (and (string? (syntax-e #'ws))
24          (regexp-match? #rx"^ *$" (syntax-e #'ws)))
25     #'(module-begin id . body)]
26    [(_ id . body)
27     #'(#%module-begin id (post-process) () . body)]))
28
29(define cls-file
30  (let ([p (scribble-file "jfp/jfp1.cls")])
31    (if (file-exists? (collects-relative->path p))
32        p
33        (downloaded-file "jfp1.cls"))))
34
35(define ((post-process) doc)
36  (add-defaults doc
37                (string->bytes/utf-8
38                 (format "\\documentclass{jfp1}\n~a\\usepackage{times}\n\\usepackage{qcourier}\n~a"
39                         unicode-encoding-packages
40                         ;; Avoid a conflict with mathabx:
41                         "\\let\\amalg\\relax\n"))
42                (scribble-file "jfp/style.tex")
43                (list cls-file)
44                #f
45                #:replacements
46                (hash "scribble-load-replace.tex" (scribble-file "jfp/replacements.tex"))))
47
48(unless (or (not (path? cls-file))
49            (file-exists? cls-file))
50  (log-error (format "File not found: ~a" cls-file))
51  (define site "ftp.cambridge.org")
52  (define path "pub/texarchive/journals/latex/jfp-cls")
53  (define file "jfp1.cls")
54  (log-error (format "Downloading via ftp://~a/~a/~a..." site path file))
55  (define c (ftp-establish-connection site 21 "anonymous" "user@racket-lang.org"))
56  (ftp-cd c path)
57  (let-values ([(base name dir?) (split-path cls-file)])
58    (make-directory* base)
59    (ftp-download-file c base file))
60  (ftp-close-connection c))
61