blob: 03c8f6955caf95c96d7b26fbd95bb521f99822bf (
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
|
%% This is part of the OpTeX project, see http://petr.olsak.net/optex
\_codedecl \ref {References <2020-03-03>} % preloaded in format
\_doc ----------------------------
\`\_Xpage` `{<gpageno>}{<pageno>}` saves the parameter pair into \`\_currpage`.
Resets `\_lfnotenum`; it is used if footnotes are numbered from one at each page.
\_cod ----------------------------
\_def\_Xpage#1#2{\_def\_currpage{{#1}{#2}}\_lfnotenum=0 }
\_doc ----------------------------
Counter for the number of unresolved references \`\_unresolvedrefs`.
\_cod ----------------------------
\_newcount\_unresolvedrefs
\_unresolvedrefs=0
\_doc ----------------------------
\`\_Xlabel` `{<label>}{<text>}` saves the <text> to `\_lab:<label>` and saves
`[pg:<gpageno>]{<pageno>}` to `\_pgref:<label>`.
\_cod ----------------------------
\_def\_Xlabel#1#2{\_sdef{_lab:#1}{#2}\_sxdef{_pgref:#1}{\_ea\_bracketspg\_currpage}}
\_def\_bracketspg#1#2{[pg:#1]{#2}}
\_doc ----------------------------
\`\label``[<label>]` saves the decalred label to `\_lastlabel` and
\`\wlabel``{<text>}` uses the `\_lastlabel` and activates
`\_wref\_Xlabel{<label>}{<text>}`.
\_cod ----------------------------
\_def\_label[#1]{\_isempty{#1}\_iftrue \_global\_let \_lastlabel=\_undefined
\_else \_isdefined{l0:#1}%
\_iftrue \_opwarning{duplicated label [#1], ignored}\_else \_xdef\_lastlabel{#1}\_fi
\_fi \_ignorespaces
}
\_def\_wlabel#1{%
\_ifx\_lastlabel\_undefined \_else
\_dest[ref:\_lastlabel]%
\_printlabel\_lastlabel
\_ewref \_Xlabel {{\_lastlabel}{#1}}%
\_sxdef{_lab:\_lastlabel}{#1}\_sxdef{l0:\_lastlabel}{}%
\_global\_let\_lastlabel=\_undefined
\_fi
}
\_public \label \wlabel ;
\_doc ----------------------------
\`\ref``[<label>]` uses saved `\_lab:<label>` and prints (linked) `<text>`.
If the reference is backward 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 the first run of \TeX/ and we print a warning and
do `\_openref`.
\nl
\`\pgref``[<label>]` uses `{<gpageno>}{<pageno>}` from `\_pgref:<label>` and
prints (linked) `<pageno>` using `\_ilink` macro.
\_cod ----------------------------
\_def\_ref[#1]{\_isdefined{_lab:#1}%
\_iftrue \_ilink[ref:#1]{\_csname _lab:#1\_endcsname}%
\_else ??\_opwarning{label [#1] unknown. Try to TeX me again}%
\_incr\_unresolvedrefs \_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}%
\_incr\_unresolvedrefs \_openref
\_fi
}
\_public \ref \pgref ;
\_doc -----------------------------
Default \`\_printlabel` is empty macro (labels are not printed).
The \`\showlabels` redefines it as box with zero dimensions and
with left lapped `[<label>]` in blue 10pt `\tt` font shifted up by 1.7ex.
\_cod -----------------------------
\_def\_printlabel#1{}
\_def\_showlabels {%
\_def\_printlabel##1{\_vbox to\_zo{\_vss\_llap{\_labelfont[##1]}\_kern1.7ex}}%
\_fontdef\_labelfont{\_setfontsize{at10pt}\setfontcolor{blue}\_tt}
}
\_public \showlabels ;
\_endcode %------------------------------------------
If the references are \"forward" (i.~e. the `\ref` is used first, the destination
is created later) or if the reference text is page number then we must read
`.ref` file first in order to get appropriate information.
See section \ref[ref-file] for more information about `.ref` file concept.
|