summaryrefslogtreecommitdiff
path: root/tex/context/base/core-ref.mkii
blob: a5937726a16e9638a2336701d12816e673c546f4 (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
%D \module
%D   [       file=core-ref,
%D        version=2008.10.14,
%D          title=\CONTEXT\ Core Macros,
%D       subtitle=Cross Referencing,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\unprotect

\def\rawreference#1#2#3%
  {\bgroup
   \the\everyreference
   \makesectionformat
   \writereference{#2}
     {\sectionformat\sectionseparator\sectionseparator\noexpand\pagenumber}%
     {\noexpand\realfolio}%
     {#3}%
   \egroup}

\def\rawpagereference#1#2%
  {\bgroup
   \the\everyreference
   \makesectionformat
   \writereference{#2}
     {\sectionformat\sectionseparator\sectionseparator\noexpand\pagenumber}%
     {\noexpand\realfolio}%
     {}%
   \egroup}

\def\rawtextreference#1#2#3%
  {\bgroup
   \the\everyreference
   \writereference{#2}
     {}%
     {\noexpand\realfolio}%
     {#3}%
   \egroup}

%D The last reference is saved in a macro named \type
%D {\lastreference} (indeed). To keep track of the order of
%D references, later we will see for what purpose, we maintain
%D a counter.

\newcount\crossreferencenumber \crossreferencenumber\plusone

\let\lastreference\empty

\def\writereference#1#2#3#4%
  {\ifreferencing
     \edef\!!stringa{#1}%
     \ifx\!!stringa\empty \else
       \def\dowritereference##1%
         {\xdef\lastreference{##1}%
          \@EA\dodowritereference\lastreference\empty\empty\end{#2}{#3}{#4}}%
       \rawprocesscommalist[\!!stringa]\dowritereference
     \fi
   \fi}

%D Beware: \type {#2} gobbles space in references so that
%D \typ {a nice ref} becomes \typ {anice ref}.

\def\dodowritereference#1#2#3\end#4#5#6%
  {\bgroup
   \global\advance\crossreferencenumber \plusone\relax
   \if#1-\if#2:%
     \let\referenceprefix\empty
     \xdef\lastreference{#3}%
   \else
     % \xdef\lastreference{#1#2#3}% here we loose the space
   \fi\else
     % \xdef\lastreference{#1#2#3}% here we loose the space
   \fi
   \ifx\lastreference\empty \else
     \doiffirstreferenceoccurance\lastreference
       {\thisisdestination{\referenceprefix\lastreference}}%
     \referenceinfo>\lastreference
     \expanded{\writeutilitycommand{\noexpand\mainreference{\referenceprefix}{\lastreference}{#4}{#5}{#6}}}%
   \fi
   \egroup}

%D We will implement \type {\doiffirstreferenceoccurance}
%D later on.

\protect