I am new in TeX, so question may be little silly. Is any chance to use already defined color to define new color which will be darkner or lighter? I want to use only TeX. So i have defined color like this:

\def\mainColor{\pdfliteral{0.1 0.5 1 rg}}

How i define new color (lighter) from this color?

  • Welcome to TeX-sx! TeX itself doesn't know anything about colours, which is left to the driver system. In your example you are using a PDF mode special to set a PDF colour. I'm not really sure what you actually want: can't you just add a second colour definition? – Joseph Wright Feb 21 '15 at 20:15
  • 1
    Why are you using pdfliterals (which restricts your document to pdftex) rather than an existing set of color macros for plain, or better a more complete format such as latex or context? – David Carlisle Feb 21 '15 at 20:16
  • Thanks for explanation. I want to have main color, which will defined other colors, like theme. I dont want to use latex. – OrdinaryNick Feb 21 '15 at 20:17
  • yes but colour has been used for decades with tex and there are many extensive sets of macros giving features, why are you directly using a tex primitive to inject literal pdf? If you do do that your question isn't about tex, simply about pdf color syntax – David Carlisle Feb 21 '15 at 20:19
  • Do you mean perhaps that you want to define a main colour and one or more secondary ones in one go using some relative specification? For example, 'take the main RGB values and make the colour lighter by X percent'? – Joseph Wright Feb 21 '15 at 20:22

If you are using colors directly by \pdfliteral as mentioned in your post and only in the form num num num rg then the \defdarker should be defined. The usage is \defdarker\newColor\oriColor{coefficient}. The macro \oriColor must be defined already as \pdfliteral{num1 num2 num3 rg} and \defdarker defines \newColor as \pdfliteral{c*num1 c*num2 c*num3 rg} where nums are multiplied by the coefficient c. It means that \defdarker\newColor\oriColor{.5} sets the new color darker (multiplying .5 by all light sources from RGB).

{\lccode`\?=`\p \lccode`\!=`\t  \lowercase{\gdef\ignorept#1?!{#1}}}
\def\defdarkerB#1 #2 #3 #4\end#5#6{%
   \tmpdim=#1pt \tmpdim=#6\tmpdim
   \tmpdim=#2pt \tmpdim=#6\tmpdim
   \edef\tmp{\tmp\space \expandafter\ignorept\the\tmpdim}%
   \tmpdim=#3pt \tmpdim=#6\tmpdim
   \edef\tmp{\tmp\space \expandafter\ignorept\the\tmpdim}%
   \edef#5{\pdfliteral{\tmp\space rg}}%

\def\Black{\pdfliteral{0 g}}
\def\mainColor{\pdfliteral{0.1 0.5 1 rg}}


\mainColor AAA
\newColor  BBB
\darkColor CCC


The problem is that this color manipulation works only locally on pages, i. e. color have to be set and reset to the \Black at the same page. If you really are using plain TeX then I recommend to use OPmac macro package where colors are implemented. But the \defdarker macro for OPmac's color management will be slight different. Maybe I will add this to my OPmac-tricks page.


enter image description here

If you use \pdfliteral then TeX just passes the string straight to pdf so the question resolves to one of pdf color syntax. here I make a variant by halving the difference between the rgb components and 1 (white) to make a lighter shade.

If you instead use a developed existing macro set such as xcolor, a more natural syntax is possible to blend colours, here I just mix with white and black, and also you are then not restricted to pdftex, and the same syntax will work with tex/dvips or xetex.


\def\mainColor{\pdfliteral{0.1 0.5 1 rg}}
\def\subColor{\pdfliteral{.55 .75 1 rg}}



{\mainColor one two three}

{\subColor one two three}


\textcolor{maincolor}{one two three}

\textcolor{maincolor!50}{one two three}

\textcolor{maincolor!50!black!50}{one two three}

  • Why do you redefine black? Just to ensure it is using rgb? – cfr Feb 21 '15 at 21:42
  • @cfr yes (although actually I think xcolor would take care of that) – David Carlisle Feb 21 '15 at 22:01
  • IMHO, mixing colors directly defined by \pdfliteral with the colors from xcolor package (using pdfcolorstack and \aftergroup technique) cannot be recommended. For example the group braces in your code {\mainColor one two three} are irrelevant here because \pdfliteral sets color independent of the TeX groups. – wipet Feb 22 '15 at 7:34
  • @wipet I agree. You would never use these two mechanisms in the same document. I just put them next to each other for ease of posting and to show xcolor was making the same color as the OPs example. Yes I known the grouping is spurious but (I hope) the OPs unshown code is doing something about providing support for that. – David Carlisle Feb 22 '15 at 10:22

This is an extension of David Carlisle's xcolor solution which shows how to use \colorlet to define additional shades for convenience.

shades of main





\textcolor{darkestmain}{one two three}

\textcolor{darkermain}{one two three}

\textcolor{darkmain}{one two three}

\textcolor{maincolor}{one two three}

\textcolor{lightmain}{one two three}

\textcolor{lightermain}{one two three}

\textcolor{lightestmain}{one two three}


More a long comment than an answer. For gradations of a custom color, say "thecolor", the simplest is not define more and more names of variations of thecolor that anybody cannot remember, but simply use percentages of that color, like thecolor!75.

Think in a fade out or a transition to another color of say...ten colors. Are you able to find the right name for each tone? But in this way is very easy :



\textcolor{black}{one two three}  

\textcolor{thecolor!25!black}{one two three} 

\textcolor{thecolor!50!black}{one two three} 

\textcolor{thecolor!75!black}{one two three} 

\textcolor{thecolor}{one two three} 

\textcolor{thecolor!75}{one two three} 

\textcolor{thecolor!50}{one two three}

\textcolor{thecolor!25}{one two three}

\textcolor{green}{one two three}

\textcolor{thecolor!25!green}{one two three}

\textcolor{thecolor!50!green}{one two three}

\textcolor{thecolor!75!green}{one two three}

\textcolor{thecolor}{one two three}



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.