add --latex-section' mode to
scribble'
original commit: 3f95fabf7c4ef7616633820e79bf4d1ea472bbb9
This commit is contained in:
parent
532feda048
commit
9f6f5d9812
|
@ -11,7 +11,8 @@
|
|||
scheme/list
|
||||
setup/main-collects
|
||||
file/convertible)
|
||||
(provide render-mixin)
|
||||
(provide render-mixin
|
||||
make-render-part-mixin)
|
||||
|
||||
(define current-table-mode (make-parameter #f))
|
||||
(define rendering-tt (make-parameter #f))
|
||||
|
@ -34,6 +35,12 @@
|
|||
(/ (cadr 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 %)
|
||||
(class %
|
||||
(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-paths v) (latex-defaults-extra-files v))
|
||||
|
||||
(define/public (render-part-depth) #f)
|
||||
|
||||
(define/override (render-one d ri fn)
|
||||
(let* ([defaults (ormap (lambda (v) (and (latex-defaults? v) v))
|
||||
(style-properties (part-style d)))]
|
||||
|
@ -72,51 +81,58 @@
|
|||
(cond
|
||||
[(bytes? v) v]
|
||||
[else (main-collects-relative->path v)])))
|
||||
scribble-style-tex)])
|
||||
(for-each
|
||||
(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
|
||||
d
|
||||
ri
|
||||
'tex
|
||||
(lambda (p) #f)
|
||||
tex-addition?
|
||||
tex-addition-path)
|
||||
(list style-file)
|
||||
style-extra-files)))
|
||||
(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" ""))
|
||||
(render-content (part-title-content d) d ri)
|
||||
(printf "}{~a}{" vers)
|
||||
(for/fold ([first? #t]) ([auth (in-list auths)])
|
||||
(unless first? (printf "\\SAuthorSep{}"))
|
||||
(do-render-paragraph auth d ri #t)
|
||||
#f)
|
||||
(printf "}\n")))
|
||||
scribble-style-tex)]
|
||||
[all-style-files (cons scribble-tex
|
||||
(append (extract-part-style-files
|
||||
d
|
||||
ri
|
||||
'tex
|
||||
(lambda (p) #f)
|
||||
tex-addition?
|
||||
tex-addition-path)
|
||||
(list style-file)
|
||||
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")
|
||||
(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" ""))
|
||||
(render-content (part-title-content d) d ri)
|
||||
(printf "}{~a}{" vers)
|
||||
(for/fold ([first? #t]) ([auth (in-list auths)])
|
||||
(unless first? (printf "\\SAuthorSep{}"))
|
||||
(do-render-paragraph auth d ri #t)
|
||||
#f)
|
||||
(printf "}\n"))))
|
||||
(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)
|
||||
(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)
|
||||
(printf "\\twocolumn\n\\parskip=0pt\n\\addcontentsline{toc}{section}{Index}\n"))
|
||||
(let ([pres (extract-pretitle d)])
|
||||
|
@ -127,7 +143,7 @@
|
|||
(or (not (car number))
|
||||
((length number) . > . 3)))])
|
||||
(printf "\n\n\\~a~a~a"
|
||||
(case (length number)
|
||||
(case (+ (length number) (or (render-part-depth) 0))
|
||||
[(0 1) "sectionNewpage\n\n\\section"]
|
||||
[(2) "subsection"]
|
||||
[(3) "subsubsection"]
|
||||
|
|
|
@ -51,6 +51,11 @@
|
|||
(current-render-mixin latex:render-mixin)]
|
||||
[("--pdf") "generate PDF-format output (with PDFLaTeX)"
|
||||
(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
|
||||
[("--dest") dir "write output in <dir>"
|
||||
(current-dest-directory dir)]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#lang scribble/manual
|
||||
@(require "utils.rkt"
|
||||
scribble/bnf
|
||||
(for-label setup/xref))
|
||||
|
||||
@(define fn (italic "fn"))
|
||||
|
@ -29,6 +30,13 @@ its file suffix:
|
|||
@item{@DFlag{pdf} --- PDF @filepath{@|fn|.pdf} that is generated
|
||||
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
|
||||
@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
|
||||
@tt{DOCTYPE} declaration of each output HTML file as a substitute for
|
||||
@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}
|
||||
declarations as a substitute for @filepath{scribble-prefix.tex} in the
|
||||
@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 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
|
||||
always resolved. When cross references span documents that are
|
||||
|
|
|
@ -68,24 +68,27 @@
|
|||
(loop (cdr keys))))))
|
||||
")")))
|
||||
|
||||
(define (add-cites group bib-entries)
|
||||
(define groups (for/fold ([h (hash)]) ([b (reverse bib-entries)])
|
||||
(hash-update h (author-element-names (auto-bib-author b))
|
||||
(lambda (cur) (cons b cur)) null)))
|
||||
(define (add-cites group bib-entries sort?)
|
||||
(define-values (groups keys)
|
||||
(for/fold ([h (hash)] [ks null]) ([b (reverse bib-entries)])
|
||||
(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
|
||||
#f
|
||||
(append
|
||||
(list 'nbsp "(")
|
||||
(add-between
|
||||
(for/list ([(k v) groups])
|
||||
(make-element
|
||||
#f
|
||||
(list*
|
||||
(add-cite group (car v) 'autobib-author #f)
|
||||
" "
|
||||
(add-between
|
||||
(for/list ([b v]) (add-cite group b 'autobib-date #t))
|
||||
", "))))
|
||||
(for/list ([k (if sort? (sort keys string-ci<?) keys)])
|
||||
(let ([v (hash-ref groups k)])
|
||||
(make-element
|
||||
#f
|
||||
(list*
|
||||
(add-cite group (car v) 'autobib-author #f)
|
||||
" "
|
||||
(add-between
|
||||
(for/list ([b v]) (add-cite group b 'autobib-date #t))
|
||||
", ")))))
|
||||
"; ")
|
||||
(list ")"))))
|
||||
|
||||
|
@ -100,8 +103,8 @@
|
|||
(let* ([author/date<?
|
||||
(lambda (a b)
|
||||
(or
|
||||
(string<? (extract-bib-key a) (extract-bib-key b))
|
||||
(and (string=? (extract-bib-key a) (extract-bib-key b))
|
||||
(string-ci<? (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)))))]
|
||||
[bibs (sort (hash-map (bib-group-ht group)
|
||||
|
@ -146,8 +149,8 @@
|
|||
(define-syntax-rule (define-cite ~cite citet generate-bibliography)
|
||||
(begin
|
||||
(define group (make-bib-group (make-hasheq)))
|
||||
(define (~cite bib-entry . bib-entries)
|
||||
(add-cites group (cons bib-entry bib-entries)))
|
||||
(define (~cite #:sort? [sort? #t] bib-entry . bib-entries)
|
||||
(add-cites group (cons bib-entry bib-entries) sort?))
|
||||
(define (citet 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"])
|
||||
|
|
|
@ -17,10 +17,11 @@ render citations.
|
|||
|
||||
The function bound to @scheme[~cite-id] produces a citation referring
|
||||
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[
|
||||
(->* (bib?) () #:rest (listof bib?) element?)
|
||||
(->* (bib?) (#:sort? any/c) #:rest (listof bib?) element?)
|
||||
]
|
||||
|
||||
The function bound to @scheme[citet-id] generates an element suitable
|
||||
|
|
Loading…
Reference in New Issue
Block a user