[Tex/LaTex] Get default text color

color

I want to go (back) to the default text color. If the default color is black then I can use \color{black}. But I'm looking for a command for the general case where black may or may not be the default color. Something like \color{defaultcolor}.

(I'm aware of the advantages of using {\color{...}...} or \textcolor instead, but I want specifically \color{defaultcolor}.)

Edit: I use the color package, or probably I could use xcolor.

Best Answer

Both color.sty and xcolor.sty contain the following two lines:

\def\normalcolor{\let\current@color\default@color\set@color}
\AtBeginDocument{\let\default@color\current@color}

So at the beginning of the document (after the preamble), \default@color is set to \current@color. Then \normalcolor returns the colour to whatever it was set to in the preamble (or DeviceGray Black if nothing is set in the preamble).

If neither color nor xcolor are loaded then \normalcolor is defined in latex.ltx as \relax, so it does nothing.

MWE

\documentclass{article}
\usepackage{color}
\color{red}
\begin{document}
\color{blue}
Blue
\normalcolor
Normal Colour (Red as set in preamble)
\end{document}

This also works in beamer when the default text colour is set using \setbeamercolor{normal text}{fg=...}.

MWE

\documentclass{beamer}
\setbeamercolor{normal text}{fg=red}
\begin{document}
\begin{frame}
  \color{blue}
  Blue
  \normalcolor
  Normal Colour (Red as set in preamble)
\end{frame}
\end{document}