Closed muzimuzhi closed 2 years ago
Why not use \begin{<table env>}{...} \csvreader... \end{<table env>}
:
Package tabularray
splits the body of its tblr
env into cells by \\
and &
, so the above usage is not supported. See https://github.com/lvjr/tabularray/issues/23#issuecomment-866469939 and this TeX-SX question.
Edit: This is a fake reason because adding table env
will not solve the tabularray
problem.
Some related thoughts:
table env args=[t]{##1}
to set to finally use \begin{<table env>}[t]{<preable>}
.\__csvsim_loop:
to store the output contents in a macro, for example \csvoutput
, rather than directly print out. Or even write to some aux file, like /tcb/saveto=<file name>
in tcolorbox
.
Update: Hmmm, this is harder than I thought. tabularray
requires the \begin{tblr}
, \end{tblr}
, \\
and &
to be directly seen in replacement text of \csvoutput
.(Was my original proposal an X-Y problem?)
As the author of tabularray
package, I will add a new feature in next version for expanding \tblrbody
command once before parsing \\
and &
, therefore you only need to \let \tblrbody = \csvoutput
, if csvsimple
could store the output in the macro.
@lvjr It seems the issue can be resolved on the csvsimple
side, and I've made a naive attempt. Also I opened
I'm not convinced about a configurable tabular environment name, because the differerent environments (existing or yet to be written) need different treatment of options and settings and just changing the name is not enough. You realized that and also proposed to configure the arguments, but this also not enough for tabularry
which needs body collection. Other environments may also need special things further.
So, I think, a common architecture with table~env
and further keys will be a moving target whenever a new environment comes up with new unforseen feature.
What I would love to have and implement is specialized support for tabularray
(and, maybe, other packages) with a tabularray
options which also sets necessary actions to collect the needed data. I have to admit that I did not know that package before, but the documentation looks very promising. @lvjr I think a new feature to set the content of the table by a macro which is expanded once, as you wrote, could be very helpful.
@T-F-S Glad to hear that you will implement specialized support for tabularray
package, I have added the feature of expanding \tblrbody
once in the latest source code. Now the following example should work:
\def\tblrbody{
\hline
20 & 30 & 40\\
50 & 60 & 70\\
\hline
}
\begin{tblr}{|c|c|c|}
\tblrbody
\end{tblr}
@lvjr I'm still experimenting with the user interface to avoid expansion specific things as far as possible.
With version 2.1.0 (2021/07/06)
, there is support for tabularray
with an equally named option. I also added some examples.
Thanks. I have tried the new release. It's wonderful!
It would be nice if csvsimple
could also support long tabularray
. Not much change, only need to change the environment name from tblr
to longtblr
.
Also in the example in page 52, \SetCell
and \SetRow
were protected by \csvexpnot
. It was because they were defined only inside tblr
environment.
In the above commit https://github.com/lvjr/tabularray/commit/8185714d459f3a921eb519fca73f29021e2e2487, I have defined all \Set***
commands outside tblr
environment. Then with the next release 2021M of tabularray
planned on 1st August, users don't need to protect these commands.
BTW, \tablenum
also need not to be protected by \csvexpnot
. Only \hline
, \cline
, etc need to be protected.
\ifcsvstrcmp{\group}{A}{\csvexpnot\SetRow{brown7}}{}
\csvexpnot\SetCell{bg=purple7}
\csvexpval\land
& \csvexpval\group
& \csvexpval\amount
& \csvexpnot\tablenum[exponent-mode=scientific, round-precision=3, round-mode=places, table-format=1.3e1]{\fpeval{pi*\amount}}
Your package evolves with large steps, because I did not see longtblr
the last time I looked into the documentation - and that was not long before 👍
Yes, I will add a long tabularray
option to use this fine new feature.
According \tablenum
you are right that \csvexpnot
is not needed. I going add some text in the documentation about when protection is needed.
Tabularray could not redefine \hline
and \cline
commands globally since other packages need them. If csvsimple
could redefine and protect these two commands before fully expanding contents inside \csvreader
(need to restore the original definitions afterwards), then users need not to protect them either.
Redefining \hline
, \cline
et.al. could be dangerous, because one does not know how user apply them exactly.
In many (most?) cases, a refinition or protection is not needed, because \hline
is likely to be used inside options like late after line
which are collected unexpanded. Only command
is (and needs to be) expanded.
Thanks for the explanation. Sorry, I am still not enough familiar with csvsimple
.
I have submitted version 2021M (2021-08-01)
of tabularray
to CTAN.
By now tabularray
has several predefined table environments: tblr
, longtblr
, talltblr
(similar to threeparttable
) and booktabs
. And users can define new table environments with \NewTblrEnviron
commands.
Maybe it would be better to make tabular env name configurable. Also there are more and more specifications in the optional arguments of various tabularray
environments. So it would be nice if users could set the contents of the optional argument too.
Spreadtab, a package for doing some spreadsheet calculation for tables, provides the following syntax for supporting various tabular envrionments:
\begin{spreadtab}{{<envname>}{<parameter>}}
......
\end{speadtab}
And after calculation, the package converts the above code to
\begin{<envname>}{<parameter>}
......
\end{<envname>}
Although it is an old package, I succeeded in writing the following:
\begin{spreadtab}{{tabularray}[<options>]{<parameter>}}
......
\end{speadtab}
Package nicematrix
has several environments with two optional arguments. In my opinion something like env head = {{<envname>}{<parameter>}}
maybe useful for supporting various tabular enviroments. Although different tabulars have different syntax, csvsimple
only need to generates cell contents, not need to touch others.
OK, I will think about adding a generic table option with configurable environment name. I still fear that tomorrow a new thing comes up which does not fit, but for the current tables (with and without data collection) a generalization is possible.
Implemented with version 2.2.0 (2021-09-09)
.
There are new options generic table
, generic collected table
, and generic table options
.
For example, to use talltblr
, something like the following can be used:
generic collected table = talltblr,
generic table options = {[caption={Test}]{colspec={XXX}}},
Great. Thank you!
Currently,
csvsimple
supports only three hard-coded tabular-like environments:tabular
,longtable
, andtabbling
. But there exist other tabular-like envs and the number of them slowly grows. For example, see newly emerged packagesnicematrix
andtabularray
.Hence the request to make the tabular env name configurable. For example, a new option
table env=<env name>
defined (and internally used) by