Debian Codegraph @

texmf-dist/tex/optex/base/references.opm

raw
1 %% This is part of the OpTeX project, see http://petr.olsak.net/optex
2
3 \_codedecl \ref {References <2023-07-03>} % preloaded in format
4
5 \_doc ----------------------------
6 \`\_Xpage` `{<gpageno>}{<pageno>}` saves the parameter pair into \`\_currpage`.
7 Resets `\_lfnotenum`; it is used if footnotes are numbered from one at each page.
8 \_cod ----------------------------
9
10 \_def\_Xpage#1#2{\_def\_currpage{{#1}{#2}}\_lfnotenum=0 }
11
12 \_doc ----------------------------
13 Counter for the number of unresolved references \`\_unresolvedrefs`.
14 It is set but unused in OpTeX versions 1.04+. You can add the report, for
15 example:
16 \begtt
17 \_addto\_byehook{\_ifnum\_unresolvedrefs>0 \_opwarning
18 {There are \_the\_unresolvedrefs\_space unresolved references}\_fi}
19 \endtt
20 \_cod ----------------------------
21
22 \_newcount\_unresolvedrefs
23 \_unresolvedrefs=0
24
25 \_doc ----------------------------
26 \`\_Xlabel` `{<label>}{<text>}` saves the <text> to `\_lab:<label>` and saves
27 `{<gpageno>}{<pageno>}` to `\_pgref:<label>`.
28 \_cod ----------------------------
29
30 \_def\_Xlabel#1#2{\_sdef{_lab:#1}{#2}\_sxdef{_pgref:#1}{\_currpage}}
31
32 \_doc ----------------------------
33 \`\label``[<label>]` saves the declared label to \`\_lastlabel` and
34 \`\wlabel``{<text>}` uses the `\_lastlabel` and activates
35 `\_wref\_Xlabel{<label>}{<text>}`.
36 \_cod ----------------------------
37
38 \_def\_label[#1]{\_isempty{#1}\_iftrue \_glet \_lastlabel=\_undefined
39 \_else \_isdefined{l0:#1}%
40 \_iftrue \_slideshook\_opwarning{Duplicated label [#1], ignored}\_else \_xdef\_lastlabel{#1}\_fi
41 \_fi \_ignorespaces
42 }
43 \_let \_slideshook=\_relax % redefined if \slides + \slideshow.
44 \_def\_wlabel#1{%
45 \_ifx\_lastlabel\_undefined \_else
46 \_dest[ref:\_lastlabel]%
47 \_printlabel\_lastlabel
48 \_ewref \_Xlabel {{\_lastlabel}{#1}}%
49 \_sxdef{_lab:\_lastlabel}{#1}\_sxdef{l0:\_lastlabel}{}%
50 \_glet\_lastlabel=\_undefined
51 \_fi
52 }
53 \_public \label \wlabel ;
54
55 \_doc ----------------------------
56 \`\ref``[<label>]{<given-text>}` prints (linked) `<given-text>`.
57 The missing optional `{<given-text>}` is replaced by `{@}`. The `@` is
58 replaced by `<implicit-text>` from saved `\lab:<label>` using \^`\_reftext` macro.
59 If the reference is backward then we know `\lab:<label>` without any need
60 to read REF file. On the other hand, if the reference is forwarded, then we
61 doesn't know `\_lab:<label>` in the first run of \TeX/ and we print a warning and
62 do `\_openref`.
63 \nl
64 \`\pgref``[<label>]{<given-text>}` prints `<given-text>` where `@` is
65 replaced by <pageno>. Data in the format `{<gpageno>}{<pageno>}`
66 are read from `\_pgref:<label>` by \`\_pgrefB``{<gpageno>}{<pageno>}{<given-text>}`.
67 \nl
68 \`\_lastreflabel` keeps the value of the last label read by \^`\ref` or \^`\pgref`.
69 You can use it for example by definig a macro \`\pgr` by `\def\pgr{\pgref[\_lastreflabel]}`
70 and then you need not repeat the same label in typical situations and you
71 can write for instance: `see section \ref[lab] at page \pgr.`
72 \_cod ----------------------------
73
74 \_def\_ref[#1]{\_xdef\_lastreflabel{#1}\_isnextchar\_bgroup{\_refA}{\_refA{@}}}
75 \_def\_refA #1{\_isdefined{_lab:\_lastreflabel}%
76 \_iftrue \_ilink[ref:\_lastreflabel]{\_reftext{\_csname _lab:\_lastreflabel\_endcsname}{#1}}%
77 \_else \_reftext{??}{#1}\_opwarning{label [\_lastreflabel] unknown. Try to TeX me again}%
78 \_incr\_unresolvedrefs \_openref
79 \_fi
80 }
81 \_def\_pgref[#1]{\_xdef\_lastreflabel{#1}\_isnextchar\_bgroup{\_pgrefA}{\_pgrefA{@}}}
82 \_def\_pgrefA #1{\_isdefined{_pgref:\_lastreflabel}%
83 \_iftrue \_ea\_ea\_ea\_pgrefB \_csname _pgref:\_lastreflabel\_endcsname{#1}%
84 \_else \_reftext{??}{#1}\_opwarning{pg-label [\_lastreflabel] unknown. Try to TeX me again}%
85 \_incr\_unresolvedrefs \_openref
86 \_fi
87 }
88 \_def\_pgrefB #1#2#3{\_ilink[pg:#1]{\_reftext{#2}{#3}}}
89
90 \_public \ref \pgref ;
91
92 \_doc -----------------------------
93 \`\_reftext``{<implicit-text>}{<given-text>}` expands to the <given-text>
94 but the optional `@` in the `<given-text>` is replaced by the `<implicit-text>` first.
95 \_cod -----------------------------
96
97 \_def\_reftext #1#2{\_isatin #2@\_iffalse \_numprint{#2}\_else\_reftextA{#1}#2\_fin \_fi}
98 \_def\_reftextA #1#2@#3\_fin {#2\_numprint{#1}#3}
99 \_def\_isatin #1@#2\_iffalse {\_ifx\_fin#2\_fin}
100
101 \_doc -----------------------------
102 Default \`\_printlabel` is empty macro (labels are not printed).
103 The \`\showlabels` redefines it as box with zero dimensions and
104 with left lapped `[<label>]` in blue 10pt `\tt` font shifted up by 1.7ex.
105 The color of labels is set by \`\_labelcolor` (default is RGB blue).
106 \_cod -----------------------------
107
108 \_def\_printlabel#1{}
109 \_def\_labelcolor{\_setrgbcolor{0 0 1}}
110 \_def\_showlabels {%
111 \_def\_printlabel##1{\_vbox to\_zo{\_vss\_llap{\_labelcolor\_labelfont[##1]}\_kern1.7ex}}%
112 \_fontdef\_labelfont{\_setfontsize{at10pt}\_tt}
113 }
114 \_public \showlabels ;
115
116 \_endcode %------------------------------------------
117
118
119 If the references are \"forward" (i.~e. the `\ref` is used first, the destination
120 is created later) or if the reference text is page number then we must read
121 `.ref` file first in order to get appropriate information.
122 See section \ref[ref-file] for more information about `.ref` file concept.
123
124 \_endinput
125
126 2023-07-03 ... obsolete \setfontcolor not used in \showlabels
127 2022-01-22 ... extended format for \ref, \pgref
128 2021-04-13 ... \_slideshook introduced (used by \slides)
129 2020-03-03 ... released