6

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.

  • So how would the default color be defined? Last \textcolor or last \color? Why not just use \def\defaultcolor{black} (for example)? – John Kormylo Jan 6 at 19:48
  • As far as I know, black is always default, at least with xcolor. You didn't specify which package you are getting color from. With xcolor, you could define a default color with \definecolor{default}{rgb}{0,0,0} (which is black, in this case) – whatisit Jan 6 at 19:49
  • @JohnKormylo default color is neither last \textcolor nor last \color. Default color is the color that would show when not using any \textcolor nor \color. I don't want to set some defaultcolor variable. I want to get the information about the currently set default color, and use it. – root Jan 6 at 19:57
  • @whatisit I edited the question to add info about packages. I don't want to define a default color. I want to get the information about the currently set default color. – root Jan 6 at 20:03
  • 1
    @root In beamer you can just use \usebeamercolor[fg]{normal text} (or \color{normal text.fg} if you prefer this syntax) – user36296 Jan 6 at 20:31
9

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}
3

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}
  • Thank you, the current color concept is nice! – root Jan 9 at 0:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.