This is sending me down the right paths (at least showing me the sign post ;0) 
- I know I'm a pain in the neck, but the attached minimal (mirroring your 
proposal with the "colored" snippet fixed) compiles to to "black" "test"s ...  

What's wrong?

Thanks, Joh

Hans Hagen wrote:

> \starttext
> 
> \startluacode
> document.commands = document.commands or { }
> function document.commands.somehexcolor(str)
> local r, g, b = str:match("#(..)(..)(..)")
> r, g, b = tonumber(r,16) or 0, tonumber(g,16) or 0,
> tonumber(b,16) or 0
> 
> tex.sprint(string.format("\\colored[r=%s,g=%s,b=%s]",r/255,g/255,b/255))
> end
> \stopluacode
> 
> \setupcolors[state=start]
> 
> \def\WhatAMess#1{\ctxlua{document.commands.somehexcolor("#1")}}
> 
> {test \WhatAMess{\letterhash FF3344} test}
> 
> \stoptext
> 
\starttext

\startluacode
     document.commands = document.commands or { }
     function document.commands.somehexcolor(str)
         local r, g, b = str:match("#(..)(..)(..)")
         r, g, b = tonumber(r,16) or 0, tonumber(g,16) or 0, tonumber(b,16) or 0
 	 tex.sprint(string.format("\\color[r=%s,g=%s,b=%s]",r/255,g/255,b/255))
     end
\stopluacode

\setupcolors[state=start]

\def\WhatAMess#1{\ctxlua{document.commands.somehexcolor("#1")}}

{test \WhatAMess{\letterhash FF3344} test}

\stoptext


___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : [email protected] / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to