section links plus scriblib/{autobib,figure}: better match acmart

Add a `link-render-style` syntax property to control the rendering of
section links --- so that HTML output can say "section <number>", and
so that Latex/PDF output can have just the section number hperlinked
(as in acmart).

It seems unfortunate that the link rendering is so hardwired into each
rendering back-end, but maybe this can be made even more configurable
in the future. Meanwhile, Latex macros already provide an additional
layer of rendering control (but not enough, it turns out, to easily
perform the same adjustments as the 'number mode that matches acmart).

For `scriblib/figure` make `figure-ref` and `Figure-ref` similarly
sensitive to the link-rendering style.

For `scriblib/autobib`, change the hyperlinking of references
so that the color can be overridden, and make `scribble/acmart`
override it.
This commit is contained in:
Matthew Flatt 2017-09-30 14:35:11 -05:00
parent 732d631951
commit 7278568040
18 changed files with 400 additions and 155 deletions

View File

@ -613,7 +613,8 @@ Generates a literal hyperlinked URL.}
@defproc[(secref [tag string?] @defproc[(secref [tag string?]
[#:doc module-path (or/c module-path? #f) #f] [#:doc module-path (or/c module-path? #f) #f]
[#:tag-prefixes prefixes (or/c (listof string?) #f) #f] [#:tag-prefixes prefixes (or/c (listof string?) #f) #f]
[#:underline? underline? any/c #t]) [#:underline? underline? any/c #t]
[#:link-render-style ref-style (or/c link-render-style? #f)])
element?]{ element?]{
Inserts a reference to the section tagged @racket[tag]. Inserts a reference to the section tagged @racket[tag].
@ -634,32 +635,35 @@ reach the @racket[tag] section. When @racket[#:doc] is not provided,
the @racket[prefixes] path is relative to any enclosing section (i.e., the @racket[prefixes] path is relative to any enclosing section (i.e.,
the youngest ancestor that produces a match). the youngest ancestor that produces a match).
For HTML output, the generated reference is the hyperlinked title of For the result @racket[link-element], if @racket[ref-style] is not
the elements in the section's title content, except that elements with @racket[#f], then it is attached as a @tech{style property} and
the @racket['aux] @tech{style property} are omitted in the hyperlink affects the rendering of the link. Alternatively, an enclosing
label. If @racket[underline?] is @racket[#f], then the hyperlink is @racket[part] can have a link-render style that adjusts the rendering
rendered in HTML without an underline. style for all links within the @tech{part}. See @racket[link-element]
for more information about the rendering of section references.
For Latex output, the generated reference's format depends on the If @racket[underline?] is @racket[#f], then a @tech{style} is attached
document style. By default, only the section number is shown in the to the result @racket[link-element] so that the hyperlink is rendered
reference, but the @racketmodname[scribble/manual] style shows the in HTML without an underline
title after the section number. Customize the output (see
@secref["config"]) by redefining the @ltx{BookRef}, @|etc|, macros (see
@secref["builtin-latex"]).
In Racket documentation that is rendered to HTML, clicking on a In Racket documentation that is rendered to HTML, clicking on a
section title normally shows the @racket[secref] call that is needed section title normally shows the @racket[secref] call that is needed
to link to the section.} to link to the section.
@history[#:changed "1.25" @elem{Added the @racket[#:link-render-style] argument.}]}
@defproc[(Secref [tag string?] @defproc[(Secref [tag string?]
[#:doc module-path (or/c module-path? #f) #f] [#:doc module-path (or/c module-path? #f) #f]
[#:tag-prefixes prefixes (or/c (listof string?) #f) #f] [#:tag-prefixes prefixes (or/c (listof string?) #f) #f]
[#:underline? underline? any/c #t]) [#:underline? underline? any/c #t]
[#:link-render-style ref-style (or/c link-render-style? #f)])
element?]{ element?]{
Like @racket[secref], but if the rendered form of the reference starts Like @racket[secref], but if the rendered form of the reference starts
with a word (e.g., ``section''), then the word is capitalized.} with a word (e.g., ``section''), then the word is capitalized.
@history[#:changed "1.25" @elem{Added the @racket[#:link-render-style] argument.}]}
@defproc[(seclink [tag string?] @defproc[(seclink [tag string?]

View File

@ -9,6 +9,7 @@
scriblib/render-cond scriblib/render-cond
xml/xexpr xml/xexpr
net/url-structs net/url-structs
scriblib/figure
(only-in scribble/html-render render-mixin))) (only-in scribble/html-render render-mixin)))
@title[#:tag "core"]{Structures And Processing} @title[#:tag "core"]{Structures And Processing}
@ -514,6 +515,11 @@ The recognized @tech{style properties} are as follows:
module path plus a section-tag string, so that the user can module path plus a section-tag string, so that the user can
create a reference to the section.} create a reference to the section.}
@item{@racket[link-render-style] structure --- Determines the default
rendering of links to sections or other destinations within the
section. See also @racket[link-element] and
@racket[current-link-render-style].}
] ]
The @racket[to-collect] field contains @techlink{content} that is The @racket[to-collect] field contains @techlink{content} that is
@ -525,7 +531,8 @@ sub-parts).
The @racket[parts] field contains sub-parts. The @racket[parts] field contains sub-parts.
@history[#:changed "1.25" @elem{Added @racket['no-index] support.}]} @history[#:changed "1.25" @elem{Added @racket['no-index] support.}
#:changed "1.26" @elem{Added @racket[link-render-style] support.}]}
@defstruct[paragraph ([style style?] [content content?])]{ @defstruct[paragraph ([style style?] [content content?])]{
@ -982,18 +989,65 @@ field.}
@defstruct[(link-element element) ([tag tag?])]{ @defstruct[(link-element element) ([tag tag?])]{
Hyperlinks the content to @racket[_tag]. Represents a hyperlink to @racket[_tag].
Normally, the content of the element is rendered as the hyperlink.
When @racket[_tag] is a part tag and the content of the element is When @racket[_tag] is a part tag and the content of the element is
@racket[null], then the hyperlink uses the target part's number and/or @racket[null], however, rendering is treated specially based on the
title as the content. In that case, if the section number is preceded @racket[_mode] value of a @racket[link-render-style] @tech{style
by a word, the word starts in uppercase if the element's style includes a property}:
@racket['uppercase] property.
The following symbol is recognized as a @tech{style property}: @itemlist[
@item{For HTML output, in the @racket['default] mode, the generated
reference is the hyperlinked title of the elements in the
section's title content, except that elements with the
@racket['aux] @tech{style property} are omitted in the
hyperlink label.
In @racket['number] mode, the section title is not shown.
Instead, the word ``section'' is shown followed by a
hyperlinked section number. The word ``section'' starts in
uppercase if the element's style includes a @racket['uppercase]
property.}
@item{For Latex/PDF output, the generated reference's format can
depend on the document style in addition the @racket[_mode].
For the @racket['default] mode and a default document style, a
section number is shown by the word ``section'' followed by the
section number, and the word ``section'' and the section number
are together hyperlinked. The word ``section'' starts in
uppercase if the element's style includes a @racket['uppercase]
property. The @racketmodname[scribble/manual] style uses the
symbol ``§'' in place of the word ``section''.
In @racket['number] mode, rendering is the same, except that
only the number is hyperlinked, not the word ``section'' or
the ``§'' symbol.
A new document style can customize Latex/PDF output (see
@secref["config"]) by redefining the @ltx{SecRefLocal}, @|etc|,
macros (see @secref["builtin-latex"]). The @ltx{SecRef},
@|etc|, variants are used in @racket['number] mode.}
]
If a @racket[link-render-style] @tech{style property} is not attached
to a @racket[link-element] that refers to a part, a
@racket[link-render-style] @tech{style property} that is attached to
an enclosing part is used, since attaching a
@racket[link-render-style] @tech{style property} to a part causes
@racket[current-link-render-style] to be set while rendering the part.
Otherwise, the render-time value of @racket[current-link-render-style]
determine's a @racket[link-element]'s rendering.
The following style properties are recognized in addition to the style
properties for all @racket[element]s:
@itemize[ @itemize[
@item{@racket[link-render-style] structure --- As described above.}
@item{@indexed-racket['indirect-link] --- For HTML output, treats the link as @item{@indexed-racket['indirect-link] --- For HTML output, treats the link as
``external''. When rendering to HTML and the ``external''. When rendering to HTML and the
@method[render-mixin set-external-tag-path] method is called to @method[render-mixin set-external-tag-path] method is called to
@ -1002,7 +1056,9 @@ The following symbol is recognized as a @tech{style property}:
some cases, patched by JavaScript when the documentation is some cases, patched by JavaScript when the documentation is
viewed in a browser).} viewed in a browser).}
]} ]
@history[#:changed "1.26" @elem{Added @racket[link-render-style] support.}]}
@defstruct[(index-element element) ([tag tag?] @defstruct[(index-element element) ([tag tag?]
@ -1139,7 +1195,7 @@ reverse order):
] ]
@history[#:changed "6.4" @elem{Added @racket[(list/c string? string?)] @history[#:changed "1.1" @elem{Added @racket[(list/c string? string?)]
number items for number items for
@tech{numberer}-generated section @tech{numberer}-generated section
numbers.}]} numbers.}]}
@ -1374,7 +1430,7 @@ Return @racket[#t] if @racket[v] is @racket[#f], an exact non-negative
integer, a string, or a list containing two strings. See @racket[collected-info] integer, a string, or a list containing two strings. See @racket[collected-info]
for information on how different representations are used for numbering. for information on how different representations are used for numbering.
@history[#:added "6.4"]} @history[#:added "1.1"]}
@deftogether[( @deftogether[(
@ -1429,7 +1485,38 @@ number for each subsection. If @racket[numberer-step] produces a plain
string for the rendered number, then it is not added as a prefix to string for the rendered number, then it is not added as a prefix to
subsection numbers. See also @racket[collected-info]. subsection numbers. See also @racket[collected-info].
@history[#:added "6.4"]} @history[#:added "1.1"]}
@defstruct[link-render-style ([mode (or/c 'default 'number)])]{
Used as a @tech{style property} for a @racket[part] or a specific
@racket[link-element] to control the way that a hyperlink is rendered
for a part via @racket[secref] or for a figure via @racket[figure-ref]
from @racketmodname[scriblib/figure].
The @racket['default] and @racket['number] modes represent generic
hyperlink-style configurations that could make sense for various kinds
of references. The @racket['number] style is intended to mean that a
specific number is shown for the reference and that only the number is
hyperlinked. The @racket['default] style is more flexible, allowing a
more appropriate choice for the rendering context, such as using the
target section's name for a hyperlink in HTML.
@history[#:added "1.26"]}
@defparam[current-link-render-style style link-render-style?]{
A parameter that determines the default rendering style for a section
link.
When a @racket[part] has a @racket[link-render-style] as one of its
@tech{style properties}, then the @racket[current-link-render-style]
parameter is set during the @tech{resolve pass} and @tech{render pass}
for the @racket[part]'s content.
@history[#:added "1.26"]}
@defstruct[collect-info ([fp any/c] [ht any/c] [ext-ht any/c] @defstruct[collect-info ([fp any/c] [ht any/c] [ext-ht any/c]

View File

@ -58,7 +58,7 @@ includes a citation to section 8 of the Racket reference.
(code:line #:date=? date-compare-expr) (code:line #:date=? date-compare-expr)
(code:line #:cite-author cite-author-id) (code:line #:cite-author cite-author-id)
(code:line #:cite-year cite-year-id)]) (code:line #:cite-year cite-year-id)])
#:contracts ([style-expr (or/c author+date-style number-style)] #:contracts ([style-expr (or/c number-style author+date-style author+date-square-bracket-style)]
[spaces-expr number?] [spaces-expr number?]
[disambiguator-expr (or/c #f (-> exact-nonnegative-integer? element?))] [disambiguator-expr (or/c #f (-> exact-nonnegative-integer? element?))]
[render-date-expr (or/c #f (-> date? element?))] [render-date-expr (or/c #f (-> date? element?))]

View File

@ -85,14 +85,28 @@ The @racket[left] binding is a synonym for @racket[left-figure-style],
provided for backward compatibility.} provided for backward compatibility.}
@defproc[(figure-ref [tag string?] ...+) element?]{ @defproc[(figure-ref [tag string?] ...+
[#:link-render-style link-style (or/c link-render-style? #f)])
element?]{
Generates a reference to one or more figures, using a lowercase word ``figure''.} Generates a reference to one or more figures, using a lowercase word ``figure''.
If @racket[link-style] or @racket[(current-link-render-style)] at the
time of rendering indicates the @racket['number] style mode, then the
word ``figure'' itself is not hyperlinked. Otherwise, the word
@racket[figure] is hyperlinked together with the referenced figure's
number.
@history[#:changed "1.26" @elem{Added the @racket[#:link-render-style] argument.}]}
@defproc[(Figure-ref [tag string?] ...+) element?]{ @defproc[(Figure-ref [tag string?] ...+
[#:link-render-style link-style (or/c link-render-style? #f)])
element?]{
Generates a reference to one or more figures, capitalizing the word ``Figure''.} Like @racket[figure-ref], but capitalizes the word ``Figure''.
@history[#:changed "1.26" @elem{Added the @racket[#:link-render-style] argument.}]}
@defproc[(Figure-target [tag string?] @defproc[(Figure-target [tag string?]

View File

@ -23,4 +23,4 @@
(define pkg-authors '(mflatt eli)) (define pkg-authors '(mflatt eli))
(define version "1.25") (define version "1.26")

View File

@ -23,4 +23,6 @@
% Normally gets re-written by the title macro: % Normally gets re-written by the title macro:
\newcommand{\SSubtitle}[1]{{\bf #1}} \newcommand{\SSubtitle}[1]{{\bf #1}}
% Use ACM color; it would be better to use `citecolor` here somehow,
% but I can't figure out how to do that
\newcommand{\AutobibLink}[1]{\color{ACMPurple}{#1}}

View File

@ -142,8 +142,16 @@
#:replacements (hash "scribble-load-replace.tex" (scribble-file "acmart/acmart-load.tex")))))) #:replacements (hash "scribble-load-replace.tex" (scribble-file "acmart/acmart-load.tex"))))))
(define (add-acmart-styles doc) (define (add-acmart-styles doc)
;; Ensure that "acmart.tex" is used, since "style.tex" (struct-copy part doc
;; re-defines commands. [to-collect
(struct-copy part doc [to-collect ;; Ensure that "acmart.tex" is used, since "style.tex"
(cons invisible-element-to-collect-for-acmart-extras ;; re-defines commands.
(part-to-collect doc))])) (cons invisible-element-to-collect-for-acmart-extras
(part-to-collect doc))]
[style (let ([s (part-style doc)])
(struct-copy style s
[properties
;; Immitate Latex-based links where only the
;; number part is hyperlinked.
(cons (link-render-style 'number)
(style-properties s))]))]))

View File

@ -39,6 +39,7 @@
render-nested-flow render-nested-flow
render-block render-block
render-other render-other
link-render-style-at-element
get-dest-directory get-dest-directory
format-number format-number
number-depth)) number-depth))
@ -748,7 +749,8 @@
(define/public (resolve-part d ri) (define/public (resolve-part d ri)
(parameterize ([current-tag-prefixes (parameterize ([current-tag-prefixes
(extend-prefix d (fresh-tag-resolve-context? d ri))]) (extend-prefix d (fresh-tag-resolve-context? d ri))]
[current-link-render-style (part-render-style d)])
(when (part-title-content d) (when (part-title-content d)
(resolve-content (part-title-content d) d ri)) (resolve-content (part-title-content d) d ri))
(resolve-flow (part-blocks d) d ri) (resolve-flow (part-blocks d) d ri)
@ -822,6 +824,15 @@
[(multiarg-element? i) [(multiarg-element? i)
(resolve-content (multiarg-element-contents i) d ri)])) (resolve-content (multiarg-element-contents i) d ri)]))
(define/public (link-render-style-at-element e)
(link-render-style-mode
(or (let ([s (element-style e)])
(and (style? s)
(for/or ([p (in-list (style-properties s))]
#:when (link-render-style? p))
p)))
(current-link-render-style))))
;; ---------------------------------------- ;; ----------------------------------------
;; render methods ;; render methods
@ -882,9 +893,16 @@
(define/public (render-part d ri) (define/public (render-part d ri)
(parameterize ([current-tag-prefixes (parameterize ([current-tag-prefixes
(extend-prefix d (fresh-tag-render-context? d ri))]) (extend-prefix d (fresh-tag-render-context? d ri))]
[current-link-render-style (part-render-style d)])
(render-part-content d ri))) (render-part-content d ri)))
(define/private (part-render-style d)
(or (for/or ([p (in-list (style-properties (part-style d)))]
#:when (link-render-style? p))
p)
(current-link-render-style)))
(define/public (render-part-content d ri) (define/public (render-part-content d ri)
(list (list
(when (part-title-content d) (when (part-title-content d)

View File

@ -549,45 +549,55 @@
;; ---------------------------------------- ;; ----------------------------------------
(provide/contract (provide
[elemtag (->* ((or/c taglet? generated-tag?)) (contract-out
() [elemtag (->* ((or/c taglet? generated-tag?))
#:rest (listof pre-content?) ()
element?)] #:rest (listof pre-content?)
[elemref (->* ((or/c taglet? generated-tag?)) element?)]
(#:underline? any/c) [elemref (->* ((or/c taglet? generated-tag?))
#:rest (listof pre-content?) (#:underline? any/c)
element?)] #:rest (listof pre-content?)
[secref (->* (string?) element?)]
(#:doc module-path? [secref (->* (string?)
#:tag-prefixes (or/c #f (listof string?))
#:underline? any/c)
element?)]
[Secref (->* (string?)
(#:doc module-path?
#:tag-prefixes (or/c #f (listof string?))
#:underline? any/c)
element?)]
[seclink (->* (string?)
(#:doc module-path? (#:doc module-path?
#:tag-prefixes (or/c #f (listof string?)) #:tag-prefixes (or/c #f (listof string?))
#:underline? any/c #:underline? any/c
#:indirect? any/c) #:link-render-style (or/c #f link-render-style?))
#:rest (listof pre-content?)
element?)] element?)]
[other-doc (->* (module-path?) [Secref (->* (string?)
(#:underline? any/c (#:doc module-path?
#:indirect (or/c #f content?)) #:tag-prefixes (or/c #f (listof string?))
element?)]) #:underline? any/c
#:link-render-style (or/c #f link-render-style?))
element?)]
[seclink (->* (string?)
(#:doc module-path?
#:tag-prefixes (or/c #f (listof string?))
#:underline? any/c
#:indirect? any/c)
#:rest (listof pre-content?)
element?)]
[other-doc (->* (module-path?)
(#:underline? any/c
#:indirect (or/c #f content?))
element?)]))
(define (elemtag t . body) (define (elemtag t . body)
(make-target-element #f (decode-content body) `(elem ,t))) (make-target-element #f (decode-content body) `(elem ,t)))
(define (elemref #:underline? [u? #t] t . body) (define (elemref #:underline? [u? #t] t . body)
(make-link-element (if u? #f "plainlink") (decode-content body) `(elem ,t))) (make-link-element (if u? #f "plainlink") (decode-content body) `(elem ,t)))
(define (secref s #:underline? [u? #t] #:doc [doc #f] #:tag-prefixes [prefix #f]) (define (secref s #:underline? [u? #t] #:doc [doc #f] #:tag-prefixes [prefix #f]
(make-link-element (if u? #f "plainlink") null (make-section-tag s #:doc doc #:tag-prefixes prefix))) #:link-render-style [link-style #f])
(define (Secref s #:underline? [u? #t] #:doc [doc #f] #:tag-prefixes [prefix #f]) (make-link-element (let ([name (if u? #f "plainlink")])
(if link-style
(style name (list link-style))
name))
null
(make-section-tag s #:doc doc #:tag-prefixes prefix)))
(define (Secref s #:underline? [u? #t] #:doc [doc #f] #:tag-prefixes [prefix #f]
#:link-render-style [link-style #f])
(let ([le (secref s #:underline? u? #:doc doc #:tag-prefixes prefix)]) (let ([le (secref s #:underline? u? #:doc doc #:tag-prefixes prefix)])
(make-link-element (make-link-element
(make-style (element-style le) '(uppercase)) (make-style (element-style le) '(uppercase))

View File

@ -162,6 +162,36 @@
;; ---------------------------------------- ;; ----------------------------------------
(define-struct link-render-style (mode)
#:constructor-name link-render-style
#:property
prop:serializable
(make-serialize-info
(lambda (s)
(vector (link-render-style-mode s)))
#'deserialize-link-render-style
#f
(or (current-load-relative-directory) (current-directory))))
(provide deserialize-link-render-style)
(define deserialize-link-render-style
(make-deserialize-info (lambda (s)
(link-render-style s))
(lambda (tag init-val)
(error "cannot allocate link-render-style for cycle"))))
(define current-link-render-style (make-parameter (link-render-style 'default)))
(provide
link-render-style?
link-render-style-mode
(contract-out
[link-render-style ((or/c 'default 'number)
. -> . link-render-style?)]
[current-link-render-style (parameter/c link-render-style?)]))
;; ----------------------------------------
(define-struct numberer (tag step-proc initial-value) (define-struct numberer (tag step-proc initial-value)
#:constructor-name numberer #:constructor-name numberer
#:property #:property

View File

@ -277,7 +277,8 @@
extract-part-style-files extract-part-style-files
extract-version extract-version
extract-authors extract-authors
extract-pretitle) extract-pretitle
link-render-style-at-element)
(inherit-field prefix-file style-file style-extra-files image-preferences) (inherit-field prefix-file style-file style-extra-files image-preferences)
(init-field [alt-paths null] (init-field [alt-paths null]
@ -373,7 +374,7 @@
(collect-put! ci key (collect-put! ci key
(let ([v (vector (or (part-title-content d) '("???")) (let ([v (vector (or (part-title-content d) '("???"))
(add-current-tag-prefix key) (add-current-tag-prefix key)
number ; for consistency with base number
(and (current-output-file) (and (current-output-file)
(path->relative (current-output-file))) (path->relative (current-output-file)))
(current-part-whole-page? d))]) (current-part-whole-page? d))])
@ -407,6 +408,8 @@
(vector-ref dest 3)) (vector-ref dest 3))
(define (dest-title dest) (define (dest-title dest)
(vector-ref dest 0)) (vector-ref dest 0))
(define (dest-number dest)
(vector-ref dest 2))
(define (dest-page? dest) (define (dest-page? dest)
(vector-ref dest 4)) (vector-ref dest 4))
(define (dest-anchor dest) (define (dest-anchor dest)
@ -1341,13 +1344,31 @@
[(and (link-element? e) (not (current-no-links))) [(and (link-element? e) (not (current-no-links)))
(parameterize ([current-no-links #t]) (parameterize ([current-no-links #t])
(define indirect-link? (link-element-indirect? e)) (define indirect-link? (link-element-indirect? e))
(let-values ([(dest ext-id) (let*-values ([(dest ext-id)
(if (and indirect-link? (if (and indirect-link?
external-tag-path) external-tag-path)
(values #f #f) (values #f #f)
(resolve-get/ext-id part ri (link-element-tag e)))]) (resolve-get/ext-id part ri (link-element-tag e)))]
[(number-link?)
(and dest
(not ext-id)
(let ([n (dest-number dest)])
;; If the section number is empty, don't generate an
;; empty link:
(not (or (not n)
(string=? "" (apply string-append (format-number n '("")))))))
(eq? 'number (link-render-style-at-element e))
(empty-content? (element-content e)))])
(if (or indirect-link? dest) (if (or indirect-link? dest)
`((a ([href `(,@(cond
[number-link?
`(,(if (let ([s (element-style e)])
(and (style? s) (memq 'uppercase (style-properties s))))
"Section "
"section "))]
[else '()])
(a ([href
,(cond ,(cond
[(and ext-id external-root-url dest [(and ext-id external-root-url dest
(let* ([ref-path (relative->path (dest-path dest))] (let* ([ref-path (relative->path (dest-path dest))]
@ -1401,7 +1422,10 @@
null)) null))
[data-pltdoc "x"]) [data-pltdoc "x"])
,@(if (empty-content? (element-content e)) ,@(if (empty-content? (element-content e))
(render-content (strip-aux (dest-title dest)) part ri) (cond
[number-link? (format-number (dest-number dest) '(""))]
[else
(render-content (strip-aux (dest-title dest)) part ri)])
(render-content (element-content e) part ri)))) (render-content (element-content e) part ri))))
(begin (begin
(when #f (when #f

View File

@ -82,7 +82,8 @@
extract-version extract-version
extract-date extract-date
extract-authors extract-authors
extract-pretitle-content) extract-pretitle-content
link-render-style-at-element)
(define/public (extract-short-title d) (define/public (extract-short-title d)
(ormap (lambda (v) (ormap (lambda (v)
@ -347,13 +348,15 @@
(format-number number null))] (format-number number null))]
[lbl? (and dest [lbl? (and dest
(not ext?) (not ext?)
(not (show-link-page-numbers)))]) (not (show-link-page-numbers)))]
[link-number? (and lbl?
(eq? 'number (link-render-style-at-element e)))])
(printf "\\~aRef~a~a~a{" (printf "\\~aRef~a~a~a{"
(case (and dest (number-depth number)) (case (and dest (number-depth number))
[(0) "Book"] [(0) "Book"]
[(1) (if (string? (car number)) "Part" "Chap")] [(1) (if (string? (car number)) "Part" "Chap")]
[else "Sec"]) [else "Sec"])
(if lbl? (if (and lbl? (not link-number?))
"Local" "Local"
"") "")
(if (let ([s (element-style e)]) (if (let ([s (element-style e)])
@ -363,9 +366,10 @@
(if (null? formatted-number) (if (null? formatted-number)
"UN" "UN"
"")) ""))
(when lbl? (when (and lbl? (not link-number?))
(printf "t:~a}{" (t-encode (vector-ref dest 1)))) (printf "t:~a}{" (t-encode (vector-ref dest 1))))
(unless (null? formatted-number) (unless (null? formatted-number)
(when link-number? (printf "\\SectionNumberLink{t:~a}{" (t-encode (vector-ref dest 1))))
(render-content (render-content
(if dest (if dest
(if (list? number) (if (list? number)
@ -376,6 +380,7 @@
'("!!!"))) '("!!!")))
(list "???")) (list "???"))
part ri) part ri)
(when link-number? (printf "}"))
(printf "}{")))) (printf "}{"))))
(let* ([es (cond (let* ([es (cond
[(element? e) (element-style e)] [(element? e) (element-style e)]
@ -385,7 +390,8 @@
(style-name es) (style-name es)
es)] es)]
[style (and (style? es) es)] [style (and (style? es) es)]
[hyperref? (and (link-element? e) [hyperref? (and (not part-label?)
(link-element? e)
(not (disable-hyperref)) (not (disable-hyperref))
(let-values ([(dest ext?) (resolve-get/ext? part ri (link-element-tag e))]) (let-values ([(dest ext?) (resolve-get/ext? part ri (link-element-tag e))])
(and dest (not ext?))))] (and dest (not ext?))))]

View File

@ -66,6 +66,8 @@
\newcommand{\SecRefLocalUCUN}[2]{\SecRefLocalUN{#1}{#2}} \newcommand{\SecRefLocalUCUN}[2]{\SecRefLocalUN{#1}{#2}}
\newcommand{\PartRefLocalUCUN}[2]{\PartRefLocalUN{#1}{#2}} \newcommand{\PartRefLocalUCUN}[2]{\PartRefLocalUN{#1}{#2}}
\newcommand{\SectionNumberLink}[2]{\hyperref[#1]{#2}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Fonts % Fonts

View File

@ -70,26 +70,28 @@
(lambda (renderer part ri) (lambda (renderer part ri)
;; (list which key) should be mapped to the bibliography element. ;; (list which key) should be mapped to the bibliography element.
(define s (resolve-get part ri `(,which ,key))) (define s (resolve-get part ri `(,which ,key)))
(make-link-element #f (define content
(list (or s "???") (list (or s "???")
(cond [(not (send style disambiguate-date?)) '()] (cond [(not (send style disambiguate-date?)) '()]
[disambiguation ;; should be a list of bib-entries with same author/date [disambiguation ;; should be a list of bib-entries with same author/date
(define disambiguation* (define disambiguation*
(add-between (for/list ([bib (in-list disambiguation)]) (add-between (for/list ([bib (in-list disambiguation)])
(define key (auto-bib-key bib)) (define key (auto-bib-key bib))
(define maybe-disambiguation (define maybe-disambiguation
(resolve-get part ri `(autobib-disambiguation ,key))) (resolve-get part ri `(autobib-disambiguation ,key)))
(case maybe-disambiguation (case maybe-disambiguation
[(#f) #f] [(#f) #f]
[(unambiguous) #f] [(unambiguous) #f]
[else (make-link-element #f maybe-disambiguation `(autobib ,key))])) [else (make-link-element "AutobibLink" maybe-disambiguation `(autobib ,key))]))
",")) ","))
(cond [(not (car disambiguation*)) '()] ;; the bib was unambiguous (cond [(not (car disambiguation*)) '()] ;; the bib was unambiguous
[else disambiguation*])] [else disambiguation*])]
[else '()]) [else '()])
(if with-specific? (if with-specific?
(auto-bib-specific bib-entry) (auto-bib-specific bib-entry)
"")) "")))
(make-link-element "AutobibLink"
content
`(autobib ,(auto-bib-key bib-entry)))) `(autobib ,(auto-bib-key bib-entry))))
(lambda () "(???)") (lambda () "(???)")
(lambda () "(???)")))) (lambda () "(???)"))))

View File

@ -8,3 +8,5 @@
\newcommand{\Autocolbibentry}[1]{\setlength{\ABcollength}{\linewidth-5ex}\parbox[t]{\ABcollength}{#1\vspace{1.0ex}}} \newcommand{\Autocolbibentry}[1]{\setlength{\ABcollength}{\linewidth-5ex}\parbox[t]{\ABcollength}{#1\vspace{1.0ex}}}
\newcommand{\Autobibref}[1]{#1} \newcommand{\Autobibref}[1]{#1}
\providecommand{\AutobibLink}[1]{#1}

View File

@ -1,6 +1,6 @@
#lang scheme/base #lang scheme/base
(require racket/contract/base
(require scribble/manual scribble/manual
scribble/core scribble/core
scribble/decode scribble/decode
scribble/html-properties scribble/html-properties
@ -12,9 +12,18 @@
figure* figure*
figure** figure**
figure-here figure-here
Figure-target (contract-out
Figure-ref [Figure-target (->* (string?)
figure-ref (#:continue? any/c)
element?)]
[Figure-ref (->* (string?)
(#:link-render-style link-render-style?)
#:rest (listof string?)
element?)]
[figure-ref (->* (string?)
(#:link-render-style link-render-style?)
#:rest (listof string?)
element?)])
left-figure-style left-figure-style
center-figure-style center-figure-style
right-figure-style right-figure-style
@ -132,24 +141,36 @@
#:continue? continue?)) #:continue? continue?))
(define (ref-proc initial) (define (ref-proc initial)
(case-lambda (lambda (tag #:link-render-style [link-style #f]
[(tag) . tags)
(make-element #f (list (counter-ref figures tag (string-append initial "igure"))))] (cond
[(tag1 tag2) [(null? tags)
(make-element #f (list (counter-ref figures tag1 (string-append initial "igures")) (make-element
" and " #f
(counter-ref figures tag2 #f)))] (counter-ref figures tag (string-append initial "igure")
[(tag . tags) #:link-render-style link-style))]
(make-element #f (cons (counter-ref figures tag (string-append initial "igures")) [(null? (cdr tags))
(let loop ([tags tags]) (define tag1 (car tags))
(cond (define tag2 (cadr tags))
[(null? (cdr tags)) (make-element #f (list (counter-ref figures tag1 (string-append initial "igures")
(list ", and " #:link-render-style link-style)
(counter-ref figures (car tags) #f))] " and "
[else (counter-ref figures tag2 #f
(list* ", " #:link-render-style link-style)))]
(counter-ref figures (car tags) #f) [else
(loop (cdr tags)))]))))])) (make-element #f (cons (counter-ref figures tag (string-append initial "igures")
#:link-render-style link-style)
(let loop ([tags tags])
(cond
[(null? (cdr tags))
(list ", and "
(counter-ref figures (car tags) #f
#:link-render-style link-style))]
[else
(list* ", "
(counter-ref figures (car tags) #f
#:link-render-style link-style)
(loop (cdr tags)))]))))])))
(define Figure-ref (ref-proc "F")) (define Figure-ref (ref-proc "F"))
(define figure-ref (ref-proc "f")) (define figure-ref (ref-proc "f"))

View File

@ -15,7 +15,7 @@
\newcommand{\LegendContinued}[1]{\Legend{#1}} \newcommand{\LegendContinued}[1]{\Legend{#1}}
\newcommand{\FigureTarget}[2]{#1} \newcommand{\FigureTarget}[2]{#1}
\newcommand{\FigureRef}[2]{\hyperref[#2]{#1}} \newcommand{\FigureRef}[2]{#1}
\newlength{\FigOrigskip} \newlength{\FigOrigskip}
\FigOrigskip=\parskip \FigOrigskip=\parskip

View File

@ -59,9 +59,13 @@
(if (counter-target-wrap counter) (if (counter-target-wrap counter)
((counter-target-wrap counter) ((counter-target-wrap counter)
c c
;; Don't use this argument:
(format "t:~a" (t-encode (tag->counter-tag counter tag)))) (format "t:~a" (t-encode (tag->counter-tag counter tag))))
c))) c)))
;; The use of this function is a leftover for backward compatibility.
;; Duplicating the linking functionality of `link-element`, etc., is
;; a bad idea.
(define (t-encode s) (define (t-encode s)
(apply (apply
string-append string-append
@ -74,31 +78,42 @@
[else (format "x~x" (char->integer c))])) [else (format "x~x" (char->integer c))]))
(string->list (format "~s" s))))) (string->list (format "~s" s)))))
(define (counter-ref counter tag label) (define (counter-ref counter tag label
(let ([n (make-delayed-element #:link-render-style [link-style #f])
(lambda (renderer part ri) (make-delayed-element
(let ([n (resolve-get part ri (tag->counter-tag counter tag "value"))]) (lambda (renderer part ri)
(if (counter-ref-wrap counter) (let ([n (resolve-get part ri (tag->counter-tag counter tag "value"))])
(let ([id (format "t:~a" (t-encode (list 'counter (list (counter-name counter) tag))))]) (let ([n (if (counter-ref-wrap counter)
((counter-ref-wrap counter) ((counter-ref-wrap counter)
(format "~a" n) (format "~a" n)
id)) ;; Don't use this argument:
(list (format "~a" n))))) (format "t:~a" (t-encode (list 'counter (list (counter-name counter) tag)))))
(lambda () (if label (list (format "~a" n)))]
(list label 'nbsp "N") [link-number-only? (eq? (link-render-style-mode
(list "N"))) (or link-style
(lambda () (if label (current-link-render-style)))
(list label 'nbsp "N") 'number)])
(list "N"))))]) (cond
(make-link-element [(and label link-number-only?)
#f (make-element #f
(if label (list label 'nbsp
(list (make-link-element
label #f
'nbsp (list n)
n) (tag->counter-tag counter tag))))]
n) [else
(tag->counter-tag counter tag)))) (make-link-element
#f
(if label
(list label 'nbsp n)
n)
(tag->counter-tag counter tag))]))))
(lambda () (if label
(list label 'nbsp "N")
(list "N")))
(lambda () (if label
(list label 'nbsp "N")
(list "N")))))
(define (counter-collect-value counter) (define (counter-collect-value counter)
(counter-n counter)) (counter-n counter))