Minimal working example:
%! TeX program = lualatex
\documentclass{article}
\usepackage{pyluatex}
\usepackage{tabularray}
\usepackage{xcolor}
\begin{document}
\let\rows\relax
\begin{python}
print("\global\def\rows{Alpha & Beta & Gamma & Delta \\ Epsilon & Zeta & Eta & Theta \\ Iota & Kappa & Lambda & Mu \\ Nu & Xi & Omicron & Pi \\}")
\end{python}
\let\trivgroups\relax
\begin{python}
mystr = ""
for i in range(1,5):
mystr += 'cell{'+str(i)+'}{'+str(i)+'} = {red4},'
print("\global\def\trivgroups{"+mystr+"}")
\end{python}
\ExplSyntaxOff
% This works
% \begin{tblr}[expand=\rows]{colspec={|c|c|c|c|},
% cell{1}{1}={red4},
% cell{2}{2}={red4},
% cell{3}{3}={red4},
% cell{4}{4}={red4}
% }
\begin{tblr}[expand=\rows]{colspec={|c|c|c|c|},\trivgroups}
\rows
\end{tblr}
\end{document}
Compilation still works
> lualatex --output-format=pdf --shell-escape pythontex-tabularray.tex
However, no colour in the output:
The commented version gives
Follow-up question of Generate rows for tabularray with pyluatex with possible related questions:
- tabularray: Expand multiple macros
- tabularray: Reading a table stored in a macro by catchfile
- Misplaced alignment tab character &. with tabularray and expl3
- What is the best way to expand macros inside keyval input in expl3
UPDATE
Before I used the new environment exptblr from the answer by egreg, I could rotate the text in the header row as following:
\documentclass{article}
\usepackage{pyluatex}
\usepackage{tabularray}
\usepackage{xcolor}
\usepackage{rotating}
\usepackage{makecell}
\UseTblrLibrary{diagbox}
\setlength\rotheadsize{5cm}
\renewcommand\theadfont{}
\ExplSyntaxOn
\NewDocumentEnvironment{exptblr}{O{}m}
{
\use:x
{
\exp_not:N \begin{tblr}
[\exp_not:n{#1}]
{#2}
}
}
{
\end{tblr}
}
\ExplSyntaxOff
\begin{document}
\let\rows\relax
\begin{python}
print("\global\def\rows{Alpha & Beta & Gamma & Delta \\ Epsilon & Zeta & Eta & Theta \\ Iota & Kappa & Lambda & Mu \\ Nu & Xi & Omicron & Pi \\}")
\end{python}
\begin{python}
mystr = ""
for i in range(2,5):
mystr += 'cell{'+str(i)+'}{'+str(i)+'} = {red4},'
\end{python}
\begin{tblr}[expand=\rows]{
colspec={|c|c|c|c|},
cell{1}{2-Z} = {halign=c,cmd=\rothead},
hlines,vlines,
% \py{mystr},
}
\diagbox[height=4cm,width=4cm]{subgroups $H$}{supergroups $G$} &
G1 Very Long & G2 Very Long & G3 Very Long \
\rows
\end{tblr}
\end{document}
But when I now use the new environment exptblr, I get following error:
! Use of \@gape doesn't match its definition.
\@ifnextchar ...eserved@d =#1\def \reserved@a {#2}
\def \reserved@b {#3}\futu...
l.45 }
?




\let\command\relax. I guess it's a PythonTeX pattern. PyLuaTeX doesn't need it because it does everything in a single run. – Aug 16 '22 at 19:51evalWholeandtlUseshould work here. – user202729 Aug 17 '22 at 16:11