154030e36a441fdc4acde642d6062d6b67d778f7
[platform/upstream/groff.git] / contrib / pdfmark / pdfmark.ms
1 .\" vim: ft=groff          -*- nroff -*-
2 .ig
3 pdfmark.ms
4
5 File position: <groff-source>/contrib/pdfmark/pdfmark.ms
6
7 This file is part of groff, the GNU roff type-setting system.
8
9 Copyright (C) 2004-2014  Free Software Foundation, Inc.
10 written by Keith Marshall <keith.d.marshall@ntlworld.com>
11
12 Permission is granted to copy, distribute and/or modify this document
13 under the terms of the GNU Free Documentation License, Version 1.3 or
14 any later version published by the Free Software Foundation; with no
15 Front-Cover Texts, no Back-Cover Texts, and the following Invariant
16 Sections:--
17
18     a)  This "Legal Matters" section, extending from the start of
19         the document, to the end of the enclosing ".ig" section.
20
21     b)  The two lines below starting with `.AU' and `.AI'.
22
23 A copy of the Free Documentation License is included as a file called
24 FDL in the main directory of the groff source package.
25 ..
26 .
27 .CS
28 Portable Document Format
29 Publishing with GNU Troff
30 .AU Keith Marshall
31 .AI <keith.d.marshall@ntlworld.com>
32 .CE
33 .\"
34 .\" Specify the Internet address for the groff web site.
35 .\" Currently, there are two available addresses; a copy is maintained at ...
36 .\"
37 .ds GROFF-WEBSITE http://www.gnu.org/software/groff
38 .\"
39 .\" ... but the official home site is at ...
40 .\"
41 .ds GROFF-WEBSITE http://groff.ffii.org
42 .\"
43 .\" Set the PDF default document view attribute, to ensure that the document
44 .\" outline is visible, each time the document is opened in Acrobat Reader.
45 .\"
46 .pdfview /PageMode /UseOutlines
47 .\"
48 .\" Initialise the outline view to show only three heading levels,
49 .\" with additional subordinate level headings folded.
50 .\"
51 .nr PDFOUTLINE.FOLDLEVEL 3
52 .\"
53 .\" Add document identification meta-data
54 .\"
55 .pdfinfo /Title     Portable Document Format Publishing with GNU Troff
56 .pdfinfo /Author    Keith Marshall
57 .pdfinfo /Subject   Tips and Techniques for Exploiting PDF Features with GNU Troff
58 .pdfinfo /Keywords  groff troff PDF pdfmark
59 .\"
60 .\" Set the default cross reference format to indicate section numbers,
61 .\" rather than page numbers, when we insert a reference pointer.
62 .\"
63 .ds PDFHREF.INFO section \\*[SN-NO-DOT] \\$*
64 .\"
65 .\" Define a macro, to print reference links WITHOUT the usual "see" prefix.
66 .\"
67 .de XR-NO-PREFIX
68 .rn PDFHREF.PREFIX xx
69 .ds PDFHREF.PREFIX
70 .XR \\$@
71 .rn xx PDFHREF.PREFIX
72 ..
73 .\"
74 .\" Define a string,
75 .\" to insert a Registered Trade Mark symbol as a superscript.
76 .\"
77 .ds rg \*{\(rg\*}
78 .\"
79 .\" Establish the page layout.
80 .\"
81 .nr PO  2.5c
82 .nr LL 17.0c
83 .nr LT 17.0c
84 .nr HY  0
85 .nr FF  3
86 .nr DI  5n
87 .\"
88 .\" Generate headers in larger point sizes, for NH levels < 4,
89 .\" with point size increasing by 1.5p, for each lesser NH level.
90 .\"
91 .nr GROWPS 4
92 .nr PSINCR 1.5p
93 .\"
94 .de EM
95 .\".I "\s'+0.3'\\$1\s0" "\\$2" "\\$3"
96 .I \\$@
97 ..
98 .de CWB
99 \\$5\fC\\$3\fP\f(CB\\$1\fP\fC\\$2\fP\\$4
100 ..
101 .de CWI
102 \\$5\fC\\$3\fP\f(CI\\$1\fP\fC\\$2\fP\\$4
103 ..
104 .de CWBI
105 \\$5\fC\\$3\fP\f[CBI]\\$1\fP\fC\\$2\fP\\$4
106 ..
107 .ds = \f(CB\\$1\f(CR\\$4\f[CBI]\\$2\f(CR\\$3
108 .\"
109 .NH 1
110 .\" When we use numbered section headings, we might like to automatically
111 .\" insert a table of contents entry, using the text of the heading itself.
112 .\" The "ms" macros don't provide any standard mechanism for doing this,
113 .\" but "spdf.tmac" adds the "XN" macro, which will do it for us.
114 .\"
115 .\" Here's a simple example of how we might use it.  In this case, the word
116 .\" "Introduction" will appear both in the body of the document, as the text
117 .\" of the heading, and it will be added to the table of contents, which is
118 .\" subsequently "printed" using the "TC" macro; in both locations, it will
119 .\" be prefixed by the section number.
120 .\"
121 .\" As an additional side effect, any use of "XN" will cause the table of
122 .\" contents entry to be automatically reproduced, with the exception of its
123 .\" page number reference, as a PDF document outline entry.  Thus, the use
124 .\" of "XN" to specify numbered section headings results in the automatic
125 .\" creation of a numbered PDF document outline.  This automatic creation
126 .\" of the outline is completely transparent, and will occur regardless
127 .\" of whether the "TC" macro is subsequently invoked, or not.
128 .\"
129 .XN Introduction
130 .\"
131 .\" If using an old s.tmac, without the SN-NO-DOT extension,
132 .\" make sure we get SOMETHING in section number references.
133 .\"
134 .if !dSN-NO-DOT .als SN-NO-DOT SN
135 .LP
136 It might appear that it is a fairly simple matter to
137 produce documents in Adobe\*(rg\~\(lqPortable\~Document\~Format\(rq,
138 commonly known as PDF, using
139 .CW groff ) GNU\~Troff\~(
140 as the document formatter.
141 Indeed,
142 .CW groff 's
143 default output format is the native Adobe\*(rg\~PostScript\*(rg format,
144 which PDF producers such as Adobe\*(rg Acrobat\*(rg Distiller\*(rg,
145 or GhostScript, expect as their input format.
146 Thus, the PDF production process would seem to entail simply
147 formatting the document source with
148 .CW groff ,
149 to produce a PostScript\*(rg version of the document,
150 which can subsequently be processed by Acrobat\*(rg Distiller\*(rg
151 or GhostScript, to generate the final PDF document.
152 .LP
153 For many PDF production requirements,
154 the production cycle described above may be sufficient.
155 However, this is a limited PDF production method,
156 in which the resultant PDF document represents no more than
157 an on screen image of the printed form of the document, if
158 .CW groff 's
159 PostScript\*(rg output were printed directly.
160 .LP
161 The Portable Document Format provides a number of features,
162 which significantly enhance the experience of reading a document on screen,
163 but which are of little or no value to a document which is merely printed.
164 It
165 .EM is
166 possible to exploit these PDF features, which are described in the Adobe\*(rg
167 .\"
168 .de pdfmark-manual
169 .\" This is an example of a resource reference specified by URI ...
170 .\" We may need to refer often to the Adobe pdfmark Reference Manual,
171 .\" so we create the internet link definition using a macro, to make
172 .\" it reusable.
173 .\"
174 .\" Note also, that we protect the description of the reference by
175 .\" preceding it with "--", to avoid "invalid character in name" type
176 .\" error messages from groff (caused by the use of "\~").
177 .\"
178 .pdfhref W -D http://partners.adobe.com/public/developer/en/acrobat/sdk/pdf/pdf_creation_apis_and_specs/pdfmarkReference.pdf \
179     -P \(lq -A \(rq\\$1 -- pdfmark\~Reference\~Manual
180 ..
181 .pdfmark-manual ,
182 with some refinement of the simple PDF production method, provided
183 appropriate \(lqfeature implementing\(rq instructions can be embedded into
184 .CW groff 's
185 PostScript\*(rg rendering of the document.
186 This, of course, implies that the original document source, which
187 .CW groff
188 will process to generate the PostScript\*(rg description of the document,
189 must include appropriate markup to exploit the desired PDF features.
190 It is this preparation of the
191 .CW groff
192 document source to exploit a number of these features,
193 which provides the principal focus of this document.
194 .LP
195 The markup techniques to be described have been utilised in the production of
196 the PDF version of this document itself.
197 This has been formatted using
198 .CW groff 's
199 .CW ms
200 macro package;
201 thus, usage examples may be found in the document source file,
202 .CW \n(.F ,
203 to which comments have been added,
204 to help identify appropriate markup examples for implementing PDF features,
205 such as:\(en
206 .QS
207 .IP \(bu
208 Selecting a default document view, which defines how the document will appear
209 when opened in the reader application; for example, when this document is
210 opened in Acrobat\*(rg\~Reader, it should display the top of the cover sheet,
211 in the document view pane, while a document outline should appear to the left,
212 in the \(lqBookmarks\(rq pane.
213 .IP \(bu
214 Adding document identification \(lqmeta\(hydata\(rq,
215 which can be accessed, in Acrobat\*(rg\~Reader,
216 by inspecting the \(lqFile\^/\^Document\~Properties\^/\^Summary\(rq.
217 .IP \(bu
218 Creating a document outline, which will be displayed in the \(lqBookmarks\(rq
219 pane of Acrobat\*(rg\~Reader, such that readers may quickly navigate to any
220 section of the document, simply by clicking on the associated heading
221 in the outline view.
222 .IP \(bu
223 Embedding active links in the body of the document, such that readers may
224 quickly navigate to related material at another location within the same
225 document, or in another PDF document, or even to a related Internet resource,
226 specified by its URI.
227 .IP \(bu
228 Adding annotations, in the form of \(lqsticky notes\(rq, at strategic
229 points within the PDF document.
230 .QE
231 .LP
232 All of the techniques described have been tested on
233 .EM both
234 GNU/Linux, and on Microsoft\*(rg Windows\(tm2000 operating platforms, using
235 .CW groff
236 .CW 1.19.1 ,\c
237 .pdfhref L -D footnote1 -- \**
238 .FS
239 .pdfhref M footnote1
240 Later versions should, and some earlier versions may, be equally suitable.
241 See
242 .pdfhref W \*[GROFF-WEBSITE]
243 for information and availability of the latest version.
244 .FE
245 in association with
246 .CW AFPL
247 .CW GhostScript
248 .CW 8.14 .\c
249 .pdfhref L -D footnote2 -- \**
250 .FS
251 .pdfhref M footnote2
252 Again, other versions may be suitable.
253 See
254 .pdfhref W http://ghostscript.com
255 for information and availability.
256 .FE
257 Other tools employed, which should be readily available on
258 .EM any
259 .SM
260 UNIX\(tm
261 .LG
262 or GNU/Linux system, are
263 .CW sed ,
264 .CW awk
265 and
266 .CW make ,
267 together with an appropriate text editor, for creating and marking up the
268 .CW groff
269 input files.
270 These additional utilities are not provided, as standard,
271 on the Microsoft\*(rg Windows\(tm platform,
272 but several third party implementations are available.
273 Some worth considering include the MKS\*(rg\~Toolkit,\**
274 .FS
275 A commercial offering; see
276 .pdfhref W http://mkssoftware.com/products/tk/default.asp
277 for information.
278 .FE
279 Cygwin,\**
280 .FS
281 A
282 .EM free
283 but comprehensive
284 .SM
285 POSIX
286 .LG
287 emulation environment and
288 .SM
289 UNIX\(tm
290 .LG
291 toolkit for 32\(hybit Microsoft\*(rg Windows\(tm platforms; see
292 .pdfhref W http://cygwin.com
293 for information and download.
294 .FE
295 or MSYS.\**
296 .FS
297 Another free, but minimal suite of common
298 .SM
299 UNIX\(tm
300 .LG
301 tools for 32\(hybit Microsoft\*(rg Windows\(tm, available for download from
302 .pdfhref W -A ; http://www.mingw.org
303 it
304 .EM does 
305 include those tools listed above,
306 and is the package which was actually used when performing the Windows\(tm2000
307 platform tests referred to in the text.
308 .FE
309 This list is by no means exhaustive, and should in no way be construed as an
310 endorsement of any of these packages, nor to imply that other similar packages,
311 which may be available, are in any way inferior to them.
312 .bp
313 .NH 1
314 .\" We may wish a section heading to represent a named destination,
315 .\" so that we can create a linked reference to it, from some other 
316 .\" part of the PDF document, (or even from another PDF document).
317 .\"
318 .\" Here we use the "-N" option of the "XN" macro, to create a named
319 .\" PDF link destination, at the location of the heading.  Notice that
320 .\" we also use the "--" marker to separate the heading text from the
321 .\" preceding option specification; it is not strictly necessary in
322 .\" this case, but it does help to set off the heading text from the
323 .\" option specification.
324 .\"
325 .XN -N pdf-features -- Exploiting PDF Document Features
326 .LP
327 To establish a consistent framework for adding PDF features, a
328 .CW groff
329 macro package, named
330 .CW pdfmark.tmac ,
331 has been provided.
332 Thus, to incorporate PDF features in a document,
333 the appropriate macro calls, as described below, may be placed in the
334 .CW groff
335 document source, which should then be processed with a
336 .CW groff
337 command of the form
338 .QP
339 .fam C
340 groff -Tps [-m
341 .I name "] -m"
342 .B pdfmark
343 .I options \& [-
344 .I "file ..." \& "...] "
345 .LP
346 (Or use the PDF post-processor to avoid using ghostscript,
347 .CW -Tpdf\c
348 ).
349 .LP
350 It may be noted that the
351 .CW pdfmark
352 macros have no dependencies on, and no known conflicts with,
353 any other
354 .CW groff
355 macro package;  thus, users are free to use any other macro package,
356 of their choice, to format their documents, while also using the
357 .CW pdfmark
358 macros to add PDF features.
359 .NH 2
360 .XN -N pdfmark-operator -- The \F[C]pdfmark\F[] Operator
361 .LP
362 All PDF features are implemented by embedding instances of the
363 .B \F[C]pdfmark\F[]
364 operator, as described in the Adobe\*(rg
365 .pdfmark-manual ,
366 into
367 .CW groff 's
368 PostScript\*(rg output stream.
369 To facilitate the use of this operator, the
370 .CW pdfmark
371 macro package defines the primitive
372 .CW pdfmark
373 macro; it simply emits its argument list,
374 as arguments to a
375 .CW pdfmark
376 operator, in the PostScript\*(rg output stream.
377 .LP
378 .pdfhref M -N pdfmark-example
379 To illustrate the use of the
380 .CW pdfmark
381 macro, the following is a much simplified example of how a bookmark
382 may be added to a PDF document outline
383 .QP
384 .CW ".pdfmark \e"
385 .RS 4
386 .nf
387 .fam C
388 /Count 2 \e
389 /Title (An Example of a Bookmark with Two Children) \e
390 /View  [/FitH \en[PDFPAGE.Y]] \e
391 /OUT
392 .RE
393 .LP
394 In general, users should rarely need to use the
395 .CW pdfmark
396 macro directly.
397 In particular, the above example is too simple for general use; it
398 .EM will
399 create a bookmark, but it does
400 .EM not
401 address the issues of setting the proper value for the
402 .CW /Count
403 key, nor of computing the
404 .CW PDFPAGE.Y
405 value used in the
406 .CW /View
407 key. The
408 .CW pdfmark
409 macro package includes a more robust mechanism for creating bookmarks,
410 .\"
411 .\" Here is an example of how a local reference may be planted,
412 .\" using the automatic formatting feature of the "pdfhref" macro.
413 .\"
414 .\" This is a forward reference to the named destination "add-outline",
415 .\" which is defined below, using the "XN" wrapper macro, from the
416 .\" "spdf.tmac" macro package.  The automatically formatted reference
417 .\" will be enclosed in parentheses, as specified by the use of
418 .\" "-P" and "-A" options.
419 .\"
420 .pdfhref L -P ( -A ), -D add-outline
421 .\"
422 which addresses these issues automatically.
423 Nevertheless, the
424 .CW pdfmark
425 macro may be useful to users wishing to implement more advanced PDF features,
426 than those currently supported directly by the
427 .CW pdfmark
428 macro package.
429 .NH 2
430 .XN -N docview -- Selecting an Initial Document View
431 .LP
432 By default,
433 when a PDF document is opened,
434 the first page will be displayed,
435 at the default magnification set for the reader,
436 and outline and thumbnail views will be hidden.
437 When using a PDF reader,
438 such as Acrobat\*(rg\~Reader,
439 which supports the
440 .CW /DOCVIEW
441 class of the
442 .CW pdfmark
443 operator,
444 these default initial view settings may be overridden,
445 using the
446 .CW pdfview
447 macro.
448 For example
449 .QP
450 .CW ".pdfview /PageMode /UseOutlines"
451 .LP
452 will cause Acrobat\*(rg\~Reader to open the document outline view,
453 to the left of the normal page view,
454 while
455 .QP
456 .CW ".pdfview /PageMode /UseThumbs"
457 .LP
458 will open the thumbnail view instead.
459 .LP
460 Note that the two
461 .CW /PageMode
462 examples, above, are mutually exclusive \(em it is not possible to have
463 .EM both
464 outline and thumbnail views open simultaneously.
465 However, it
466 .EM is
467 permitted to add
468 .CW /Page
469 and
470 .CW /View
471 keys, to force the document to open at a page other than the first,
472 or to change the magnification at which the document is initially displayed;
473 see the
474 .pdfmark-manual
475 for more information.
476 .LP
477 It should be noted that the view controlling meta\(hydata, defined by the
478 .CW pdfview
479 macro, is not written immediately to the PostScript\*(rg output stream,
480 but is stored in an internal meta\(hydata \(lqcache\(rq,
481 (simply implemented as a
482 .CW groff
483 diversion).
484 This \(lqcached\(lq meta\(hydata must be written out later, by invoking the
485 .CW pdfsync
486 macro,
487 .\"
488 .\" Here is another example of how we may introduce a forward reference.
489 .\" This time we are using the shorter notation afforded by the "XR" macro
490 .\" provided by "spdf.tmac"; this example is equivalent to the native
491 .\" "pdfmark.tmac" form
492 .\"     .pdfhref L -D pdfsync -P ( -A ).
493 .\"
494 .XR pdfsync ). (
495 .\"
496 .NH 2
497 .XN -N docinfo -- Adding Document Identification Meta-Data
498 .LP
499 In addition to the
500 .CW /DOCVIEW
501 class of meta\(hydata described above,
502 .XR docview ), (
503 we may also wish to include document identification meta\(hydata,
504 which belongs to the PDF
505 .CW /DOCINFO
506 class.
507 .LP
508 To do this, we use the
509 .CW pdfinfo
510 macro.
511 As an example of how it is used,
512 the identification meta\(hydata attached to this document
513 was specified using a macro sequence similar to:\(en
514 .DS I
515 .CW
516 \&.pdfinfo /Title     PDF Document Publishing with GNU Troff
517 \&.pdfinfo /Author    Keith Marshall
518 \&.pdfinfo /Subject   How to Exploit PDF Features with GNU Troff
519 \&.pdfinfo /Keywords  groff troff PDF pdfmark
520 .DE
521 Notice that the
522 .CW pdfinfo
523 macro is repeated, once for each
524 .CW /DOCINFO
525 record to be placed in the document.
526 In each case, the first argument is the name of the applicable
527 .CW /DOCINFO
528 key, which
529 .EM must
530 be named with an initial solidus character;
531 all additional arguments are collected together,
532 to define the value to be associated with the specified key.
533 .LP
534 As is the case with the
535 .CW pdfview
536 macro,
537 .XR docview ), (
538 the
539 .CW /DOCINFO
540 records specified with the
541 .CW pdfinfo
542 macro are not immediately written to the PostScript\*(rg output stream;
543 they are stored in the same meta\(hydata cache as
544 .CW /DOCVIEW
545 specifications, until this cache is explicitly flushed,
546 by invoking the
547 .CW pdfsync
548 macro,
549 .XR pdfsync ). (
550 .NH 2
551 .XN -N add-outline -- Creating a Document Outline
552 .LP
553 A PDF document outline comprises a table of references,
554 to \(lqbookmarked\(rq locations within the document.
555 When the document is viewed in an \(lqoutline\~aware\(rq PDF document reader,
556 such as Adobe\*(rg Acrobat\*(rg Reader,
557 this table of \(lqbookmarks\(rq may be displayed in a document outline pane,
558 or \(lqBookmarks\(rq pane, to the left of the main document view.
559 Individual references in the outline view may then be selected,
560 by clicking with the mouse,
561 to jump directly to the associated marked location in the document view.
562 .LP
563 The document outline may be considered as a collection of \(lqhypertext\(rq
564 references to \(lqbookmarked\(rq locations within the document.
565 The
566 .CW pdfmark
567 macro package provides a single generalised macro,
568 .CW pdfhref ,
569 for creating and linking to \(lqhypertext\(rq reference marks.
570 This macro will be described more comprehensively in a later section,
571 .XR pdfhref ); (
572 the description here is restricted to its use for defining document outline entries.
573 .NH 3
574 .XN -N basic-outline -- A Basic Document Outline
575 .LP
576 In its most basic form, the document outline comprises a structured list of headings,
577 each associated with a marked location, or \(lqbookmark\(rq, in the document text,
578 and a specification for how that marked location should be displayed,
579 when this bookmark is selected.
580 .LP
581 To create a PDF bookmark, the
582 .CW pdfhref
583 macro is used,
584 at the point in the document where the bookmark is to be placed,
585 in the form
586 .QP
587 .fam C
588 .B ".pdfhref O"
589 .I level > <
590 .I "descriptive text ..."
591 .LP
592 in which the reference class
593 .CWB O \& \& \(rq \(lq
594 stipulates that this is an outline reference.
595 .LP
596 Alternatively, for those users who may prefer to think of a document outline
597 simply as a collection of bookmarks, the
598 .CW pdfbookmark
599 macro is also provided \(em indeed,
600 .CW pdfhref
601 invokes it, when processing the
602 .CWB O \& \& \(rq \(lq
603 reference class operator.
604 It may be invoked directly, in the form
605 .QP
606 .fam C
607 .B .pdfbookmark
608 .I level > <
609 .I "descriptive text ..."
610 .LP
611 Irrespective of which of the above macro forms is employed, the
612 .CWI level > <
613 argument is required.
614 It is a numeric argument, defining the nesting level of the \(lqbookmark\(rq
615 in the outline hierarchy, with one being the topmost level.
616 Its function may be considered analagous to the
617 .EM "heading level"
618 of the document's section headings,
619 for example, as specified with the
620 .CW NH
621 macro, if using the
622 .CW ms
623 macros to format the document.
624 .LP
625 All further arguments, following the
626 .CWI level > <
627 argument, are collected together, to specify the heading text which will appear
628 in the document's outline view.
629 Thus, the outline entry for this section of this document,
630 which has a level three heading,
631 might be specified as
632 .QP
633 .CW
634 \&.pdfhref O 3 \*(SN A Basic Document Outline
635 .LP
636 or, in the alternative form using the
637 .CW pdfbookmark
638 macro, as
639 .QP
640 .CW
641 \&.pdfbookmark 3 \*(SN A Basic Document Outline
642 .NH 3
643 .XN Hierarchical Structure in a Document Outline
644 .LP
645 When a document outline is created, using the
646 .CW pdfhref
647 macro as described in
648 .\"
649 .\" Here is an example of how we can temporarily modify the format of
650 .\" a reference link, in this case to indicate only the section number
651 .\" of the link target, in the form "section #", (or, if we define
652 .\" "SECREF.BEGIN" before the call, its content followed by the
653 .\" section number).
654 .\"
655 .\" We first define a macro, which will get the reference data from
656 .\" pdfhref, as arguments, and will return the formatted output, as we
657 .\" require it, the string "PDFHREF.TEXT".
658 .\"
659 .de SECREF
660 .while \\n(.$ \{\
661 .   ie '\\$1'section' \{\
662 .      if !dSECREF.BEGIN .ds SECREF.BEGIN \\$1
663 .      ds PDFHREF.TEXT \\*[SECREF.BEGIN]\~\\$2
664 .      rm SECREF.BEGIN
665 .      shift \\n(.$
666 .      \}
667 .   el .shift
668 .   \}
669 ..
670 .\" We now tell "pdfhref" to use our formatting macro, in place of
671 .\" its builtin default formatter, before we specify the reference.
672 .\"
673 .pdfhref F SECREF
674 .pdfhref L -A , -D basic-outline
675 .\"
676 .\" At this point, we would normally revert the "pdfhref" formatter
677 .\" to use its default, built in macro.  However, in this particular
678 .\" case, we want to use our custom format one more time, before we
679 .\" revert it, so we will omit the reversion step this time.
680 .\"
681 and any entry is added at a nesting level greater than one,
682 then a hierarchical structure is automatically defined for the outline.
683 However, as was noted in the simplified
684 .pdfhref L -D pdfmark-example -- example
685 in
686 .pdfhref L -A , -D pdfmark-operator
687 .\"
688 .\" And now, we revert to default "pdfhref" formatting behaviour,
689 .\" by completing the call we delayed above.
690 .\"
691 .pdfhref F
692 .\"
693 the data required by the
694 .CW pdfmark
695 operator to create the outline entry may not be fully defined,
696 when the outline reference is defined in the
697 .CW groff
698 document source.
699 Specifically, when the outline entry is created, its
700 .CW /Count
701 key must be assigned a value equal to the number of its subordinate entries,
702 at the next inner level of the outline hierarchy;
703 typically however,
704 these subordinate entries will be defined
705 .EM later
706 in the document source, and the appropriate
707 .CW /Count
708 value will be unknown, when defining the parent entry.
709 .LP
710 To resolve this paradox, the
711 .CW pdfhref
712 macro creates the outline entry in two distinct phases \(em
713 a destination marker is placed in the PostScript\*(rg output stream immediately,
714 when the outline reference is defined,
715 but the actual outline entry is stored in an internal \(lqoutline cache\(rq,
716 until its subordinate hierarchy has been fully defined;
717 it can then be inserted in the output stream, with its
718 .CW /Count
719 value correctly assigned.
720 Effectively, to ensure integrity of the document outline structure,
721 this means that each top level outline entry, and
722 .EM all
723 of its subordinates, are retained in the cache, until the
724 .EM next
725 top level entry is defined.
726 .LP
727 One potential problem, which arises from the use of the \(lqoutline cache\(rq,
728 is that, at the end of any document formatting run, the last top level outline entry,
729 and any subordinates defined after it, will remain in the cache, and will 
730 .EM not
731 be automatically written to the output stream.
732 To avoid this problem, the user should follow the guidelines given in
733 .\"
734 .\" Here is a more conventional example of how to temporarily change
735 .\" to the format used to display reference links.  We will again use
736 .\" the "SECREF" format, which we defined above, but on this occasion
737 .\" we will immediately revert to the default format, after the link
738 .\" has been placed.
739 .\"
740 .pdfhref F SECREF
741 .pdfhref L -D pdfsync -A ,
742 .pdfhref F
743 .\"
744 to synchronise the output state with the cache state,
745 .XR pdfsync ), (
746 at the end of the
747 .CW groff
748 formatting run.
749 .NH 3
750 .XN -N outline-view -- Associating a Document View with an Outline Reference
751 .LP
752 Each \(lqbookmark\(rq entry, in a PDF document outline,
753 is associated with a specific document view.
754 When the reader selects any outline entry,
755 the document view changes to display the document context
756 associated with that entry.
757 .LP
758 The document view specification,
759 to be associated with any document outline entry,
760 is established at the time when the outline entry is created.
761 However, rather than requiring that each individual use of the
762 .CW pdhref
763 macro, to create an outline entry,
764 should include its own view specification,
765 the actual specification assigned to each entry is derived from
766 a generalised specification defined in the string
767 .CW PDFBOOKMARK.VIEW ,
768 together with the setting of the numeric register
769 .CW PDFHREF.VIEW.LEADING ,
770 which determine the effective view specification as follows:\(en
771 .QS
772 .IP \*[= PDFBOOKMARK.VIEW]
773 Establishes the magnification at which the document will be viewed,
774 at the location of the \(lqbookmark\(rq; by default, it is defined by
775 .RS
776 .QP
777 .CW ".ds PDFBOOKMARK.VIEW /FitH \e\en[PDFPAGE.Y] u"
778 .RE
779 .IP
780 which displays the associated document view,
781 with the \(lqbookmark\(rq location positioned at the top of the display window,
782 and with the magnification set to fit the page width to the width of the window.
783 .IP \*[= PDFHREF.VIEW.LEADING]
784 Specifies additional spacing,
785 to be placed between the top of the display window
786 and the actual location of the \(lqbookmark\(rq on the displayed page view.
787 By default, it is set as
788 .RS
789 .QP
790 .CW ".nr PDFHREF.VIEW.LEADING 5.0p"
791 .RE
792 .IP
793 Note that
794 .CW PDFHREF.VIEW.LEADING
795 does not represent true \(lqleading\(rq, in the typographical sense,
796 since any preceding text, set in the specified display space,
797 will be visible at the top of the document viewing window,
798 when the reference is selected.
799 .IP
800 Also note that the specification of
801 .CW PDFHREF.VIEW.LEADING
802 is shared by
803 .EM all
804 reference views defined by the
805 .CW pdfhref
806 macro; whereas
807 .CW PDFBOOKMARK.VIEW
808 is applied exclusively to outline references,
809 there is no independent
810 .CW PDFBOOKMARK.VIEW.LEADING
811 specification.
812 .QE
813 .LP
814 If desired, the view specification may be changed, by redefining the string
815 .CW PDFBOOKMARK.VIEW ,
816 and possibly also the numeric register
817 .CW PDFHREF.VIEW.LEADING .
818 Any alternative definition for
819 .CW PDFBOOKMARK.VIEW
820 .EM must
821 be specified in terms of valid view specification parameters,
822 as described in the Adobe\*(rg
823 .pdfmark-manual .
824 .LP
825 Note the use of the register
826 .CW PDFPAGE.Y ,
827 in the default definition of
828 .CW PDFBOOKMARK.VIEW
829 above.
830 This register is computed by
831 .CW pdfhref ,
832 when creating an outline entry;
833 it specifies the vertical position of the \(lqbookmark\(rq,
834 in basic
835 .CW groff
836 units, relative to the
837 .EM bottom
838 edge of the document page on which it is defined,
839 and is followed, in the
840 .CW PDFBOOKMARK.VIEW
841 definition, by the
842 .CW grops
843 .CW u \(rq \(lq
844 operator, to convert it to PostScript\*(rg units on output.
845 It may be used in any redefined specification for
846 .CW PDFBOOKMARK.VIEW ,
847 (or in the analogous definition of
848 .CW PDFHREF.VIEW ,
849 described in
850 .XR-NO-PREFIX pdfhref-view ),
851 but
852 .EM not
853 in any other context,
854 since its value is undefined outside the scope of the
855 .CW pdfhref
856 macro.
857 .LP
858 Since
859 .CW PDFPAGE.Y
860 is computed relative to the
861 .EM bottom
862 of the PDF output page,
863 it is important to ensure that the page length specified to
864 .CW troff
865 correctly matches the size of the logical PDF page.
866 This is most effectively ensured,
867 by providing
868 .EM identical
869 page size specifications to
870 .CW groff ,
871 .CW grops
872 and to the PostScript\*(rg to PDF converter employed,
873 and avoiding any page length changes within the document source.
874 .LP
875 Also note that
876 .CW PDFPAGE.Y
877 is the only automatically computed \(lqbookmark\(rq location parameter;
878 if the user redefines
879 .CW PDFBOOKMARK.VIEW ,
880 and the modified view specification requires any other positional parameters,
881 then the user
882 .EM must
883 ensure that these are computed
884 .EM before
885 invoking the
886 .CW pdfhref
887 macro.
888 .NH 3
889 .XN -N outline-folding -- Folding the Outline to Conceal Less Significant Headings
890 .LP
891 When a document incorporates many subheadings,
892 at deeply nested levels,
893 it may be desirable to \(lqfold\(rq the outline
894 such that only the major heading levels are initially visible,
895 yet making the inferior subheadings accessible,
896 by allowing the reader to expand the view of any heading branch on demand.
897 .LP
898 The
899 .CW pdfmark
900 macros support this capability,
901 through the setting of the
902 .CW PDFOUTLINE.FOLDLEVEL
903 register.
904 This register should be set to the number of heading levels
905 which it is desired to show in expanded form, in the
906 .EM initial
907 document outline display;
908 all subheadings at deeper levels will still be added to the outline,
909 but will not become visible until the outline branch containing them is expanded.
910 'ne 5
911 For example, the setting used in this document:
912 .QS
913 .LD
914 .fam C
915 \&.\e" Initialise the outline view to show only three heading levels,
916 \&.\e" with additional subordinate level headings folded.
917 \&.\e"
918 \&.nr PDFOUTLINE.FOLDLEVEL 3
919 .DE
920 .QE
921 .LP
922 results in only the first three levels of headings being displayed
923 in the document outline,
924 .EM until
925 the reader chooses to expand the view,
926 and so reveal the lower level headings in any outline branch.
927 .LP
928 The initial default setting of
929 .CW PDFOUTLINE.FOLDLEVEL ,
930 if the document author does not choose to change it,
931 is 10,000.
932 This is orders of magnitude greater than the maximum heading level
933 which is likely to be used in any document;
934 thus the default behaviour will be to show document outlines fully expanded,
935 to display all headings defined,
936 at all levels within each document.
937 .LP
938 The setting of
939 .CW PDFOUTLINE.FOLDLEVEL
940 may be changed at any time;
941 however, the effect of each such change may be difficult to predict,
942 since it is applied not only to outline entries which are defined
943 .EM after
944 the setting is changed,
945 but also to any entries which remain in the outline cache,
946 .EM at
947 this time.
948 Therefore, it is recommended that
949 .CW PDFOUTLINE.FOLDLEVEL
950 should be set
951 .EM once ,
952 at the start of each document;
953 if it
954 .EM is
955 deemed necessary to change it at any other time,
956 the outline cache should be flushed,
957 .XR pdfsync ), (
958 .EM immediately
959 before the change,
960 which should immediately preceed a level one heading.
961 .NH 3
962 .XN -N multipart-outline -- Outlines for Multipart Documents
963 .LP
964 When a document outline is created, using the
965 .CW pdfhref
966 macro, each reference mark is automatically assigned a name,
967 composed of a fixed stem followed by a serially generated numeric qualifier.
968 This ensures that, for each single part document, every outline reference
969 has a uniquely named destination.
970 .LP
971 As the overall size of the PDF document increases,
972 it may become convenient to divide it into smaller,
973 individually formatted PostScript\*(rg components,
974 which are then assembled, in the appropriate order,
975 to create a composite PDF document.
976 While this strategy may simplify the overall process of creating and
977 editing larger documents, it does introduce a problem in creating
978 an overall document outline,
979 since each individual PostScript\*(rg component will be assigned
980 duplicated sequences of \(lqbookmark\(rq names,
981 with each name ultimately referring to multiple locations in the composite document.
982 To avoid such reference naming conflicts, the
983 .CW pdfhref
984 macro allows the user to specify a \(lqtag\(rq,
985 which is appended to the automatically generated \(lqbookmark\(rq name;
986 this may be used as a discriminating mark, to distinguish otherwise
987 similarly named destinations, in different sections of the composite document.
988 .LP
989 To create a \(lqtagged\(rq document outline,
990 the syntax for invocation of the
991 .CW pdfhref
992 macro is modified, by the inclusion of an optional \(lqtag\(rq specification,
993 .EM before
994 the nesting level argument, i.e.
995 .QP
996 .fam C
997 .B ".pdfhref O"
998 .B -T \& [
999 .I tag >] <
1000 .I level > <
1001 .I "descriptive text ..."
1002 .LP
1003 The optional
1004 .CWI tag > <
1005 argument may be composed of any characters of the user's choice;
1006 however, its initial character
1007 .EM "must not"
1008 be any decimal digit, and ideally it should be kept short
1009 \(em one or two characters at most.
1010 .LP
1011 By employing a different tag in each section,
1012 the user can ensure that \(lqbookmark\(rq names remain unique,
1013 throughout all the sections of a composite document.
1014 For example, when using the
1015 .CW spdf.tmac
1016 macro package, which adds
1017 .CW pdfmark
1018 capabilities to the standard
1019 .CW ms
1020 package,
1021 .XR using-spdf ), (
1022 the table of contents is collected into a separate PostScript\*(rg section
1023 from the main body of the document.
1024 In the \(lqbody\(rq section, the document outline is \(lquntagged\(rq,
1025 but in the \(lqTable\~of\~Contents\(rq section, a modified version of the
1026 .CW TC
1027 macro adds an outline entry for the start of the \(lqTable\~of\~Contents\(rq,
1028 invoking the
1029 .CW pdfhref
1030 macro as
1031 .QP
1032 .CW ".pdfhref O -T T 1 \e\e*[TOC]"
1033 .LP
1034 to tag the associated outline destination name with the single character suffix,
1035 .CW T \(rq. \(lq
1036 Alternatively, as in the case of the basic outline,
1037 .XR basic-outline ), (
1038 this may equally well be specified as
1039 .QP
1040 .CW ".pdfbookmark -T T 1 \e\e*[TOC]"
1041 .NH 3
1042 .XN Delegation of the Outline Definition
1043 .LP
1044 Since the most common use of a document outline
1045 is to provide a quick method of navigating through a document,
1046 using active \(lqhypertext\(rq links to chapter and section headings,
1047 it may be convenient to delegate the responsibility of creating the outline
1048 to a higher level macro, which is itself used to
1049 define and format the section headings.
1050 This approach has been adopted in the
1051 .CW spdf.tmac
1052 package, to be described later,
1053 .XR using-spdf ). (
1054 .LP
1055 When such an approach is adopted,
1056 the user will rarely, if ever, invoke the
1057 .CW pdfhref
1058 macro directly, to create a document outline.
1059 For example, the structure and content of the outline for this document
1060 has been exclusively defined, using a combination of the
1061 .CW NH
1062 macro, from the
1063 .CW ms
1064 package, to establish the structure, and the
1065 .CW XN
1066 macro from
1067 .CW spdf.tmac ,
1068 to define the content.
1069 In this case,
1070 the responsibility for invoking the
1071 .CW pdfhref
1072 macro, to create the document outline,
1073 is delegated to the
1074 .CW XN
1075 macro.
1076 .NH 2
1077 .XN -N pdfhref -- Adding Reference Marks and Links
1078 .LP
1079 .pdfhref F SECREF
1080 .ds SECREF.BEGIN Section
1081 .pdfhref L -D add-outline
1082 .pdfhref F
1083 has shown how the
1084 .CW pdfhref
1085 macro may be used to create a PDF document outline.
1086 While this is undoubtedly a powerful capability,
1087 it is by no means the only trick in the repertoire of this versatile macro.
1088 .LP
1089 The macro name,
1090 .CW pdfhref ,
1091 which is a contraction of \(lqPDF HyperText Reference\(rq,
1092 indicates that the general purpose of this macro is to define
1093 .EM any
1094 type of dynamic reference mark, within a PDF document.
1095 Its generalised usage syntax takes the form
1096 .QP
1097 .fam C
1098 .B .pdfhref
1099 .BI class > <
1100 .I "-options ...\&" ] [
1101 [--]
1102 .I "descriptive text ...\&" ] [
1103 .LP
1104 where
1105 .CW <\f(CIclass\fP>
1106 represents a required single character argument,
1107 which defines the specific reference operation to be performed,
1108 and may be selected from:\(en
1109 .QS
1110 .IP \*[= O]
1111 Add an entry to the document outline.
1112 This operation has been described earlier,
1113 .XR add-outline ). (
1114 .IP \*[= M]
1115 Place a \(lqnamed destination\(rq reference mark at the current output position,
1116 in the current PDF document,
1117 .XR mark-dest ). (
1118 .IP \*[= D]
1119 Specify the content of a PDF document reference dictionary entry;
1120 typically, such entries are generated automatically,
1121 by transformation of the intermediate output resulting from the use of
1122 .CW pdfhref
1123 .CWB M \& \& \(rq, \(lq
1124 with the
1125 .CWB -X \& \& \(rq \(lq
1126 modifier,
1127 .XR create-map ); (
1128 however, it is also possible to specify such entries manually,
1129 .XR user-format ). (
1130 .IP \*[= L]
1131 Insert an active link to a named destination,
1132 .XR link-named ), (
1133 at the current output position in the current PDF document,
1134 such that when the reader clicks on the link text,
1135 the document view changes to show the location of the named destination.
1136 .IP \*[= W]
1137 Insert an active link to a \(lqweb\(rq resource,
1138 .XR add-weblink ), (
1139 at the current output position in the current PDF document.
1140 This is effectively the same as using the
1141 .CWB L \& \& \(rq \(lq
1142 operator to establish a link to a named destination in another PDF document,
1143 .XR link-extern ), (
1144 except that in this case, the destination is specified by a
1145 \(lquniform resource identifier\(rq, or
1146 .CW URI ;
1147 this may represent any Internet or local resource
1148 which can be specified in this manner.
1149 .IP \*[= F]
1150 Specify a user defined macro, to be called by
1151 .CW pdfhref ,
1152 when formatting the text in the active region of a link,
1153 .XR set-format ). (
1154 .IP \*[= Z]
1155 Define the absolute position on the physical PDF output page,
1156 where the \(lqhot\(hyspot\(rq associated with an active link is to be placed.
1157 Invoked in pairs, marking the starting and ending PDF page co\(hyordinates
1158 for each link \(lqhot\(hyspot\(rq, this operator is rarely, if ever,
1159 specified directly by the user;
1160 rather, appropriate
1161 .CW pdfhref
1162 .CWB Z \& \& \(rq \(lq
1163 specifications are inserted automatically into the document reference map
1164 during the PDF document formatting process,
1165 .XR create-map ). (
1166 .IP \*[= I]
1167 Initialise support for
1168 .CW pdfhref
1169 features.
1170 The current
1171 .CW pdfhref
1172 implementation provides only one such feature which requires initialisation
1173 \(em a helper macro which must be attached to a user supplied page trap handler,
1174 in order to support mapping of reference \(lqhot\(hyspots\(rq
1175 which extend through a page transition;
1176 .XR page-trap ). (
1177 .QE
1178 .NH 3
1179 .XN Optional Features of the \F[C]pdfhref\F[] Macro
1180 .LP
1181 The behaviour of a number of the
1182 .CW pdfhref
1183 macro operations can be modified,
1184 by including
1185 .EM "option specifiers" \(rq \(lq
1186 after the operation specifying argument,
1187 but
1188 .EM before
1189 any other arguments normally associated with the operation.
1190 In
1191 .EM all
1192 cases, an option is specified by an
1193 .EM "option flag" \(rq, \(lq
1194 comprising an initial hyphen,
1195 followed by one or two option identifying characters.
1196 Additionally,
1197 .EM some
1198 options require
1199 .EM "exactly one"
1200 option argument;
1201 for these options, the argument
1202 .EM must
1203 be specified, and it
1204 .EM must
1205 be separated from the preceding option flag by one or more
1206 .EM spaces ,
1207 (tabs
1208 .EM "must not"
1209 be used).
1210 It may be noted that this paradigm for specifying options
1211 is reminiscent of most
1212 .SM
1213 UNIX\(tm
1214 .LG
1215 shells; however, in the case of the
1216 .CW pdfhref
1217 macro, omission of the space separating an option flag from its argument is
1218 .EM never
1219 permitted.
1220 .LP
1221 A list of
1222 .EM all
1223 general purpose options supported by the
1224 .CW pdfhref
1225 macro is given below.
1226 Note that not all options are supported for all
1227 .CW pdfhref
1228 operations; the operations affected by each option are noted in the list.
1229 For
1230 .EM most
1231 operations, if an unsupported option is specified,
1232 it will be silently ignored; however, this behaviour should
1233 not be relied upon.
1234 .LP
1235 The general purpose options, supported by the
1236 .CW pdfhref
1237 macro, are:\(en
1238 .QS
1239 .IP \*[= -N\0 name > <]
1240 Allows the
1241 .CWI name > <
1242 associated with a PDF reference destination
1243 to be defined independently from the following text,
1244 which describes the reference.
1245 This option affects only the
1246 .CWB M \& \& \(rq \(lq
1247 operation of the
1248 .CW pdfhref
1249 macro,
1250 .XR mark-dest ). (
1251 .IP \*[= -E]
1252 Also used exclusively with the
1253 .CWB M \& \& \(rq \(lq
1254 operator, the
1255 .CWB -E
1256 option causes any specified
1257 .CWI descriptive \& \& \~\c
1258 .CWI text
1259 arguments,
1260 .XR mark-dest ), (
1261 to be copied, or
1262 .EM echoed ,
1263 in the body text of the document,
1264 at the point where the reference mark is defined;
1265 (without the
1266 .CWB -E
1267 option, such
1268 .CWI descriptive \& \& \~\c
1269 .CWI text
1270 will appear
1271 .EM only
1272 at points where links to the reference mark are placed,
1273 and where the standard reference display format,
1274 .XR set-format ), (
1275 is used).
1276 .IP \*[= -D\0 dest > <]
1277 Specifies the
1278 .CW URI ,
1279 or the destination name associated with a PDF active link,
1280 independently of the following text,
1281 which describes the link and demarcates the link \(lqhot\(hyspot\(rq.
1282 This option affects the behaviour of the
1283 .CW pdfhref
1284 macro's
1285 .CWB L \& \& \(rq \(lq
1286 and
1287 .CWB W \& \& \(rq \(lq
1288 operations.
1289 .IP
1290 When used with the
1291 .CWB L \& \& \(rq \(lq
1292 operator, the
1293 .CWI dest > <
1294 argument must specify a PDF \(lqnamed destination\(rq,
1295 as defined using
1296 .CW pdfhref
1297 with the
1298 .CWB M \& \& \(rq \(lq
1299 operator.
1300 .IP
1301 When used with the
1302 .CWB W \& \& \(rq \(lq
1303 operator,
1304 .CWI dest > <
1305 must specify a link destination in the form of a
1306 \(lquniform resource identifier\(rq, or
1307 .CW URI ,
1308 .XR add-weblink ). (
1309 .IP \*[= -F\0 file > <]
1310 When used with the
1311 .CWB L \& \& \(rq \(lq
1312 .CW pdfhref
1313 operator,
1314 .CWI file > <
1315 specifies an external PDF file in which the named destination
1316 for the link reference is defined.
1317 This option
1318 .EM must
1319 be specified with the
1320 .CWB L \& \& \(rq \(lq
1321 operator,
1322 to create a link to a destination in a different PDF document;
1323 when the
1324 .CWB L \& \& \(rq \(lq
1325 operator is used
1326 .EM without
1327 this option, the link destination is assumed to be defined
1328 within the same document.
1329 .IP \*[= -P\0 \(dqprefix\(hytext\(dq > <]
1330 Specifies
1331 .CWI \(dqprefix\(hytext\(dq > <
1332 to be attached to the
1333 .EM start
1334 of the text describing an active PDF document link,
1335 with no intervening space, but without itself being included in the
1336 active area of the link \(lqhot\(hyspot\(rq;
1337 it is effective with the
1338 .CWB L \& \& \(rq \(lq
1339 and
1340 .CWB W \& \& \(rq \(lq
1341 .CW pdfhref
1342 operators.
1343 .IP
1344 Typically, this option would be used to insert punctuation before
1345 the link \(lqhot\(hyspot\(rq.
1346 Thus, there is little reason for the inclusion of spaces in
1347 .CWI \(dqprefix\(hytext\(dq > < ;
1348 however, if such space is required, then the enclosing double quotes
1349 .EM must
1350 be specified, as indicated.
1351 .IP \*[= -A\0 \(dqaffixed\(hytext\(dq > <]
1352 Specifies
1353 .CWI \(dqaffixed\(hytext\(dq > <
1354 to be attached to the
1355 .EM end
1356 of the text describing an active PDF document link,
1357 with no intervening space, but without itself being included in the
1358 active area of the link \(lqhot\(hyspot\(rq;
1359 it is effective with the
1360 .CWB L \& \& \(rq \(lq
1361 and
1362 .CWB W \& \& \(rq \(lq
1363 .CW pdfhref
1364 operators.
1365 .IP
1366 Typically, this option would be used to insert punctuation after
1367 the link \(lqhot\(hyspot\(rq.
1368 Thus, there is little reason for the inclusion of spaces in
1369 .CWI \(dqaffixed\(hytext\(dq > < ;
1370 however, if such space is required, then the enclosing double quotes
1371 .EM must
1372 be specified, as indicated.
1373 .IP \*[= -T\0 tag > <]
1374 When specified with the
1375 .CWB O \& \& \(rq \(lq
1376 operator,
1377 .CWI tag > <
1378 is appended to the \(lqbookmark\(rq name assigned to the generated outline entry.
1379 This option is
1380 .EM required ,
1381 to distinguish between the series of \(lqbookmark\(rq names generated in
1382 individual passes of the
1383 .CW groff
1384 formatter, when the final PDF document is to be assembled
1385 from a number of separately formatted components;
1386 .XR multipart-outline ). (
1387 .IP \*[= -X]
1388 This
1389 .CW pdfhref
1390 option is used with either the
1391 .CWB M \& \& \(rq \(lq
1392 operator, or with the
1393 .CWB L \& \& \(rq \(lq
1394 operator.
1395 .IP
1396 When used with the
1397 .CWB M \& \& \(rq \(lq
1398 operator,
1399 .XR mark-dest ), (
1400 it ensures that a cross reference record for the marked destination
1401 will be included in the document reference map,
1402 .XR export-map ). (
1403 .IP
1404 When used with the
1405 .CWB L \& \& \(rq \(lq
1406 operator,
1407 .XR link-named ), (
1408 it causes the reference to be displayed in the standard cross reference format,
1409 .XR set-format ), (
1410 but substituting the
1411 .CWI descriptive \& \& \~\c
1412 .CWI text
1413 specified in the
1414 .CW pdfhref \& \(lq
1415 .CW L \(rq
1416 argument list,
1417 for the description specified in the document reference map.
1418 .IP \*[= --]
1419 Marks the end of the option specifiers.
1420 This may be used with all
1421 .CW pdfhref
1422 operations which accept options, to prevent
1423 .CW pdfhref
1424 from interpreting any following arguments as option specifiers,
1425 even if they would otherwise be interpreted as such.
1426 It is also useful when the argument list to
1427 .CW pdfhref
1428 contains special characters \(em any special character,
1429 which is not valid in a
1430 .CW groff
1431 macro name, will cause a parsing error, if
1432 .CW pdfhref
1433 attempts to match it as a possible option flag;
1434 using the
1435 .CW -- \(rq \(lq
1436 flag prevents this, so suppressing the
1437 .CW groff
1438 warning message, which would otherwise ensue.
1439 .IP
1440 Using this flag after
1441 .EM all
1442 sequences of macro options is recommended,
1443 even when it is not strictly necessary,
1444 if only for the entirely cosmetic benefit of visually separating
1445 the main argument list from the sequence of preceding options.
1446 .QE
1447 .LP
1448 In addition to the
1449 .CW pdfhref
1450 options listed above, a supplementary set of two character options are defined.
1451 These supplementary options, listed below, are intended for use with the
1452 .CWB L \& \& \(rq \(lq
1453 operator, in conjunction with the
1454 .CWB -F \& \& \~\c
1455 .CWBI file > <
1456 option, to specify alternate file names,
1457 in formats compatible with the file naming conventions
1458 of alternate operating systems;
1459 they will be silently ignored, if used in any other context.
1460 .LP
1461 The supported alternate file name options,
1462 which are ignored if the
1463 .CWB -F \& \& \~\c
1464 .CWBI file > <
1465 option is not specified, are:\(en
1466 .QS
1467 .IP \*[= -DF\0 dos\(hyfile > <]
1468 Specifies the name of the file in which a link destination is defined,
1469 using the file naming semantics of the
1470 .CW MS\(hyDOS \*(rg
1471 operating system.
1472 When the PDF document is read on a machine
1473 where the operating system uses the
1474 .CW MS\(hyDOS \*(rg
1475 file system, then
1476 .CWI dos\(hyfile > <
1477 is used as the name of the file containing the reference destination,
1478 overriding the
1479 .CWI file > <
1480 argument specified with the
1481 .CWB -F
1482 option.
1483 .IP \*[= -MF\0 mac\(hyfile > <]
1484 Specifies the name of the file in which a link destination is defined,
1485 using the file naming semantics of the
1486 .CW Apple \*(rg
1487 .CW Macintosh \*(rg
1488 operating system.
1489 When the PDF document is read on a machine
1490 where the operating system uses the
1491 .CW Macintosh \*(rg
1492 file system, then
1493 .CWI mac\(hyfile > <
1494 is used as the name of the file containing the reference destination,
1495 overriding the
1496 .CWI file > <
1497 argument specified with the
1498 .CWB -F
1499 option.
1500 .IP \*[= -UF\0 unix\(hyfile > <]
1501 Specifies the name of the file in which a link destination is defined,
1502 using the file naming semantics of the
1503 .CW UNIX \(tm
1504 operating system.
1505 When the PDF document is read on a machine
1506 where the operating system uses
1507 .CW POSIX
1508 file naming semantics, then
1509 .CWI unix\(hyfile > <
1510 is used as the name of the file containing the reference destination,
1511 overriding the
1512 .CWI file > <
1513 argument specified with the
1514 .CWB -F
1515 option.
1516 .IP \*[= -WF\0 win\(hyfile > <]
1517 Specifies the name of the file in which a link destination is defined,
1518 using the file naming semantics of the
1519 .CW MS\(hyWindows \*(rg
1520 32\(hybit operating system.
1521 When the PDF document is read on a machine
1522 where the operating system uses any of the
1523 .CW MS\(hyWindows \*(rg
1524 file systems, with long file name support, then
1525 .CWI win\(hyfile > <
1526 is used as the name of the file containing the reference destination,
1527 overriding the
1528 .CWI file > <
1529 argument specified with the
1530 .CWB -F
1531 option.
1532 .QE
1533 .NH 3
1534 .XN -N mark-dest -- Marking a Reference Destination
1535 .LP
1536 The
1537 .CW pdfhref
1538 macro may be used to create active links to any Internet resource,
1539 specified by its
1540 .CW URI ,
1541 or to any \(lqnamed destination\(rq,
1542 either within the same document, or in another PDF document.
1543 Although the PDF specification allows link destinations to be defined
1544 in terms of a page number, and an associated view specification,
1545 this style of reference is not currently supported by the
1546 .CW pdfhref
1547 macro, because it is not possible to adequately bind the specification
1548 for the destination with the intended reference context.
1549 .LP
1550 References to Internet resources are interpreted in accordance with the
1551 .CW W3C
1552 standard for defining a
1553 .CW URI ;
1554 hence the only prerequisite, for creating a link to any Internet resource,
1555 is that the
1556 .CW URI
1557 be properly specified, when declaring the reference;
1558 .XR add-weblink ). (
1559 In the case of references to \(lqnamed destinations\(rq in PDF documents,
1560 however, it is necessary to provide a mechanism for creating such
1561 \(lqnamed destinations\(rq.
1562 This may be accomplished, by invoking the
1563 .CW pdfhref
1564 macro in the form
1565 .QP
1566 .fam C
1567 .B ".pdfhref M"
1568 .B -N \& [
1569 .I name >] <
1570 .B -X ] [
1571 .B -E ] [
1572 .I "descriptive text ...\&" ] [
1573 .LP
1574 This creates a \(lqnamed destination\(rq reference mark, with its name specified by
1575 .CWI name > < ,
1576 or, if the
1577 .CWB -N
1578 option is not specified, by the first word of
1579 .CWI descriptive \& \& \~\c
1580 .CWI text \& \& ;
1581 (note that this imposes the restriction that,
1582 if the
1583 .CWB -N
1584 option is omitted, then
1585 .EM "at least"
1586 one word of
1587 .CWI descriptive \& \& \~\c
1588 .CWI text
1589 .EM must
1590 be specified).
1591 Additionally, a reference view will be automatically defined,
1592 and associated with the reference mark,
1593 .XR pdfhref-view ), (
1594 .\" and, if any
1595 .\" .CWI descriptive
1596 .\" .CWI text
1597 .\" is specified, or the
1598 and, if the
1599 .CWB -X
1600 option is specified, and no document cross reference map has been imported,
1601 .XR import-map ), (
1602 then a cross reference mapping record,
1603 .XR export-map ), (
1604 will be written to the
1605 .CW stdout
1606 stream;
1607 this may be captured, and subsequently used to generate a cross reference map
1608 for the document,
1609 .XR create-map ). (
1610 .LP
1611 When a \(lqnamed destination\(rq reference mark is created, using the
1612 .CW pdfhref
1613 macro's
1614 .CWB M \& \& \(rq \(lq
1615 operator, there is normally no visible effect in the formatted document; any
1616 .CWI descriptive \& \& \~\c
1617 .CWI text
1618 which is specified will simply be stored in the cross reference map,
1619 for use when a link to the reference mark is created.
1620 This default behaviour may be changed, by specifying the
1621 .CWB -E
1622 option, which causes any specified
1623 .CWI descriptive \& \& \~\c
1624 .CWI text
1625 to be \(lqechoed\(rq in the document text,
1626 at the point where the reference mark is placed,
1627 in addition to its inclusion in the cross reference map.
1628 .NH 4
1629 .XN -N export-map -- Mapping a Destination for Cross Referencing
1630 .LP
1631 Effective cross referencing of
1632 .EM any
1633 document formatted by
1634 .CW groff
1635 requires multiple pass formatting.
1636 Details of how this multiple pass formatting may be accomplished,
1637 when working with the
1638 .CW pdfmark
1639 macros, will be discussed later,
1640 .XR do-xref ); (
1641 at this stage, the discussion will be restricted to the initial preparation,
1642 which is required at the time when the cross reference destinations are defined.
1643 .LP
1644 The first stage, in the process of cross referencing a document,
1645 is the generation of a cross reference map.
1646 Again, the details of
1647 .EM how
1648 the cross reference map is generated will be discussed in
1649 .pdfhref F SECREF L -D do-xref -A ;
1650 .pdfhref F
1651 however, it is important to recognise that
1652 .EM what
1653 content is included in the cross reference map is established
1654 when the reference destination is defined \(em it is derived
1655 from the reference data exported on the
1656 .CW stderr
1657 stream by the
1658 .CW pdfhref
1659 macro, when it is invoked with the
1660 .CWB M \& \& \(rq \(lq
1661 operator, and is controlled by whatever definition of the string
1662 .CW PDFHREF.INFO
1663 is in effect, when the
1664 .CW pdfhref
1665 macro is invoked.
1666 .LP
1667 The initial default setting of
1668 .CW PDFHREF.INFO
1669 is
1670 .QP
1671 .CW ".ds PDFHREF.INFO page \e\en% \e\e$*"
1672 .LP
1673 which ensures that the cross reference map will contain
1674 at least a page number reference, supplemented by any
1675 .CWI descriptive \& \& \~\c
1676 .CWI text
1677 which is specified for the reference mark, as defined by the
1678 .CW pdfhref
1679 macro, with its
1680 .CWB M \& \& \(rq \(lq
1681 operator; this may be redefined by the user,
1682 to export additional cross reference information,
1683 or to modify the default format for cross reference links,
1684 .XR set-format ). (
1685 .NH 4
1686 .XN -N pdfhref-view -- Associating a Document View with a Reference Mark
1687 .LP
1688 In the same manner as each document outline reference, defined by the
1689 .CW pdfhref
1690 macro with the
1691 .CWB O \& \& \(rq \(lq
1692 operator,
1693 .XR add-outline ), (
1694 has a specific document view associated with it,
1695 each reference destination marked by
1696 .CW pdfhref
1697 with the
1698 .CWB M \& \& \(rq \(lq
1699 operator, requires an associated document view specification.
1700 .LP
1701 The mechanism whereby a document view is associated with a reference mark
1702 is entirely analogous to that employed for outline references,
1703 .XR outline-view ), (
1704 except that the
1705 .CW PDFHREF.VIEW
1706 string specification is used, in place of the
1707 .CW PDFBOOKMARK.VIEW
1708 specification.
1709 Thus, the reference view is defined in terms of:\(en
1710 .QS
1711 .IP \*[= PDFHREF.VIEW]
1712 A string,
1713 establishing the position of the reference mark within the viewing window,
1714 and the magnification at which the document will be viewed,
1715 at the location of the marked reference destination;
1716 by default, it is defined by
1717 .RS
1718 .QP
1719 .CW ".ds PDFHREF.VIEW /FitH \e\en[PDFPAGE.Y] u"
1720 .RE
1721 .IP
1722 which displays the reference destination at the top of the viewing window,
1723 with the magnification set to fit the page width to the width of the window.
1724 .IP \*[= PDFHREF.VIEW.LEADING]
1725 A numeric register,
1726 specifying additional spacing, to be placed between the top of the display
1727 window and the actual position at which the location of the reference
1728 destination appears within the window.
1729 This register is shared with the view specification for outline references,
1730 and thus has the same default initial setting,
1731 .RS
1732 .QP
1733 .CW ".nr PDFHREF.VIEW.LEADING 5.0p"
1734 .RE
1735 .IP
1736 as in the case of outline reference views.
1737 .IP
1738 Again, notice that
1739 .CW PDFHREF.VIEW.LEADING
1740 does not represent true typographic \(lqleading\(rq,
1741 since any preceding text, set in the specified display space,
1742 will be visible at the top of the viewing window,
1743 when the reference is selected.
1744 .QE
1745 .LP
1746 Just as the view associated with outline references may be changed,
1747 by redefining
1748 .CW PDFBOOKMARK.VIEW ,
1749 so the view associated with marked reference destinations may be changed,
1750 by redefining
1751 .CW PDFHREF.VIEW ,
1752 and, if desired,
1753 .CW PDFHREF.VIEW.LEADING ;
1754 such changes will become effective for all reference destinations marked
1755 .EM after
1756 these definitions are changed.
1757 (Notice that, since the specification of
1758 .CW PDFHREF.VIEW.LEADING
1759 is shared by both outline reference views and marked reference views,
1760 if it is changed, then the views for
1761 .EM both
1762 reference types are changed accordingly).
1763 .LP
1764 It may again be noted, that the
1765 .CW PDFPAGE.Y
1766 register is used in the definition of
1767 .CW PDFHREF.VIEW ,
1768 just as it is in the definition of
1769 .CW PDFBOOKMARK.VIEW ;
1770 all comments in
1771 .pdfhref F SECREF L -D outline-view
1772 .pdfhref F
1773 relating to its use, and indeed to page position computations in general,
1774 apply equally to marked reference views and to outline reference views.
1775 .NH 3
1776 .XN -N link-named -- Linking to a Marked Reference Destination
1777 .LP
1778 Any named destination, such as those marked by the
1779 .CW pdfhref
1780 macro, using it's
1781 .CWB M \& \& \(rq \(lq
1782 operator, may be referred to from any point in
1783 .EM any
1784 PDF document, using an
1785 .EM "active link" ;
1786 such active links are created by again using the
1787 .CW pdfhref
1788 macro, but in this case, with the
1789 .CWB L \& \& \(rq \(lq
1790 operator.
1791 This operator provides support for two distinct cases,
1792 depending on whether the reference destination is defined in 
1793 the same document as the link,
1794 .XR link-intern ), (
1795 or is defined as a named destination in a different PDF document,
1796 .XR link-extern ). (
1797 .NH 4
1798 .XN -N link-intern -- References within a Single PDF Document
1799 .LP
1800 The general syntactic form for invoking the
1801 .CW pdfhref
1802 macro,
1803 when creating a link to a named destination within the same PDF document is
1804 .QP
1805 .fam C
1806 .B .pdfhref
1807 .B L
1808 .B -D \& [
1809 .BI dest-name >] <
1810 .B -P \& [
1811 .BI prefix-text >] <
1812 .B -A \& [
1813 .BI affixed-text >] <
1814 \e
1815 .br
1816 \0\0\0
1817 .B -X ] [
1818 .B -- ] [
1819 .I "descriptive text ...\&" ] [
1820 .LP
1821 where
1822 .CWI dest-name > <
1823 specifies the name of the link destination,
1824 as specified using the
1825 .CW pdfhref
1826 .CWB M \& \& \(rq \(lq
1827 operation; (it may be defined either earlier in the document,
1828 to create a backward reference, or later, to create a forward reference).
1829 .\"
1830 .\" Here's a example of how to add an iconic annotation.
1831 .\"
1832 .\".pdfnote -T "Internal Cross References" \
1833 .\"   This description is rather terse, and could benefit from \
1834 .\"   the inclusion of an example.
1835 .LP
1836 If any
1837 .CWI descriptive \& \& \~\c
1838 .CWI text
1839 arguments are specified, then they will be inserted into the
1840 .CW groff
1841 output stream, to define the text appearing in the \(lqhot\(hyspot\(rq
1842 region of the link;
1843 this will be printed in the link colour specified by the string,
1844 .CW PDFHREF.TEXT.COLOUR ,
1845 which is described in
1846 .XR-NO-PREFIX set-colour .
1847 If the
1848 .CWB -X
1849 option is also specified, then the
1850 .CWI descriptive \& \& \~\c
1851 .CWI text
1852 will be augmented, by prefacing it with page and section number indicators,
1853 in accordance with the reference formatting rules which are in effect,
1854 .XR set-format ); (
1855 such indicators will be included within the active link region,
1856 and will also be printed in the link colour.
1857 .LP
1858 Note that
1859 .EM either
1860 the
1861 .CWB -D \& \& \~\c
1862 .CWBI dest\(hyname > <
1863 option,
1864 .EM or
1865 the
1866 .CWI descriptive \& \& \~\c
1867 .CWI text
1868 arguments,
1869 .EM "but not both" ,
1870 may be omitted.
1871 If the
1872 .CWB -D \& \& \~\c
1873 .CWBI dest\(hyname > <
1874 option is omitted, then the first word of
1875 .CWI descriptive \& \& \~\c
1876 .CWI text \& \& ,
1877 i.e.\~all text up to but not including the first space,
1878 will be interpreted as the
1879 .CWBI dest\(hyname > <
1880 for the link; this text will also appear in the running text of the document,
1881 within the active region of the link.
1882 Alternatively, if the
1883 .CWB -D \& \& \~\c
1884 .CWBI dest\(hyname > <
1885 option
1886 .EM is
1887 specified, and
1888 .CWI descriptive \& \& \~\c
1889 .CWI text
1890 is not,
1891 then the running text which defines the reference,
1892 and its active region,
1893 will be derived from the reference description which is specified
1894 when the named destination is marked,
1895 .XR mark-dest ), (
1896 and will be formatted according to the reference formatting rules
1897 which are in effect, when the reference is placed,
1898 .XR set-format ); (
1899 in this case, it is not necessary to specify the
1900 .CWB -X
1901 option to activate automatic formatting of the reference \(em it is implied,
1902 by the omission of all
1903 .CWI descriptive \& \& \~\c
1904 .CWI text
1905 arguments.
1906 .LP
1907 The
1908 .CWB -P \& \& \~\c
1909 .CWBI prefix\(hytext > <
1910 and
1911 .CWB -A \& \& \~\c
1912 .CWBI affixed\(hytext > <
1913 options may be used to specify additional text
1914 which will be placed before and after the linked text respectively,
1915 with no intervening space.
1916 Such prefixed and affixed text will be printed in the normal text colour,
1917 and will not be included within the active region of the link.
1918 This feature is mostly useful for creating parenthetical references,
1919 or for placing punctuation adjacent to,
1920 but not included within,
1921 the text which defines the active region of the link.
1922 .LP
1923 The operation of the
1924 .CW pdfhref
1925 macro, when used with its
1926 .CWB L \& \& \(rq \(lq
1927 operator to place a link to a named PDF destination,
1928 may best be illustrated by an example.
1929 However, since the appearance of the link will be influenced by
1930 factors established when the named destination is marked,
1931 .XR mark-dest ), (
1932 and also by the formatting rules in effect when the link is placed,
1933 the presentation of a suitable exanple will be deferred,
1934 until the formatting mechanism has been explained,
1935 .XR set-format ). (
1936 .NH 4
1937 .XN -N link-extern -- References to Destinations in Other PDF Documents
1938 .LP
1939 The
1940 .CW pdfhref
1941 macro's
1942 .CWB L \& \& \(rq \(lq
1943 operator is not restricted to creating reference links
1944 within a single PDF document.
1945 When the link destination is defined in a different document,
1946 then the syntactic form for invoking
1947 .CW pdfhref
1948 is modified, by the addition of options to specify the
1949 name and location of the PDF file in which the destination is defined.
1950 Thus, the extended
1951 .CW pdfhref
1952 syntactic form becomes
1953 .QP
1954 .fam C
1955 .B .pdfhref
1956 .B L
1957 .B -F
1958 .BI file > <
1959 .B -D \& [
1960 .BI dest-name >] <
1961 \e
1962 .br
1963 \0\0\0
1964 .B -DF \& [
1965 .BI dos-file >] <
1966 .B -MF \& [
1967 .BI mac-file >] <
1968 .B -UF \& [
1969 .BI unix-file >] <
1970 \e
1971 .br
1972 \0\0\0
1973 .B -WF \& [
1974 .BI win-file >] <
1975 .B -P \& [
1976 .BI prefix-text >] <
1977 .B -A \& [
1978 .BI affixed-text >] <
1979 \e
1980 .br
1981 \0\0\0
1982 .B -X ] [
1983 .B -- ] [
1984 .I "descriptive text ...\&" ] [
1985 .LP
1986 where the
1987 .CWB -F \& \& \~\c
1988 .CWBI file > <
1989 option serves
1990 .EM two
1991 purposes: it both indicates to the
1992 .CW pdfhref
1993 macro that the specified reference destination
1994 is defined in an external PDF file,
1995 and it also specifies the normal path name,
1996 which is to be used to locate this file,
1997 when a user selects the reference.
1998 .LP
1999 In addition to the
2000 .CWB -F \& \& \~\c
2001 .CWBI file > <
2002 option, which
2003 .EM must
2004 be specified when referring to a destination in an external PDF file,
2005 the
2006 .CWB -DF \& \& \~\c
2007 .CWBI dos\(hyfile > < ,
2008 .CWB -MF \& \& \~\c
2009 .CWBI mac\(hyfile > < ,
2010 .CWB -UF \& \& \~\c
2011 .CWBI unix\(hyfile > <
2012 and
2013 .CWB -WF \& \& \~\c
2014 .CWBI win\(hyfile > <
2015 options may be used to specify the location of the file
2016 containing the reference destination,
2017 in a variety of operating system dependent formats.
2018 These options assign their arguments to the
2019 .CW /DosFile ,
2020 .CW /MacFile ,
2021 .CW /UnixFile
2022 and
2023 .CW /WinFile
2024 keys of the generated
2025 .CW pdfmark
2026 respectively; thus when any of these options are specified,
2027 .EM "in addition to"
2028 the
2029 .CWB -F \& \& \~\c
2030 .CWBI file > <
2031 option, and the document is read on the appropriate operating systems,
2032 then the path names specified by
2033 .CWBI dos\(hyfile > < ,
2034 .CWBI mac\(hyfile > < ,
2035 .CWBI unix\(hyfile > <
2036 and
2037 .CWBI win\(hyfile > <
2038 will be searched,
2039 .EM instead
2040 of the path name specified by
2041 .CWBI file > < ,
2042 for each of the
2043 .CW MS\(hyDOS \*(rg,
2044 .CW Apple \*(rg
2045 .CW Macintosh \*(rg,
2046 .CW UNIX \(tm
2047 and
2048 .CW MS\(hyWindows \*(rg
2049 operating systems, respectively; see the
2050 .pdfmark-manual ,
2051 for further details.
2052 .LP
2053 Other than the use of these additional options,
2054 which specify that the reference destination is in an external PDF file,
2055 the behaviour of the
2056 .CW pdfhref
2057 .CWB L \& \& \(rq \(lq
2058 operator, with the
2059 .CWB -F \& \& \~\c
2060 .CWBI file > <
2061 option, remains identical to its behaviour
2062 .EM without
2063 this option,
2064 .XR link-intern ), (
2065 with respect to the interpretation of other options,
2066 the handling of the
2067 .CWI descriptive \& \& \~\c
2068 .CWI text
2069 arguments, and the formatting of the displayed reference.
2070 .LP
2071 Once again, since the appearance of the reference is determined by
2072 factors specified in the document reference map,
2073 and also by the formatting rules in effect when the reference is placed,
2074 the presentation of an example of the placing of
2075 a reference to an external destination will be deferred,
2076 until the formatting mechanism has been explained,
2077 .XR set-format ). (
2078 .NH 3
2079 .XN -N add-weblink -- Linking to Internet Resources
2080 .LP
2081 In addition to supporting the creation of cross references
2082 to named destinations in PDF documents, the
2083 .CW pdfhref
2084 macro also has the capability to create active links to Internet resources,
2085 or indeed to
2086 .EM any
2087 resource which may be specified by a Uniform Resource Identifier,
2088 (which is usually abbreviated to the acronym \(lqURI\(rq,
2089 and sometimes also referred to as a Uniform Resource Locator,
2090 or \(lqURL\(rq).
2091 .LP
2092 Since the mechanism for creating a link to a URI differs somewhat
2093 from that for creating PDF references, the
2094 .CW pdfhref
2095 macro is invoked with the
2096 .CWB W \& \& \(rq \(lq
2097 (for \(lqweb\(hylink\(rq) operator, rather than the
2098 .CWB L \& \& \(rq \(lq
2099 operator; nevertheless, the invocation syntax is similar, having the form
2100 .QP
2101 .fam C
2102 .B .pdfhref
2103 .B W
2104 .B -D \& [
2105 .BI URI >] <
2106 .B -P \& [
2107 .BI prefix-text >] <
2108 .B -A \& [
2109 .BI affixed-text >] <
2110 \e
2111 .br
2112 \0\0\0
2113 .B -- ] [
2114 .I "descriptive text ...\&"
2115 .LP
2116 where the optional
2117 .CWB -D
2118 .CWBI URI > <
2119 modifier specifies the address for the target Internet resource,
2120 in any appropriate
2121 .EM "Uniform Resource Identifier"
2122 format, while the
2123 .CWI descriptive
2124 .CWI text
2125 argument specifies the text which is to appear in the \(lqhot\(hyspot\(rq
2126 region, and the
2127 .CWB -P
2128 .CWBI prefix\(hytext > <
2129 and
2130 .CWB -A
2131 .CWBI affixed\(hytext > <
2132 options have the same effect as in the case of local document links,
2133 .XR link-intern ). (
2134 .LP
2135 Notice that it is not mandatory to include the
2136 .CWB -D
2137 .CWBI URI > <
2138 in the link specification; if it
2139 .EM is
2140 specified, then it is not necessary for the URI to appear,
2141 in the running text of the document \(em the
2142 .CWI descriptive
2143 .CWI text
2144 argument exactly defines the text
2145 which will appear within the \(lqhot\(hyspot\(rq region,
2146 and this need not include the URI.
2147 However, if the
2148 .CWB -D \& \& \~\c
2149 .CWBI URI > <
2150 specification is omitted, then the
2151 .CWI descriptive
2152 .CWI text
2153 argument
2154 .EM must
2155 be an
2156 .EM exact
2157 representation of the URI, which
2158 .EM will ,
2159 therefore, appear as the entire content of the \(lqhot\(hyspot\(rq.
2160 For example, we could introduce a reference to
2161 .pdfhref W -D \*[GROFF-WEBSITE] -A , the groff web site
2162 in which the actual URI is concealed, by using mark up such as:\(en
2163 .DS I
2164 .CW
2165 For example, we could introduce a reference to
2166 \&.pdfhref W -D \*[GROFF-WEBSITE] -A , the groff web site
2167 in which the actual URI is concealed,
2168 .DE
2169 Alternatively,
2170 to refer the reader to the groff web site,
2171 making it obvious that the appropriate URI is
2172 .pdfhref W -A , \*[GROFF-WEBSITE]
2173 the requisite mark up might be:\(en
2174 .DS I
2175 .CW
2176 to refer the reader to the groff web site,
2177 making it obvious that the appropriate URI is
2178 \&.pdfhref W -A , \*[GROFF-WEBSITE]
2179 the requisite mark up might be:\e(en
2180 .DE
2181 .NH 3
2182 .XN -N set-format -- Establishing a Format for References
2183 .LP
2184 There are two principal aspects to be addressed,
2185 when defining the format to be used when displaying references.
2186 Firstly, it is desirable to provide a visual cue,
2187 to indicate that the text describing the reference is imbued
2188 with special properties \(em it is dynamically linked to the reference
2189 destination \(em and secondly, the textual content should
2190 describe where the link leads, and ideally,
2191 it should also describe the content of the reference destination.
2192 .LP
2193 The visual cue,
2194 that a text region defines a dynamically linked reference,
2195 is most commonly provided by printing the text within the active
2196 region in a distinctive colour.
2197 This technique will be employed automatically by the
2198 .CW pdfhref
2199 macro \(em
2200 .XR set-colour
2201 \(em unless the user specifically chooses to adopt, and implement,
2202 some alternative strategy.
2203 .NH 4
2204 .XN -N set-colour -- Using Colour to Demarcate Link Regions
2205 .LP
2206 Typically, when a PDF document contains
2207 .EM active
2208 references to other locations, either within the same document,
2209 or even in other documents, or on the World Wide Web,
2210 it is usually desirable to make the regions
2211 where these active links are placed stand out from the surrounding text.
2212 .NH 4
2213 .XN -N user-format -- Specifying Reference Text Explicitly
2214 .NH 4
2215 .XN -N auto-format -- Using Automatically Formatted Reference Text
2216 .NH 4
2217 .XN -N custom-format -- Customising Automatically Formatted Reference Text
2218 .LP
2219 It is incumbent on the user,
2220 if employing automatic formatting of the displayed reference,
2221 .XR set-format ), (
2222 to ensure that an appropriate reference definition
2223 is created for the reference destination,
2224 and is included in the reference map for the document
2225 in which the reference will appear;
2226 thus, it may be easiest to
2227 .EM always
2228 use manual formatting for external references.
2229 .NH 3
2230 .XN Problematic Links
2231 .LP
2232 Irrespective of whether a
2233 .CW pdfhref
2234 reference is placed using the
2235 .CWB L \& \& \(rq \(lq
2236 operator, or the
2237 .CWB W \& \& \(rq \(lq
2238 operator, there may be occasions when the resulting link
2239 does function as expected.
2240 A number of scenarios, which are known to be troublesome,
2241 are described below.
2242 .NH 4
2243 .XN -N page-trap -- Links with a Page Transition in the Active Region
2244 .LP
2245 When a link is placed near the bottom of a page,
2246 it is possible that its active region, or \(lqhot\(hyspot\(rq,
2247 may extend on to the next page.
2248 In this situation, a page trap macro is required
2249 to intercept the page transition, and to restart the mapping of
2250 the \(lqhot\(hyspot\(rq boundary on the new page.
2251 .LP
2252 The
2253 .CW pdfmark
2254 macro package includes a suitable page trap macro, to satisfy this requirement.
2255 However, to avoid pre\(hyempting any other requirement the user may have for
2256 a page transition trap, this is
2257 .EM not
2258 installed as an active page trap,
2259 unless explicitly requested by the user.
2260 .LP
2261 To enable proper handling of page transitions,
2262 which occur within the active regions of reference links,
2263 the user should:\(en
2264 .QS
2265 .nr ITEM 0 1
2266 .IP \n+[ITEM].
2267 Define a page transition macro, to provide whatever features may be required,
2268 when a page transition occurs \(em e.g.\& printing footnotes,
2269 adding page footers and headers, etc.
2270 This macro should end by setting the output position at the correct
2271 vertical page offset, where the printing of running text is to restart,
2272 following the page transition.
2273 .IP \n+[ITEM].
2274 Plant a trap to invoke this macro, at the appropriate vertical position
2275 marking the end of normal running text on each page.
2276 .KS
2277 .IP \n+[ITEM].
2278 Initialise the
2279 .CW pdfhref
2280 hook into this page transition trap, by invoking
2281 .RS
2282 .IP
2283 .fam C
2284 .B "pdfhref I -PT"
2285 .BI macro-name > <
2286 .LP
2287 where
2288 .CWBI macro-name > <
2289 is the name of the user supplied page trap macro,
2290 to ensure that
2291 .CW pdfhref
2292 will correctly restart mapping of active link regions,
2293 at the start of each new page.
2294 .KE
2295 .RE
2296 .QE
2297 .LP
2298 It may be observed that this initialisation of the
2299 .CW pdfhref
2300 page transition hook is, typically, required only once
2301 .EM before
2302 document formatting begins.
2303 Users of document formatting macro packages may reasonably expect that
2304 this initialisation should be performed by the macro package itself.
2305 Thus, writers of such macro packages which include
2306 .CW pdfmark
2307 bindings, should provide appropriate initialisation,
2308 so relieving the end user of this responsibility.
2309 The following example, abstracted from the sample
2310 .CW ms
2311 binding package,
2312 .CW spdf.tmac ,
2313 illustrates how this may be accomplished:\(en
2314 .DS I
2315 .CW
2316 \&.\e" groff "ms" provides the "pg@bottom" macro, which has already
2317 \&.\e" been installed as a page transition trap.  To ensure proper
2318 \&.\e" mapping of "pdfhref" links which overflow the bottom of any
2319 \&.\e" page, we need to install the "pdfhref" page transition hook,
2320 \&.\e" as an addendum to this macro.
2321 \&.
2322 \&.pdfhref I -PT pg@bottom
2323 .DE
2324 .NH 2
2325 .XN -N add-note -- Annotating a PDF Document using Pop-Up Notes
2326 .NH 2
2327 .XN -N pdfsync -- Synchronising Output and \F[C]pdfmark\F[] Contexts
2328 .LP
2329 It has been noted previously, that the
2330 .CW pdfview
2331 macro,
2332 .XR docview ), (
2333 the
2334 .CW pdfinfo
2335 macro,
2336 .XR docinfo ), (
2337 and the
2338 .CW pdfhref
2339 macro, when used to create a document outline,
2340 .XR add-outline ), (
2341 do not immediately write their
2342 .CW pdfmark
2343 output to the PostScript\*(rg data stream;
2344 instead, they cache their output, in a
2345 .CW groff
2346 diversion, in the case of the
2347 .CW pdfview
2348 and
2349 .CW pdfinfo
2350 macros, or in an ordered collection of strings and numeric registers,
2351 in the case of the document outline,
2352 until a more appropriate time for copying it out.
2353 In the case of
2354 .CW pdfview
2355 and
2356 .CW pdfinfo
2357 \(lqmeta\(hydata\(rq,
2358 this \(lqmore appropriate time\(rq is explicitly chosen by the user;
2359 in the case of document outline data,
2360 .EM some
2361 cached data may be implicitly written out as the document outline is compiled,
2362 but there will
2363 .EM always
2364 be some remaining data, which must be explicitly flushed out, before the
2365 .CW groff
2366 formatting process is allowed to complete.
2367 .LP
2368 To allow the user to choose when cached
2369 .CW pdfmark
2370 data is to be flushed to the output stream, the
2371 .CW pdfmark
2372 macro package provides the
2373 .CW pdfsync
2374 macro, (to synchronise the cache and output states).
2375 In its simplest form, it is invoked without arguments, i.e.
2376 .QP
2377 .fam C
2378 .B .pdfsync
2379 .LP
2380 This form of invocation ensures that
2381 .EM both
2382 the \(lqmeta\(hydata cache\(rq, containing
2383 .CW pdfview
2384 and
2385 .CW pdfinfo
2386 data,
2387 .EM and 
2388 the \(lqoutline cache\(rq,
2389 containing any previously uncommitted document outline data,
2390 are flushed; ideally, this should be included in a
2391 .CW groff
2392 \(lqend macro\(rq, to ensure that
2393 .EM both
2394 caches are flushed, before
2395 .CW groff
2396 terminates.
2397 .LP
2398 Occasionally,
2399 it may be desirable to flush either the \(lqmeta\(hydata cache\(rq,
2400 without affecting the \(lqoutline cache\(rq, or vice\(hyversa,
2401 at a user specified time, prior to reaching the end of the document.
2402 This may be accomplished, by invoking the
2403 .CW pdfsync
2404 macro with an argument, i.e.
2405 .QP
2406 .fam C
2407 .B ".pdfsync M"
2408 .LP
2409 to flush only the \(lqmeta\(hydata cache\(rq, or
2410 .QP
2411 .fam C
2412 .B ".pdfsync O"
2413 .LP
2414 to flush only the \(lqoutline cache\(rq.
2415 .LP
2416 The \(lqmeta\(hydata cache\(rq can normally be safely flushed
2417 in this manner, at any time
2418 .EM after
2419 output of the first page has started;
2420 (it may cause formatting problems,
2421 most notably the appearance of unwanted white space, if flushed earlier,
2422 or indeed, if flushed immediately after a page transition,
2423 but before the output of the content on the new page has commenced).
2424 Caution is required, however, when explicitly flushing the
2425 \(lqoutline cache\(rq, since if the outline is to be
2426 subsequently extended, then the first outline entry after flushing
2427 .EM must
2428 be specified at level 1.
2429 Nevertheless, such explicit flushing may occasionally be necessary;
2430 for example, the
2431 .CW TC
2432 macro in the
2433 .CW spdf.tmac
2434 package,
2435 .XR using-spdf ), (
2436 invokes
2437 .CW ".pdfsync\ O" \(rq \(lq
2438 to ensure that the outline for the \(lqbody\(rq section of the document
2439 is terminated,
2440 .EM before
2441 it commences the formatting of the table of contents section.
2442 .bp
2443 .NH 1
2444 .XN -N pdf-layout -- PDF Document Layout
2445 .LP
2446 The
2447 .CW pdfmark
2448 macros described in the preceding section,
2449 .XR pdf-features ), (
2450 provide no inherent document formatting capability of their own.
2451 However,
2452 they may be used in conjunction with any other
2453 .CW groff
2454 macro package of the user's choice,
2455 to add such capability.
2456 .LP
2457 In preparing this document, the standard
2458 .CW ms
2459 macro package, supplied as a component of the GNU Troff distribution,
2460 has been employed.
2461 To facilitate the use of the
2462 .CW pdfmark
2463 macros with the
2464 .CW ms
2465 macros,
2466 a binding macro package,
2467 .CW spdf.tmac ,
2468 has been created.
2469 The use of this binding macro package is described in the following section,
2470 .XR using-spdf ); (
2471 it may also serve as an example to users of other standard
2472 .CW groff
2473 macro packages,
2474 as to how the
2475 .CW pdfmark
2476 macros may be employed with their chosen primary macro package.
2477 .NH 2
2478 .XN -N using-spdf -- Using \F[C]pdfmark\F[] Macros with the \F[C]ms\F[] Macro Package
2479 .LP
2480 The use of the binding macro package,
2481 .CW spdf.tmac ,
2482 allows for the use of the
2483 .CW pdfmark
2484 macros in conjunction with the
2485 .CW ms
2486 macros,
2487 simply by issuing a
2488 .CW groff
2489 command of the form
2490 .QP
2491 .fam C
2492 groff -Tps
2493 .B -mspdf
2494 .I "-options ...\&" ] [
2495 file(s) ...
2496 .LP
2497 (Or use the PDF post-processor to avoid using ghostscript,
2498 .CW -Tpdf\c
2499 ).
2500 .LP
2501 When using the
2502 .CW spdf.tmac
2503 package, the
2504 .CW groff
2505 input files may be marked up using any of the standard
2506 .CW ms
2507 macros to specify document formatting,
2508 while PDF features may be added,
2509 using any of the
2510 .CW pdfmark
2511 macros described previously,
2512 .XR pdf-features ). (
2513 Additionally,
2514 .CW spdf.tmac
2515 defines a number of convenient extensions to the
2516 .CW ms
2517 macro set, to better accomodate the use of PDF features within the
2518 .CW ms
2519 formatting framework,
2520 and to address a number of
2521 .CW ms
2522 document layout issues,
2523 which require special handling when producing PDF documents.
2524 These additional macros,
2525 and the issues they are intended to address,
2526 are described below.
2527 .NH 3
2528 .XN \F[C]ms\F[] Section Headings in PDF Documents
2529 .LP
2530 Traditionally,
2531 .CW ms
2532 provides the
2533 .CW NH
2534 and
2535 .CW SH
2536 macros, to specify section headings.
2537 However,
2538 there is no standard mechanism for generating a
2539 table of contents entry based on the text of the section heading;
2540 neither is there any recognised standard method for establishing a
2541 cross reference link to the section.
2542 .LP
2543 To address this
2544 .CW ms
2545 limitation,
2546 .CW spdf.tmac
2547 defines the
2548 .CW XN
2549 macro,
2550 .XR xn-macro ), (
2551 to be used in conjunction with the
2552 .CW NH
2553 macro.
2554 .NH 4
2555 .XN -N xn-macro -- The \F[C]XN\F[] Macro
2556 .NH 1
2557 .XN The PDF Publishing Process
2558 .NH 2
2559 .XN -N do-xref -- Resolving Cross References
2560 .NH 3
2561 .XN -N create-map -- Creating a Document Reference Map
2562 .NH 3
2563 .XN -N import-map -- Deploying a Document Reference Map
2564 .TC