tabularray
tabularray copied to clipboard
expand multiple macros
When I have more than one macro needed to expand in the table, and the macro including & or \\ placed after the macro not including & or \\, the table broken.
This sample code is ok:
\def\a{a &b\\}
\def\b{z}
\begin{tblr}[expand={\a,\b}]{hlines,vlines}
\b \\
\a
\end{tblr}

But when I changed the order of expand macroes, the table broken:
\begin{tblr}[expand={\b,\a}]{hlines,vlines}
\b \\
\a
\end{tblr}

In addition, when both two macros include & or \\, no matter what order it will make the table broken.
In fact, tabularray can only expand one macro. You can not put multiple macros there.
So, will more macros be expanded in futrue? :-)
Yes, I will make it possible to expand multiple macros in the future.
Thank you very much!
In fact, if all macros don't include & or \\, the table will be built correctly as expected.
Also interested in this feature, especially if the macros can take arguments as inputs. See my issue here https://tex.stackexchange.com/questions/675331/tabularray-expand-multiple-macros-with-background-color
@tobiasBora It doesn't really help even if tabularray could expand multiple macros. For commands with optional arguments, you need exhaustive expansions, which are provided by \expanded command:
\documentclass{memoir}
\usepackage{xcolor}
\usepackage{tabularray}
\NewExpandableDocumentCommand{\yes}{O{Yes}m}{\SetCell{bg=green9}#1}
\NewExpandableDocumentCommand{\no}{O{No}m}{\SetCell{bg=red8}#1}
\begin{document}
\begin{tblr}[expand=\expanded]{cc}
What I want & is below \\
\SetCell{bg=green9} Yes & \SetCell{bg=red8} No \\
\SetCell{bg=green9} Great & \SetCell{bg=red8} Bad \\
What I get & is below \\
\expanded{\yes{}} & \expanded{\no{}} \\
\expanded{\yes[Great]{}} & \expanded{\no[Bad]{}}
\end{tblr}
\end{document}

Note that you need to protect fragile commands (if any) inside them with \unexpanded command.
Awesome trick, thanks a lot! This should be documented.
Hi @lvjr. I faced upon this issue too and wondering if this is the intended behavior of tabularray. I noticed @muzimuzhi already worked on multiple macros expansion feature, but we still need to declare the macros list to be expanded.
I mean, is this inability to do automatic macros expansion of tabularray is the intended behavior, or it will be worked out in the future to reach "behavior parity" with tabular for the automatic macros expansion?
One of the use case would be if-else usage in the table environment.