blob: 8eb1fba2e27393bdf0fc04f5379a05ae2e22e18c (
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
|
%% This is part of OpTeX project, see http://petr.olsak.net/optex
\_codedecl \ref {references <2020-02-22>}
%> \_Xpage
\_newcount\_lastpage \_lastpage=0 % the last page of the document
\_newcount\_fnotenumlocal
\_def\_Xpage#1#2{\_def\_currpage{{#1}{#2}}\_lastpage=#2 \_fnotenumlocal=0 }
%> \_Xlabel
\_def\_Xlabel#1#2{\_sdef{_lab:#1}{#2}\_sxdef{_pgref:#1}{\_ea\_bracketspg\_currpage}}
\_def\_bracketspg#1#2{[pg:#1]{#2}}
%> \label \wlabel
\_def\_label[#1]{\_isdefined{l0:#1}%
\_iftrue \_opwarning{duplicated label [#1], ignored}\_else \_xdef\_lastlabel{#1}\_fi
\_ignorespaces
}
\_def\_wlabel#1{%
\_ifx\_lastlabel\_undefined \_else
\_dest[ref:\_lastlabel]%
\_edef\_tmp{{\_lastlabel}{#1}}%
\_ea\_wref \_ea\_Xlabel \_ea{\_tmp}%
\_sxdef{_lab:\_lastlabel}{#1}\_sxdef{l0:\_lastlabel}{}%
\_global\_let\_lastlabel=\_undefined
\_fi
}
%> \ref \pgref
\_def\_ref[#1]{\_isdefined{_lab:#1}%
\_iftrue \_ilink[ref:#1]{\_csname _lab:#1\_endcsname}%
\_else ??\_opwarning{label [#1] unknown. Try to TeX me again}\_openref
\_fi
}
\_def\_pgref[#1]{\isdefined{_pgref:#1}%
\_iftrue \_ea\_ea\_ea\_ilink \_csname _pgref:#1\_endcsname
\_else ??\_opwarning{pg-label [#1] unknown. Try to TeX me again}\_openref
\_fi
}
%> \begoutput
\addto\_begoutput{%
\_incr \_gpageno % global pageno from one independent on pagination
\immediate\_wref\_Xpage{{\the\gpageno}{\_the\_pageno}}%
}
\_newcount\_gpageno
\_public
\label \wlabel \ref \pgref \gpageno ;
\_endcode % -------------------------------------
The REF file looks like:
\begtt
\_Xpage{<gpageno>}{<pageno>}
\_Xlabel{<label>}{<text>}
\_Xlabel{<label>}{<text>}
\_Xlabel{<label>}{<text>}
...
\_Xpage{<gpageno>}{<pageno>}
\_Xlabel{<label>}{<text>}
...
\endtt
where <gpageno> is internal page number numbered from one and <pageno> is
a page number used in pagination. Each page begins with `\_Xpage`.
The <label> is <label> used by user in `\label[<label>]` and <text> is a
<text> which shoul be referenced (the number of section or table, for
example).
The REF file is scanned at the begining of the document using `\inputref`
invoked by `\everyjob`.
\%> \_Xpage
`\_Xpage {<gpageno>}{<pageno>}` saves the patameter pair into `\_currpage`
and actualizes `\lastpage`. Resets `\_fnotenumlocal` used if footnotes are
numbered from one at each page.
\%> \_Xlabel
`\_Xlabel {<label>}{<text>}` saves <text> to `\_lab:<label>` nad saves
`[<gpageno>]{<pageno>}` to `\_pgref:<label>`.
\%> \label \wlabel
`\label[<label>]` saves decalred labet to `\_lastlabel` and `\wlabel{<text>}`
uses `\lastlabel` and activetes `\wref\_Xlabel{<label>}{<text>}`.
\%> \ref \pgref
`\ref[<label>]` uses saved `\_lab:<label>` and prints (linked) <text>.
If the reference is backwarded then we know `\lab:<label>` without any need
to read REF file. On the other hand, if the reference is forwarded, then we
doesn't know `\_lab:<label>` in first run of \TeX/ and we print warning and
do `\_openref`.
`\pgref[<label>]` uses `{<gpageno>}{<pageno>}` from `\_pgref:<label>` and
prints (linked) <pageno> using `\_ilink` macro.
\%> \begoutput
We add to `\_begoutput` incrementing `<gpageno>` and writting
`\_Xpage {<gpageno>}{<pageno>}`.
|