
を使用して のマクロtabularray
のラッパーを作成します。 を使用して を生成すると、直接入力した場合とは異なる結果が生成されます。 2 つの結果を一致させる方法について何かご意見はありますか?\SetCell
lualatex
tex.sprint
\SetCell[c=2]{c}
MWE:
\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
は組み込みのテーブル コマンドの 1 つであり\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}