Page LayoutInstead of invoking \clearpage, how to update \thepage soon?

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
yoyoimut
Posts: 120
Joined: Mon Oct 19, 2009 6:58 am

Instead of invoking \clearpage, how to update \thepage soon?

Post by yoyoimut »

yoyoimut wrote:...Because I don't need labeling so the \pageref is irrelevant in my situation...
gmedina wrote: You don't need it, but you might use it to solve your problem, so it doesn't seem to be irrelevant.

I need the value of the page counter to be passed to \isodd command to specify special layout for odd pages only.

So your method does not guarantees the page counter consistent.


Thank you.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

yoyoimut
Posts: 120
Joined: Mon Oct 19, 2009 6:58 am

Instead of invoking \clearpage, how to update \thepage soon?

Post by yoyoimut »

Code: Select all

\documentclass{article}
\usepackage[margin=3cm]{geometry}
\usepackage{lipsum,multido,ifthen,xcolor}



\newcounter{UPC}

\newcommand{\UpdatePageCounter}%
{%
\stepcounter{UPC}\label{UPC-\theUPC}%	
\ifthenelse{\isodd{\pageref{UPC-\theUPC}}}%
 	{\fbox{\Huge\color{blue}\bf\pageref{UPC-\theUPC}}}%
 	{\fbox{\Huge\color{red}\bf\pageref{UPC-\theUPC}}}%	
}

\begin{document}

\multido{\i=1+1}{200}{%
	% 
 \UpdatePageCounter
 	\lipsum[1]%  
  }

\end{document}


Your method does not guarantee that the \pageref will give us the correct value.
daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

Instead of invoking \clearpage, how to update \thepage soon?

Post by daleif »

with a bit of memoir magic

Code: Select all

\documentclass{memoir}
\usepackage[margin=3cm]{geometry}
\usepackage{lipsum,multido,ifthen,xcolor}

\strictpagecheck


\newcounter{UPC}

\newcommand{\UpdatePageCounter}%
{%
  \parnopar
  \checkoddpage
  \stepcounter{UPC}\label{UPC-\theUPC}
  \ifoddpage
  {\fbox{\Huge\color{blue}\bfseries\pageref{UPC-\theUPC}}}%
  \else
  {\fbox{\Huge\color{red}\bfseries\pageref{UPC-\theUPC}}}%   
  \fi
}

\begin{document}

\multido{\i=1+1}{200}{%
   %
\UpdatePageCounter
   \lipsum[1]% 
  }

\end{document}
yoyoimut
Posts: 120
Joined: Mon Oct 19, 2009 6:58 am

Instead of invoking \clearpage, how to update \thepage soon?

Post by yoyoimut »

I can solve it by placing an auxilary anchor \rule{0pt}{0pt} before \label{}.

Code: Select all

\documentclass{article}
\usepackage[margin=3cm]{geometry}
\usepackage{lipsum,multido,ifthen,xcolor}



\newcounter{UPC}

\newcommand{\UpdatePageCounter}%
{%
\stepcounter{UPC}\rule{0pt}{0pt}\label{UPC-\theUPC}%   
\ifthenelse{\isodd{\pageref{UPC-\theUPC}}}%
   {\fbox{\Huge\color{blue}\bf\pageref{UPC-\theUPC}}}%
   {\fbox{\Huge\color{red}\bf\pageref{UPC-\theUPC}}}%   
}

\begin{document}

\multido{\i=1+1}{200}{%
   % 
\UpdatePageCounter
   \lipsum[1]%  
  }

\end{document}

Post Reply