T-F-S / csvsimple

A LaTeX package for lightweight CSV file processing.
http://www.ctan.org/pkg/csvsimple
LaTeX Project Public License v1.3c
24 stars 5 forks source link

Collect the processed results #15

Closed muzimuzhi closed 2 years ago

muzimuzhi commented 3 years ago

In certain cases, it is desired that the processed results are collected and stored in a macro rather than being print piece by piece, so the results could be further processed. For example, package tabularray need collect

the whole body and spliting it into cells by \\ and & with regex. Therefore you can not hide \\ and & characters in commands. see https://github.com/lvjr/tabularray/issues/23#issuecomment-866469939

In this answer on TeX-SX, I did a naive patch to csvsimple-legacy (I should have patched the -l3 version, hmmm.), in which a bool key store only and a command \csvoutput are provided. Then I realized that the collection can be turned on by default, and store only can only control if the collected results are auto used at the end of \csvloop / \__csvsim_loop:.

T-F-S commented 3 years ago

Collecting all material automatically by a global key is perhaps a goal to high to reach. The general assumption of your nice patch on TeX-SX is that material by keys like before line can be collected and processed at the end. But, that is not always true, because I have applications where keys like that contain computations which influence the further processing (filter, for example).

Maybe, something like the \gappto etc. macros from etoolbox package could be used to collect and build up data into a macro. No concrete solution, just brainstorming:

before line=<compute something>\csvapp{xy},        % with computation and saving xy

before line=\csvapp{xy},     % no computation, just saving xy

before line app=xy,        % shortcut

command=\csvappo{\csvcoli} \csvapp{&} \csvappo{\csvcolii},    % possibly not so nice; \csvappo for expanding once
T-F-S commented 3 years ago

After some experiments, maybe, command keys could be identified to be collected automatically and others not. Also, computing stuff could be forbidden to put into before line...

E.g. after line is a candidate for collection and before filter is a candidate for not being collected...

muzimuzhi commented 3 years ago

brainstorming continued

[...] But, that is not always true, because I have applications where keys like that contain computations which influence the further processing (filter, for example).

Seems like a call for piped processors: generator, filter (with write to aux), accumulator, and writer. As you said, "perhaps a goal too high to reach".

T-F-S commented 3 years ago

I just uploaded version 2.1.0 (2021/07/01). With the new option collect data I would consider the feature request to be fulfilled as far as possible. The collection is limited, but I think a lot of things can be done with the new code.

muzimuzhi commented 3 years ago

So quick!

A minor improvement: doc for options no table, before table, table head,table foot, and after table need mention one of tabularray, \begin{tabularray}, and \end{tabularray}. Or, use a placeholder, e.g. <tabular-like env> which stands for one of the supported tabular-like env name, to get a more compact and easy-to-extend (documentary) style.

https://github.com/T-F-S/csvsimple/blob/db30cc51928617709ba02d9565e9498f94c618d0/doc/latex/csvsimple/csvsimple-l3.tex#L1427-L1453

lvjr commented 3 years ago

Great! I found typos on page 37 of the documentation: 2021-07-26 should be 2021-07-06.

T-F-S commented 3 years ago

Thank you both - I will correct and improve all mentioned things.

T-F-S commented 2 years ago

Corrected and improved with version 2.2.0 (2021-09-09)