From 1c865ed71d6f913a8c94521c1efb4e550f7415c2 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sat, 26 May 2007 02:12:34 +0000 Subject: [PATCH] fix and improve latex rendering svn: r6332 original commit: 574c9b5f7890f64a1c9ea2dc387f223b652ae457 --- collects/scribble/base-render.ss | 26 ++++++++++++++------------ collects/scribble/html-render.ss | 4 ++-- collects/scribble/latex-render.ss | 13 +++++++++++-- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/collects/scribble/base-render.ss b/collects/scribble/base-render.ss index 7a5e8d82..b7e5ac2c 100644 --- a/collects/scribble/base-render.ss +++ b/collects/scribble/base-render.ss @@ -24,13 +24,14 @@ (andmap not number)) null (cons - (apply - string-append - (map (lambda (n) - (if n - (format "~s." n) - "")) - (reverse number))) + (let ([s (apply + string-append + (map (lambda (n) + (if n + (format "~s." n) + "")) + (reverse number)))]) + (substring s 0 (sub1 (string-length s)))) sep))) ;; ---------------------------------------- @@ -61,7 +62,7 @@ (when (part-title-content d) (collect-content (part-title-content d) p-ht)) (when (part-tag d) - (collect-part-tag d p-ht)) + (collect-part-tag d p-ht number)) (collect-flow (part-flow d) p-ht) (let loop ([parts (part-parts d)] [pos 1]) @@ -82,8 +83,8 @@ (lambda (k v) (hash-table-put! ht k v))))) - (define/public (collect-part-tag d ht) - (hash-table-put! ht `(part ,(part-tag d)) (part-title-content d))) + (define/public (collect-part-tag d ht number) + (hash-table-put! ht `(part ,(part-tag d)) (list (part-title-content d) number))) (define/public (collect-content c ht) (for-each (lambda (i) @@ -124,7 +125,7 @@ (element-content i)))) (define/public (collect-target-element i ht) - (hash-table-put! ht (target-element-tag i) i)) + (hash-table-put! ht (target-element-tag i) (list i))) (define/public (collect-index-element i ht) (hash-table-put! ht `(index-entry ,(index-element-tag i)) @@ -207,7 +208,7 @@ (null? (element-content i))) (let ([v (lookup part ht (link-element-tag i))]) (if v - (render-content v part ht) + (render-content (car v) part ht) (render-content (list "[missing]") part ht)))] [(element? i) (render-content (element-content i) part ht)] @@ -277,6 +278,7 @@ (append (format-number number (list + "." (make-element 'hspace '(" ")))) (part-title-content part)) `(part ,(part-tag part)))))))) diff --git a/collects/scribble/html-render.ss b/collects/scribble/html-render.ss index dde3a6ce..2edcd09e 100644 --- a/collects/scribble/html-render.ss +++ b/collects/scribble/html-render.ss @@ -48,7 +48,7 @@ (define/public (part-whole-page? d) #f) - (define/override (collect-part-tag d ht) + (define/override (collect-part-tag d ht number) (hash-table-put! ht `(part ,(part-tag d)) (list (current-output-file) @@ -92,7 +92,7 @@ [(0) 'h2] [(1) 'h3] [else 'h4]) - ,@(format-number number '((tt nbsp))) + ,@(format-number number '("." (tt nbsp))) ,@(if (part-tag d) `((a ((name ,(format "~a" `(part ,(part-tag d))))))) null) diff --git a/collects/scribble/latex-render.ss b/collects/scribble/latex-render.ss index 4c186bca..929cf8c8 100644 --- a/collects/scribble/latex-render.ss +++ b/collects/scribble/latex-render.ss @@ -15,7 +15,9 @@ (inherit render-flow render-content - install-file) + install-file + format-number + lookup) (define (define-color s s2) (printf "\\newcommand{\\~a}[1]{{\\texttt{\\color{~a}{#1}}}}\n" s s2)) @@ -94,7 +96,14 @@ (pair? (link-element-tag e)) (eq? 'part (car (link-element-tag e))) (null? (element-content e))) - (printf "\\S\\ref{section:~a} " (cadr (link-element-tag e)))) + (printf "\\S") + (render-content (let ([dest (lookup part ht (link-element-tag e))]) + (if dest + (format-number (cadr dest) null) + (list "???"))) + part + ht) + (printf " ")) (let ([style (and (element? e) (element-style e))] [wrap (lambda (e s tt?)