L3color’s colors: unusable with tikz

colorexpl3tikz-pgf

In the following MCE, the myred color is defined thanks to l3color syntax (\color_set:nnn {myred} {rgb} {1,0,0}):

\documentclass{article}
\usepackage{tikz}
\usepackage{l3draw}

\begin{document}
\ExplSyntaxOn
\tikz \draw[red] (0,0) circle [radius=10pt];
%
\color_set:nnn {myred} {rgb} {1,0,0}
\color_fill:n { myred }
\draw_begin:
\draw_path_circle:nn {0,0} {10pt}
\draw_path_use_clear:n { draw }
\draw_end:
%
% \tikz \draw[myred] (0,0) circle [radius=10pt];
\ExplSyntaxOff
\end{document}

This color works well e.g. in a l3draw's drawing but not in a tikz's drawing, as one can see by uncommenting the instruction \tikz \draw[myred] (0,0) circle [radius=10pt];, the error being:

! Package pgfkeys Error: I do not know the key '/tikz/myred' and I am going to
ignore it. Perhaps you misspelled it.

Is there a way to make l3color's colors usable with tikz?

Best Answer

Colors defined with \color_set:nnn are not usable with xcolor. Minimal example

\documentclass{article}
\usepackage{xcolor}

\ExplSyntaxOn
\color_set:nnn { myred } { rgb } { 1,0,0 }
\ExplSyntaxOff

\begin{document}

\textcolor{myred}{Test}

\end{document}

This results in

! Package xcolor Error: Undefined color `myred'.

You can define your own version.

\documentclass{article}
\usepackage{tikz}
\usepackage{l3draw}

\ExplSyntaxOn

\cs_new_protected:Nn \db_color_set:nnn
 {
  \color_set:nnn { #1 } { #2 } { #3 }
  \definecolor { #1 } { #2 } { #3 }
 }

\ExplSyntaxOff

\begin{document}

\tikz \draw[red] (0,0) circle [radius=10pt];

\ExplSyntaxOn
\db_color_set:nnn {myred} {rgb} {1,0,0}
\color_fill:n { myred }
\draw_begin:
\draw_path_circle:nn {0,0} {10pt}
\draw_path_use_clear:n { draw }
\draw_end:
\ExplSyntaxOff

\tikz \draw[color=myred] (0,0) circle [radius=10pt];

\end{document}

enter image description here

Related Question