0

I want to test if

  • the current page when I generating layout, and
  • the page where the layout appears after the work of the page builder,

are the same page. In code it could look so:

\bindpage{some-id}{code-page-is-the-same}{code-page-changes}

I can solve the task using the aux file and two passes, but: probably such module exists already?

Edit.

I hope an use case explains my intentions better than the text of the original question.

For the left and right pages, I have different layout of noteboxes.

Now consider the actions:

  • I emit a heading

  • I want to put a notebox. The current page is the left page. Currently I'm near the bottom of the page, but there is enough space. So, I emit the notebox in the design for the left page.

  • I emit some other thing, which completes the page.

  • The page builder is activated. For some good reason, it decides that it is very good to make a page break before the heading.

  • Therefore, the heading and the notebox appear on the next page. But the next page is the right page, and the design of the notebox is for the left page. Bad.

My idea is to track the pages of the noteboxes on the first pass. And on the second pass, if the current page is not the page where a notebox appears, force the page builder to work.

  • I'm not sure I get what you mean...? You want to test whether two things are on the same page? – yo' Nov 3 '15 at 13:06
  • @yo' I want to test that the one thing has not moved from one page to another after possible activation of the page builder. – olpa Nov 3 '15 at 13:40
  • See also tex.stackexchange.com/questions/196033/… – John Kormylo Nov 3 '15 at 14:14
  • 1
    The question is't really easy to answer as currently worded: The page builder never moves things from one page to another. It moves things from the main vertical list (where page numbering doesn't really have a meaning) to a page but once it is on a page it gets shipped out and stays on that page. – David Carlisle Nov 3 '15 at 16:58
1

Well, you can use the refcount package, that allows to check for equality of page numbers for different labels, as in this code:

\documentclass[a4paper]{article}

\usepackage{refcount}

\usepackage{lipsum}

\makeatletter
\newcommand\Ifpagerefequal[4]{%
  \edef\IPRE@a{\getpagerefnumber{#1}}% store the pageref for #1
  \edef\IPRE@b{\getpagerefnumber{#2}}% store the pageref for #2
  \ifx\IPRE@a\IPRE@b#3\else#4\fi% compare the refs and execute either #3 or #4
}
\makeatother

\begin{document}

\lipsum[1-2]

q IS HERE \label{q}

\lipsum[3-4]

r IS HERE \label{r}

\lipsum[5-6]

s IS HERE \label{s}

\Ifpagerefequal{q}{r}{``q'' is on the same page as ``r''}{``q'' is on a different page than ``r''}

\Ifpagerefequal{r}{s}{``r'' is on the same page as ``s''}{``r'' is on a different page than ``s''}

\end{document}
  • This will explode if the pagenumber is e.g. \pagenumbering{Roman}. You should better use either zref or test simply if \pageref{a} is equal to \pageref{b}. – Ulrike Fischer Nov 3 '15 at 13:29
  • Ah right. Well, one can't use \pageref directly because it's unexpandable. – yo' Nov 3 '15 at 13:30
  • 1
    \newcommand\Ifpagerefequal[4]{% \ifthenelse{\equal{\pageref{#1}}{\pageref{#2}}}{#3}{#4}% } works fine for me in your example. – Ulrike Fischer Nov 3 '15 at 13:39
  • that's because "someone" kindly fudged \pageref so it works in \ifthenelse :-) – David Carlisle Jan 26 '16 at 23:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.