New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NewDocumentCommand to generate row content #18
Comments
The major limitation of |
At this moment, the above example can be written as follows (with version 2021K of \documentclass{article}
\usepackage{tabularray}
\begin{document}
\newcommand\printdate[1]{\texttt{#1}}
\begin{tblr}{
cell{-}{1}={preto=\printdate\bgroup,appto=\egroup},
cell{-}{3}={preto=(,appto=)},
}
2021-05-12 & Alpha & Beta & Gamma Delta \\
2021-06-01 & Epsilon & Rho & Phi Nu Mu \\
\end{tblr}
\end{document} |
You are so totally right, of course: separate content from styling! I was clinging to my old mental model still. And your solution is also so much more elegant, because it saves me from making that same function call again and again for each row. Super cool! The selectors ( The prefix/postfix approach you have now is easy to understand, and straightforward to use. So I guess it is well suited for most users. What do you think about generalising this by also allowing to specify a function, that will be invoked for each selected cell? The function would take a single, mandatory argument, in which it would receive the cell's content. If the selection is for a row, or column, the function would be invoked for each cell in the selected row or column. With such a mechanism, the MWE could hypothetically be written as: \documentclass{article}
\usepackage{tabularray}
\ExplSyntaxOn
\cs_new:Npn \my_datepr:n #1 { \texttt{#1} }
\cs_new:Npn \my_braces:n #1 { (#1) }
\ExplSyntaxOff
\begin{document}
\begin{tblr}{
column{1}={proc=\my_datepr:n},
column{3}={proc=\my_braces:n},
}
2021-05-12 & Alpha & Beta & Gamma Delta \\
2021-06-01 & Epsilon & Rho & Phi Nu Mu \\
\end{tblr}
\end{document} |
Good idea. I will add this option for rows/columns/cells later (maybe with a better name?). |
Cool! Yes, please feel free to choose a name. |
I have added |
I have added \newcommand{\printdate}[1]{\texttt{#1}}
\newcommand{\tabentry}[4]{
\printdate{#1} & #2 & (#3) & #4 \\
}
\begin{tblr}[expand=\tabentry]{ccc}
\tabentry{2021-05-12}{Alpha}{Beta}{Gamma Delta}
\tabentry{2021-06-01}{Epsilon}{Rho}{Phi Nu Mu}
\end{tblr} |
I would like to be able to define a new command to generate table row content according to a defined scheme. In the old days I would do something like this in my class file:
And in my documents:
But with
tblr
I get a "misplaced alignment tab character &" error.I tried my luck with
\NewTableCommand
, but it seems that whatever I define is inserted at the beginning, or at the end of a row only. It seems\NewTableCommand
is forhline
-type use cases only?When I escape the alignment tab as
\&
or\string&
I get literal ampersands in the rendered output.Also, the way of specifying the arguments to
\NewTableCommand
seems to be quite specific to how it is used intabularray
itself.So I guess my ideal solution would be a way of using the standard
\NewDocumentCommand
(or\NewExpandableDocumentCommand
if need be), and enjoy the power ofxparse
, to define a function producing table row content.I would not mind whether the
\\
is inserted by the newly defined command (as shown i the example above), or in the table, btw.The text was updated successfully, but these errors were encountered: