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