summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex/optex/references.opm
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/luatex/optex/references.opm')
-rw-r--r--Master/texmf-dist/tex/luatex/optex/references.opm113
1 files changed, 113 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/luatex/optex/references.opm b/Master/texmf-dist/tex/luatex/optex/references.opm
new file mode 100644
index 00000000000..8eb1fba2e27
--- /dev/null
+++ b/Master/texmf-dist/tex/luatex/optex/references.opm
@@ -0,0 +1,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>}`.
+