How do I get correct values from the %refpage variable and partial (Range+) composition?

XPP 9.3.1, using XML mode (without CSS) and the Looseleaf add-on

We have a situation where we need to display the number of pages between the current page and some specific forward destination. The way that we currently implement this is by putting a <rx;end-1> macro at the destination. Then, at the place where we want to print the number of pages, we have:

<rf;end-1;0;0></ns;52;%refpage-%pagenum+1></ri;#52;an>

All of this happens in main blocks.

This works perfectly as long as we compose the entire division. However, if we do a Range+ compose, though, we sometimes get an incorrect count. We need the Range+ compose to return the correct result because we will be using Looseleaf, which may do partial composes.

As part of the debugging process, I outputted the values of the %refpage and %pagenum variables using </ri;%refpage;an> and </ri;%pagenum;an>. What I've generally observed is that the %pagenum variable is accurate, but the %refpage variable seems to return the wrong value when the destination marked spot "end-1" is part of the range compose. When that happens, %refpage returns the page position relative to the range being composed, instead of relative to the entire division. For example, in the case where "end-1" is on page 13 and we're printing the count on page 12, I expect %refpage to return "13". However, the result depends on which pages I compose:

  • Range+ compose 12 => %refpage = 13
  • Range+ compose 12 thru 13 => %refpage = 2
  • Range+ compose 11 thru 13 => %refpage = 3

The odd thing to me is that if I then look at the output of show_xref, the entry for end-1 always shows the correct page number 13.

(I kind of glossed over this, but in all cases, we've already done one full compose pass, so I'm sure that the forward cross-reference is resolving to some value)

Assuming this is a bug, or just some edge case that I'm not understanding, is there a more reliable way to get the count that I'm looking for? The multipart page numbers (%refpg1, etc.) seem to return the correct result, but I can't use that because it won't tell me about potential insert pages.

  • Hi Cheran,

    Due to the way that the composition engine works, the %refpage value will not always be correct when you are not composing the whole division (and with forward references you may even need to compose the whole division twice).

    Details: the pages being composed are made into a separate "input stack" that is composed, and that affects the in-progress page numbers. Even if composition tried to do a better job of accounting for this in the page numbers saved for <rx>/<rf>, while the composition is in progress it will never be able to fully account for cases where there are forward references and e.g. the compose Range+ operation might result in fewer pages or more pages (before the <rx> occurs).

    It's the purpose of the Compose Xrefs function (compose -sx for command-line or Xref Errors from compose menu), that is performed after the "regular" composition is done (and all the composed pages are reassembled back with the other pages), to account for this and "fix up" (or recompose) the lines with <rf> macros on them.

    So in your Range+ testing (outside of Looseleaf), try doing the "Xref Errors" composition after you do the Range+ composition and see if that doesn't get you the desired results.

    In Looseleaf mode (and I assume you mean Auto-looseleaf), if you have the "Compose Changed Cross-References" field in the ALL spec set to 'yes' then Looseleaf composition will perform the Compose Xrefs function on just the composed pages (after it is done with the Looseleaf composition of them).

    Hopefully that will help you get the desired results.

    Jonathan Dagresta
    SDL XPP Engineering

  • Jonathan,

    Thanks for the detailed response. We are indeed using Auto-looseleaf, and we do have "Compose Changed Cross-References" set to "yes". I must not have been paying close enough attention during my auto-looseleaf tests, because it is getting the correct page number. I can also see that doing "Xref Errors" after the Range+ compose also gets the page numbers that I expect to see.

  • Cheran,

    As Jonathan explained to you, compose will not solve your problem if you want to continue to use compose range pages.

    But there is always xyPerl that can help you.
    You could write out the relative page number of your (end-1?) reference point(s) into a file.
    And then use that value to calculate how many pages you are away from that point.

    You will still need to do at least 2 composes to get the correct answer.
    But once the end point is set, you can do any compose you like, you will get the correct answer.

    Kind Regards

    Bart