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

csvsimple-l3 runs out of memory #32

Closed pkl97 closed 9 months ago

pkl97 commented 9 months ago

When csvsimple-l3 (version 2.3.2) is combined with siunitx and the last column in the table is of type "S", TeX runs out of memory.

This sample document shows the behavior:

\documentclass[12pt,a4paper]{article}

\usepackage[utf8]{inputenc}

\usepackage{csvsimple-l3}
\usepackage{siunitx}

\begin{filecontents}[overwrite,noheader]{TheCSVFile.csv}
station,rClear
VIENNA,0.985
\end{filecontents}

\begin{document}

\csvreader[
    head to column names,
    tabular = l|S,
]{TheCSVFile.csv}{}{ \station & \rClear }

\end{document}

The error message of command 'pdflatex example.tex':

Runaway argument?
{\g__csvsim_hook_before_filter_tl \g__csvsim_filter_tl \bool_if:NT \g__csvsim_l
ine_accepted_bool \ETC.
! TeX capacity exceeded, sorry [main memory size=5000000].
<argument> ...dy_tl \g__csvsim_hook_after_line_tl 
                                                  }}}}
l.20 \end
         {document}
!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on test.log.

If the last column is of type "r", the problem disappears.

T-F-S commented 9 months ago

This is a known incompatibility which is documented on page 55 of the documentation. S cannot be used as a first or last column.

Fortunately, it is easy to circumvent the problem. The best choice is to use \tablenum instead of an S column:

\documentclass[12pt,a4paper]{article}

\usepackage[utf8]{inputenc}

\usepackage{csvsimple-l3}
\usepackage{siunitx}

\begin{filecontents}[overwrite,noheader]{TheCSVFile.csv}
station,rClear
VIENNA,0.985
\end{filecontents}

\begin{document}

\csvreader[
    head to column names,
    tabular = l|c,
]{TheCSVFile.csv}{}{ \station & \tablenum{\rClear} }

\end{document}

Alternatively, you could an invisible dummy final column:

\documentclass[12pt,a4paper]{article}

\usepackage[utf8]{inputenc}

\usepackage{csvsimple-l3}
\usepackage{siunitx}

\begin{filecontents}[overwrite,noheader]{TheCSVFile.csv}
station,rClear
VIENNA,0.985
\end{filecontents}

\begin{document}

\csvreader[
    head to column names,
    tabular = l|S@{}c,
]{TheCSVFile.csv}{}{ \station & \rClear & }

\end{document}

Finally, you could collect the table data before using it:

\documentclass[12pt,a4paper]{article}

\usepackage[utf8]{inputenc}

\usepackage{csvsimple-l3}
\usepackage{siunitx}

\begin{filecontents}[overwrite,noheader]{TheCSVFile.csv}
station,rClear
VIENNA,0.985
\end{filecontents}

\begin{document}

\csvreader[
    collect data,
    head to column names,
]{TheCSVFile.csv}{}{ \csvexpval\station & \csvexpval\rClear }

\begin{tabular}{l|S}
\csvdatacollection
\end{tabular}

\end{document}

Personally, I would go for the first possibily, i.e. using \tablenum

pkl97 commented 9 months ago

Thanks a lot for the documentation hint and the 3 workarounds!

The first two worked out-of-the-box.

For the third an additional \\ was necessary in case the table has more than one row:

]{TheCSVFile.csv}{}{ \csvexpval\station & \csvexpval\rClear \\ }