Debian Codegraph @

texmf-dist/doc/eplain/demo/xhyper.tex

raw
1 % $Id: xhyper.tex 60 2022-10-05 22:42:54Z karl $
2 % (This file is public domain.)
3 %
4 % This file demonstrates the following features of Eplain:
5 %
6 % - explicit and implicit hyperlinks;
7 % - symbolic cross-references;
8 % - inserting external graphics using |\includegraphics| from
9 % the \LaTeX\ package |graphicx.sty|.
10 % - rotating text using |\rotatebox| from |graphicx.sty|.
11 %
12 % The compiled demo can be downloaded from
13 %
14 % https://tug.org/eplain/demo
15 %
16 % In order to compile this file yourself, you will need the CTAN lion
17 % drawing by Duane Bibby from
18 %
19 % ftp://tug.ctan.org/ftpmaint/CTAN_lion/ctan_lion_350x350.png
20 %
21 % (thanks, |www.ctan.org|). Place the image file in the same
22 % directory with this file, and change to that directory. Now, to
23 % produce a PDF, run twice the command
24 %
25 % pdftex xhyper.tex
26 %
27 % During the first run, Eplain will write the information about the
28 % cross-references into |xhyper.aux|, and during the second run this
29 % information will be read by Eplain to typeset the references.
30 %
31 % Demo case:
32 %
33 % Suppose you are using pdf\TeX, have a figure you want to insert
34 % scaled to $200\,pt$ horizontally, and you want this figure to
35 % completely fill the PDF viewer's window whenever the reader
36 % selects a link pointing to this figure. Additionally, you want to
37 % typeset some text as live hyperlinks, clicking on which will start
38 % a Web browser and open a URL.
39
40 \input eplain
41
42 % Load \LaTeX\ packages.
43 \beginpackages
44 % |url.sty| provides the |\url| command which we will use to typeset
45 % a URL. We request that |url.sty| be the version from June~27,
46 % 2005, or later, because earlier versions had problems interacting
47 % with plain \TeX.
48 \usepackage{url}[2005/06/27]
49 % |color.sty| provides support for colored text; all hyperlinks are
50 % automatically colored by Eplain when this package is loaded. We give
51 % the |dvipsnames| option because we want to use named colors from the
52 % |dvips| graphics driver.
53 \usepackage[dvipsnames]{color}
54 % Finally, we load |graphicx.sty|, for the macros |\includegraphics|
55 % and |\rotatebox|.
56 \usepackage{graphicx}
57 \endpackages
58
59 % Remember that hyperlinks are off by default. Therefore, we need to
60 % enable them.
61 \enablehyperlinks
62
63 % Customize some hyperlink options. First, we set border width to~$0$
64 % for all links to get rid of the default boxes around links (we
65 % prefer colored links over the boxed links). Next, we say that all
66 % links created by the |url| hyperlink group (which means the |\url|
67 % command from |url.sty|) must be colored using the named color
68 % |BlueViolet|.
69 \hlopts{bwidth=0}
70 \hlopts[url]{colormodel=named,color=BlueViolet}
71
72 % Inhibit page numbering (we have only one page).
73 \nopagenumbers
74
75 % Define a class word for the cross-reference class |figure|. This
76 % word, when defined, will be automatically prepended by Eplain to the
77 % reference created by |\ref| (read on to see its use).
78 \def\figureword{fig.}
79
80 % Allocate a count register for the figure's number, and a box
81 % register which we'll use to measure dimensions of the image.
82 \newcount\fignumber
83 \newbox\imgbox
84
85 % Now comes the fun part--constructing the figure for the image of the
86 % \CTAN\ lion. We define a macro
87 %
88 % \fig{LABEL}{FILENAME}{CAPTION}{WIDTH}
89 %
90 % which creates a figure using LABEL for the cross-reference and
91 % hyperlink label, reading the image from file FILENAME, using CAPTION
92 % to name the figure, and WIDTH to scale the image horizontally.
93 \def\fig#1#2#3#4{%
94 % Leave some space above the figure. This will also ensure that we
95 % are in the vertical mode before we produce a |\vbox|.
96 \medskip
97 % Advance the figure number. |\global| ensures that the change to
98 % the count register is global, even when |\fig| is buried inside a
99 % group.
100 \global\advance\fignumber by 1
101 % We use |\includegraphics| (from |graphicx.sty|) to load the image,
102 % scaled to the specified width, into our ``measuring'' box
103 % |\imgbox|.
104 \setbox\imgbox = \hbox{\includegraphics[width=#4]{#2}}%
105 % To make the demo even more exciting, let's put the figure's
106 % caption to the left of the image into the |\indent| space of the
107 % new paragraph, and rotate the caption~$90^\circ$.
108 \textindent{%
109 \rotatebox{90}{F{\sc IGURE}~\the\fignumber. #3}%
110 }%
111 % Continue the paragraph by constructing a |\vbox| with the image of
112 % the lion. We use |\definexref| to define the cross-reference
113 % label.
114 \vbox{%
115 % In addition to the cross-reference label, |\definexref| will
116 % create a hyperlink destination with the same label. Therefore,
117 % we customize this destination to do what we need. We say that
118 % destination type for the hyperlink group |definexref| (to which
119 % |\definexref| belongs) should be |fitr|. This destination type
120 % will magnify the rectangle specified by the options |width|,
121 % |height| and |depth| to the PDF viewer's window. Therefore, we
122 % set those options accordingly with |\hldestopts| (notice the use
123 % of |depth| instead of |height|---we will want the rectangle to
124 % extend {\it downward}, to cover the image which will come
125 % next). Notice that these settings will be isolated within the
126 % current group (i.e., the |\vbox| we're constructing).
127 \hldesttype[definexref]{fitr}%
128 \hldestopts[definexref]{width=\wd\imgbox,height=0pt,depth=\ht\imgbox}%
129 % We define a symbolic label so that we can later refer
130 % to the figure with |\ref|. The command |\definexref| does
131 % exactly that. The last argument to |\definexref| specifies
132 % class of the label, which determines the word used by |\ref| in
133 % front of the reference text (remember that we've defined
134 % |\figureword| above).
135 \definexref{#1}{\the\fignumber}{figure}%
136 % Finally, produce the image which we've been stashing in the box
137 % register |\imgbox|.
138 \box\imgbox
139 }%
140 \medskip
141 }
142
143 % Create the figure.
144 \fig{CTANlion}{ctan_lion_350x350}{Lion in the archives}{200pt}
145
146 % Finished with the fun part, we can relax and typeset some
147 % hyperlinks. The easiest way to do that is to use the |\ref|
148 % cross-reference command. We can even pass an optional argument
149 % (|the lion in|), which will be placed before the class word (|fig.|)
150 % and become part of the link (to make sure the reader does not have
151 % to aim too hard).
152 Show me \ref[the lion in]{CTANlion}.
153
154 % If you are the restless kind, here's another way to create a
155 % hyperlink to the image: we create a link explicitly by using
156 % |\hlstart ... \hlend|. We don't specify the link type, therefore
157 % the default type |name| will be used (these are ``named links'',
158 % i.e., links pointing to destinations identified by labels). In the
159 % options argument, we specify that the border of the link should be
160 % inverted when the user clicks the link (|hlight=O|), and also set
161 % special color for this link, overriding the default dark-red. The
162 % label for the destination is the same as the cross-reference label,
163 % |CTANlion|.
164 Show me
165 \hlstart{}{hlight=O,colormodel=named,color=OliveGreen}{CTANlion}
166 the CTAN lion\hlend.
167
168 % Let's now point somewhere outside our document. Eplain homepage is
169 % a good target. In the similar spirit, let's consider two
170 % approaches. The easy one is to use the |\url| command from
171 % |url.sty|. Remember that we have customized the color of |url|
172 % hyperlinks, so this one will show up with a different color than the
173 % default dark-red.
174 Take me to \url{https://tug.org/eplain}.
175
176 % The second approach is to create an explicit URL link. We specify
177 % yet another border highlighting mode, |P|, which means that the
178 % region underneath the bounding box of the link will be drawn inset
179 % into the page. Also, let's set the color of the hyperlink to an RGB
180 % color |0.4,0.1,0.4|. Since we cannot use commas to separate the
181 % color elements inside the options parameter to |\hlstart| (commas
182 % there separate options), we have to first create a user-defined
183 % color with |\definecolor| from |color.sty|, and use that in
184 % |\hlstart|.
185 \definecolor{mycolor}{rgb}{0.4,0.1,0.4}
186
187 Take me to
188 \hlstart{url}{hlight=P,colormodel=,color=mycolor}{https://tug.org/eplain}
189 Eplain homepage\hlend.
190
191 \bye