lang.rkt (7099B)
1 #lang racket/base 2 (require scribble/doclang 3 scribble/core 4 (except-in scribble/base author title) 5 scribble/acmart 6 scribble/latex-prefix 7 racket/list 8 "../private/defaults.rkt" 9 (for-syntax racket/base 10 syntax/parse)) 11 (provide (except-out (all-from-out scribble/doclang) #%module-begin) 12 (all-from-out scribble/acmart) 13 (all-from-out scribble/base) 14 (rename-out [module-begin #%module-begin])) 15 16 (define-syntax (module-begin stx) 17 (syntax-case stx () 18 [(_ id . body) 19 (let ([format? #f] 20 [review? #f] 21 [screen? #f] 22 [natbib? #f] 23 [anonymous? #f] 24 [authorversion? #f] 25 [font-size #f] 26 [nonacm? #f] 27 [timestamp? #f] 28 [author-draft? #f] 29 [acmthm? #f]) 30 (let loop ([stuff #'body]) 31 (syntax-parse stuff 32 #:datum-literals (manuscript acmsmall acmlarge acmtog sigconf siggraph sigplan sigchi 33 sigchi-a dtrap pacmcgit tiot tdsci review screen natbib 34 anonymous authorversion 9pt 10pt 11pt 12pt nonacm timestamp 35 authordraft acmthm) 36 37 ;; Skip intraline whitespace to find options: 38 [(ws . body) 39 #:when (and (string? (syntax-e #'ws)) 40 (regexp-match? #rx"^ *$" (syntax-e #'ws))) 41 (loop #'body)] 42 43 ; boolean options 44 [((review #t) . body) 45 (set! review? "review=true") 46 (loop #'body)] 47 [((review #f) . body) 48 (set! review? "review=false") 49 (loop #'body)] 50 [(review . body) 51 (set! review? "review=true") 52 (loop #'body)] 53 [((screen #t) . body) 54 (set! screen? "screen=true") 55 (loop #'body)] 56 [((screen #f) . body) 57 (set! screen? "screen=false") 58 (loop #'body)] 59 [(screen . body) 60 (set! screen? "screen=true") 61 (loop #'body)] 62 [((natbib #t) . body) 63 (set! natbib? "natbib=true") 64 (loop #'body)] 65 [((natbib #f) . body) 66 (set! natbib? "natbib=false") 67 (loop #'body)] 68 [(natbib . body) 69 (set! natbib? "natbib=true") 70 (loop #'body)] 71 72 [((anonymous #t) . body) 73 (set! anonymous? "anonymous=true") 74 (loop #'body)] 75 [((anonymous #f) . body) 76 (set! anonymous? "anonymous=false") 77 (loop #'body)] 78 [(anonymous . body) 79 (set! anonymous? "anonymous=true") 80 (loop #'body)] 81 [((authorversion #t) . body) 82 (set! authorversion? "authorversion=true") 83 (loop #'body)] 84 [((authorversion #f) . body) 85 (set! authorversion? "authorversion=false") 86 (loop #'body)] 87 [(authorversion . body) 88 (set! authorversion? "authorversion=true") 89 (loop #'body)] 90 [(9pt . body) 91 (set! font-size "9pt") 92 (loop #'body)] 93 [(10pt . body) 94 (set! font-size "10pt") 95 (loop #'body)] 96 [(11pt . body) 97 (set! font-size "11pt") 98 (loop #'body)] 99 [(12pt . body) 100 (set! font-size "12pt") 101 (loop #'body)] 102 [((nonacm #t) . body) 103 (set! nonacm? "nonacm=true") 104 (loop #'body)] 105 [((nonacm #f) . body) 106 (set! nonacm? "nonacm=false") 107 (loop #'body)] 108 [(nonacm . body) 109 (set! nonacm? "nonacm=true") 110 (loop #'body)] 111 [(timestamp . body) 112 (set! timestamp? "timestamp=true") 113 (loop #'body)] 114 [((timestamp #t) . body) 115 (set! timestamp? "timestamp=true") 116 (loop #'body)] 117 [((timestamp #f) . body) 118 (set! timestamp? "timestamp=false") 119 (loop #'body)] 120 [(authordraft . body) 121 (set! author-draft? "authordraft=true") 122 (loop #'body)] 123 [((authordraft #t) . body) 124 (set! author-draft? "authordraft=true") 125 (loop #'body)] 126 [((authordraft #f) . body) 127 (set! author-draft? "authordraft=false") 128 (loop #'body)] 129 [(acmthm . body) 130 (set! acmthm? "acmthm=true") 131 (loop #'body)] 132 [((acmthm #t) . body) 133 (set! acmthm? "acmthm=true") 134 (loop #'body)] 135 [((acmthm #f) . body) 136 (set! acmthm? "acmthm=false") 137 (loop #'body)] 138 139 ; format options 140 [((~and fmt 141 (~or manuscript 142 acmsmall 143 acmlarge 144 acmtog 145 sigconf 146 siggraph 147 sigplan 148 sigchi 149 sigchi-a 150 dtrap 151 pacmcgit 152 tiot 153 tdsci)) 154 . body) 155 (set! format? (symbol->string (syntax->datum #'fmt))) 156 (loop #'body)] 157 158 [body 159 #`(#%module-begin id (post-process #,review? #,screen? #,natbib? #,anonymous? 160 #,authorversion? #,font-size #,nonacm? #,timestamp? 161 #,author-draft? #,acmthm? #,format?) () . body)])))])) 162 163 (define ((post-process . opts) doc) 164 (let ([options 165 (if (ormap values opts) 166 (format "[~a]" (apply string-append (add-between (filter values opts) ", "))) 167 "")]) 168 (add-acmart-styles 169 (add-defaults doc 170 (string->bytes/utf-8 171 (format "\\documentclass~a{acmart}\n~a" 172 options 173 unicode-encoding-packages)) 174 (scribble-file "acmart/style.tex") 175 (list (scribble-file "acmart/acmart.cls")) 176 #f 177 #:replacements (hash "scribble-load-replace.tex" (scribble-file "acmart/acmart-load.tex")))))) 178 179 (define (add-acmart-styles doc) 180 (struct-copy part doc 181 [to-collect 182 ;; Ensure that "acmart.tex" is used, since "style.tex" 183 ;; re-defines commands. 184 (cons invisible-element-to-collect-for-acmart-extras 185 (part-to-collect doc))] 186 [style (let ([s (part-style doc)]) 187 (struct-copy style s 188 [properties 189 ;; Immitate Latex-based links where only the 190 ;; number part is hyperlinked. 191 (cons (link-render-style 'number) 192 (style-properties s))]))]))