racket / scribble

Other
197 stars 91 forks source link

Support reference to page numbers of an element tag #242

Open chihyang opened 4 years ago

chihyang commented 4 years ago

This is a pull request working in progress.

For docs such as pdf, page number reference is sometimes very useful. To support page reference, a new kind of tag is added to scribble/base. Besides, a new command PageRef is added to scribble.tex. Its argument is a page number. By default, it shows 'page' before the page number. Users can redefine this command to get different outputs.

chihyang commented 4 years ago

@mflatt @samth This is a pull request working in progress. I am not sure if it is suitable for merging into the main scribble repo. So I put it here for discussion.

Support for page number reference in PDF is very useful. Support for page number reference in HTML or other formats seems less meaningful, because most of time there is no fix-sized paper in such documents (maybe this is why pageref is not added to scribble code?). In these formats, maybe it's better to render pageref as a hyperlink with configurable text like "here".

This is also a problem about how to use tags more conveniently: how can I use something like LaTeX \ref in scribble, and make it work in all the supported documents? I read the documents several times, but I didn't find an easy way. Now enconde-tag (in different names) is implemented in different renders, so this seems a little hard. But if there is a way to use the real content of a tag in the document directly, things like pageref can be avoided.

For example, once we can use the "real" content of a tag, I can define the following style:

\newcommand{\PageRef}[1]{page~\pageref{#1}}

then in the style file:

(define PageRef
  (make-style "PageRef" (list (make-tex-addition "pageref.tex"))))

then in the scribble file:

;;; tag here
(elemtag "a-tag")

;;; use the tag somewhere else
(elem #:style PageRef (encode-tag "a-tag"))

Because encode-tag extracts content of a tag, it is also possible to define different styles for different formats.