From 5a0cc3d55f10fdbb2ee6f715f1cf12b0a3e1479f Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Wed, 6 Jun 2007 01:20:49 +0000 Subject: [PATCH] latex output, especially margin notes svn: r6496 original commit: 0b9493032b3a6d55d85c291ad54e84a513d6fb80 --- collects/scribble/latex-render.ss | 101 ++++++++++++++++-------------- 1 file changed, 55 insertions(+), 46 deletions(-) diff --git a/collects/scribble/latex-render.ss b/collects/scribble/latex-render.ss index a6f9ac55..1e110a41 100644 --- a/collects/scribble/latex-render.ss +++ b/collects/scribble/latex-render.ss @@ -88,56 +88,65 @@ (define/override (render-paragraph p part ht) (printf "\n\n") - (if (toc-paragraph? p) - (printf "\\newpage \\tableofcontents \\newpage") - (super render-paragraph p part ht)) + (let ([margin? (and (styled-paragraph? p) + (equal? "refpara" (styled-paragraph-style p)))]) + (when margin? + (printf "\\marginpar{\\footnotesize ")) + (if (toc-paragraph? p) + (printf "\\newpage \\tableofcontents \\newpage") + (super render-paragraph p part ht)) + (when margin? + (printf "}"))) (printf "\n\n") null) (define/override (render-element e part ht) - (when (and (link-element? e) - (pair? (link-element-tag e)) - (eq? 'part (car (link-element-tag e))) - (null? (element-content 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?) - (printf "{\\~a{" s) - (parameterize ([rendering-tt (or tt? - (rendering-tt))]) - (super render-element e part ht)) - (printf "}}"))]) - (cond - [(symbol? style) - (case style - [(italic) (wrap e "textit" #f)] - [(bold) (wrap e "textbf" #f)] - [(tt) (wrap e "texttt" #t)] - [(sf) (wrap e "textsf" #f)] - [(subscript) (wrap e "textsub" #f)] - [(superscript) (wrap e "textsuper" #f)] - [(hspace) (let ([s (content->string (element-content e))]) - (case (string-length s) - [(0) (void)] - [(1) (printf "{\\texttt{ }}")] ; allows a line break to replace the space - [else - (printf "{\\texttt{~a}}" - (regexp-replace* #rx"." s "~"))]))] - [else (error 'latex-render "unrecognzied style symbol: ~s" style)])] - [(string? style) - (wrap e style (regexp-match? #px"^scheme(?!error)" style))] - [(image-file? style) - (let ([fn (install-file (image-file-path style))]) - (printf "\\includegraphics{~a}" fn))] - [else (super render-element e part ht)])) + (let ([part-label? (and (link-element? e) + (pair? (link-element-tag e)) + (eq? 'part (car (link-element-tag e))) + (null? (element-content e)))]) + (when part-label? + (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?) + (printf "{\\~a{" s) + (parameterize ([rendering-tt (or tt? + (rendering-tt))]) + (super render-element e part ht)) + (printf "}}"))]) + (cond + [(symbol? style) + (case style + [(italic) (wrap e "textit" #f)] + [(bold) (wrap e "textbf" #f)] + [(tt) (wrap e "texttt" #t)] + [(sf) (wrap e "textsf" #f)] + [(subscript) (wrap e "textsub" #f)] + [(superscript) (wrap e "textsuper" #f)] + [(hspace) (let ([s (content->string (element-content e))]) + (case (string-length s) + [(0) (void)] + [(1) (printf "{\\texttt{ }}")] ; allows a line break to replace the space + [else + (printf "{\\texttt{~a}}" + (regexp-replace* #rx"." s "~"))]))] + [else (error 'latex-render "unrecognzied style symbol: ~s" style)])] + [(string? style) + (wrap e style (regexp-match? #px"^scheme(?!error)" style))] + [(image-file? style) + (let ([fn (install-file (image-file-path style))]) + (printf "\\includegraphics{~a}" fn))] + [else (super render-element e part ht)])) + (when part-label? + (printf "''"))) null) (define/override (render-table t part ht)