commit e4f618d24d7bc573c75531ac81ad12651e2a99ce
parent dc3a4f59e8819c296495ef654cf98b38d47b6dfd
Author: Matthew Flatt <mflatt@racket-lang.org>
Date: Sun, 15 May 2011 19:22:53 -0600
scribble: add support for setting a document date
in Latex output, and also document and generalize
the 'pretitle paragraph style
original commit: 66178570b6f13fe2f6163d7b15e9e4118a4d0bad
Diffstat:
6 files changed, 50 insertions(+), 6 deletions(-)
diff --git a/collects/scribble/base-render.rkt b/collects/scribble/base-render.rkt
@@ -139,11 +139,17 @@
(define/public (extract-version d)
(or (ormap (lambda (v)
- (and (document-version? v)
- (document-version-text v)))
+ (and (document-version? v)
+ (document-version-text v)))
(style-properties (part-style d)))
""))
+ (define/public (extract-date d)
+ (ormap (lambda (v)
+ (and (document-date? v)
+ (document-date-text v)))
+ (style-properties (part-style d))))
+
(define/private (extract-pre-paras d sym)
(let loop ([l (part-blocks d)])
(cond
diff --git a/collects/scribble/base.rkt b/collects/scribble/base.rkt
@@ -27,7 +27,8 @@
(#:tag (or/c #f string? (listof string?))
#:tag-prefix (or/c #f string? module-path?)
#:style (or/c style? string? symbol? (listof symbol?) #f)
- #:version (or/c string? #f))
+ #:version (or/c string? #f)
+ #:date (or/c string? #f))
#:rest (listof pre-content?)
title-decl?)]
[section (title-like-contract)]
@@ -60,12 +61,18 @@
[else (raise-type-error who "style, string, symbol, list of symbols, or #f" s)]))
(define (title #:tag [tag #f] #:tag-prefix [prefix #f] #:style [style plain]
- #:version [version #f] . str)
+ #:version [version #f] #:date [date #f]
+ . str)
(let ([content (decode-content str)])
(make-title-decl (prefix->string prefix)
(convert-tag tag content)
version
- (convert-part-style 'title style)
+ (let ([s (convert-part-style 'title style)])
+ (if date
+ (make-style (style-name s)
+ (cons (make-document-date date)
+ (style-properties s)))
+ s))
content)))
(define (section #:tag [tag #f] #:tag-prefix [prefix #f] #:style [style plain]
diff --git a/collects/scribble/core.rkt b/collects/scribble/core.rkt
@@ -176,6 +176,7 @@
[properties list?])]
;; properties:
[document-version ([text (or/c string? false/c)])]
+ [document-date ([text (or/c string? false/c)])]
[target-url ([addr path-string?])]
[color-property ([color (or/c string? (list/c byte? byte? byte?))])]
[background-color-property ([color (or/c string? (list/c byte? byte? byte?))])]
diff --git a/collects/scribble/latex-render.rkt b/collects/scribble/latex-render.rkt
@@ -49,6 +49,7 @@
format-number
extract-part-style-files
extract-version
+ extract-date
extract-authors
extract-pretitle)
@@ -93,10 +94,13 @@
(printf "\\begin{document}\n\\preDoc\n")
(when (part-title-content d)
(let ([vers (extract-version d)]
+ [date (extract-date d)]
[pres (extract-pretitle d)]
[auths (extract-authors d)])
(for ([pre (in-list pres)])
+ (printf "\n\n")
(do-render-paragraph pre d ri #t))
+ (when date (printf "\\date{~a}\n" date))
(printf "\\titleAnd~aVersionAnd~aAuthors{"
(if (equal? vers "") "Empty" "")
(if (null? auths) "Empty" ""))
@@ -115,6 +119,10 @@
(when (and (part-title-content d) (pair? number))
(when (eq? (style-name (part-style d)) 'index)
(printf "\\twocolumn\n\\parskip=0pt\n\\addcontentsline{toc}{section}{Index}\n"))
+ (let ([pres (extract-pretitle d)])
+ (for ([pre (in-list pres)])
+ (printf "\n\n")
+ (do-render-paragraph pre d ri #t)))
(let ([no-number? (and (pair? number)
(or (not (car number))
((length number) . > . 3)))])
diff --git a/collects/scribblings/scribble/base.scrbl b/collects/scribblings/scribble/base.scrbl
@@ -65,6 +65,7 @@ have @racketmodname[scribble/manual]).
[#:tag-prefix tag-prefix (or/c false/c string? module-path?) #f]
[#:style style (or/c style? #f string? symbol? (listof symbol?)) #f]
[#:version vers (or/c string? false/c) #f]
+ [#:date date (or/c string? false/c) #f]
[pre-content pre-content?] ...+)
title-decl?]{
@@ -92,6 +93,11 @@ The @racket[vers] argument is propagated to the @racket[title-decl]
structure. Use @racket[""] as @racket[vers] to suppress version
rendering in the output.
+The @racket[date] argument is propagated to the @racket[title-decl]
+structure via a @racket[document-date] @tech{style property}. Use
+@racket[""] as @racket[date] to suppress date rendering in Latex
+output.
+
The section title is automatically indexed by
@racket[decode-part]. For the index key, leading whitespace and a
leading ``A'', ``An'', or ``The'' (followed by more whitespace) is
diff --git a/collects/scribblings/scribble/core.scrbl b/collects/scribblings/scribble/core.scrbl
@@ -369,6 +369,13 @@ The recognized @tech{style properties} are as follows:
attached to a part representing the whole document. The default
version for a document is @racket[(version)].}
+ @item{@racket[document-date] structure --- A date for the part,
+ normally used on a document's main part for for Latex
+ output. The default date for a document is @racket[#f], which
+ avoids explicitly specifying a date at the Latex level, so that
+ the current date is used as the document date. Set the date to
+ @racket[""] to suppress a date in an output document.}
+
@item{@racket[body-id] structure --- Generated HTML uses the given
string @tt{id} attribute of the @tt{body} tag; this style can
be set separately for parts that start different HTML pages,
@@ -408,6 +415,9 @@ recognized:
by the Latex renderer by moving the author information to the
title.}
+ @item{@racket['pretitle] --- Typeset before the title of the
+ enclosing part.}
+
]
The currently recognized @tech{style properties} are as follows:
@@ -918,10 +928,16 @@ than a file path.}
@defstruct[document-version ([text (or/c string? false/c)])]{
-Used as a @tech{style property} for a @racket[path] to indicate a
+Used as a @tech{style property} for a @racket[part] to indicate a
version number.}
+@defstruct[document-date ([text (or/c string? false/c)])]{
+
+Used as a @tech{style property} for a @racket[part] to indicate a
+date (which is typically used for Latex output).}
+
+
@defstruct[color-property ([color (or/c string? (list/c byte? byte? byte?))])]{
Used as a @tech{style property} for an @racket[element] to set its