Requirements
(A) create identical text to appear in both (i) the table of contents and (ii) the right header;
(B) reduce the redundancy in my code so that I can pass the same string to both right header and invisible section;
(C) do not produce any extra pages
Problem
The code below meets requirements (A); but not (B) and (C).
If I remove `\clearpage', then all pages in the appendix have the same rightheader -- namely the right header of the last invisiblesection.
Also, please note the redundancy in that I have to pass my string twice: once for the header, and once for the table of contents.
Request
Please, include a complete minimum working example to your solution.
MINIMUM WORKING EXAMPLE
\documentclass[12pt]{book}
\usepackage{fancyhdr}
\newcommand\invisiblesection[1]{%
\refstepcounter{section}%
\addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}%
\sectionmark{#1}\phantom{}}
\makeatother
\begin{document}
\tableofcontents
\appendix
\addcontentsline{toc}{chapter}{Exhibits}
\def\thesection{Exhibit~\Roman{section}}
\pagestyle{fancy}
\newcommand{\exName}[3]{#1~#2~#3}
\invisiblesection{\exName{Student Portfolio}{\#1:}{Best}\label{ex:10}}
\rhead{\textbf{\thesection.~\exName{Student Portfolio}{\#1:}{Best}}}
\begin{figure}
\includegraphics{image1}
\end{figure}
\clearpage %% IF I REMOVE THIS, HEADER IS IDENTICAL THROUGHOUT
\invisiblesection{\exName{Student Portfolio}{\#2:}{Most-Improved}\label{ex:20}}
\rhead{\textbf{\thesection.~\exName{Student Portfolio}{\#2:}{Most-Improved}}}
\begin{figure}
\includegraphics{image2}
\end{figure}
\end{document}