Following this answer by @JasperHabicht, in my code, I would like to add an option to that macro so, depending on a flag I can execute either \drawMoveFromSgfCoords or \drawStoneFromSgfCoords. I still don't know much about expl3, so this is kinda my pseudocode:
% Parameters
%
% 1: array of {<black | white>, <coordinates}
%
% Example usage: `drawStonesOrMovesFromSgfCoords{{black, ab}, {white, cd}}{true}`
\ExplSyntaxOn
\NewExpandableDocumentCommand{\drawStonesOrMovesFromSgfCoords}{ m }{ m }{
\clist_set:Nn \l_tmpa_clist { #1 }
\clist_map_inline:Nn \l_tmpa_clist {
\clist_set:Nn \l_tmpb_clist { ##1 }
\clist_pop:NN \l_tmpb_clist \l_tmpa_tl
\clist_pop:NN \l_tmpb_clist \l_tmpb_tl
% I'm trying to fix what's in-between parentheses below:
\exp_args:Noo (\bool_if:NN ##2 \drawStoneFromSgfCoords \drawMoveFromSgfCoords) { \l_tmpa_tl } { \l_tmpb_tl }
}
}
\ExplSyntaxOff
Here's a more or less complete example (if you know the syntax, this is probably gonna be unnecessary):
\documentclass{article}
\usepackage{tikz}
% From this answer by @DavidCarlisle.
\newcommand\notwhite{black}
\newcommand\notblack{white}
% From this answer by @DavidCarlisle.
\ExplSyntaxOn
\cs_generate_variant:Nn \int_from_alph:n {e}
\NewExpandableDocumentCommand{\stringToCoordX}{ m }{
\int_from_alph:e { \use_i:nn #1 }
}
\NewExpandableDocumentCommand{\stringToCoordY}{ m }{
\int_from_alph:e { \use_ii:nn #1 }
}
\ExplSyntaxOff
\newcommand{\drawStoneFromSgfCoords}[2]{
\pgfmathsetmacro{\x}{\stringToCoordX{#2} - 1}
\pgfmathsetmacro{\y}{\stringToCoordY{#2} - 1}
\draw[draw = \UseName{not#1}, fill = #1, line width = 0.1mm]
(\x * 10cm / 18, \y * 10cm / 18)
circle [radius = 0.2575cm];
}
\newcounter{moveCounter}
\setcounter{moveCounter}{1}
\newcommand{\drawMoveFromSgfCoords}[2]{
\pgfmathsetmacro{\x}{\stringToCoordX{#2} - 1}
\pgfmathsetmacro{\y}{\stringToCoordY{#2} - 1}
\draw[draw = \UseName{not#1}, fill = #1, line width = 0.1mm]
(\x * 10cm / 18, \y * 10cm / 18)
circle [radius = 0.2575cm]
node[color = \UseName{not#1}]
{\themoveCounter};
\stepcounter{moveCounter}
}
\ExplSyntaxOn
% Example usage: drawMovesOrStonesFromSgfCoords{{black, ab}, {white, cd}}
\NewExpandableDocumentCommand{\drawMovesOrStonesFromSgfCoords}{ m }{
\clist_set:Nn \l_tmpa_clist { #1 }
\clist_map_inline:Nn \l_tmpa_clist {
\clist_set:Nn \l_tmpb_clist { ##1 }
\clist_pop:NN \l_tmpb_clist \l_tmpa_tl
\clist_pop:NN \l_tmpb_clist \l_tmpb_tl
\exp_args:Noo \drawStoneFromSgfCoords { \l_tmpa_tl } { \l_tmpb_tl }
}
}
\ExplSyntaxOff
\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro{\step}{10 / 18}
\draw[step=\step] (0, 0) grid (10, 10);
%\drawStoneFromSgfCoords{black}{ab}
%\drawStoneFromSgfCoords{white}{cd}
\drawMovesOrStonesFromSgfCoords{{black, ab}, {white, cd}}
\end{tikzpicture}
\end{document}

\str_case:nn. – 314159265358979323 Feb 08 '24 at 14:30exp_args:...explicitly, and\exp_args:Noois a bit odd asojust expand one step whereas normally ou want full expansioneif you want it at all but\exp_args:Noo (\bool_if:NN ##appliesNto(,oto\bool_if:NNand#which probably wan't the intention? – David Carlisle Feb 08 '24 at 14:56\NewExpandableDocumentCommand{\drawStonesOrMovesFromSgfCoords}{ m }{ m }{ ...}won't work. You need to pass the specification of all the arguments (metc.) as a single argument. So you'd need\NewExpandableDocumentCommand{\drawStonesOrMovesFromSgfCoords}{ m m }{ ...}. Your code never actually uses the second argument. Probably you wanted#2rather than##2? – cfr Feb 08 '24 at 17:40