Text FormattingHow to save the current colour

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
JustA_LaTeXusr
Posts: 42
Joined: Tue Jul 23, 2013 6:48 pm

How to save the current colour

Post by JustA_LaTeXusr »

If I want to gray out large swaths of text in a report, I know that I can use the xcolor package's \color{black!50} command:
http://tex.stackexchange.com/questions/ ... k-of-texts
http://alvinalexander.com/blog/post/lat ... -documents

Is there any way to confirm that the default color is indeed black before I issue the above command?

In a related search, I found that I can even push the current colour onto a stack:
http://www.cs.stir.ac.uk/~kjt/software/ ... lours.html

However, that page is from 1997, targets slides, and uses a different package. I am currently very bound to the color package.

This question has been posted at:
http://tex.stackexchange.com/questions/ ... ent-colour
http://latex-community.org/forum/viewto ... 44&t=25431

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

How to save the current colour

Post by Johannes_B »

Hi, you already got a pretty good answer by Heiko Oberdiek. I would stick to that. ;-)

To sum it up, use either groups (compatible with package color) or save the current color using the single dot:

Code: Select all

Code, edit and compile here:
\documentclass{article}
\usepackage[x11names]{xcolor}
\usepackage{blindtext}
\begin{document}
\blindtext
\begingroup\color{Blue3} You can use groups to locally switch the
color \blindtext\endgroup
you can also save the current color, with a single dot. Just like
unix uses the single dot for the current directory.
\colorlet{colorsave}{.}
\color{Brown4}\blindtext
and later restore the savedcolor \color{colorsave} \blindtext
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
JustA_LaTeXusr
Posts: 42
Joined: Tue Jul 23, 2013 6:48 pm

Re: How to save the current colour

Post by JustA_LaTeXusr »

Thanks, Johannes. Interesting example you provided, educating me on the blindtext package.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: How to save the current colour

Post by Johannes_B »

On the one side there are people saying this is lazyness, others called it efficiency. I think you need to be both to get the work done. ;-)
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply