diff --git a/fontspec-code-keyval.dtx b/fontspec-code-keyval.dtx index e4dc19f..84bb91a 100644 --- a/fontspec-code-keyval.dtx +++ b/fontspec-code-keyval.dtx @@ -697,30 +697,51 @@ % \end{macrocode} % % \paragraph{Color} -% Hooks into pkg{xcolor}, which names its colours \texttt{\char`\\color@}. +% Test first if the color is a named l3color, then if it is a color from +% \pkg{xcolor}, which names its colours \texttt{\char`\\color@}. +% If this fails the argument is assumed to be a hex color. +% % \begin{macrocode} \@@_keys_define_code:nnn {fontspec} {Color} { %<*XE> - \cs_if_exist:cTF { \token_to_str:N \color@ #1 } + \color_if_exist:nTF {#1} { - \convertcolorspec{named}{#1}{HTML}\l_@@_hexcol_tl + \color_export:nnN {#1} {HTML}\l_@@_hexcol_tl } { - \int_compare:nTF { \tl_count:n {#1} == 6 } - { \tl_set:Nn \l_@@_hexcol_tl {#1} } + \cs_if_exist:cTF { \token_to_str:N \color@ #1 } + { + \convertcolorspec{named}{#1}{HTML}\l_@@_hexcol_tl + } { - \int_compare:nTF { \tl_count:n {#1} == 8 } - { \fontspec_parse_colour:viii #1 } + \int_compare:nTF { \tl_count:n {#1} == 6 } + { \tl_set:Nn \l_@@_hexcol_tl {#1} } { - \bool_if:NF \l_@@_firsttime_bool - { \@@_warning:nx {bad-colour} {#1} } + \int_compare:nTF { \tl_count:n {#1} == 8 } + { \fontspec_parse_colour:viii #1 } + { + \bool_if:NF \l_@@_firsttime_bool + { \@@_warning:nx {bad-colour} {#1} } + } } } } % %<*LU> - \tl_set:Nn \l_@@_hexcol_tl {#1} + \color_if_exist:nTF {#1} + { + \tl_set:Nn \l_@@_hexcol_tl {#1} + } + { + \cs_if_exist:cTF { \token_to_str:N \color@ #1 } + { + \convertcolorspec{named}{#1}{HTML}\l_@@_hexcol_tl + } + { + \tl_set:Nn \l_@@_hexcol_tl {#1} + } + } % } % \end{macrocode}