encabezado/pie de página solo en la página actual, o también en sus páginas siguientes

encabezado/pie de página solo en la página actual, o también en sus páginas siguientes

Defino una macro llamada \pagecurrentque se usará en otras macros relacionadas con el encabezado y el pie de página, por ejemplo \cfoot, \chead, \renewcommand{\headrule}... Su función es determinar si la acción de la macro ( \cfoot,\chead,\renewcommand{\headrule}etc.) es solo en la página actual o también en el resto de páginas. En el siguiente ejemplo, quiero que el contenido del encabezado de la segunda página sea "página actual", la tercera página tenga un encabezado "otras páginas". Pero, de hecho, ambas páginas tienen el mismo encabezado: "página actual". Supongo que esto se debe a " \the\value{page}". Pero no quiero agregar código adicional \pagecurrent. ¿Existe un enfoque simple para abordar este problema?

MWE:

\documentclass{article}
\usepackage{fancyhdr,geometry,etoolbox}
\geometry{showframe}

\begin{document}
\pagestyle{fancy}
\pagenumbering{Roman}
%
\newcommand{\pagecurrent}[3]{%
  % #1-the current page number. If #1=0 then act on all pages from the current page, else only on the current page.
  % #2-action on the current page
  % #3-action on the following pages other than the current page
  \ifboolexpr{
    test {\ifnumequal{#1}{\value{page}}}
    or
    test {\ifnumequal{#1}{0}}
  }
  {#2} {#3}
}
% example:
first page\clearpage
\chead{\pagecurrent{\the\value{page}}{current page}{other pages}}
second page\clearpage third page
\end{document}

EDITAR: Me gustaría proporcionar el siguiente código para que mi pregunta sea más clara y concentrada:

\documentclass{article}
\usepackage{fancyhdr,geometry,etoolbox}
\geometry{showframe}

\begin{document}
\pagenumbering{Roman}
\pagestyle{fancy}

\chead{...}\rhead{...}\cfoot{...}\renewcommand{headrule}{...}...% macros related to header/footer that defines the original header/footer content.

...some text

at a certain page: \chead{\pagecurrent{content of chead from only this page changed}} 
% all other headers/footers of this page keep there original content. All headers/footers before/after this page keep there original content.

...some text

%\chead is used to illustrate my intention, maybe other macros like \rhead, \lfoot...in real article meet also the same problem.

\end{document}

Respuesta1

Aquí hay una manera, pero cambié los argumentos de su comando y también agregué el paquete atbgshien lugar de etoolbox:

\documentclass[twoside]{article}
\usepackage{fancyhdr,geometry}
\usepackage{atbegshi}
\geometry{showframe}
\usepackage{lipsum}
\newcommand{\pagecurrent}[4][\empty]{%
% #2 is the command to be executed with:
% optional argument #1 (if not empty=default)
% argument #3 for current page and 
% argument #4 for the upcoming page.
  \xdef\FArg{#1}%
  \ifx\FArg\empty
  #2{#3}%
  \AtBeginShipout{#2{#4}}%
  \else 
  #2[\FArg]{#3}%
  \AtBeginShipout{#2[\FArg]{#4}}%
  \fi
}

\begin{document}
\pagestyle{fancy}
% example:
\section{Test section 1}
\pagenumbering{Roman}
first page\clearpage
\subsection{Test subsection 1}
\pagecurrent{\chead}{current page}{other pages}
\pagecurrent{\cfoot}{Current Page: \arabic{page}}{Other pages: \arabic{page}}
\pagecurrent{\rhead}{Current Page:\rightmark}{\rightmark}
\pagecurrent[LE,RO]{\fancyfoot}{Current page: \thepage}{Other pages: \thepage}
second page\clearpage third page
\lipsum[1-20]
\section{Test section 2}
\lipsum[1-15]
\subsection{Test subsection 1}
\lipsum[1-20]
\end{document}

PD: Editado para ser un ejemplo completo con muchos comandos aceptados

información relacionada