I am trying to branch on whether a color (defined in xcolor
or xcolor-material
or using the utilities provided by these packages) has a name that can be used in the \color
command (from the xcolor
package). The current code is:
% Preamble
\documentclass[varwidth=true]{standalone}
\usepackage{xcolor}
\usepackage{xcolor-material}
% Should return TRUE if the \color command from xcolor works with the
% provided color name, and FALSE otherwise.
\ExplSyntaxOn
\makeatletter
\newcommand{\checkxcolor}[1]{
\cs_if_exist:cTF{color@#1}{[#1=TRUE]}{[#1=FALSE]}\newline
}
\makeatother
\ExplSyntaxOff
% Test
\begin{document}
\checkxcolor{blue} % should return TRUE
\checkxcolor{red} % should return TRUE
\checkxcolor{nocolor} % should return FALSE
\checkxcolor{lime} % should return TRUE
\checkxcolor{MaterialIndigo900} % should return TRUE
\checkxcolor{MaterialIndigo999} % should return FALSE
\end{document}
Currently it returns FALSE in all cases. However given this answer to the question Check whether a color passed as argument to a package is defined my guess is that it should work. How to make it work?
Note: I know that latex3 now has \color_if_exist:nTF
, but I'm working with older packages and colors defined with latex2e.
\colorlet{blue}{red}
,\newcommand\niceorange{red!94!yellow}
. Other packages can also define colour names. Is the question about validating Material3 names (only)?