TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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

Is there a way to scale/remap/transform the colors in a pstricks picture?

More detailed: I have some pstricks code which uses grayscale colors. I want to remap the colors from [0,1] to [a,b], where 0 <= a <= b <= 1.

Obviously I can do any geometrical transformation, like:

\rput(0,0) % translating...
  \psscalebox{0.166} % scaling...
    \psset{xunit=.5pt,yunit=.5pt,runit=.5pt} % changing units...
      \input{./somepstricks.tex} % including alien pstricks-code

But how can I add a color transformation on somepstricks.tex here as well?

Some additional thoughts:

  • I could overlay the picture with two transparent black and white layers and achieve any combination of a and b (using opacity property). Problem: In general, it is hard to exactly overlay the elements from somepstricks.tex and nothing else. In the case I don't know the content of the external code, I don't even see a way to realize this.
  • Although I don't need it at this point, I would admire some additional features:
    • including color remapping (not only gray scale)
    • supporting non-linear remapping
    • allowing saturation, i.e. allow for a < 0 and b > 1
share|improve this question
Please always post full documents not just fragments, that allow people to test possible answers. – David Carlisle Apr 4 '14 at 11:47
Usually I provide an MWE, but this would be misleading here. I am not looking for a special but a general solution, like some command or option. If this doesn't lead to a solution, I will post some special case as an example of course. – matheburg Apr 4 '14 at 12:09
Even for a general solution a test case helps:-) I knew pstricks color support quite well last century when I was checking that the latex2e color support was compatible, but I'd be hard pressed to generate an example now, preferably involving some stroke and fill colour. It should be possible to hook into the pstricks macro that generates the postscript colour from the tex representation and cause it to change the emitted colour model parameters. – David Carlisle Apr 4 '14 at 12:53
@DavidCarlisle "last century?" Don't you mean last millennium? – Steven B. Segletes Apr 4 '14 at 23:46

You can redefine the setgray function of PostScript:


Color range from $0\cdots1$\\

\def\rLeft{0.2 } \def\rRight{0.6 }%  spaces!!
\pstVerb{%  redefine /setgray
  /savesetgray /setgray load def
  /setgray { % on the stack is the value for gray 
    \rRight \rLeft sub mul \rLeft add savesetgray } def 

Color range from $0.2\cdots0.6$\\

\end {document}

enter image description here

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.