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

Suggestion: optional prefix when using `head to column names` #7

Closed mikkelee closed 3 years ago

mikkelee commented 5 years ago

I currently name my columns with prefixes in the csv file itself to avoid clashes, but I'd like to be able to configure this, perhaps via /csv/head to column name prefix=⟨string⟩. Thoughts?

T-F-S commented 5 years ago

I think that is a valuable enhancement of the column name feature.

I made some tests and there seem to be no problems in implementing it. So, the new option will be part of the next release, but that may come not very soon.

For the meantime, the following patch could be used:

\makeatletter

\def\set@csv@autohead{%
  \toks0=\expandafter{\csname\csv@headnameprefix\csv@current@col\endcsname}%
  \toks1=\expandafter{\csname csvcol\romannumeral\c@csvcol\endcsname}%
  \begingroup\edef\csv@temp{\endgroup\noexpand\gdef\the\toks0{\the\toks1}\noexpand\csv@AtEndLoop{\noexpand\gdef\the\toks0{}}}%
  \csv@temp%
}

\csvset{%
  head to column names prefix/.store in=\csv@headnameprefix,%
  head to column names prefix=,%
}

\makeatother
mikkelee commented 5 years ago

Thanks! There's no rush :)

T-F-S commented 3 years ago

Implemented with version 1.22 (2021/06/07).