
我將使用圍繞tabularray
的巨集製作一個包裝器。然而,使用“生成”會產生與直接輸入不同的結果。關於如何使兩個結果匹配有什麼想法嗎?\SetCell
lualatex
tex.sprint
\SetCell[c=2]{c}
微量元素:
\documentclass{scrartcl}
\usepackage{luacode}
\usepackage{tabularray}
\begin{luacode*}
function setcell(s)
tex.sprint('\\SetCell[c='..s..']{c}')
end
\end{luacode*}
\NewDocumentCommand{\SC}{O{}}{\luadirect{setcell(\luastring{#1})}}
\begin{document}
SetCell demonstration:\\
\begin{tblr}{|lll|}
\SetCell[c=2]{c} MULTI & & z \\
a & b & c\\
\end{tblr}
tex.sprinting SetCell thru lualatex:\\
\begin{tblr}{|lll|}
\SC[2] MULTI & & z \\
a & b & c\\
\end{tblr}
\end{document}
答案1
根據tabularray
包裝手冊(v2024A,2024-02-16),秒。 2.1“新舊介面”,
tabular
與環境相同array
,所有表格命令必須放置在儲存格文字的開頭。另外,新的表格指令必須被定義為\NewTableCommand
.
\SetCell
是內建表格指令之一\SC
,您的指令也需要是表格指令的包裝器\SetCell
,因此它必須使用\NewTableCommand
.
% !TeX program = lualatex
\documentclass{scrartcl}
\usepackage{luacode}
\usepackage{tabularray}
\begin{luacode*}
function setcell(s)
tex.sprint('\\SetCell[c='..s..']{c}')
end
\end{luacode*}
\NewTableCommand{\SC}[1][]{\luadirect{setcell(\luastring{#1})}}
\begin{document}
SetCell demonstration:\\
\begin{tblr}{|lll|}
\SetCell[c=2]{c} MULTI & & z \\
a & b & c\\
\end{tblr}
tex.sprinting SetCell thru lualatex:\\
\begin{tblr}{|lll|}
\SC[2] MULTI & & z \\
a & b & c\\
\end{tblr}
\end{document}