They work nicely for me. I haven't looked at the code in years, so there may be some dependencies, likely minor, maybe just in documentation, on some of my other macros.
There may be some subtle bugs, but I haven't found any. If you find a bug and know just what usage encounters the bug, then don't do that usage again! Or fix the bug!
There is enough documentation so that you can see the ideas -- actually they are all quite simple. The macros were a good TeX exercise.
\newread\XREFileIn
% \message{\string\XREFileIn = \the\XREFileIn}
\newwrite\XREFileOut
%
\newcount\SNChapter
\newcount\SNUnit
\newcount\SNTable
\newcount\SNFigure
%
\SNChapter=0
\SNTable=0
\SNFigure=0
%
\def\SNChapterPrefix{}
%
\def\TrimTag#1 {#1} % For trimming trailing blanks.
\def\First#1 #2 #3 {#1} % Parsing first token.
\def\Second#1 #2 #3 {#2} % " second "
\def\Third#1 #2 #3 {#3} % " third "
\def\SNUNone{CH UN PG} % Value for tags before there is an XRF file.
\def\SNTNone{TB JUNK PG} % Value for tags before there is an XRF file.
\def\SNFNone{FG JUNK PG} % Value for tags before there is an XRF file.
\def\SNPNone{PT JUNK PG} % Value for tags before there is an XRF file.
%
\def\SNUAdvanceChapter{\advance\SNChapter by1
\SNUnit=0}
%
% Define a 'chapter' tag:
%
% Need a \global on \advance because might have the \SNC from
% within a group, e.g., {\bf \SNC ...}.
%
\def\SNC#1{{\global\SNUnit=0
\write\XREFileOut{\string#1}%
\def\JUNKA{\SNChapterPrefix\the\SNChapter\space JUNK}%
{\edef\JUNKB{\write\XREFileOut{\JUNKA}}\JUNKB}%
\write\XREFileOut{\the\count0}}}%
%
% Define a 'unit' tag:
%
% To be more sure page number is correct, add text to list
% BEFORE writing page number to XRF file. In principle could
% do the same for \SNT and \SNF but from how these are used in
% practice a page number error would be nearly impossible.
%
\def\SNU#1{{\global\advance\SNUnit by1
\write\XREFileOut{\string#1}%
\SNChapterPrefix\the\SNChapter.\the\SNUnit
\def\JUNKA{\SNChapterPrefix\the\SNChapter\space\the\SNUnit}%
{\edef\JUNKB{\write\XREFileOut{\JUNKA}}\JUNKB}%
\write\XREFileOut{\the\count0}}}%
%
% BEGIN Modified at 04:16:31 on Tuesday, December 29th, 2015.
%
% In this collection, we now have a new
% macro
%
% \SNP -- Sequentially Number Pointer
%
% This macro intended for cross
% referencing to a place in text, that
% is not specifically to a 'unit'
% (definition, theorem), table, or
% figure.
%
% In short, can have
%
% Note\SNP{\SNTagCU}
% that, for $a, b \in R$ and
%
% which will define tag \SNTagCU but
% insert nothing into the document.
%
% Then elsewhere can have
%
% Since as on page
% \SNCGetPage{\SNTagCU}
% an inner product is bilinear,
%
% which will insert into the document
% the page number of the page where the
% macro \SNTagCU was defined. Many
% more details below:
%
% The macro \SNP is part of this
% package of cross referencing and
% sequential numbering but does not
% actually 'number' or 'sequentially
% number' anything. We start the name
% of \SNP with 'SN' just to regard
% macro names of the form SNx as
% 'reserved' in own TeX usage.
%
% Then elsewhere in the document, can
% refer to that place by its page
% number, chapter number (apparently
% with its chapter prefix), etc.
%
% E.g., if give a little discussion of,
% say, bilinear, can type, say,
%
% Note\SNP{\SNTagCU}
% that, for $a, b \in R$ and
%
% and that will just 'define' tag
% SNTagCU. Of course the tag SNTagCU
% was likely from running own KEdit
% macro isntag to find the new tag name
% SNTagCU and insert it in the argument
% of the macro \SPP. That is, in KEdit
% we would have line
%
% Note\SNP{}
%
% current, run KEdit macro isntag, and
% get a new tag found an inserted to
% have something like
%
% Note\SNP{\SNTagCU}
%
% Then elsewhere in the document can
% write, say,
%
% Since as on page
% \SNCGetPage{\SNTagCU}
% an inner product is bilinear,
%
% and get the page number of the page
% in the document with
%
% Note\SNP{\SNTagCU}
%
% that is, where tag \SNTagCU was
% defined.
%
% So, the lines
%
% Note\SNP{\SNTagCU}
% that, for $a, b \in R$ and
%
% write to the XRF file the standard
% three lines that would be written by,
% say, macro \SNU. With those three
% lines, the first has the tag
%
% \SNTagCU
%
% the next line has chapter and unit
% and the third line has the page
% number, all for what was the case for
% that part of that page when the macro
% \SNP was run.
%
% Then, macros
%
% \SNUGetChapter\SNTagCU
% \SNUGetUnit\SNTagCU
% \SNUGetPage\SNTagCU
%
% will all work fine to extract the
% data on, respectively, chapter, unit,
% and page and insert it into the
% document. That is, there is no
% reason to have separate macros to
% extract and for macro \SNP.
%
% Really the macro \SNP is just like
% macro \SNU except does not add 1 to
% SNUnit and does not insert into the
% document the chapter prefix, chapter
% number, and unit number. So, where
% macro \SNP is used, nothing is
% inserted into the document; this is
% in contrast with, say, macro \SNU and
% is why need the new macro \SNT
%
% XREF001.TEX --
%
% Created at 02:29:35 on Thursday, April 13th, 2006.
% ======================================================================
%
% Modified at 01:03:52 on Thursday, April 13th, 2006.
%
% Macros for sequential numbering and cross-references
%
% Macros \SNUAdvanceChapter, \SNU#1, \SNT#1, \SNF#1,
% \GetSN, \SNC#1, \SNCGetChapter#1, \SNCGetPage#1,
% \SNUGetChapter#1, \SNUGetUnit#1, \SNUGetPage#1,
% \SNTGetTable#1, \SNTGetPage#1, \SNFGetFigure#1,
% \SNFGetPage#1, \SNChapterPrefix
%
% Counters \SNChapter, \SNUnit, \SNTable, \SNFigure,
%
% Here SN abbreviates 'sequential numbering'.
%
% Here we have a start on a fairly general collection of
% macros for sequential numbering and cross-referencing.
%
% For example, maybe in some chapter, that at present is
% chapter 3, we want to sequentially number definitions,
% theorems, remarks, and examples -- call them all 'units'
% -- as in:
%
% 3.1 Definition:
%
% 3.2 Theorem:
%
% 3.3 Definition:
%
% 3.4 Remark:
%
% 3.5 Example:
%
% Then with this package we would select some tags, say,
% starting with SNTag, and type
%
% \SNU{\SNTagA} Definition:
%
% \SNU{\SNTagB} Theorem:
%
% \SNU{\SNTagC} Definition:
%
% \SNU{\SNTagD} Remark:
%
% \SNU{\SNTagE} Example:
%
% So, macro \SNU abbreviates 'sequential numbering with
% units'. So, with macro \SNU we get a case of automatic
% sequential numbering.
%
% Suppose 3.1 Definition: appeared on page 43. Then
% elsewhere we could write
%
% See \SNUGetChapter\SNTagA.\SNUGetUnit\SNTagA Theorem
% on page \SNUGetPage\SNTagA.
%
% and get
%
% See 3.1 Theorem on page 43.
%
% So, we get automatic cross-referencing.
%
% Of course, to do cross-referencing in such a general way,
% need to run TeX at least twice, once to find, for each
% sequentially numbered 'unit', its page and write this
% data to a file, and once to read this file and insert the
% sequential numbering and page numbers where desired in
% cross-references.
%
% The file is \jobname.XRF.
%
% To use this sequential numbering with units,
%
% o At each chapter, after the \eject, if there is
% one, and just before the \hOne, have
%
% \SNUAdvanceChapter
%
% to increment by one the counter \SNChapter and
% set the counter \SNUnit to 0.
%
% o Otherwise use macros
%
% \SNU\SNTagA
% \SNUGetChapter\SNTagA
% \SNUGetUnit\SNTagA
% \SNUGetPage\SNTagA
%
% as illustrated.
%
% o Then run TeX at least twice, basically until
% the file \jobname.XRF quits changing.
%
% So, we get sequential numbering and cross-referencing with
% 'units'. The macros and counters particular to 'units'
% all begin with \SNU.
%
% We let
%
% \newcount\SNUnit
%
% keep track of the number of the unit. So, when we use
%
% \def\SNUAdvanceChapter{\advance\SNChapter by1
% \SNUnit=0}
%
% to increment
%
% \newcount\SNChapter
%
% we also set \SNUnit=0 for the new chapter.
%
% With the \SNU macros as illustrated, will get file
% \jobnane.XRF like
%
% \SNTagA
% 1 1
% 1
% \SNTagB
% 1 2
% 1
% \SNTagC
% 1 3
% 1
% \SNTagD
% 1 4
% 1
% \SNTagE
% 1 5
% 1
% \SNTagF
% 1 6
% 1
% \SNTagG
% 1 7
% 1
% \SNTagH
% 1 8
% 1
% \SNTagI
% 1 9
% 1
%
% So, get three lines for each invocation of \SNU. The
% first line has the tag. The second line has data
% particular to 'units' macros. And the third line has the
% page number.
%
% For in Appendix I, may want units to go
%
% A.I.1.2
%
% that is, to have a 'prefix' of 'A.I.'. To this end there
% is macro
%
% SNChapterPrefix
%
% which is default empty. Setting this macro to
%
% \def\SNChapterPrefix{A.I.}
%
% will give the prefix 'A.I.'. But, such a prefix should
% have no blanks else the parsing of the macros that get
% cross-referencing information will get confused!
%
% But we may also want sequential numbering and
% cross-referencing for tables, figures, equations, etc.
%
% Then the idea is to have more sequential numbering
% macros. But, do not want a proliferation of files. So,
% these other macros should also use the file \jobname.XRF.
% For compatibility, each of these other macros should also
% write three lines to file \jobname.XRF. The main freedom
% is just in the second line.
%
% Each tag, e.g., \SNTagA, becomes a macro. So, each tag
% should be spelled like a TeX macro and have spelling
% different from all other TeX macros in use.
%
% During the first pass of TeX, macros
%
% \SNUGetChapter\SNTagA
%
% \SNUGetUnit\SNTagA
%
% \SNUGetPage\SNTagA
%
% will notice that \SNTagA is not defined and will define
% it as the macro \SNUNone from
%
% \def\SNUNone{CH UN PG}
%
% the three tokens of which are intended to abbreviate,
% respectively, chapter, unit, and page.
%
% Then each of the three macros
%
% \SNUGetChapter\SNTagA
%
% \SNUGetUnit\SNTagA
%
% \SNUGetPage\SNTagA
%
% will return 'CH', 'UN', and 'PG', respectively, as
% temporary place holders and a way to get page breaking
% approximately correct before another pass of TeX that
% will read and use the XRF file written on the previous
% pass.
%
% We also have macros for tables and figures. For tables,
% the names begin with SNT; figures, SNF.
%
% The main challenge was in macro SNU (SNT, SNF) that has
% to write both the sequential numbering and the page
% number. The cause of the challenge was how, really,
% when, TeX actually does page breaking. So, once TeX
% starts a new page, it keeps adding lines until it clearly
% has enough, and maybe too many, lines for that page.
% Then TeX decides where to break the page, uses any left
% over lines for the next page, and continues. So, when a
% macro in the text executes, TeX does not yet know the
% page number but the macro does know the chapter number
% and, say, the unit number.
%
% When TeX sees a \write, TeX temporarily puts the \write
% in a 'whatsit' until the page breaking and then executes
% the \write. 'Whatsits' are discussed starting a line
% 14,007 of the file of TEXBOOK.TEX.
%
% The trick, then, is to have
%
% \def\JUNKA{\the\SNChapter\space\the\SNUnit}
% {\edef\JUNKB{\write\XREFileOut{\JUNKA}}\JUNKB}
% \write\XREFileOut{\the\count0}
%
% In the first line we define \JUNKA that has the data to
% be written. The second line has a group with an \edef
% (define a macro expanded immediately) of a temporary
% macro \JUNKB with the \write and with the data to be
% written and, then, with an invocation of \JUNKB. Due to
% the \edef, the whatsit for the \write has only constants
% and the right constants. Those constants are from
% counters
%
% \SNChapter
% \SNUnit
%
% which might well change by the time the \write is
% executed; but, the constants will still have the values
% we need to have written.
%
% On the third line, we use \write to write the page
% number, and the page number in \count0 is expanded at the
% time of the page breaking and, thus, has the correct page
% number.
%
% Another challenge is how to handle the data read from
% file \jobname.XRF: As each line is read, it has a
% trailing blank. So, have to use and/or parse the blank.
%
Offered as-is, no warranties. Use at own risk.
They work nicely for me. I haven't looked at the code in years, so there may be some dependencies, likely minor, maybe just in documentation, on some of my other macros.
There may be some subtle bugs, but I haven't found any. If you find a bug and know just what usage encounters the bug, then don't do that usage again! Or fix the bug!
There is enough documentation so that you can see the ideas -- actually they are all quite simple. The macros were a good TeX exercise.