blob: e16e89ab7b57a3b82c8f20d1dd905352bb2fe1a5 (
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
|
%% This is part of OpTeX project, see http://petr.olsak.net/optex
\_codedecl \_openref {references <2020-02-14>}
\_newwrite\_reffile
\_def\_wrefrelax#1#2{}
\_let\_wref=\_wrefrelax
\_def\_inputref {%
\_isfile{\_jobname.ref}\_iftrue
\input {\jobname.ref}
\_fnotenum=0 \_mnotenum=0
\_openrefA{\_string\inputref}%
\_fi
}
\_def\_openref {%
\_ifx \_wref\_wrefrelax \_openrefA{\_string\openref}\_fi
\_gdef\_openref{}%
}
\_def\_openrefA #1{%
\_immediate\_openout\_reffile="\_jobname.ref"\_relax
\_gdef\_wref ##1##2{\_write\_reffile{\_string##1##2}}%
\_immediate\_write\_reffile {\_pcent\_pcent\_space OPTeX - REF file (#1)}%
\_immediate\_wref \_Xrefversion{{\_REFversion}}%
}
\_def\_REFversion{3}
\_def\_Xrefversion#1{\_ifnum #1=\_REFversion\_relax \_else \_endinput \_fi}
\_def\_Xprocess#1{#1}
\_public \Xrefversion ;
\_endcode % -------------------------------------
The `\_inputref` macro is used in `\everyjob`. It reads `\jobname.ref` file
if it exists. After the file is read then it is removed and opened to write
a new contents to this file.
If the file does not exists then it is not created. It means that if you
process a document without any forward references then no `\jobname.ref`
file is created because it is unusable. The `\_wref` macro is unusable in
such case.
If a macro needs to ceate and to use REF file then such file must be created by
`\_openref`. When the file is created (using internal `\_openrefA`) then
`\_opneref` destroys itself, because we need not to open the file again.
We are using a convention that the macros used in REF file are named
`\_X<foo>`. If there is a new wersion of \OpTeX/ with different collection
of such macros then we don't want to read the REF files produced by an
old version of \OpTeX/. So first line of REF line is in the form
\begtt
\_Xrefversion{<version>}
\endtt
We can check the verion compatibility by this macro.
User can write the `\_openref\_wref\_Xpocess{<comething>}` at beginning of
the document if he/she needs to define a macros used in REF file later.
|