If all your key=value contents can be subject to full expansion you could use \expanded
to expand it before the tblr
-environment reads it. You should then protect the \begin
from expanding (using either \noexpand
as in the code below, or \unexpanded{<stuff>}
with <stuff>
replaced with whatever shouldn't expand further).
As already pointed out in my comment, arguments in TeX are separate sets of braces, so it would be \newcell{4}{4}{4}
instead of \newcell{4, 4, 4}
. Additionally the number of arguments for \newcommand
is given in brackets, not braces, as that's an optional argument: \newcommand{\newcell}[3]{<replacement text>}
.
With these things applied your code becomes the following:
\documentclass[preview]{standalone}
\usepackage{tabularray}
% previous parameter definition, does not scale
\def\cellax{1}
\def\cellay{2}
\def\cellaw{4}
\def\cellbx{2}
\def\cellby{3}
\def\cellbw{5}
% want to use a macro taking arguments
\newcommand{\newcell}[3]{
hline{#2-{#2+1}}={#1-{#1 + #3 - 1}}{solid},
vline{#1,#1+#3}={#2}{solid},
cell{#2}{#1}={c=#3}{c},
}
\begin{document}
\begin{table}[!ht]
\ttfamily
\centering
$\expanded{\noexpand\begin{tblr}{
hline{1}={1-Z}{solid},
hline{2}={1-Z}{solid},
vline{1}={1}{solid},
vline{2-11}={1}{dashed},
%
hline{\cellay-{\cellay+1}}={\cellax-{\cellax + \cellaw - 1}}{solid},
vline{\cellax,\cellax+\cellaw}={\cellay}{solid},
cell{\cellay}{\cellax}={c=\cellaw}{c},
%
hline{\cellby-{\cellby+1}}={\cellbx-{\cellbx + \cellbw - 1}}{solid},
vline{\cellbx,\cellbx+\cellbw}={\cellby}{solid},
cell{\cellby}{\cellbx}={c=\cellbw}{c},
% Want to use it here ....
\newcell{4}{4}{4},
%
hspan = even,
}}
x_1&x_2&x_3&x_4&x_5&x_6&x_7&x_8&x_9&x_{10}&\ldots\\
n_1&\\
&n_2 \\
&&n_3 \\
&&&&\ddots \\
\end{tblr}$
\end{table}
\end{document}

An alternative that gives more control could be to use expkv
1 and its key=value-expansion syntax. In the following the V:
in front of \newcell
tells expkv
to expand the following once (if it had a =
it'd expand the value instead of the key). Everything else is forwarded untouched (or at least almost untouched, one set of outer braces around a key-name would be stripped -- something not present in your MWE).
To simplify the job of wrapping your key-list in expkv
just for the expansion mechanism I wrote a short helper macro \keyexpander
. If you need explanations for it just ask.
\documentclass[preview]{standalone}
\usepackage{tabularray}
\usepackage{expkv-cs}
\newcommand*\keyexpander{\ekvoptarg\keyexpanderKV{}}
\ekvcSplitAndForward\keyexpanderKV\keyexpanderDO
{
pre = {}
,post = {}
,keyProc = \keyexpanderKEY
,pairProc = \keyexpanderPAIR
}
\ekvcSecondaryKeys\keyexpanderKV
{
nmeta oarg = { pre = [, post = ] }
,nmeta brace-keys =
{ keyProc = \keyexpanderKEYBR, pairProc = \keyexpanderPAIRBR }
,nmeta plain-keys =
{ keyProc = \keyexpanderKEY, pairProc = \keyexpanderPAIR }
}
\newcommand\keyexpanderDO[6]
{%
\expanded
{%
\unexpanded{#5#1}%
{%
\IfBlankF{#6}
{%
\unexpanded\expandafter\expandafter\expandafter
{%
\expandafter\keyexpanderCOMMA\expanded
{\expanded{\ekvparse{#3}{#4}{#6}}}%
}%
}%
}%
}%
#2%
}
\def\keyexpanderCOMMA, {}
\newcommand\keyexpanderKEY[1]{, \unexpanded{#1}}
\newcommand\keyexpanderPAIR[2]{, \unexpanded{#1}= {\unexpanded{#2}}}
\newcommand\keyexpanderKEYBR[1]{, {\unexpanded{#1}}}
\newcommand\keyexpanderPAIRBR[2]{, {\unexpanded{#1}}= {\unexpanded{#2}}}
% previous parameter definition, does not scale
\def\cellax{1}
\def\cellay{2}
\def\cellaw{4}
\def\cellbx{2}
\def\cellby{3}
\def\cellbw{5}
% want to use a macro taking arguments
\newcommand{\newcell}[3]{
hline{#2-{#2+1}}={#1-{#1 + #3 - 1}}{solid},
vline{#1,#1+#3}={#2}{solid},
cell{#2}{#1}={c=#3}{c},
}
\begin{document}
\begin{table}[!ht]
\ttfamily
\centering
$\keyexpander{\begin{tblr}}{
hline{1}={1-Z}{solid},
hline{2}={1-Z}{solid},
vline{1}={1}{solid},
vline{2-11}={1}{dashed},
%
hline{\cellay-{\cellay+1}}={\cellax-{\cellax + \cellaw - 1}}{solid},
vline{\cellax,\cellax+\cellaw}={\cellay}{solid},
cell{\cellay}{\cellax}={c=\cellaw}{c},
%
hline{\cellby-{\cellby+1}}={\cellbx-{\cellbx + \cellbw - 1}}{solid},
vline{\cellbx,\cellbx+\cellbw}={\cellby}{solid},
cell{\cellby}{\cellbx}={c=\cellbw}{c},
% Want to use it here ....
V: \newcell{4}{4}{4},
%
hspan = even,
}
x_1&x_2&x_3&x_4&x_5&x_6&x_7&x_8&x_9&x_{10}&\ldots\\
n_1&\\
&n_2 \\
&&n_3 \\
&&&&\ddots \\
\end{tblr}$
\end{table}
\end{document}
Output like above.
1Disclaimer: I'm the author of expkv
.
\newcommand\foo[3]{<stuff>}
should be used as\foo{a}{b}{c}
, not as\foo{a, b, c}
.