%% 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`. 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{} \endtt We can check the verion compatibility by this macro. User can write the `\_openref\_wref\_Xpocess{}` at beginning of the document if he/she needs to define a macros used in REF file later.