# dimension too large in pgfmathsetmacro

This works for

\test{500}

but not for let say

\test{50000}

\documentclass[10pt,german]{article}

\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{pgffor} %foreach

\newcommand{\Beleg}[2]{%
\expandafter\xdef\csname BelegKontozweiSoll#1\endcsname{#2}
}

\newcommand{\test}[1]{%
\pgfmathsetmacro{\saldoo}{#1}
\foreach \x in {10,20,30}{%
\pgfmathsetmacro{\saldo}{\csname BelegKontozweiSoll\x\endcsname+\saldoo}
\global\let\saldoo=\saldo
}
\textbf{\saldoo}
}

\begin{document}
\Beleg{10}{50.60}
\Beleg{20}{145.05}
\Beleg{30}{603.28}

\test{500}
\end{document}


how can i pass this problem? Note: in general my tex file is a little bit longer, so i want to keep

\csname .... \endcsname

vice versa, i have to change a lot of things in my original tex file, which i wont do that.

Someone have an idea?

Don't use pgf for such large numbers. As it internally uses dimensions its range is a bit restricted. With expl3 and its fp-library there is no problem:

\documentclass[10pt,german]{article}

\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{pgffor} %foreach
\sisetup{locale=DE}

\newcommand{\Beleg}[2]{%
\expandafter\xdef\csname BelegKontozweiSoll#1\endcsname{#2}
}

\ExplSyntaxOn
\newcommand{\test}[1]
{
\fp_set:Nn\l_tmpa_fp{#1}
\clist_map_inline:nn {10,20,30}
{
\fp_add:Nn \l_tmpa_fp { \use:c{ BelegKontozweiSoll##1} }
}
\textbf{\num[detect-weight]{\fp_eval:n{\l_tmpa_fp}}}
}
\ExplSyntaxOff

\begin{document}
\Beleg{10}{50.60}
\Beleg{20}{145.05}
\Beleg{30}{603.28}

\test{50000}
\end{document}

• Thanks a lot! But i dont like to work with this. Is it possible to combine FPeval with csname...endcsname? If it is possible, then i also can use let say round(..) and a lot of other stuff which is easy to use. expl3 is a little bit weird... – Bilal Yilmaz Apr 16 at 8:33
• Sure replace \use:c {...} by \csname ... \endcsname. \use:c is only a wrapper around this primitive (and shorter to type ...). – Ulrike Fischer Apr 16 at 8:36
• could you please adapt the codes to fpeval so i can see explicit how do you mean that. I will be very very apretiate – Bilal Yilmaz Apr 16 at 8:37
• Hm. I think you should better get used to expl3. The colons and underscore may look a bit weird at the first glance, but you get quite fast used to it - better than \csname, \xdef and \expandafter. round() and so works there fine too. You can e.g. replace \fp_add:Nn by \fp_set:Nn . – Ulrike Fischer Apr 16 at 8:53
• can you please read my new answer. I have written down what im looking for. – Bilal Yilmaz Apr 16 at 9:07

I mean something like this:

\documentclass[10pt,german]{article}

\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{pgffor} %foreach
\usepackage[nomessages]{fp}% http://ctan.org/pkg/fp   -> FPeval
\usepackage{fp}

\newcommand{\Beleg}[2]{%
\expandafter\xdef\csname BelegKontozweiSoll#1\endcsname{#2}
}

\newcommand{\test}[1]{%
\pgfmathsetmacro{\saldoo}{#1}
\foreach \x in {10,20,30}{%
\FPeval{\saldo}{ {\csname BelegKontozweiSoll\x \endcsname} + \saldoo}
\FPeval{\saldoo}{\saldo}
}
\textbf{\saldoo}
}

\begin{document}
\Beleg{10}{50.60}
\Beleg{20}{145.05}
\Beleg{30}{603.28}

\test{50000}
\end{document}


This works also fine for 50000 but FPeval doesnt take the value

{\csname BelegKontozweiSoll\x \endcsname}

Can you please adapt this part of the code? So then i have not to use expl3. I like FPeval....

• You are forgetting that \foreach builds a group, the calculated value can't escape. – Ulrike Fischer Apr 16 at 9:22
• I got it! Solution below :) Finally, puhh! Thanks a lot Ulrike – Bilal Yilmaz Apr 16 at 9:22

Now i got it :) - its possible to combine FPeval with csname ... endcsname - its possible that the calculated value in foreach is global (xdef....)

\documentclass[10pt,german]{article}

\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{pgffor} %foreach
\usepackage[nomessages]{fp}% http://ctan.org/pkg/fp   -> FPeval
\usepackage{fp}

\newcommand{\Beleg}[2]{%
\expandafter\xdef\csname BelegKontozweiSoll#1\endcsname{#2}
}

\newcommand{\test}[1]{%
\FPeval{\saldoo}{#1}
\foreach \x in {1,...,5}{%
\FPeval{\saldo}{ \csname BelegKontozweiSoll\x \endcsname + \saldoo}
\FPeval{\saldoo}{\saldo}
\xdef\saldoo{\saldo}
}
\saldoo
}

\begin{document}
\Beleg{1}{25}
\Beleg{2}{25}
\Beleg{3}{25}
\Beleg{4}{100}
\Beleg{5}{100}

\test{50000}
\end{document}


Finish :)

• You shouldn't assign \saldoo both locally and globally, it will use up your stack. (fp does it wrong too in quite some places, and that's why e.g. this exploded: tex.stackexchange.com/questions/459626/…. One reason why I don't use fp). – Ulrike Fischer Apr 16 at 9:36
• ok thanks! i changed it to something else. – Bilal Yilmaz Apr 16 at 9:40