3

I will be making a wrapper around tabularray's \SetCell macro using lualatex. Using tex.sprint to produce \SetCell[c=2]{c} however produces a different results than typing it in out directly. Any thoughts on how I can get the two results to match?

enter image description here

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}
3
  • Thanks @DavidCarlisle. I was able to make a wrapper around multicolumn/row/makecell using luadirect and NewExpandableDocumentCommand in my lutabulartools package, though. Apr 17 at 20:42
  • actually I think I'll delete that comment, as it's confusing here, tabulararray has the additional issue that it normally doesn't expand stuff until too late, see the expand key Apr 17 at 20:47
  • see also tex.stackexchange.com/a/624065/1090 but I'm not sure expand= is expanded early enough to control column spans Apr 17 at 20:49

1 Answer 1

5

According to the tabularray package manual (v2024A, 2024-02-16), sec. 2.1 "Old and New Interfaces",

Same as tabular and array environments, all table commands must be put at the beginning of the cell text. Also, new table commands must be defined with \NewTableCommand.

\SetCell is one of built-in table commands and your \SC command, a wrapper for \SetCell need to be a table command too, thus it must be defined with \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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .