# How to change font color for only the current page?

As mentioned by the title, I need to change font color for only the current page. After searching the internet, the afterpage package seems to be a good choice, as well as \colorlet{saved}{.} from the xcolor package. Hence the following code.

\documentclass{article}
\usepackage{xcolor}
\usepackage{afterpage}
\usepackage{blindtext}
\begin{document}
\blindtext
\colorlet{saved}{.}
\color{yellow}
\afterpage{\color{saved}}

\blindtext
\clearpage
\blindtext
\end{document}


However, color of font in the second page remains unchanged.

• Does your real use case have a forced page break? if so the answer is easy just put \color{saved} after \clearpage or do you want the colour to change at an automatic-page break, possibly mid-paragrarah? That is harder and in general not always possible automatically. May 14 '17 at 11:49
• This could be an XY question, using \afterpage could be the wrong thing to do from the beginning. What is your greater goal? May 14 '17 at 11:53
• @DavidCarlisle It depends. Sometimes a \clearpage will be added and thus I could be able to declare color clearly. However, it's hard for me to add such color declaration in automatically process, for example in the toc output process. What if the fact is ensured that no float processing will try to break our color restore mechanism? Or, maybe we could have a try to handle this after the ltx2e layout codes have decided not to build a float page (column)? May 14 '17 at 12:00
• @Johannes_B, Thanks for the reply. The original problem is that I need to change the background color of specific area in the chapter title page. In the very page, a light color of font is therefore needed, and in the following pages, black should be recovered. Do you have any clues? May 14 '17 at 12:02
• Use only the chapter title on a page of its own. May 14 '17 at 12:04

\afterpage adds a group. This here works as expected (but I wouldn't rely on it in all cases):

\documentclass{article}
\usepackage{xcolor}
\usepackage{afterpage}
\usepackage{blindtext}
\begin{document}
\blindtext
\colorlet{saved}{.}
\color{yellow}
\newcommand\restorecolor{\color{saved}}
\afterpage{\aftergroup\restorecolor}

\blindtext
\blindtext
\blindtext
\blindtext
\blindtext\par
\end{document}


• Fantastic! It's a shame that I didn't know \aftergroup before. However, I guess this could be broke by the floating process? May 14 '17 at 12:05
• @Ch'enMeng this could be broken by anything :-) please read the warnings in the afterpage documentation. I wouldn't use it in any production setting. Changing a colour at a page change is such an odd thing to do, is there really no structural change in the document at that point which corresponds to the colour change? May 14 '17 at 12:08
• @Ch'enMeng: As I said: I wouldn't rely on it. I use afterpage only very seldom and very carefully. I only wanted to show why it didn't work in your (simple) example. Like David I find your requirement rather odd and imho there should be something more logical (as you mentioned the titlepage: I would simply use grouping there). May 14 '17 at 12:19
• @DavidCarlisle Well, let me think twice about this. Thank you for the help. : ) May 14 '17 at 12:21
• @Ch'enMeng try replacing that \par by \blindtext ..... May 14 '17 at 12:49