Closed chupinmaxime closed 4 months ago
up?
You can make your own macro like this:
\documentclass{article}
\usepackage{luamplib,xcolor}
\def\mympcolor#1{%
runscript" %
tex.runtoks(function() %
tex.sprint[[\string\extractcolorspecs{#1}\string\tmpa\string\tmpb %
\string\convertcolorspec{\string\tmpa}{\string\tmpb}{rgb}\string\tmpc]] %
end) %
return string.format('(\csstring\%s)', token.get_macro'tmpc') %
"
}
\begin{document}
\begin{mplibcode}
color reddish;
reddish := \mympcolor{red!50} ;
beginfig(0);
fill fullcircle scaled 20 withcolor reddish ;
endfig;
\end{mplibcode}
\end{document}
Tank you, I’ve done something like that too, but I think that it would be nice to adapt the macro \mpcolor
.
It's not possible to adapt \mpcolor
without redefining withcolor
operator.
Instead, v2.29 provides mplibtexcolor
and mplibrgbtexcolor
operators which can be used in color definitions (or other places that accept color expressions). I hope the latter one fits your request. If you feel the name is too long, you can declare let mpcolor = mplibrgbtexcolor;
somewhere in the metapost code and use mpcolor
thereafter.
That’s great thank you.
\mpcolor
only works withwithcolor
. Is that possible to allow it to define color? In my LuaLaTeX code, I wrote a function withxcolor
to get the specs (\extractcolorspecs
) and convert (\convertcolorspec
) any LaTeX color to rgb metapost color codage.