The way composition works:
- Normally, XPP oversets each block by a number of lines, approximately 20 lines depending on whether anything else is effectively doing an <eb> or <ep>.
- Composition performs vertical justification of each block
- Composition then kicks out overset lines back into the input, and those lines will get processed (composed) again.
- If there’s any balancing occurring, whole blocks of lines can get kicked out and recomposed multiple times until the balancing result is the “best” result.
It’s very easy for a line to get composed on page # as an “overset” line, and then be kicked out. If that’s the last block on the page, that line will get composed again on page #+1 (or later).
You will need to “know” or determine which is the last value written out for each occurrence of the desired macro.
If the value cannot be determined by the data currently being written out by the perl subroutine, a unique “id” can be added to each desired macro and that “id” would need to be passed to the perl subroutine.
That could then be output with the other data so that a later process can determine which is the last value written out for a particular “id”; or you could enhance the perl subroutine to overwrite the value for an “id” that had been written out earlier.