I have a many pdf documents written in standard LaTeX format. I was interested, is it possible to make my pages be black but my text be white? In other words, invert black/white, I am curious how nice it would look like.
2 Answers
Colors can be set via package color
. It is important to set the color to white in the preamble. Then package color
uses this color as \normalcolor
. LaTeX uses this color at various places. For example, it resets the color in header and footers to make them independent from the color that is active at the time the output routine is called.
\documentclass{article}
\usepackage{blindtext}
\usepackage{color}
\pagecolor{black}
\color{white}
\begin{document}
\blinddocument
\end{document}
Switching colors
Also the colors can be switched on a page level. Some pages can be put as white on black and others as black on white.
The page color can be turned off by \nopagecolor
. This is only supported by few drivers (pdftex.def
, dvips.def
). For other drivers, \pagecolor{white}
can be used.
The \normalcolor
is more tricky, the following example hacks into the internals to define \whiteonblack
and \blackonwhite
, which also changes the \normalcolor
accordingly.
\documentclass{article}
\usepackage{blindtext}
\usepackage{color}
\makeatletter
\let\default@color@black\current@color
\newcommand*{\blackonwhite}{%
\newpage
\let\default@color\default@color@black
\normalcolor
\@ifundefined{no@page@color}{%
\pagecolor{white}%
}{%
\nopagecolor
}%
}
\color{white}
\let\default@color@white\current@color
\newcommand*{\whiteonblack}{%
\newpage
\let\default@color\default@color@white
\normalcolor
\pagecolor{black}%
}
\pagecolor{black}
\makeatother
\begin{document}
\blinddocument
\blackonwhite \blinddocument
\whiteonblack \blinddocument
\end{document}
-
Thank you, but my page numbering disappears! (Presummably stays as black). Jun 24, 2015 at 5:40
-
1@NicolasBourbaki No, as you can see, the page numbers are correctly set in white. You have to move
\color{white}
to the preamble. See my updated answer with a little more explanation. Jun 24, 2015 at 5:46 -
-
@juanuni Yes,
\pagecolor
is defined in packagecolor
. It is supported in driverspdftex.def
,dvips.def
,dvipdfmx.def
, for example. Jun 24, 2015 at 6:01 -
1@juanuni The pagecolor package provides
\thepagecolor
, which does not "change the color of this page", but returns the color of this page. (While you did not ask for this, I add this comment to prevent confusion of those two commands.)– StephenFeb 4, 2022 at 15:03
Try this:
\documentclass{article}
\usepackage{color,lipsum}
\pagecolor{black}
\color{white}
\begin{document}
\lipsum[2-4]
\end{document}
-
Thank you. Two problems. (i) I get a bunch of random words in the beginning. (ii) My page numbering disappears! Jun 24, 2015 at 5:38
-
1
\color{white}
should be moved before\begin{document}
. Then this color becomes the\normalcolor
instead of the default black and the page number will reappear as white on black. Jun 24, 2015 at 5:45 -
@Heiko Oberdiek Thank you for pointing out. Edited my answer for page number colour in white. Jun 24, 2015 at 6:01