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

How can I convert a color name (such as used with the xcolor package) to a pdfliteral code, like q 1 0 0 rg (for red)?

share|improve this question
What is the context here? The drivers for the color package normally deal with this for LaTeX users, as this keeps code driver-independent. Also, with a sufficiently up-to-date pdfTeX or LuaTeX, why use \pdfliteral rather than \pdfcolorstack? – Joseph Wright Sep 19 '11 at 9:28
@JosephWright The context is in Lua code, and I can't use \color there because I'm inserting PDF annotations from the Lua code. – ℝaphink Sep 19 '11 at 9:30
The way that named colours are done is by defining what they convert to: a colour model and then some values. I'd imagine a Lua solution would be done the same way. Can't you just access the appropriate macro definitions from the Lua end? – Joseph Wright Sep 19 '11 at 9:36
@JosephWright Sure, then I guess my question would be if there is such a macro which converts a color name into a space separated triplet of RGB components? – ℝaphink Sep 19 '11 at 9:38
up vote 14 down vote accepted
\pdfcompresslevel=0 % to make everything visible in the pdf 


in pdf it is: 1 0 0 rg 1 0 0 RG

share|improve this answer
So \usecolor{red} outputs 1 0 0 rg 1 0 0 RG? – ℝaphink Sep 19 '11 at 9:48
yes, can already been seen in the pdf – Herbert Sep 19 '11 at 9:52
Yes, that works great! Thank you! – ℝaphink Sep 19 '11 at 9:54

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.