(This is a follow-up of the (unfortunately closed) question Is there a way to change the style of a float depending on whether it is on the same page of call out or not?))
In order to change the style of a float depending on whether it is on the same page of call out or not, I tried to implement the David's suggestion:
set a label,then check the
\pagerefwith the current page and fix up the typesetting on the next run if they are the same
(AFAICS, I have to resort to refcount's \getpagerefnumber since it is not possible to directly compare the \thepage with the string \pageref{...}, but the problem I encounter arises with the two.)
But it seems to be an issue with this approach: in the following MCE, both the call out page (theoretically given by the current page counter \thepage) and the displayed page (given by both \pageref{...} and \getpagerefnumber{...}) of the (second) float is the page 2 but \thepage tells it is page 1.
OK, \thepage is known for always giving the right number. So the question remains: is there a way to change the style of a float depending on whether it is on the same page of call out or not?
\documentclass{article}
\usepackage{refcount}
\usepackage{mwe}
\AddToHook{env/figure/end}{
\caption{The nice figure #\thefigure{}
(%
thepage: \thepage,
pageref: \pageref{ex-\thefigure},
getpagerefnumber: \getpagerefnumber{ex-\thefigure}%
)%
}
\label{ex-\thefigure}
}
\begin{document}
\begin{figure}[htb]
\centering
\includegraphics[width=.5\linewidth]{example-image-a}
\end{figure}
\begin{itemize}
\item Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a,
magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique
senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras
viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla
ultrices. Phasellus eu tellus sit amet tortor gravida placerat. In- teger
sapien est, iaculis in, pretium quis, viverra ac, nunc. Praesent eget sem vel
leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla, male- suada eu,
pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius
orci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis,
diam. Duis eget orci sit amet orci dignissim rutrum.
\item Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a,
magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique
senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras
viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla
ultrices. Phasellus eu tellus sit amet tortor gravida placerat. In- teger
sapien est, iaculis in, pretium quis, viverra ac, nunc. Praesent eget sem vel
leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla, male- suada eu,
pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius
orci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis,
diam. Duis eget orci sit amet orci dignissim rutrum.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a,
magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique
senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras
viverra metus rhoncus sem. Nulla et lectus vestibulum urna
\item Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a,
magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique
senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras
viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla
ultrices. Phasellus eu tellus sit amet tortor gravida placerat. In- teger
sapien est, iaculis in, pretium quis, viverra ac, nunc. Praesent eget sem vel
leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla, male- suada eu,
pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius
orci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis,
diam. Duis eget orci sit amet orci dignissim rutrum.
\begin{figure}[htb]
\centering
\includegraphics[width=.5\linewidth]{example-image-b}
\end{figure}
\end{itemize}
\end{document}




\thepageis only expected to get correct value at shipout. egreg says as much in the link you provided: "You can rely upon the value of\thepageonly immediately after a\newpagecommand". – gusbrs Mar 15 '22 at 10:55\thepageto\getpagerefnumber{ex-\thefigure}(if I understood correctly). In neither MCE of this question or the original question the "callout" appears. As far as I can tell, you need two labels, one at the float and another at the "callout", and then you can compare pageref's of both. You may or may not need\getpagerefnumber, depending on the test you want to make. ... – gusbrs Mar 15 '22 at 11:06\getpagerefnumberregardless, since\pagerefis not expandable, so we cannot retrieve its value for comparison. – gusbrs Mar 15 '22 at 11:59