From f96e6f14e0ea1efc5c8e08ba18e27099b302b8b2 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Tue, 1 Mar 2011 14:35:50 -0700 Subject: [PATCH] Scribble: add `#:left?' optional argument to `margin-note' original commit: ec2a9177492705c66d39c2e48d909ba3bd2115b6 --- collects/scribble/base.rkt | 18 ++++++++++-------- collects/scribble/latex-render.rkt | 2 +- collects/scribble/scribble.css | 24 ++++++++++++++++++++++-- collects/scribble/scribble.tex | 6 +++++- collects/scribblings/scribble/base.scrbl | 14 +++++++++++--- 5 files changed, 49 insertions(+), 15 deletions(-) diff --git a/collects/scribble/base.rkt b/collects/scribble/base.rkt index cd9a456a..1925e459 100644 --- a/collects/scribble/base.rkt +++ b/collects/scribble/base.rkt @@ -510,8 +510,8 @@ #:rest (listof pre-content?) element?)] [url (-> string? element?)] - [margin-note (->* () () #:rest (listof pre-flow?) block?)] - [margin-note* (->* () () #:rest (listof pre-content?) element?)] + [margin-note (->* () (#:left? any/c) #:rest (listof pre-flow?) block?)] + [margin-note* (->* () (#:left? any/c) #:rest (listof pre-content?) element?)] [centered (->* () () #:rest (listof pre-flow?) block?)] [verbatim (->* (string?) (#:indent exact-nonnegative-integer?) #:rest (listof string?) block?)]) @@ -534,22 +534,24 @@ (define (url str) (hyperlink str (make-element 'url str))) -(define (margin-note . c) +(define (margin-note #:left? [left? #f] . c) (make-nested-flow - (make-style "refpara" '(command never-indents)) + (make-style (if left? "refparaleft" "refpara") + '(command never-indents)) (list (make-nested-flow - (make-style "refcolumn" null) + (make-style (if left? "refcolumnleft" "refcolumn") + null) (list (make-nested-flow (make-style "refcontent" null) (decode-flow c))))))) -(define (margin-note* . c) +(define (margin-note* #:left? [left? #f] . c) (make-element - (make-style "refelem" null) + (make-style (if left? "refelemleft" "refelem") null) (make-element - (make-style "refcolumn" null) + (make-style (if left? "refcolumnleft" "refcolumn") null) (make-element (make-style "refcontent" null) (decode-content c))))) diff --git a/collects/scribble/latex-render.rkt b/collects/scribble/latex-render.rkt index 81a7cc32..8d18c1cf 100644 --- a/collects/scribble/latex-render.rkt +++ b/collects/scribble/latex-render.rkt @@ -313,7 +313,7 @@ (let ([v (car l)]) (cond [(target-url? v) - (printf "\\href{~a}{" (target-url-addr v)) + (printf "\\href{~a}{" (regexp-replace* #rx"%" (target-url-addr v) "\\\\%")) (loop (cdr l) #t) (printf "}")] [(color-property? v) diff --git a/collects/scribble/scribble.css b/collects/scribble/scribble.css index 8f1e2b4c..1e38f357 100644 --- a/collects/scribble/scribble.css +++ b/collects/scribble/scribble.css @@ -8,7 +8,7 @@ see if any font is set. */ /* Monospace: */ -.maincolumn, .refpara, .tocset, .stt, .hspace { +.maincolumn, .refpara, .refelem, .tocset, .stt, .hspace, .refparaleft, .refelemleft { font-family: monospace; } @@ -161,7 +161,7 @@ table td { margin: 0em -13em 0em 0em; } -.refpara { +.refpara, .refparaleft { top: -1em; } @@ -184,6 +184,26 @@ table td { margin-bottom: 0; } +.refparaleft { + position: relative; + float: left; + right: 2em; + height: 0em; + width: 13em; + margin: 0em 0em 0em -13em; +} + +.refcolumnleft, .refelemleft { + background-color: #F5F5DC; + display: block; + position: relative; + width: 13em; + font-size: 85%; + border: 0.5em solid #F5F5DC; + margin: 0 0 0 0; +} + + /* ---------------------------------------- */ /* Table of contents, inline */ diff --git a/collects/scribble/scribble.tex b/collects/scribble/scribble.tex index 4734c70d..cbfbddb6 100644 --- a/collects/scribble/scribble.tex +++ b/collects/scribble/scribble.tex @@ -104,11 +104,15 @@ % The \refpara command corresponds to `margin-note'. The % refcolumn and refcontent environments also wrap the note, % because they simplify the CSS side. -\newcommand{\refpara}[1]{\marginpar{\raggedright \footnotesize #1}} +\newcommand{\refpara}[1]{\normalmarginpar\marginpar{\raggedright \footnotesize #1}} \newcommand{\refelem}[1]{\refpara{#1}} \newenvironment{refcolumn}{}{} \newenvironment{refcontent}{}{} +\newcommand{\refparaleft}[1]{\reversemarginpar\marginpar{\raggedright \footnotesize #1}} +\newcommand{\refelemleft}[1]{\refparaleft{#1}} +\newenvironment{refcolumnleft}{\begin{refcolumn}}{\end{refcolumn}} + % Macros used by `title' and `author': \newcommand{\titleAndVersionAndAuthors}[3]{\title{#1\\{\normalsize Version #2}}\author{#3}\maketitle} \newcommand{\titleAndVersionAndEmptyAuthors}[3]{\title{#1\\{\normalsize Version #2}}#3\maketitle} diff --git a/collects/scribblings/scribble/base.scrbl b/collects/scribblings/scribble/base.scrbl index 3c7c2186..41ad4c03 100644 --- a/collects/scribblings/scribble/base.scrbl +++ b/collects/scribblings/scribble/base.scrbl @@ -168,13 +168,21 @@ address-harvesting robots.} Produces a @tech{nested flow} whose content is centered.} -@defproc[(margin-note [pre-flow pre-flow?] ...) block?]{ +@defproc[(margin-note [pre-flow pre-flow?] ... + [#:left? left? any/c #f]) + block?]{ Produces a @tech{nested flow} that is typeset in the margin, instead -of inlined.} +of inlined. + +If @racket[left?] is true, then the note is shown on the opposite as +it would normally be shown (which is the left-hand side for HTML +output). Beware of colliding with output for a table of contents.} -@defproc[(margin-note* [pre-content pre-content?] ...) element?]{ +@defproc[(margin-note* [pre-content pre-content?] ... + [#:left? left? any/c #f]) + element?]{ Produces an @racket[element] that is typeset in the margin, instead of inlined. Unlike @racket[margin-note], @racket[margin-note*] can be