add --latex-section' mode to scribble'

original commit: 3f95fabf7c4ef7616633820e79bf4d1ea472bbb9
This commit is contained in:
Matthew Flatt 2011-06-22 07:39:01 -06:00
parent 532feda048
commit 9f6f5d9812
5 changed files with 97 additions and 64 deletions

View File

@ -11,7 +11,8 @@
scheme/list scheme/list
setup/main-collects setup/main-collects
file/convertible) file/convertible)
(provide render-mixin) (provide render-mixin
make-render-part-mixin)
(define current-table-mode (make-parameter #f)) (define current-table-mode (make-parameter #f))
(define rendering-tt (make-parameter #f)) (define rendering-tt (make-parameter #f))
@ -34,6 +35,12 @@
(/ (cadr c) 255.0) (/ (cadr c) 255.0)
(/ (caddr c) 255.0)))) (/ (caddr c) 255.0))))
(define (make-render-part-mixin n)
(lambda (%)
(class (render-mixin %)
(define/override (render-part-depth) n)
(super-new))))
(define (render-mixin %) (define (render-mixin %)
(class % (class %
(inherit-field prefix-file style-file style-extra-files) (inherit-field prefix-file style-file style-extra-files)
@ -56,6 +63,8 @@
(define/override (auto-extra-files? v) (latex-defaults? v)) (define/override (auto-extra-files? v) (latex-defaults? v))
(define/override (auto-extra-files-paths v) (latex-defaults-extra-files v)) (define/override (auto-extra-files-paths v) (latex-defaults-extra-files v))
(define/public (render-part-depth) #f)
(define/override (render-one d ri fn) (define/override (render-one d ri fn)
(let* ([defaults (ormap (lambda (v) (and (latex-defaults? v) v)) (let* ([defaults (ormap (lambda (v) (and (latex-defaults? v) v))
(style-properties (part-style d)))] (style-properties (part-style d)))]
@ -72,16 +81,8 @@
(cond (cond
[(bytes? v) v] [(bytes? v) v]
[else (main-collects-relative->path v)]))) [else (main-collects-relative->path v)])))
scribble-style-tex)]) scribble-style-tex)]
(for-each [all-style-files (cons scribble-tex
(lambda (style-file)
(if (bytes? style-file)
(display style-file)
(with-input-from-file style-file
(lambda ()
(copy-port (current-input-port) (current-output-port))))))
(list* prefix-file
scribble-tex
(append (extract-part-style-files (append (extract-part-style-files
d d
ri ri
@ -90,7 +91,18 @@
tex-addition? tex-addition?
tex-addition-path) tex-addition-path)
(list style-file) (list style-file)
style-extra-files))) style-extra-files))]
[whole-doc? (not (render-part-depth))])
(if whole-doc?
(for ([style-file (in-list (cons prefix-file all-style-files))])
(if (bytes? style-file)
(display style-file)
(with-input-from-file style-file
(lambda ()
(copy-port (current-input-port) (current-output-port))))))
(for ([style-file (in-list all-style-files)])
(install-file style-file)))
(when whole-doc?
(printf "\\begin{document}\n\\preDoc\n") (printf "\\begin{document}\n\\preDoc\n")
(when (part-title-content d) (when (part-title-content d)
(let ([vers (extract-version d)] (let ([vers (extract-version d)]
@ -110,13 +122,17 @@
(unless first? (printf "\\SAuthorSep{}")) (unless first? (printf "\\SAuthorSep{}"))
(do-render-paragraph auth d ri #t) (do-render-paragraph auth d ri #t)
#f) #f)
(printf "}\n"))) (printf "}\n"))))
(render-part d ri) (render-part d ri)
(printf "\n\n\\postDoc\n\\end{document}\n"))) (when whole-doc?
(printf "\n\n\\postDoc\n\\end{document}\n"))))
(define/override (render-part-content d ri) (define/override (render-part-content d ri)
(let ([number (collected-info-number (part-collected-info d ri))]) (let ([number (collected-info-number (part-collected-info d ri))])
(when (and (part-title-content d) (pair? number)) (when (and (part-title-content d)
(or (pair? number)
(let ([d (render-part-depth)])
(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 d)])
@ -127,7 +143,7 @@
(or (not (car number)) (or (not (car number))
((length number) . > . 3)))]) ((length number) . > . 3)))])
(printf "\n\n\\~a~a~a" (printf "\n\n\\~a~a~a"
(case (length number) (case (+ (length number) (or (render-part-depth) 0))
[(0 1) "sectionNewpage\n\n\\section"] [(0 1) "sectionNewpage\n\n\\section"]
[(2) "subsection"] [(2) "subsection"]
[(3) "subsubsection"] [(3) "subsubsection"]

View File

@ -51,6 +51,11 @@
(current-render-mixin latex:render-mixin)] (current-render-mixin latex:render-mixin)]
[("--pdf") "generate PDF-format output (with PDFLaTeX)" [("--pdf") "generate PDF-format output (with PDFLaTeX)"
(current-render-mixin pdf:render-mixin)] (current-render-mixin pdf:render-mixin)]
[("--latex-section") n "generate LaTeX-format output for section depth <n>"
(let ([v (string->number n)])
(unless (exact-nonnegative-integer? v)
(raise-user-error 'scribble (format "bad section depth: ~a" n)))
(current-render-mixin (latex:make-render-part-mixin v)))]
#:once-each #:once-each
[("--dest") dir "write output in <dir>" [("--dest") dir "write output in <dir>"
(current-dest-directory dir)] (current-dest-directory dir)]

View File

@ -1,5 +1,6 @@
#lang scribble/manual #lang scribble/manual
@(require "utils.rkt" @(require "utils.rkt"
scribble/bnf
(for-label setup/xref)) (for-label setup/xref))
@(define fn (italic "fn")) @(define fn (italic "fn"))
@ -29,6 +30,13 @@ its file suffix:
@item{@DFlag{pdf} --- PDF @filepath{@|fn|.pdf} that is generated @item{@DFlag{pdf} --- PDF @filepath{@|fn|.pdf} that is generated
via @exec{pdflatex}} via @exec{pdflatex}}
@item{@DFlag{latex-section} @nonterm{n} --- LaTeX source
@filepath{@|fn|.tex} plus additional @filepath{.tex} files to
be included in the enclosing document's preamble, where the
enclosing document must use the UTF-8 input encoding and T1
font encoding; use @tt{1} for @nonterm{n} to make the rendered
document a section, @tt{2} for a subsection, etc.}
@item{@DFlag{text} --- plain text in a single file @item{@DFlag{text} --- plain text in a single file
@filepath{@|fn|.txt}, with non-ASCII content encoded as UTF-8} @filepath{@|fn|.txt}, with non-ASCII content encoded as UTF-8}
@ -73,7 +81,7 @@ Use @DFlag{prefix} to specify an alternate format-specific to start of
the output file. For HTML output, the starting file specifies the the output file. For HTML output, the starting file specifies the
@tt{DOCTYPE} declaration of each output HTML file as a substitute for @tt{DOCTYPE} declaration of each output HTML file as a substitute for
@filepath{scribble-prefix.html} in the @filepath{scribble} @filepath{scribble-prefix.html} in the @filepath{scribble}
collection. For Latex (or PDF) output, the the starting file specifies collection. For Latex (or PDF) output (but not Latex-section output), the starting file specifies
the @ltx{documentclass} declaration and initial @ltx{usepackage} the @ltx{documentclass} declaration and initial @ltx{usepackage}
declarations as a substitute for @filepath{scribble-prefix.tex} in the declarations as a substitute for @filepath{scribble-prefix.tex} in the
@filepath{scribble} collection. See also @racket[html-defaults], @filepath{scribble} collection. See also @racket[html-defaults],
@ -84,7 +92,7 @@ to the build destination, such as an image file that is referenced in
the generated output but not included via @racket[image] (which copies the generated output but not included via @racket[image] (which copies
the file automatically). the file automatically).
@subsection[#:tag "xref-flags"]{Handling Cross-References} @section[#:tag "xref-flags"]{Handling Cross-References}
Cross references within a document or documents rendered together are Cross references within a document or documents rendered together are
always resolved. When cross references span documents that are always resolved. When cross references span documents that are

View File

@ -68,16 +68,19 @@
(loop (cdr keys)))))) (loop (cdr keys))))))
")"))) ")")))
(define (add-cites group bib-entries) (define (add-cites group bib-entries sort?)
(define groups (for/fold ([h (hash)]) ([b (reverse bib-entries)]) (define-values (groups keys)
(hash-update h (author-element-names (auto-bib-author b)) (for/fold ([h (hash)] [ks null]) ([b (reverse bib-entries)])
(lambda (cur) (cons b cur)) null))) (let ([k (author-element-names (auto-bib-author b))])
(values (hash-update h k (lambda (cur) (cons b cur)) null)
(cons k (remove k ks))))))
(make-element (make-element
#f #f
(append (append
(list 'nbsp "(") (list 'nbsp "(")
(add-between (add-between
(for/list ([(k v) groups]) (for/list ([k (if sort? (sort keys string-ci<?) keys)])
(let ([v (hash-ref groups k)])
(make-element (make-element
#f #f
(list* (list*
@ -85,7 +88,7 @@
" " " "
(add-between (add-between
(for/list ([b v]) (add-cite group b 'autobib-date #t)) (for/list ([b v]) (add-cite group b 'autobib-date #t))
", ")))) ", ")))))
"; ") "; ")
(list ")")))) (list ")"))))
@ -100,8 +103,8 @@
(let* ([author/date<? (let* ([author/date<?
(lambda (a b) (lambda (a b)
(or (or
(string<? (extract-bib-key a) (extract-bib-key b)) (string-ci<? (extract-bib-key a) (extract-bib-key b))
(and (string=? (extract-bib-key a) (extract-bib-key b)) (and (string-ci=? (extract-bib-key a) (extract-bib-key b))
(extract-bib-year a) (extract-bib-year b) (extract-bib-year a) (extract-bib-year b)
(< (extract-bib-year a) (extract-bib-year b)))))] (< (extract-bib-year a) (extract-bib-year b)))))]
[bibs (sort (hash-map (bib-group-ht group) [bibs (sort (hash-map (bib-group-ht group)
@ -146,8 +149,8 @@
(define-syntax-rule (define-cite ~cite citet generate-bibliography) (define-syntax-rule (define-cite ~cite citet generate-bibliography)
(begin (begin
(define group (make-bib-group (make-hasheq))) (define group (make-bib-group (make-hasheq)))
(define (~cite bib-entry . bib-entries) (define (~cite #:sort? [sort? #t] bib-entry . bib-entries)
(add-cites group (cons bib-entry bib-entries))) (add-cites group (cons bib-entry bib-entries) sort?))
(define (citet bib-entry . bib-entries) (define (citet bib-entry . bib-entries)
(add-inline-cite group (cons bib-entry bib-entries))) (add-inline-cite group (cons bib-entry bib-entries)))
(define (generate-bibliography #:tag [tag "doc-bibliography"] #:sec-title [sec-title "Bibliography"]) (define (generate-bibliography #:tag [tag "doc-bibliography"] #:sec-title [sec-title "Bibliography"])

View File

@ -17,10 +17,11 @@ render citations.
The function bound to @scheme[~cite-id] produces a citation referring The function bound to @scheme[~cite-id] produces a citation referring
to one or more bibliography entries with a preceding non-breaking to one or more bibliography entries with a preceding non-breaking
space. It has the contract space, by default sorting the entries to match the bibliography order.
It has the contract
@schemeblock[ @schemeblock[
(->* (bib?) () #:rest (listof bib?) element?) (->* (bib?) (#:sort? any/c) #:rest (listof bib?) element?)
] ]
The function bound to @scheme[citet-id] generates an element suitable The function bound to @scheme[citet-id] generates an element suitable