4

There are several solutions for accessing the current text color. But is there a xcolor's \XC@magick@command magick command that let us access the current (background) color of the page? Something like that:

\documentclass{article}
\usepackage{xcolor}
\pagecolor{red}
\begin{document}
\color{\XC@magick@command}%
The current text is colored with the page color's one (hence invisible).
\end{document}

2 Answers 2

2

You could use the pagecolor package:

\documentclass{article}
\usepackage{xcolor}
\usepackage{pagecolor}
\pagecolor{red}
\begin{document}
Not invisible
\color{\thepagecolor}%
The current text is colored with the page color's one (hence invisible).
\end{document}
3

This is set up in a driver dependent way unfortunately

with latex/dvips, dvips.def has

\def\set@page@color{\special{%
        background \current@color}}

so the information is only recorded in the back end special

with pdftex on current releases the definition in pdftex.def is

 \@ifl@t@r\fmtversion{2020/10/01}
  {%
    \def\set@page@color{%
     \global\GPT@pagecolortrue
     \global\let\current@page@color\current@color
     \IfHookEmptyTF{shipout/background}{\AddToHook{shipout/background}{\relax}}
...

so the color is available as \current@page@color

If you need this reliably I would subvert the \pagecolor command to make it save its argument somewhere.

4
  • Also note that 'page color' was not the best plan in the world: really it's a background rectangle that could have been handled very differently
    – Joseph Wright
    May 22, 2021 at 11:21
  • @JosephWright certainly that's how it turned out, it was exposed as a special in dvips, and that was the reference colour implementation at the time, but even there it was tricky to make work well with tex's view of what was on each page, in other back ends where it is just a rule drawn by tex, it's not really a lot of help at all. May 22, 2021 at 11:24
  • With \pagecolor{red}, \makeatletter\fcolorbox{black}{\current@page@color}{Foo}\makeatother gives "! Package xcolor Error: Undefined color `1 0 0 rg 1 0 0 RG'." May 22, 2021 at 11:52
  • About subverting \pagecolor, the point is: it is for a package of my own that I'd like to know the current page color specified by the document author. May 22, 2021 at 14:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .