diff --git a/collects/scribble/base-render.ss b/collects/scribble/base-render.ss index 8d1b60ac..0c7865db 100644 --- a/collects/scribble/base-render.ss +++ b/collects/scribble/base-render.ss @@ -21,6 +21,9 @@ (define/public (get-suffix) #".txt") + (define/public (index-manual-newlines?) + #f) + (define/public (format-number number sep) (if (or (null? number) (andmap not number)) diff --git a/collects/scribble/basic.ss b/collects/scribble/basic.ss index 465f6d93..2f809684 100644 --- a/collects/scribble/basic.ss +++ b/collects/scribble/basic.ss @@ -221,10 +221,12 @@ (make-table 'index (map (lambda (row) (list (make-flow (list (make-paragraph row))))) rows))) - (define line-break (make-element 'newline '("\n"))) (define contents (lambda (renderer sec ri) (define l null) + (define line-break (if (send renderer index-manual-newlines?) + (make-element 'newline '("\n")) + "")) (define alpha-starts (make-hash-table)) (hash-table-for-each (let ([parent (collected-info-parent (part-collected-info sec ri))]) @@ -235,7 +237,8 @@ (when (and (pair? k) (eq? 'index-entry (car k))) (set! l (cons (cons (cadr k) v) l))))) (set! l (sort l cadr-string-lists (lambda (let) - (make-element (make-url-anchor - (format "alpha:~a" (char-upcase let))) - (list e)))] - [else e])) - l)))) + ((if (send renderer index-manual-newlines?) + list + (lambda (v) + (map list v))) + (map (lambda (i) + (define e + (make-link-element "indexlink" + `(,@(commas (caddr i)) ,line-break) + (car i))) + (cond [(hash-table-get alpha-starts i #f) + => (lambda (let) + (make-element (make-url-anchor + (format "alpha:~a" (char-upcase let))) + (list e)))] + [else e])) + l))))) (list (make-delayed-flow-element contents))) ;; ---------------------------------------- diff --git a/collects/scribble/html-render.ss b/collects/scribble/html-render.ss index 0df04334..36e6acbc 100644 --- a/collects/scribble/html-render.ss +++ b/collects/scribble/html-render.ss @@ -193,6 +193,9 @@ (define/override (get-suffix) #".html") + (define/override (index-manual-newlines?) + #t) + ;; ---------------------------------------- (define/override (start-collect ds fns ci) diff --git a/collects/scribble/latex-render.ss b/collects/scribble/latex-render.ss index 55e3a004..a4653bc8 100644 --- a/collects/scribble/latex-render.ss +++ b/collects/scribble/latex-render.ss @@ -1,7 +1,10 @@ (module latex-render scheme/base (require "struct.ss" - mzlib/class) + mzlib/class + scheme/runtime-path + scheme/port + (for-syntax scheme/base)) (provide render-mixin) (define current-table-mode (make-parameter #f)) @@ -10,6 +13,8 @@ (define-struct (toc-paragraph paragraph) ()) + (define-runtime-path scribble-tex "scribble.tex") + (define (render-mixin %) (class % (define/override (get-suffix) #".tex") @@ -20,75 +25,21 @@ install-file format-number) - (define (define-color s s2) - (printf "\\newcommand{\\~a}[1]{{\\mytexttt{\\color{~a}{#1}}}}\n" s s2)) - (define/override (render-one d ri fn) - (printf "\\documentclass{article}\n") - (printf "\\parskip=10pt%\n") - (printf "\\parindent=0pt%\n") - (printf "\\usepackage{graphicx}\n") - (printf "\\usepackage{hyperref}\n") - (printf "\\renewcommand{\\rmdefault}{ptm}\n") - ;; (printf "\\usepackage{fullpage}\n") - (printf "\\usepackage{longtable}\n") - (printf "\\usepackage[usenames,dvipsnames]{color}\n") - (printf "\\hypersetup{bookmarks=true,bookmarksopen=true,bookmarksnumbered=true}\n") - (printf "\\newcommand{\\mytexttt}[1]{{\\small \\texttt{#1}}}\n") - (define-color "schemeplain" "black") - (printf "\\newcommand{\\schemekeyword}[1]{{\\color{black}{\\mytexttt{\\textbf{#1}}}}}\n") - (printf "\\newcommand{\\schemesyntaxlink}[1]{\\schemekeyword{#1}}\n") - (printf "\\definecolor{CommentColor}{rgb}{0.76,0.45,0.12}\n") - (printf "\\definecolor{ParenColor}{rgb}{0.52,0.24,0.14}\n") - (printf "\\definecolor{IdentifierColor}{rgb}{0.15,0.15,0.50}\n") - (printf "\\definecolor{ResultColor}{rgb}{0.0,0.0,0.69}\n") - (printf "\\definecolor{ValueColor}{rgb}{0.13,0.55,0.13}\n") - (printf "\\definecolor{OutputColor}{rgb}{0.59,0.00,0.59}\n") - (define-color "schemecomment" "CommentColor") - (define-color "schemeparen" "ParenColor") - (define-color "schemeinputbg" "ParenColor") - (define-color "schemesymbol" "IdentifierColor") - (define-color "schemevalue" "ValueColor") - (define-color "schemevaluelink" "blue") - (define-color "schememodlink" "blue") - (define-color "schemeresult" "ResultColor") - (define-color "schemestdout" "OutputColor") - (define-color "schememeta" "IdentifierColor") - (define-color "schememod" "black") - (define-color "schemereader" "black") - (define-color "schemevariablecol" "IdentifierColor") - (printf "\\newcommand{\\schemevariable}[1]{{\\schemevariablecol{\\textsl{#1}}}}\n") - (define-color "schemeerrorcol" "red") - (printf "\\newcommand{\\schemeerror}[1]{{\\schemeerrorcol{\\textrm{\\textit{#1}}}}}\n") - (printf "\\newcommand{\\schemeopt}[1]{#1}\n") - (printf "\\newcommand{\\textsub}[1]{$_{#1}$}\n") - (printf "\\newcommand{\\textsuper}[1]{$^{#1}$}\n") - (printf "\\newcommand{\\refcolumn}[1]{#1}\n") - (printf "\\newcommand{\\refcontent}[1]{#1}\n") - (printf "\\newcommand{\\smaller}[1]{{\\footnotesize #1}}\n") - (printf "\\definecolor{PaleBlue}{rgb}{0.90,0.90,1.0}\n") - (printf "\\definecolor{LightGray}{rgb}{0.90,0.90,0.90}\n") - (printf "\\newcommand{\\intextcolor}[2]{\\textcolor{#1}{#2}}\n") - (printf "\\newcommand{\\intextrgbcolor}[2]{\\textcolor[rgb]{#1}{#2}}\n") - (printf "\\newcommand{\\incolorbox}[2]{{\\fboxrule=0pt\\fboxsep=0pt\\colorbox{#1}{#2}}}\n") - (printf "\\newcommand{\\inrgbcolorbox}[2]{{\\fboxrule=0pt\\fboxsep=0pt\\colorbox[rgb]{#1}{#2}}}\n") - (printf "\\newcommand{\\schemeinput}[1]{\\incolorbox{LightGray}{\\schemeinputbg{#1}}}\n") - (printf "\\newcommand{\\highlighted}[1]{\\colorbox{PaleBlue}{\\hspace{-0.5ex}\\schemeinputbg{#1}\\hspace{-0.5ex}}}\n") - (printf "\\newcommand{\\plainlink}[1]{#1}\n") - (printf "\\newcommand{\\techlink}[1]{#1}\n") - (printf "\\newcommand{\\badlink}[1]{#1}\n") - (printf "\\newcommand{\\indexlink}[1]{#1}\n") - (printf "\\newcommand{\\imageleft}[1]{} % drop it\n") - (printf "\\begin{document}\n\\sloppy\n") + (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 "\\title{") + (printf "\\titleAndVersion{") (render-content (part-title-content d) d ri) - (printf "\\\\{\\normalsize Version ~a}}\\maketitle\n" + (printf "}{~a}\n" (or (and (versioned-part? d) (versioned-part-version d)) (version)))) (render-part d ri) - (printf "\\end{document}\n")) + (printf "\\postDoc\n\\end{document}\n")) (define/override (render-part d ri) (let ([number (collected-info-number (part-collected-info d ri))]) diff --git a/collects/scribble/scribble.tex b/collects/scribble/scribble.tex new file mode 100644 index 00000000..fe24dbc3 --- /dev/null +++ b/collects/scribble/scribble.tex @@ -0,0 +1,82 @@ +% This is the default prefix for Scribble-generated HTML + +\documentclass{article} + +\parskip=10pt +\parindent=0pt + +% Adjust margins to match HTML width for +% fixed-width font +\advance \oddsidemargin by -0.15in +\advance \evensidemargin by -0.15in +\advance \textwidth by 0.3in + +\usepackage{graphicx} +\usepackage{hyperref} +\renewcommand{\rmdefault}{ptm} +\usepackage{longtable} +\usepackage[htt]{hyphenat} +\usepackage[usenames,dvipsnames]{color} +\hypersetup{bookmarks=true,bookmarksopen=true,bookmarksnumbered=true} + +\newcommand{\inColor}[2]{{\mytexttt{\color{#1}{#2}}}} +\definecolor{CommentColor}{rgb}{0.76,0.45,0.12} +\definecolor{ParenColor}{rgb}{0.52,0.24,0.14} +\definecolor{IdentifierColor}{rgb}{0.15,0.15,0.50} +\definecolor{ResultColor}{rgb}{0.0,0.0,0.69} +\definecolor{ValueColor}{rgb}{0.13,0.55,0.13} +\definecolor{OutputColor}{rgb}{0.59,0.00,0.59} +\definecolor{PaleBlue}{rgb}{0.90,0.90,1.0} +\definecolor{LightGray}{rgb}{0.90,0.90,0.90} + +\newcommand{\mytexttt}[1]{{\texttt{#1}}} +\newcommand{\schemeplain}[1]{\inColor{black}{#1}} +\newcommand{\schemekeyword}[1]{{\color{black}{\mytexttt{\textbf{#1}}}}} +\newcommand{\schemesyntaxlink}[1]{\schemekeyword{#1}} +\newcommand{\schemecomment}[1]{\inColor{CommentColor}{#1}} +\newcommand{\schemeparen}[1]{\inColor{ParenColor}{#1}} +\newcommand{\schemeinputbg}[1]{\inColor{ParenColor}{#1}} +\newcommand{\schemesymbol}[1]{\inColor{IdentifierColor}{#1}} +\newcommand{\schemevalue}[1]{\inColor{ValueColor}{#1}} +\newcommand{\schemevaluelink}[1]{\inColor{blue}{#1}} +\newcommand{\schememodlink}[1]{\inColor{blue}{#1}} +\newcommand{\schemeresult}[1]{\inColor{ResultColor}{#1}} +\newcommand{\schemestdout}[1]{\inColor{OutputColor}{#1}} +\newcommand{\schememeta}[1]{\inColor{IdentifierColor}{#1}} +\newcommand{\schememod}[1]{\inColor{black}{#1}} +\newcommand{\schemereader}[1]{\inColor{black}{#1}} +\newcommand{\schemevariablecol}[1]{\inColor{IdentifierColor}{#1}} +\newcommand{\schemevariable}[1]{{\schemevariablecol{\textsl{#1}}}} +\newcommand{\schemeerrorcol}[1]{\inColor{red}{#1}} +\newcommand{\schemeerror}[1]{{\schemeerrorcol{\textrm{\textit{#1}}}}} +\newcommand{\schemeopt}[1]{#1} +\newcommand{\textsub}[1]{$_{#1}$} +\newcommand{\textsuper}[1]{$^{#1}$} +\newcommand{\refcolumn}[1]{#1} +\newcommand{\refcontent}[1]{#1} +\newcommand{\intextcolor}[2]{\textcolor{#1}{#2}} +\newcommand{\intextrgbcolor}[2]{\textcolor[rgb]{#1}{#2}} +\newcommand{\incolorbox}[2]{{\fboxrule=0pt\fboxsep=0pt\colorbox{#1}{#2}}} +\newcommand{\inrgbcolorbox}[2]{{\fboxrule=0pt\fboxsep=0pt\colorbox[rgb]{#1}{#2}}} +\newcommand{\schemeinput}[1]{\incolorbox{LightGray}{\schemeinputbg{#1}}} +\newcommand{\highlighted}[1]{\colorbox{PaleBlue}{\hspace{-0.5ex}\schemeinputbg{#1}\hspace{-0.5ex}}} +\newcommand{\plainlink}[1]{#1} +\newcommand{\techlink}[1]{#1} +\newcommand{\badlink}[1]{#1} +\newcommand{\indexlink}[1]{#1} +\newcommand{\imageleft}[1]{} % drop it +\newcommand{\smaller}[1]{{\footnotesize #1}} + +\newcommand{\titleAndVersion}[2]{\title{#1\\{\normalsize Version #2}}\maketitle} + +\newcommand{\preDoc}{\sloppy} +\newcommand{\postDoc}{} + +% Scribble then generates the following: +% +% \begin{document} +% \preDoc +% \titleAndVersion{...}{...} +% ... document content ... +% \postDoc +% \end{document}