I'm working on a command that involves checking several arguments to see if they're colours, and doing something with those that are. I can't get \tl_if_eq
to recognise matches.
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\IsColour}{m}{
\clist_if_in:nnTF {
red,
orange,
yellow,
green,
blue,
purple,
white,
gray,
brown,
black
} { #1 } { TRUE } { FALSE }
}
\NewDocumentCommand{\TestA}{}{
\tl_set:Nn \l_test { TRUE }
\tl_if_eq:NnTF \l_test { TRUE } { TRUE } { FALSE }
}
\NewDocumentCommand{\TestB}{}{
\tl_set:Nn \l_test { \IsColour{red} }
\tl_if_eq:NnTF \l_test { TRUE } { TRUE } { FALSE }
}
\ExplSyntaxOff
\begin{document}
\TestA % works as desired
\hspace{1em}
\IsColour{red} % works as desired
\hspace{1em}
\TestB % doesn't work
\end{document}
Edit 1 in response to egreg's request for more detail.
The ultimate aim is to create a \Style
function with two mandatory arguments, the first being a comma- or semicolon-separated list of parameters, and the second being the body of text to which the style should be applied.
I'm interested in the possibility of an unordered syntax for the list of parameters, without using explicit key-value pairs. For that, I'm trying to check each argument to see what type of parameter it is (e.g. colour, emphasis, etc.) and use it accordingly, assuming that no parameter belongs to multiple categories.
The finished product would look like this:
\Style{red,italic}{hi} % returns \textit{\color{red}hi}
\Style{italic,red}{hi} % returns \textit{\color{red}hi}
My specific question could also be phrased as: how can I check if the output of a function matches a specified value?
Edit 2 in response to David Carlisle's suggestion.
I guess I'm missing something because I can't get this to work.
\documentclass{article}
\def\ZZred#1{\textcolor{red}{#1}}
\newcommand{\Style}[2]{
\csname ZZ#1\endcsname{#2}
}
\begin{document}
\Style{red}{hi}
\end{document}
\IsColour
is not expandable.\NewExpandableDocumentCommand
doesn't seem to fix it. Can you give any more detail?\IsColour{red}
withTRUE
and of course this will return false. Please, add some more details about your aim.interface3
is meant as a reference manual, hence the relatively small number of examples. As far as possible, it does detail formally the nature of each function including any restrictions. We know that a 'Programming usingexpl3
' guide is needed, but these things are hard to write. We have pointed to a very good web resource which aims to do that: latex-project.org/news/2020/11/09/l3-tutorial.