Add a pretitle style property for nested flows. (#94)

* Add a pretitle style property for nested flows.

This allows us to raise nested flows above the title. So that we do
things like raise the abstract above the title:

```
\begin{abstract}
Abstract text
\end{abstract}
\titleCommand{...}
```

This style is required by the acmart style guide.

* Paragraphs and nested flows extracted in the same order

* Fix `scribble/acmart`'s abstract form so that it gets lifted above `maketitle`, where it should be.
This commit is contained in:
Leif Andersen 2017-03-25 10:08:18 -04:00 committed by GitHub
parent 5c7c8a3bd0
commit 9da2f4f40f
4 changed files with 71 additions and 44 deletions

View File

@ -729,6 +729,8 @@ The following @tech{style properties} are currently recognized:
@item{@racket[alt-tag] structure --- Generates the indicated HTML tag @item{@racket[alt-tag] structure --- Generates the indicated HTML tag
instead of @tt{<blockquote>}.} instead of @tt{<blockquote>}.}
@item{@racket['pretitle] --- For Latex, raises the contents
of the flow to above the title.}
]} ]}
@ -1115,7 +1117,7 @@ reverse order):
any number or lists element, while @racket[""] is used in place any number or lists element, while @racket[""] is used in place
of all non-empty strings.} of all non-empty strings.}
]} ]
@history[#:changed "6.4" @elem{Added @racket[(list/c string? string?)] @history[#:changed "6.4" @elem{Added @racket[(list/c string? string?)]
number items for number items for

View File

@ -141,7 +141,7 @@
;; ---------------------------------------- ;; ----------------------------------------
;; Abstracts: ;; Abstracts:
(define abstract-style (make-style "abstract" acmart-extras)) (define abstract-style (make-style "abstract" (cons 'pretitle acmart-extras)))
(define command-props (cons 'command acmart-extras)) (define command-props (cons 'command acmart-extras))
(define multicommand-props (cons 'multicommand acmart-extras)) (define multicommand-props (cons 'multicommand acmart-extras))

View File

@ -251,25 +251,42 @@
(document-date-text v))) (document-date-text v)))
(style-properties (part-style d)))) (style-properties (part-style d))))
(define/private (extract-pre-paras d sym) (define/private (extract-content d lift-proc)
(let loop ([l (part-blocks d)]) (let loop ([l (part-blocks d)])
(cond (apply append
[(null? l) null] (for/list ([b (in-list l)])
[else (let ([v (car l)]) (define lifted (lift-proc b loop))
lifted))))
(define/private (extract-pre-paras-proc sym)
(λ (v loop)
(cond (cond
[(and (paragraph? v) [(and (paragraph? v)
(eq? sym (style-name (paragraph-style v)))) (eq? sym (style-name (paragraph-style v))))
(cons v (loop (cdr l)))] (list v)]
[(compound-paragraph? v) [(compound-paragraph? v)
(append (loop (compound-paragraph-blocks v)) (loop (compound-paragraph-blocks v))]
(loop (cdr l)))] [else '()])))
[else (loop (cdr l))]))])))
(define/private (extract-pre-content-proc sym)
(λ (v loop)
(define pre-para ((extract-pre-paras-proc sym) v loop))
(cond
[(not (null? pre-para)) pre-para]
[(and (nested-flow? v)
(member sym (style-properties (nested-flow-style v))))
(list v)]
[else '()])))
(define/public (extract-authors d) (define/public (extract-authors d)
(extract-pre-paras d 'author)) (extract-content d (extract-pre-paras-proc 'author)))
(define/public (extract-pretitle d) (define/public (extract-pretitle d)
(extract-pre-paras d 'pretitle)) (extract-content d (extract-pre-paras-proc 'pretitle)))
(define/public (extract-pretitle-content d)
(extract-content d (extract-pre-content-proc 'pretitle)))
;; ---------------------------------------- ;; ----------------------------------------

View File

@ -81,7 +81,7 @@
extract-version extract-version
extract-date extract-date
extract-authors extract-authors
extract-pretitle) extract-pretitle-content)
(define/public (extract-short-title d) (define/public (extract-short-title d)
(ormap (lambda (v) (ormap (lambda (v)
@ -150,14 +150,19 @@
(when (part-title-content d) (when (part-title-content d)
(let ([vers (extract-version d)] (let ([vers (extract-version d)]
[date (extract-date d)] [date (extract-date d)]
[pres (extract-pretitle d)] [pres (extract-pretitle-content d)]
[auths (extract-authors d)] [auths (extract-authors d)]
[short (extract-short-title d)]) [short (extract-short-title d)])
(for ([pre (in-list pres)]) (for ([pre (in-list pres)])
(printf "\n\n") (printf "\n\n")
(do-render-paragraph pre d ri #t #f)) (cond
[(paragraph? pre)
(do-render-paragraph pre d ri #t #f)]
[(nested-flow? pre)
(do-render-nested-flow pre d ri #t #f #t)]))
(when date (printf "\\date{~a}\n" date)) (when date (printf "\\date{~a}\n" date))
(printf "\\titleAnd~aVersionAnd~aAuthors~a{" (printf "\\titleAnd~aVersionAnd~aAuthors~a{"
(if (equal? vers "") "Empty" "") (if (equal? vers "") "Empty" "")
(if (null? auths) "Empty" "") (if (null? auths) "Empty" "")
(if short "AndShort" "")) (if short "AndShort" ""))
@ -187,7 +192,7 @@
(and d (positive? d))))) (and d (positive? d)))))
(when (eq? (style-name (part-style d)) 'index) (when (eq? (style-name (part-style d)) 'index)
(printf "\\twocolumn\n\\parskip=0pt\n\\addcontentsline{toc}{section}{Index}\n")) (printf "\\twocolumn\n\\parskip=0pt\n\\addcontentsline{toc}{section}{Index}\n"))
(let ([pres (extract-pretitle d)]) (let ([pres (extract-pretitle-content d)])
(for ([pre (in-list pres)]) (for ([pre (in-list pres)])
(printf "\n\n") (printf "\n\n")
(do-render-paragraph pre d ri #t #f))) (do-render-paragraph pre d ri #t #f)))
@ -645,6 +650,7 @@
part part
ri ri
#t #t
#f
#f) #f)
(when (string? s-name) (when (string? s-name)
(printf "\\end{~a}" s-name))) (printf "\\end{~a}" s-name)))
@ -848,7 +854,7 @@
[(table? p) [(table? p)
(render-table* p part ri #f (format "[~a]" mode))] (render-table* p part ri #f (format "[~a]" mode))]
[(nested-flow? p) [(nested-flow? p)
(do-render-nested-flow p part ri #f mode)] (do-render-nested-flow p part ri #f mode #f)]
[(paragraph? p) [(paragraph? p)
(do-render-paragraph p part ri #f mode)])) (do-render-paragraph p part ri #f mode)]))
@ -879,7 +885,7 @@
(printf "\\end{~a}" mode) (printf "\\end{~a}" mode)
null)) null))
(define/private (do-render-nested-flow t part ri single-column? as-box-mode) (define/private (do-render-nested-flow t part ri single-column? as-box-mode show-pre?)
(let* ([props (style-properties (nested-flow-style t))] (let* ([props (style-properties (nested-flow-style t))]
[kind (or (and as-box-mode [kind (or (and as-box-mode
(or (or
@ -900,6 +906,8 @@
[multicommand? (memq 'multicommand props)] [multicommand? (memq 'multicommand props)]
[command? (or (and as-box-mode (not multicommand?)) [command? (or (and as-box-mode (not multicommand?))
(memq 'command props))]) (memq 'command props))])
(unless (and (not show-pre?)
(member 'pretitle props))
(cond (cond
[command? (printf "\\~a{" kind)] [command? (printf "\\~a{" kind)]
[multicommand? (printf "\\~a" kind)] [multicommand? (printf "\\~a" kind)]
@ -919,10 +927,10 @@
[command? (printf "}")] [command? (printf "}")]
[multicommand? (void)] [multicommand? (void)]
[else (printf "\\end{~a}" kind)]) [else (printf "\\end{~a}" kind)])
null)) null)))
(define/override (render-nested-flow t part ri starting-item?) (define/override (render-nested-flow t part ri starting-item?)
(do-render-nested-flow t part ri #f #f)) (do-render-nested-flow t part ri #f #f #f))
(define/override (render-compound-paragraph t part ri starting-item?) (define/override (render-compound-paragraph t part ri starting-item?)
(let ([kind (style-name (compound-paragraph-style t))] (let ([kind (style-name (compound-paragraph-style t))]