I almost confranted with the same question as this link:
I get to know that:
\newcommandcouldn't be expanded with\edef\NewExpandableDocumentCommandcould be used with\edef
But in my following case, it seemed that it also related with the optional arguments?
\documentclass[border=6pt,tikz]{standalone} \usetikzlibrary{matrix} \NewExpandableDocumentCommand\testB{m}{\node {#1};} \newcommand{\testC}[1]{\node {#1};} \NewExpandableDocumentCommand\testBB{O{orange} m}{\node[draw=#1] {#2};} \newcommand{\testCC}[2][magenta]{\node[draw=#1] {#2};} \begin{document} \begin{tikzpicture} \matrix (m) [matrix of nodes] { TEST & REASON \\ \testB{I'm test B} & works with Expandable without optional argument\\ \testBB{I'm test BB} & works with Expandable with optional argument\\ \testC{I'm test C} & work with newcommand without optional argument\\ % \testCC{testCC} why? \testC is okay but \testCC failed? \texttt{testCC failed} & failed\\ }; \end{tikzpicture} \tikz{\testB{B}} \tikz{\testC{C}} \tikz{\testBB{BB}} \tikz{\testCC{CC}} \end{document} which yields:
Undefined control sequence. \\testCC [#1]#2->\node My Question:
Is there the exists of optional argument that differed between \newcommand and \NewExpandableDocumentCommand? Why? \testC is okay but \testCC failed in the above case?
Edit Confustion in comment:
Thanks to your paraphase, but if in my case if want to give the color to be optional assigned inside the \matrix, I think can't use \NewExpandandableDocumentCommand,because with the unexpandable \node inside, this will make the NewExpandableDocumentCommand NOT fully expandable.
Meanwhile the \newcommand*{<cmd>}[2][cyan]{<code>} doesn't track expandablity(failed with testCC), how can I make my cmd \node to handle the color argument properly?

\testCCfails because of the PGF/TikZ-matrix. If you use\path;\testCC{…}it works. It doesn't detect that your cell actually starts with\nodeand assumes the cell to be just text. So it does\node{\testCC{testCC} why?};which is a\nodecommand inside a node's text. And since\nodeis not defined outside of TikZ (and thus inside of nodes), you get an error message. What you can do is\newcomand*\testCCaux{\path;\testCC}\newcommand\testCC[2][magenta]{…}.nodeinside Expandable cmd.