\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