Maybe I have a similar problem as in this question, as well as this?
I must commit, that I haven't understand the answer from David Carlisle in the second link, concerning the direct expansion, so I am not able to adapt his solution onto my situation. :-(
I have a great collection of >60 logo files. The logo file names are made up from components, each representing some specifications (e.g. german language vs. english language, ...).
I want to create a macro, which will receive input about one or two of the components and should compute the desired logo file name, which should be handed over to includegraphics, to be used as input in the mandatory brace.
Of course the planned macro is somewhat more complex, than this MWE, but it shows my actual problem very well. My intention was, to return a string like LOGO-compA-compB-compC as result of the macro. (The logo files will be found on the TEXMF-tree, I only compute the name of the file.)
\documentclass[parskip=full]{scrartcl}
\usepackage{graphicx}
%%% New commands, to compute a grahics file name.
%% Simple
\newcommand{\foo}{example-image-c}
%% Defining one argument, which is not used.
\newcommand{\baz}[1]{example-image-b}
%% Enabling a default for the argument.
\newcommand{\foobar}[1][example-image-a]{#1}
\begin{document}
\includegraphics[height=.7cm]{\foo} \ % works
\includegraphics[height=.7cm]{\baz{}} \ % Works also
%% won't work. Missing endcsname inserted??
\includegraphics[height=.7cm]{\foobar[example-image-c]} \
%% Won't work either
\includegraphics[height=.7cm]{\foobar} \
\includegraphics[height=.7cm]{\foobar[example-image-c]} \
\end{document}
What is the trick to get it working?

\newcommandis not expandable, this can't work as you plan. – Skillmon May 29 '21 at 17:52