xcolor - What is the equivalent of default text color?

The default color is black; but if you are unsure that some package might change it, it's possible to extract the one LaTeX will start with by saying

\AtBeginDocument{\colorlet{defaultcolor}{.}}

since . refers to the current color. Then you can say \color{defaultcolor} to go back to the starting color.

Example:

\documentclass{article}
\usepackage{xcolor}

% Emulate the possible action of a package that changes the default color
\color{olive}

\AtBeginDocument{\colorlet{defaultcolor}{.}}

\begin{document}

Some text
\extractcolorspec{.}{\temp} \texttt{\meaning\temp}

\color{teal}

Some text
\extractcolorspec{.}{\temp} \texttt{\meaning\temp}

\color{defaultcolor}

Some Text
\extractcolorspec{.}{\temp} \texttt{\meaning\temp}

\end{document}

enter image description here


The precise definition of black depends on the color model. Both color and xcolor load the 'default' dvipsnam.def file and especially xcolor uses

\definecolorset{rgb/hsb/cmyk/gray}{}{}%
 {red,1,0,0/0,1,1/0,1,1,0/.3;%
  green,0,1,0/.33333,1,1/1,0,1,0/.59;%
  blue,0,0,1/.66667,1,1/1,1,0,0/.11;%
  brown,.75,.5,.25/.083333,.66667,.75/0,.25,.5,.25/.5475;%
  lime,.75,1,0/.20833,1,1/.25,0,1,0/.815;%
  orange,1,.5,0/.083333,1,1/0,.5,1,0/.595;%
  pink,1,.75,.75/0,.25,1/0,.25,.25,0/.825;%
  purple,.75,0,.25/.94444,1,.75/0,.75,.5,.25/.2525;%
  teal,0,.5,.5/.5,1,.5/.5,0,0,.5/.35;%
  violet,.5,0,.5/.83333,1,.5/0,.5,0,.5/.205}%
\definecolorset{cmyk/rgb/hsb/gray}{}{}%
 {cyan,1,0,0,0/0,1,1/.5,1,1/.7;%
  magenta,0,1,0,0/1,0,1/.83333,1,1/.41;%
  yellow,0,0,1,0/1,1,0/.16667,1,1/.89;%
  olive,0,0,1,.5/.5,.5,0/.16667,1,.5/.39}
\definecolorset{gray/rgb/hsb/cmyk}{}{}%
 {black,0/0,0,0/0,0,0/0,0,0,1;%
  darkgray,.25/.25,.25,.25/0,0,.25/0,0,0,.75;%
  gray,.5/.5,.5,.5/0,0,.5/0,0,0,.5;%
  lightgray,.75/.75,.75,.75/0,0,.75/0,0,0,.25;%
  white,1/1,1,1/0,0,1/0,0,0,0}

whereas color uses

\ifx\color@gray\@undefined
  \ifx\color@rgb\@undefined
  \else
    \definecolor{black}{rgb}{0,0,0}
    \definecolor{white}{rgb}{1,1,1}
  \fi
\else
  \definecolor{black}{gray}{0}
  \definecolor{white}{gray}{1}
\fi

So in both packages the definitions are the same if the color model names mean the same models then.

Since xcolor explicitly uses \color{black} at the end of the package, the textcolor is black then.


FWIW, xcolor provides a quick check on the system's default color. This system is a G5 running OSX 10.5.8, which shouldn't make a bit of difference. But, the default color here isn't "black."

xcolor.pdf https://ctan.org/pkg/xcolor?lang=en v2.12 Dr. Kern (11 May 2016)

pp.23-24 ¶ 2.6.4 Color testing

(borrowing your insightful code from the foregoing discussion, and using \estractcolorspecs, with the final "s":) [see xcolor.pdf ¶ 2.13 pp.28-29]

\extractcolorspecs {(color)}{(model-cmd)}{(color-cmd)} Extracts the color specification of (color) and puts it into (model-cmd) and (color-cmd), respectively.

\documentclass[12pt]{article}

\usepackage[margin=0.5in]{geometry}

\usepackage[dvipsnames*, x11names, svgnames, hyperref]{xcolor}

% Create some commands a la \TeX style (\LaTeX would use \newcommand)
\def\dfltColorModel
\def\dfltColor

% Get the system's default color
\AtBeginDocument{\colorlet{defaultcolor}{.}}

\begin{document}

% extract the color into Model and Color
\extractcolorspecs{.}{\dfltColorModel}{\dfltColor}

Default Color Model: \dfltColorModel

Default Color: \dfltColor

\bigskip

\begin{testcolors}[rgb,cmyk,hsb,HTML,gray]
\testcolor{.}
\end{testcolors}

\end{document}

enter image description here

From the \testcolor paragraph (p.23):

If the column-model matches the model of the color in question, its parameters are underlined.

Here, the system's default color is "gray" "0," as confirmed by the underlining in the testcolors printout.

Tags:

Color