I am trying to define a colour (using the xcolor package) where the colour is provided by a macro in hex HTML format. I have a macro \colorGet{#1}{#2} which takes two arguments and returns the colour in hex format, which I would like to pass to the \definecolor macro.
Unfortunately, my naïve approach of simply passing one macro as the argument of the other doesn't work, and I understand this is because of the order in which LaTeX expands the macros. However, I don't understand how to ensure they are expanded in the correct order. I have attempted to modify this answer by Heiko Oberdiek to a similar question, but was unsuccessful. I don't understand \expandafter enough to know where I'm going wrong. A minimal (non-)working example of my attempt is below.
\documentclass{article}
%
\usepackage{xcolor}
%
\newcommand{\colorGet}[2]{D3523C} % A macro which returns a different hex-code for each combination of arguments, simplified for this example.
\newcommand{\colordefine}[2]{%
\expandafter\colordefineAux#2{#1}%
}
\newcommand{\colordefineAux}[2]{%
\definecolor{#2}{HTML}{#1}%
}
%
\begin{document}
\colordefine{mycolor}{\colorGet{SchemeName}{ColourName}}
\end{document}
Attempting to compile this gives the following error:
! Argument of \xs_newmacro_ has an extra }.
<inserted text>
\par
l.14 ...rdefine{Accent2}{\colorGet{Bold}{Accent2}}
Is there a relatively simple way to do this?
EDIT: As highlighted by Phelype Oleinik, the error message above is caused by the xstring package, which was used in the original definition of \colorGet. Since asking the question, I've realised that the xstring package isn't needed.
xstringpackage, which you don't load in your example code. The code from the post can be adapted to work, but the solution will not work withxstring, so please provide a complete example. (A side note: Heiko's answer works because the second argument of\colordefineis a single token, so\expandafterworks: yours are several tokens, so you need another approach). – Phelype Oleinik Jun 30 '20 at 13:11\colorGetmacro uses thexstringpackage for its\IfStrEqCasemacro, but I've since realised that it's not actually necessary, and I've edited the question accordingly. – pbc Jun 30 '20 at 13:44