TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can anyone write a macro that will modify the xcolor package so that using !x will darken colors when x < 100 and lighten colors when x is between 100 and 200?

e.g., I would like to be able to do red!50 and red!150 to get a dark and light red color respectively instead of having to do red!50!black.

share|improve this question

Here a suggestion. I defined a command \mycolorcmd which behaves like \color but with the test if the number is greater than 100. The following output is created by:

\mycolorcmd{blue} Text Text

\mycolorcmd{red!140} Text Text

\mycolorcmd{blue!40} Text Text

enter image description here

%    \color{#1}%
   \edef\@tempa##1!{ \@tempcnta=##1}%
    \@tempa #2\relax
    \ifnum \@tempcnta > 100\relax%
      \advance \@tempcnta by -100\relax%
\mycolorcmd{blue} Text Text

\mycolorcmd{red!140} Text Text

\mycolorcmd{blue!40} Text Text
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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