\errorcontextlines=10000
\documentclass{article}
\usepackage[user]{zref}
\usepackage{atveryend}
\makeatletter
@ifdefinable\UD@stopromannumeral{\chardef\UD@stopromannumeral=\^^00}% \zref@newprop{labelnumber}{0}% \newcommand*\labelcount{0}% \ZREF@Robust\edef\zref@newlabel{% \xdef\noexpand\labelcount{\noexpand\number\numexpr\noexpand\labelcount+1\relax}% \noexpand\expandafter\noexpand\AddElementAndCallNewlabel\noexpand\expandafter{\noexpand\labelcount}{\ZREF@RefPrefix}% } \makeatother \ExplSyntaxOn \makeatletter \NewDocumentCommand\AddElementAndCallNewlabel {mmmm} { % #1 = number of label % #2 \@newl@bel-prefix % #3 name of label % #4 property-list of label \__MyStuff_AddElement:nn{#1}{#3} \@newl@bel{MYmapping}{#1}{#3} \@newl@bel{#2}{#3}{#4\labelnumber{#1}} } \newcommand\GetLabelNameFromLabelNumber[2]{ % #1 = number of label % #2 = tokens in case no label name is mapped to number of label \romannumeral \cs_if_exist:cTF{MYmapping@#1} { \exp_args:Nc \use_ii_i:nn {MYmapping@#1} {\exp_args:No \use_ii_i:nn}{\UD@stopromannumeral} } {\UD@stopromannumeral#2} } % Error-message in case no label name is mapped to number of label; % like zref@refused, but for prefix MYmapping instead of \ZREF@RefPrefix=Z@R: \NewDocumentCommand\LabelNumberNotMapped{m}{ % #1 = term denoting number of label \protect\G@refundefinedtrue\@latex@warning {No~zref-label~is~mapped~to~number~#1'~on~page~\thepage}
}
\makeatother
\seq_new:N \g__zrefcheck_auxfile_labelseq_seq
\cs_new:Nn __MyStuff_AddElement:nn {
\seq_gput_right:Nn \g__zrefcheck_auxfile_labelseq_seq {{#1}{#2}}
}
\NewDocumentCommand \ListOfZrefLabels {} {%
\seq_map_function:NN \g__zrefcheck_auxfile_labelseq_seq __MyStuff_PrintElement:n
}
\cs_new:Nn __MyStuff_PrintElement:n {
__MyStuff_PrintElement:nn #1
}
\cs_new:Nn __MyStuff_PrintElement:nn{
#1.\nobreakspace#2,~
}
\AfterLastShipout{\xdef\labelcount{0}\cs_set:Nn __MyStuff_AddElement:nn {}}%
\ExplSyntaxOff
\makeatletter
% For the sake of having fun define a loop which prints the names of all labels defined
% before and after the label specified as argument:
@ifdefinable\gobbletorelax{\long\def\gobbletorelax#1\relax{}}%
@ifdefinable\delivertorelax{\long\def\delivertorelax#1\relax{#1}}%
\newcommand\UD@CheckWhetherRelax[1]{%
\ifcat$\detokenize\expandafter{\gobbletorelax#1\relax}$%
\expandafter@secondoftwo\else\expandafter@firstofone\fi
{%
\ifcat$\detokenize\expandafter{\romannumeral\delivertorelax\UD@stopromannumeral#1}$%
\expandafter@firstoftwo\else\expandafter@secondoftwo\fi
{@firstoftwo}%
}%
{@secondoftwo}%
}%
\newcommand\AllPreceedingAndFollowingLabels[2]{%
\romannumeral
\zref@ifrefundefined{#1}{\UD@stopromannumeral#2}{%
\AllSubSequentLabelsLoop{#1}{%
\AllSubSequentLabelsLoop{#1}%
{\expandafter\UD@stopromannumeral@firstofone}%
{+}%
}{-}{\textbf{#1}}%
}%
}%
\newcommand\jointhem[4]{\AllSubSequentLabelsLoop{#1}{#2}{#3}{#4, #1}}%
\newcommand\jointhemexchanged[4]{\AllSubSequentLabelsLoop{#1}{#2}{#3}{#1, #4}}%
\newcommand\AllSubSequentLabelsLoop[4]{%
% #1 = name of label.
% #2 = tokens to aplly to the list of label-names gathered so far when the loop is done.
% #3 = +/- ; marker for obtaining name of following/previous label.
% #4 = list of label-names gathered so far.
\expandafter\expandafter\expandafter\UD@CheckWhetherRelax
\expandafter\expandafter\expandafter{%
\GetLabelNameFromLabelNumber{%
\number\numexpr\zref@extractdefault{#1}{labelnumber}{-2}#31\relax
}{\relax}%
}%
{#2{#4}}%
{%
\ifx#3-%
\expandafter@firstoftwo\else\expandafter@secondoftwo\fi
{\expandafter\expandafter\expandafter\jointhemexchanged}%
{\expandafter\expandafter\expandafter\jointhem}%
\expandafter\expandafter\expandafter{%
\GetLabelNameFromLabelNumber{%
\number\numexpr\zref@extractdefault{#1}{labelnumber}{-2}#31\relax
}{\relax}%
}{#2}{#3}{#4}%
}%
}%
\makeatother
\begin{document}
\hrulefill
Some text.
\hrulefill
\ListOfZrefLabels
\hrulefill
\makeatletter
LabelUndef has number \zref@extractdefault{LabelUndef}{labelnumber}{\zref@refused{LabelUndef}\textsf{-not available-}}%
LabelA has number \zref@extractdefault{LabelA}{labelnumber}{\zref@refused{LabelA}\textsf{-not available-}}%
LabelB has number \zref@extractdefault{LabelB}{labelnumber}{\zref@refused{LabelB}\textsf{-not available-}}%
LabelC has number \zref@extractdefault{LabelC}{labelnumber}{\zref@refused{LabelC}\textsf{-not available-}}%
LabelD has number \zref@extractdefault{LabelD}{labelnumber}{\zref@refused{LabelD}\textsf{-not available-}}%
LabelE has number \zref@extractdefault{LabelE}{labelnumber}{\zref@refused{LabelE}\textsf{-not available-}}%
\hrulefill
The name of label number 0 is
\GetLabelNameFromLabelNumber{0}{\LabelNumberNotMapped{0}\textsf{-not available-}}
The name of label number 1 is
\GetLabelNameFromLabelNumber{1}{\LabelNumberNotMapped{1}\textsf{-not available-}}
The name of label number 2 is
\GetLabelNameFromLabelNumber{2}{\LabelNumberNotMapped{2}\textsf{-not available-}}
The name of label number 3 is
\GetLabelNameFromLabelNumber{3}{\LabelNumberNotMapped{3}\textsf{-not available-}}
The name of label number 4 is
\GetLabelNameFromLabelNumber{4}{\LabelNumberNotMapped{4}\textsf{-not available-}}
The name of label number 5 is
\GetLabelNameFromLabelNumber{5}{\LabelNumberNotMapped{5}\textsf{-not available-}}
The name of label number 6 is
\GetLabelNameFromLabelNumber{6}{\LabelNumberNotMapped{6}\textsf{-not available-}}
The name of label number W is
\GetLabelNameFromLabelNumber{W}{\LabelNumberNotMapped{W}\textsf{-not available-}}
The name of the label which was placed after LabelC is
\GetLabelNameFromLabelNumber{%
\number\numexpr\zref@extractdefault{LabelC}{labelnumber}{-2}+1\relax
}{\LabelNumberNotMapped{%
<Number of LabelC>+1
}%
\textsf{-not available-}%
}
The name of the label which was placed after LabelE is
\GetLabelNameFromLabelNumber{%
\number\numexpr\zref@extractdefault{LabelE}{labelnumber}{-2}+1\relax
}{\LabelNumberNotMapped{%
<Number of LabelE>+1
}%
\textsf{-not available-}%
}
\hrulefill
\AllPreceedingAndFollowingLabels{LabelUndef}{\zref@refused{LabelUndef}\textsf{-not available-}}%
\AllPreceedingAndFollowingLabels{LabelA}{\zref@refused{LabelA}\textsf{-not available-}}%
\AllPreceedingAndFollowingLabels{LabelB}{\zref@refused{LabelB}\textsf{-not available-}}%
\AllPreceedingAndFollowingLabels{LabelC}{\zref@refused{LabelC}\textsf{-not available-}}%
\AllPreceedingAndFollowingLabels{LabelD}{\zref@refused{LabelD}\textsf{-not available-}}%
\AllPreceedingAndFollowingLabels{LabelE}{\zref@refused{LabelE}\textsf{-not available-}}%
\hrulefill
\zref@labelbylist{LabelA}{main}%
\zref@labelbylist{LabelB}{main}%
\zref@labelbylist{LabelC}{main}%
\zref@labelbylist{LabelD}{main}%
\zref@labelbylist{LabelE}{main}%
\end{document}
\zlabel(is that what you are suggesting?), I'd have the order in which the labels occur in the source. If you check the aux of the MWE, the label tofig:figure-1:referenceoccurs before the onefig:figure-1. This is inverted relative to the sequence they occur in the document, because of the float, of course. And it is that inversion I'm trying to capture. Is there any other way you know of? – gusbrs Jul 08 '21 at 20:55zrefis indeed pretty cool, thanks again for the tip. I do miss thehyperrefsupport, but I'm having lots of fun with it. – gusbrs Jul 08 '21 at 20:57\ZREF@labelby stepping a counter in the second argument of\protected@write(the same way\ZREF@labeldoes it's stuff) to try to capture the "shipout sequence". And added that counter to a starred version of\zref@newprop*{shipoutseq}. However, for reasons I do not understand, all the steps of the counter would run once per page "en block", so that I missed precisely the information I wanted, which is the relative position within the page. – gusbrs Jul 08 '21 at 21:06\zsaveposmacro, because I want to get the position of a regular\zlabel, again, at the position it occurs on the page, so if we wanted to use\zsaveposwe'd have to hack\caption, not\zlabel). But it may fail in cases such as columns and so on. Anyway, are you saying the order labels in the aux file is useless? Or that "I'd better not" try to retrieve it this way? I think it makes sense, but... – gusbrs Jul 08 '21 at 21:25variorefhas a solution to that. I'd be willing to pay the computational price (if it works, and if there's no equivalent better alternative). Anyway, at this point I'm at a "playing with stuff" stage. I'd like to try this. – gusbrs Jul 08 '21 at 21:58\cs_gset_protected:Npn \zref@newlabel #1#2 { \seq_gput_right:Nn \g__zrefcheck_auxfile_labelseq_seq {#1} \@newl@bel {Z@R} {#1} {#2}}. – Ulrike Fischer Jul 08 '21 at 22:11\ProvidesExplPackageand completely forgot\makeatletterwhen transposing things to the MWE, sorry. But, your definition does work. Thank you very much! If you'd like to convert it to an answer, I'd happily accept it. :-) – gusbrs Jul 08 '21 at 22:27begindocumentto a property list, so that I can retrieve the index pretty much as I would extract a zlabel's property value every time I want to compare any two labels. – gusbrs Jul 08 '21 at 23:33\labelalso writes the name of the last named destination placed into the .pdf-file and the heading of the last section or the like. The further is in\@currentHref. The latter is in\@currentlabelname. If loading both hyperref and zref you can use\@currentHref/\@currentlabelnamefor new zref-properties and this way bring info about destination-names/sections into zref-labels. Then you can easily retrieve this info for defining your own zref-referencing-commands that create hyperlinks. But I wouldn't do this... – Ulrich Diez Jul 12 '21 at 20:41\label-command and labels created by zref may have the same name. Therefore it might be more easy to write commands that create both a normal label (bringing along hyperref-functionality) and a zref-label at the same time. – Ulrich Diez Jul 12 '21 at 20:43zref'shyperrefsupport, since I commented. It is actually viable, even if somewhat bare-bones, out of the box.zref's documentation states about the hyperref module "UNFINISHED :-(" (literally that). However, theanchorproperty is implemented! So, if you do load the module, you get the anchor in the mainlist. And you can build a link to that withhyperref's\hyperlink. It works! – gusbrs Jul 12 '21 at 20:53