ho-tex / zref

zref packages for LaTeX
LaTeX Project Public License v1.3c
6 stars 2 forks source link

zref-abspage is off by one #3

Closed Skillmon closed 4 years ago

Skillmon commented 4 years ago

While the label references with the abspage module are correct, the counter itself is off by one if one tries to access it directly, that's because it is initialized as 0 not as 1 as \c@page would be. If one now wants to create an \cleartoevenpage macro analogue to \cleardoublepage but using the abspage counter, one gets wrong results.

\usepackage{zref-abspage}
\makeatletter
% this is analogue to how `\cleardoublepage' works, but with `abspage'
\newcommand*\cleartoevenpage
  {%
    \clearpage
    \if@twoside
      \ifodd\c@abspage
        \hbox{}\newpage
        \if@twocolumn
          \hbox{}\newpage
        \fi
      \fi
    \fi
  }
\makeatother

If it is impossible to change the behaviour of that counter (because it might be used in documents in some ways), at least the documentation should be adapted to tell people about this off-by-one error.

u-fischer commented 4 years ago

I don't think that we can change it. I found a number of uses of the counter in other packages. But I added a sentence in the documentation.

Skillmon commented 4 years ago

@u-fischer thank you very much!

frougon commented 4 years ago

Hi,

This feature of the abspage counter is even used by the \ChapterStop macro of zref-example.tex. Indeed, since the label is written after the \cleardoublepage, one could believe it will contain the absolute page number of the first page of the chapter that is being started, and then the +1 in \ChapterPages would be incorrect. But since the end-of-chapter label is written via \zref@wrapper@immediate, the value of the abspage counter that is stored in this label is from before the \AtBeginShipout for the first page of the chapter that is being started; therefore, it holds the absolute number of the last page of the preceding chapter, which is why the computation in \ChapterPages is correct.

u-fischer commented 1 year ago

hm, looking at the perpage/zref-abspage clash in issue #18 I realized that in perpage the counter is not zero-based, which means that one gets a different number of page here, depending on if zref-abspage is used or not:

\documentclass[twoside]{article}
%
%\usepackage{zref-abspage}
\usepackage{perpage}

\makeatletter
% this is analogue to how `\cleardoublepage' works, but with `abspage'
\newcommand*\cleartoevenpage
  {%
    \clearpage
    \if@twoside
      \ifodd\c@abspage
        \hbox{}\newpage
        \if@twocolumn
          \hbox{}\newpage
        \fi
      \fi
    \fi
  }
\makeatother
\begin{document}
x \arabic{abspage}
\cleartoevenpage
x even
\end{document}

What a mess ;-( (The LaTeX count \ReadonlyShipoutCounter is zero based too, so works similar to the zref-abspage.)