From ab02db12522102d5fae2ff3b81ee75d6311f66d6 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Mon, 31 Mar 2008 15:27:12 +0000 Subject: [PATCH] more scribble configurability and latex back-end improvements svn: r9120 original commit: f5268bed2a0bb1a4d548bb1f073432047455ced8 --- collects/scribble/html-render.ss | 67 +++++++++++++++++-------------- collects/scribble/latex-render.ss | 54 +++++++++++++------------ collects/scribble/manual.ss | 2 +- collects/scribble/run.ss | 7 +++- collects/scribble/scribble.tex | 4 +- collects/scribble/text-render.ss | 2 + 6 files changed, 76 insertions(+), 60 deletions(-) diff --git a/collects/scribble/html-render.ss b/collects/scribble/html-render.ss index 36e6acbc..919bbe24 100644 --- a/collects/scribble/html-render.ss +++ b/collects/scribble/html-render.ss @@ -189,7 +189,8 @@ quiet-table-of-contents) (init-field [css-path #f] - [up-path #f]) + [up-path #f] + [style-file #f]) (define/override (get-suffix) #".html") @@ -449,37 +450,41 @@ (define/public (render-one-part d ri fn number) (parameterize ([current-output-file fn]) - (let ([xpr `(html () - (head - (meta ((http-equiv "content-type") - (content "text-html; charset=utf-8"))) - ,@(let ([c (part-title-content d)]) - (if c - `((title ,@(format-number number '(nbsp)) - ,(content->string c this d ri))) - null)) - ,(if (eq? 'inline css-path) - `(style ([type "text/css"]) - "\n" - ,(with-input-from-file scribble-css - (lambda () - ;; note: file-size can be bigger that the - ;; string, but that's fine. - (read-string (file-size scribble-css)))) - "\n") - `(link ((rel "stylesheet") - (type "text/css") - (href ,(or css-path "scribble.css")) - (title "default"))))) - (body ,@(render-toc-view d ri) - (div ((class "maincolumn")) - (div ((class "main")) - ,@(render-version d ri) - ,@(navigation d ri #f) - ,@(render-part d ri) - ,@(navigation d ri #t)))))]) + (let* ([style-file (or style-file scribble-css)] + [xpr `(html () + (head + (meta ((http-equiv "content-type") + (content "text-html; charset=utf-8"))) + ,@(let ([c (part-title-content d)]) + (if c + `((title ,@(format-number number '(nbsp)) + ,(content->string c this d ri))) + null)) + ,(if (eq? 'inline css-path) + `(style ([type "text/css"]) + "\n" + ,(with-input-from-file style-file + (lambda () + ;; note: file-size can be bigger that the + ;; string, but that's fine. + (read-string (file-size style-file)))) + "\n") + `(link ((rel "stylesheet") + (type "text/css") + (href ,(or css-path + (let-values ([(base name dir?) + (split-path style-file)]) + (path->string name)))) + (title "default"))))) + (body ,@(render-toc-view d ri) + (div ((class "maincolumn")) + (div ((class "main")) + ,@(render-version d ri) + ,@(navigation d ri #f) + ,@(render-part d ri) + ,@(navigation d ri #t)))))]) (unless css-path - (install-file scribble-css)) + (install-file style-file)) (printf "\n") (xml:write-xml/content (xml:xexpr->xml xpr))))) diff --git a/collects/scribble/latex-render.ss b/collects/scribble/latex-render.ss index a4653bc8..5048ef99 100644 --- a/collects/scribble/latex-render.ss +++ b/collects/scribble/latex-render.ss @@ -17,6 +17,8 @@ (define (render-mixin %) (class % + (init-field [style-file #f]) + (define/override (get-suffix) #".tex") (inherit render-flow @@ -26,20 +28,22 @@ format-number) (define/override (render-one d ri fn) - (with-input-from-file scribble-tex - (lambda () - (copy-port (current-input-port) - (current-output-port)))) - (printf "\\begin{document}\n\\preDoc\n") - (when (part-title-content d) - (printf "\\titleAndVersion{") - (render-content (part-title-content d) d ri) - (printf "}{~a}\n" - (or (and (versioned-part? d) - (versioned-part-version d)) - (version)))) - (render-part d ri) - (printf "\\postDoc\n\\end{document}\n")) + (let ([style-file (or style-file + scribble-tex)]) + (with-input-from-file style-file + (lambda () + (copy-port (current-input-port) + (current-output-port)))) + (printf "\\begin{document}\n\\preDoc\n") + (when (part-title-content d) + (printf "\\titleAndVersion{") + (render-content (part-title-content d) d ri) + (printf "}{~a}\n" + (or (and (versioned-part? d) + (versioned-part-version d)) + (version)))) + (render-part d ri) + (printf "\\postDoc\n\\end{document}\n"))) (define/override (render-part d ri) (let ([number (collected-info-number (part-collected-info d ri))]) @@ -49,7 +53,7 @@ (printf "\\twocolumn\n\\parskip=0pt\n\\addcontentsline{toc}{section}{Index}\n")) (printf "\\~a~a{" (case (length number) - [(0 1) "newpage\n\n\\section"] + [(0 1) "sectionNewpage\n\n\\section"] [(2) "subsection"] [(3) "subsubsection"] [else "subsubsection*"]) @@ -186,16 +190,16 @@ (= 1 (length (car (table-flowss t))))) (let ([m (current-table-mode)]) (and m - (equal? "longtable" (car m)) + (equal? "supertabular" (car m)) (= 1 (length (car (table-flowss (cadr m))))))))] [tableform (cond [index? "list"] [(and (not (current-table-mode)) (not inline-table?)) - "longtable"] + "supertabular"] [else "tabular"])] [opt (cond - [(equal? tableform "longtable") "[l]"] + [(equal? tableform "supertabular") "[l]"] [(equal? tableform "tabular") "[t]"] [else ""])] [flowss (if index? @@ -216,9 +220,7 @@ (if boxed? (format "{~a\\begin{picture}(1,0)\\put(0,0){\\line(1,0){1}}\\end{picture}}~a\n\\nopagebreak\n" "\\setlength{\\unitlength}{\\linewidth}" - (if (equal? tableform "longtable") - "\\vspace{-5ex}" - "\n\n")) + "\n\n") "") tableform opt @@ -266,11 +268,11 @@ (unless (null? (cdr flowss)) (loop (cdr flowss) (cdr row-styles))))) (unless inline? - (printf "\n\n\\end{~a}~a\n" - tableform - (if (equal? tableform "longtable") - "\\vspace{-3ex}" ;; counteracts mysterious space added after longtable - "")))))) + (printf "~a\n\n\\end{~a}\n" + (if (equal? tableform "supertabular") + "\n\\\\" + "") + tableform))))) null) (define/override (render-itemization t part ri) diff --git a/collects/scribble/manual.ss b/collects/scribble/manual.ss index 200d132a..a744c88f 100644 --- a/collects/scribble/manual.ss +++ b/collects/scribble/manual.ss @@ -1880,7 +1880,7 @@ (make-link-element #f content (or (find-scheme-tag p ri stx-id #f) - (format "--UNDEFINED:~a--" (syntax-e stx-id)))))) + `(undef ,(format "--UNDEFINED:~a--" (syntax-e stx-id))))))) (lambda () content) (lambda () content)))) diff --git a/collects/scribble/run.ss b/collects/scribble/run.ss index fe0215a9..dc55a366 100644 --- a/collects/scribble/run.ss +++ b/collects/scribble/run.ss @@ -29,6 +29,8 @@ (make-parameter #f)) (define current-info-input-files (make-parameter null)) + (define current-style-file + (make-parameter #f)) (define (get-command-line-files argv) (command-line @@ -48,6 +50,8 @@ (current-dest-directory dir)] [("--dest-name") name "write output as " (current-dest-name name)] + [("--style") file "use given .css/.tex file" + (current-style-file file)] [("--info-out") file "write format-specific link information to " (current-info-output-file file)]] [multi @@ -68,7 +72,8 @@ (make-directory* dir)) (let ([renderer (new ((current-render-mixin) render%) - [dest-dir dir])]) + [dest-dir dir] + [style-file (current-style-file)])]) (send renderer report-output!) (let* ([fns (map (lambda (fn) (let-values ([(base name dir?) (split-path fn)]) diff --git a/collects/scribble/scribble.tex b/collects/scribble/scribble.tex index fe24dbc3..4c18f48b 100644 --- a/collects/scribble/scribble.tex +++ b/collects/scribble/scribble.tex @@ -14,7 +14,7 @@ \usepackage{graphicx} \usepackage{hyperref} \renewcommand{\rmdefault}{ptm} -\usepackage{longtable} +\usepackage{supertabular} \usepackage[htt]{hyphenat} \usepackage[usenames,dvipsnames]{color} \hypersetup{bookmarks=true,bookmarksopen=true,bookmarksnumbered=true} @@ -69,6 +69,8 @@ \newcommand{\titleAndVersion}[2]{\title{#1\\{\normalsize Version #2}}\maketitle} +\newcommand{\sectionNewpage}{\newpage} + \newcommand{\preDoc}{\sloppy} \newcommand{\postDoc}{} diff --git a/collects/scribble/text-render.ss b/collects/scribble/text-render.ss index d11cf47b..6f28d38a 100644 --- a/collects/scribble/text-render.ss +++ b/collects/scribble/text-render.ss @@ -6,6 +6,8 @@ (define (render-mixin %) (class % + (init [style-file #f]) + (define/override (get-substitutions) '((#rx"---" "\U2014") (#rx"--" "\U2013")