2

I have to send quite a bit of documentation to Germany for taxes. I created some TeX files which use some CSV files to automatically generate this report. So far, I was a student and numbers were low. Last year I started working and I just noticed that my earnings last year cause csvsimple to fail. How do I fix it?

Minimal Example

2017-nicht-selbststaendig.csv:

Datum;Text;Betrag
18.12.2017;Lohnsteuer Empoyer 2017;16384.00

main.tex:

\documentclass[a4paper, 12pt]{article}
\usepackage[utf8]{inputenc} % this is needed for umlauts
\usepackage[ngerman]{babel} % this is needed for umlauts
\usepackage[T1]{fontenc}    % needed for right umlaut output in pdf
\usepackage[ngerman, num]{isodate} % get DD.MM.YYYY dates
\usepackage[locale=DE,group-minimum-digits={3}]{siunitx}
\usepackage{parskip}
\usepackage{fancyhdr}
\usepackage[rmargin=2.4cm]{geometry}
\usepackage{csvsimple}
\usepackage{pgfplots}

\fancypagestyle{appendix}{%
    \fancyhead{}
    \renewcommand{\headrulewidth}{0pt}
}

\setlength{\headheight}{15pt} % fixes \headheight warning
\lhead{Martin Thoma, Poststraße 1, 81234 München}
\rhead{Id-Nr. 72 123 123}

% Begin document %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\pagestyle{fancy}
\section*{Überschussrechnung 2017}

\subsection*{Einnahmen aus nicht-selbstständiger Tätigkeit}
\csvreader[before reading=\def\nichstselbststaendig{0},separator=semicolon]{2017-nicht-selbststaendig.csv}{Betrag=\Betrag}{%
\pgfmathsetmacro{\nichstselbststaendig}{\nichstselbststaendig+\Betrag}%
}

\begin{tabular}{|p{2cm}|p{10.4cm}|p{2cm}|}\hline%
\textbf{Datum} & \textbf{Text} & \textbf{Betrag}
\csvreader[head to column names,separator=semicolon]{2017-nicht-selbststaendig.csv}{}%
{\\\hline\Datum & \Text &\hfill\num[round-mode=places,round-precision=2]{\Betrag}}%
\\\hline\hline
\multicolumn{2}{|l|}{Summe} & \hfill\num[round-mode=places,round-precision=2]{\nichstselbststaendig}
\\\hline
\end{tabular}

\end{document}

The error

! Dimension too large.
<to be read again> 
                   \relax 
l.30 }
2

The problem is not csvsimple but pgfmath. If you use xfp and \fpeval to do the sum, it works:

\documentclass[a4paper, 12pt]{article}
\usepackage[utf8]{inputenc} % this is needed for umlauts
\usepackage[ngerman]{babel} % this is needed for umlauts
\usepackage[T1]{fontenc}    % needed for right umlaut output in pdf
\usepackage[ngerman, num]{isodate} % get DD.MM.YYYY dates
\usepackage[locale=DE,group-minimum-digits={3}]{siunitx}
\usepackage{parskip}
\usepackage{fancyhdr}
\usepackage[rmargin=2.4cm]{geometry}
\usepackage{csvsimple,xfp}

\fancypagestyle{appendix}{%
    \fancyhead{}
    \renewcommand{\headrulewidth}{0pt}
}

\setlength{\headheight}{15pt} % fixes \headheight warning
\lhead{Martin Thoma, Poststraße 1, 81234 München}
\rhead{Id-Nr. 72 123 123}

% Begin document %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\pagestyle{fancy}
\section*{Überschussrechnung 2017}

\subsection*{Einnahmen aus nicht-selbstständiger Tätigkeit}
\csvreader[before reading=\def\nichstselbststaendig{0},separator=semicolon]{testcsv.csv}{Betrag=\Betrag}{%
\edef\nichstselbststaendig{\fpeval{\nichstselbststaendig+\Betrag}}%
}

\begin{tabular}{|p{2cm}|p{10.4cm}|p{2cm}|}\hline%
\textbf{Datum} & \textbf{Text} & \textbf{Betrag}
\csvreader[head to column names,separator=semicolon]{testcsv.csv}{}%
{\\\hline\Datum & \Text &\hfill\num[round-mode=places,round-precision=2]{\Betrag}}%
\\\hline\hline
\multicolumn{2}{|l|}{Summe} & \hfill\num[round-mode=places,round-precision=2]{\nichstselbststaendig}
\\\hline
\end{tabular}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.