Get default text color
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}
As Devid Purton stated in his answer the default color is the color active at begin of the document (\begin{document}
). You can access the current color by using '.
' (dot) as color name and store that under a new name using \colorlet
. Now to define the default color under the color name defaultcolor
simply add \colorlet{defaultcolor}{.}
at the begin of the document. This can be done either in the preamble after loading xcolor
with \AtBeginDocument
or simply adding it directly after \begin{document}
.
These are features of the xcolor
package, the older color
package is not sufficient.
The following example will make blue the default color and switch back to it inside an green text.
\documentclass{article}
\usepackage{xcolor}
\AtBeginDocument{\colorlet{defaultcolor}{.}}
\color{blue}
\begin{document}
Some text
{\color{green} Text \textcolor{defaultcolor}{default} Text}
More text
\end{document}