summaryrefslogtreecommitdiff
path: root/doc/context/sources/general/magazines/mag-1103-mkiv.tex
blob: 90a5f08487040da6d17c4c8df8e9800c841f62ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
% language=uk

% author    : Hans Hagen
% copyright : PRAGMA ADE & ConTeXt Development Team
% license   : Creative Commons Attribution ShareAlike 4.0 International
% reference : pragma-ade.nl | contextgarden.net | texlive (related) distributions
% origin    : the ConTeXt distribution
%
% comment   : Because this manual is distributed with TeX distributions it comes with a rather
%             liberal license. We try to adapt these documents to upgrades in the (sub)systems
%             that they describe. Using parts of the content otherwise can therefore conflict
%             with existing functionality and we cannot be held responsible for that. Many of
%             the manuals contain characteristic graphics and personal notes or examples that
%             make no sense when used out-of-context.
%
% comment   : Some chapters might have been published in TugBoat, the NTG Maps, the ConTeXt
%             Group journal or otherwise. Thanks to the editors for corrections. Also thanks
%             to users for testing, feedback and corrections.

\usemodule[mag-01,abr-02]

\startbuffer[abstract]
    The (cross) reference mechanism in \CONTEXT\ is rather complex (in terms of
    code) and provides a lot of functionality. Of course one can ask for page
    numbers, section numbers, titles, or arbitrary text, but also control the
    viewer, go to locations and have chains of actions. In this document we only
    discuss some aspects of cross document referencing. This is not a complete
    manual.
\stopbuffer

\startdocument
  [title={Cross document referencing},
   author=Hans Hagen,
   affiliation=PRAGMA ADE,
   date=September 2011,
   number=1103 \MKIV]

\subject{Other documents}

A straightforward way to refer to something in an other document is by prefixing
the reference by a document tag. Take for instance:

\startscite[tex]
\in{chapter}[other::whatever]
\stopscite

Here, \type {other} is either a tag or a filename. In the case if a tag, you also
need a definition like:

\startscite[tex]
\useexternalfile[other][somefilename]
\stopscite

Because we load the references of the other file (when present), you can also ask
for titles of chapters. In fact, all the following work:

\startscite[tex]
\at      {page}[other::whatever]
\in   {chapter}[other::whatever]
\about         [other::whatever]
\goto{location}[other::whatever]
\stopscite

given of course that in the other file we have set a reference:

\startscite[tex]
\startchapter[reference=whatever,title={Who cares}]
  ...
\stopchapter
\stopscite

In \MKIV\ this mechanisms has been extended to deal with products and components.
In order not to get clashes between references in multiple chapters, you can do
something like this:

\startscite[tex]
\setuphead[chapter][referenceprefix=whatever]
\stopscite

This will create a namespace for this chapter. A more automated alternative is:

\startscite[tex]
\setuphead[chapter][referenceprefix=+]
\stopscite

Here the given reference (\type {whatever}) will automatically become the
namespace for that chapter.

\subject{Products and components}

This is however somewhat cumbersome when we deal with a project structure. There
we have the complication that we can process components within a product and
although one will only do this for proofing it makes sense at least to deal with
references in other components.

In the test suite there are four files demonstrating what is possible. They can
be recognized by the name \type {cross-*.tex}. The product file \type {cross-100}
includes two components:

\startscite[tex]
\startproduct cross-100

    \component cross-001
    \component cross-002

\stopproduct
\stopscite

In these components there are references to the other component. The cross
reference mechanism will automatically use the component's name as namespace but
only when you say:

\startscite[tex]
\setupreferencing[autofile=yes]
\stopscite

A component looks as follows:

\startscite[tex]
\setupreferencing[autofile=yes]
\setupinteraction[state=start]

\startcomponent cross-001

\product cross-100

\startchapter[title=One,reference=one]
  ...
\stopchapter

\stopcomponent
\stopscite

When a component is processed, the references of the product are also loaded.
Actually, some more information fetched so that for instance the chapter number
gets set as well as the page number.

Of course this will not guarantee that all referencing turns out right, but it's
better than nothing. There are now several ways to refer to something, and as we
have quite some fallback heuristics in place all the following will work out
well. However, keep in mind that when multiple \type {one}'s are uses you might
end up with the wrong one when no prefix is given.

\startscite[tex]
\at      {page}[one]
\in   {chapter}[one]
\about         [one]
\goto{location}[one]

\at      {page}[cross-001:one]
\in   {chapter}[cross-001:one]
\about         [cross-001:one]
\goto{location}[cross-001:one]

\at      {page}[cross-001::one]
\in   {chapter}[cross-001::one]
\about         [cross-001::one]
\goto{location}[cross-001::one]

\at      {page}[cross-001:::one]
\in   {chapter}[cross-001:::one]
\about         [cross-001:::one]
\goto{location}[cross-001:::one]
\stopscite

So what do the (subtle) differences in colons mean? The \type {cross-001:} prefix
is just a prefix. Such a prefix is not always related to a document but it
happens that when no other match is found, an extra check takes place to see if
it is a component namespace. This is new per September 2011.

The \type {cross-001::} prefix is the official way to refer to another document
and this is no news. However, the \type {cross-001:::} prefix is new and
depending on how the document is run, is either a regular namespace prefix (one
colon) or an external reference (two colons). When you use the project structure
this might be the best way to go. The reason is that order of looking (and
fallbacks) is better defined this way.

So, given that you have a proper usage of product and components, the following
method is to be preferred:

\startscite[tex]
\at     {page}[other:::one] in \from[other]
\in   chapter}[other:::one] of \from[other] (\about[other:::one])
\goto{details}[other:::one]
\stopscite

Keep in mind that in most cases a combination of components and extra prefixes
(that is, explicitly set prefixes) work ok. The prefixing mechanism is controlled
with:

\startscite[tex]
\setupreferencing[prefix=blabla]
\stopscite

but you will seldom need this command. In order to prevent clashes you can best
use some redundancy:

\startscite[tex]
\placefigure[here][fig:foo]{}{}{}
\placetable [here][tab:foo]{}{}{}
\stopscite

works out quite well.

\subject{Reference commands}

In \MKII\ the main reference mechanism handled not only user references but also
stored section numbers, section titles, captions and all that made sense to refer
to. In \MKIV\ we carry around way more information and references are stored in
and retrieved from several data structures. Although we keep much more
information in memory and store more information in the auxiliary file, we save
some too because now (for instance) section titles are stored only once.

The following two commands store an explicit reference, unrelated to a structural
component. However, with the page number we also store information about the
current section so that we can add a prefix any time we want.

\startscite[tex]
\textreference[sometag]{some text}
\pagereference[sometag]
\stopscite

Keep in mind that these commands insert a so called node so they can best be
attached to some content in order not to dangle around and interfere with
spacing. The following works okay:

\startscite[tex]
\dontleavehmode\textreference[ward]{Quoting Ward}\input ward
\stopscite

A rather low level (not interactive) fetching can be done as follows:

\startscite[tex]
\ref[text][sometag]
\ref[page][sometag]
\stopscite

We already saw some more advanced commands to retrieve reference data:

\startscite[tex]
\at      {page}[one]
\in   {chapter}[one]
\about         [one]
\goto{location}[one]
\stopscite

These commands will create a hyperlink when interactivity is turned on.

The \type {\at} command typesets the page number and the \type {\in} command
typesets a number. The \type {\about} command deals with the title. In the case
of a regular reference the last two commands do a similar thing but the last one
adds quotes (by default). The \type {\goto} command only has a meaning in
interactive documents. It does not add anything to the text.

In interactive mode all these commands will apply a so called contrast color in
case the reference refers to the page itself.

There are two commands that relate to current location:

\startscite[tex]
\somewere{before}{current}{after}[one]
\atpage[one]
\stopscite

The first command typesets one of the three texts, which one depends of the
typeset and referred \type {one} being on the same page. The second command
generates a text automatically.

Although not related to the kind of references we discuss here, you can define
symbolic references with:

\startscite[tex]
\definereference[symbolic name][real reference]
\resetreference[symbolic name]
\stopscite

Using this only makes sense in interactive documents where we can have special
operations with arguments and combinations of such references.

\subject{Reference formats}

You can control the formatting of references in detail using the setup command.
For instance you can tweak the way sections numbers are prefixed but as this
relates to numbering this will not be discussed here. Reference formats are
another way to control the rendering

\startscite[tex]
\definereferenceformat[informula]  [left=(,right=),text=formula]
\definereferenceformat[informulas] [left=(,right=),text=formulas]
\definereferenceformat[andformula] [left=(,right=),text=and]
\definereferenceformat[andformulas][left=(,right=),text=and]

\informula [b] and \informula [for:c]
the \informula {formulas}[b] \informula {and} [for:c]
the \informulas {formulas}[b] \informula {and} [for:c]
the \informulas [b] \informula {en} [for:c]
the \informulas [b] \andformula [for:c]
\stopscite

Instead of a text, one can specify a label, which should be defined with \type
{\setuplabeltext}.

\subject{User references}

You can create user references too. This is done with the following command:

\startscite[tex]
\setreference[myref][key-1=value-1,key-2=value-2]
\stopscite

You can then ask for keys using:

\startscite[tex]
\getreference[myref][key-2]
\stopscite

In principle you can add filters and rendering variants as well using \LUA\ code
but that is rather specialized and often not needed.

\stopdocument