1#lang racket/base
2(require scribble/doclang
3         scribble/core
4         scribble/base
5         scribble/sigplan
6         scribble/latex-prefix
7         racket/list
8         "../private/defaults.rkt"
9         (for-syntax racket/base))
10(provide (except-out (all-from-out scribble/doclang) #%module-begin)
11         (all-from-out scribble/sigplan)
12         (all-from-out scribble/base)
13         (rename-out [module-begin #%module-begin]))
14
15(define-syntax (module-begin stx)
16  (syntax-case stx ()
17    [(_ id . body)
18     (let ([preprint? #f]
19           [10pt? #f]
20           [onecolumn? #f]
21           [nocopyright? #f]
22           [times? #t]
23           [qcourier? #t])
24       (let loop ([stuff #'body])
25         (syntax-case* stuff (onecolumn preprint 10pt nocopyright notimes noqcourier) (lambda (a b) (eq? (syntax-e a) (syntax-e b)))
26           [(ws . body)
27            ;; Skip intraline whitespace to find options:
28            (and (string? (syntax-e #'ws))
29                 (regexp-match? #rx"^ *$" (syntax-e #'ws)))
30            (loop #'body)]
31           [(preprint . body)
32            (set! preprint? "preprint")
33            (loop #'body)]
34           [(onecolumn . body)
35            (set! onecolumn? "onecolumn")
36            (loop #'body)]
37           [(nocopyright . body)
38            (set! nocopyright? "nocopyrightspace")
39            (loop #'body)]
40           [(10pt . body)
41            (set! 10pt? "10pt")
42            (loop #'body)]
43           [(noqcourier . body)
44            (set! qcourier? #f)
45            (loop #'body)]
46           [(notimes . body)
47            (set! times? #f)
48            (loop #'body)]
49           [body
50            #`(#%module-begin id (post-process #,times? #,qcourier? #,preprint? #,10pt? #,nocopyright? #,onecolumn?) () . body)])))]))
51#|
52
53The docs for the times.sty package suggests that it should not be used
54so maybe we want to disable it permanently (or replace it with something else).
55
56Read here for more:
57
58  http://www.ctan.org/tex-archive/macros/latex/required/psnfss/psnfss2e.pdf
59
60|#
61
62(define ((post-process times? qcourier? . opts) doc)
63  (let ([options
64         (if (ormap values opts)
65             (format "[~a]" (apply string-append (add-between (filter values opts) ", ")))
66             "")])
67    (add-sigplan-styles
68     (add-defaults doc
69                   (string->bytes/utf-8
70                    (format "\\documentclass~a{sigplanconf}\n~a~a~a"
71                            options
72                            unicode-encoding-packages
73                            (if times?
74                                "\\usepackage{times}\n"
75                                "")
76                            (if qcourier?
77                                "\\usepackage{qcourier}\n"
78                                "")))
79                   (scribble-file "sigplan/style.tex")
80                   (list (scribble-file "sigplan/sigplanconf.cls"))
81                   #f))))
82
83(define (add-sigplan-styles doc)
84  ;; Ensure that "sigplan.tex" is used, since "style.tex"
85  ;; re-defines commands.
86  (struct-copy part doc [to-collect
87                         (cons (terms)
88                               (part-to-collect doc))]))
89