0

When I run the following code, there is a "dimension too large" error:

\documentclass[tikz]{standalone}

\usetikzlibrary{decorations.markings}
\usetikzlibrary{hobby}

\definecolor{col1}{RGB}{24,127,127}
\definecolor{col2}{RGB}{240,240,240}

\begin{document}

\begin{tikzpicture}[use Hobby shortcut]
    \clip (0,0) rectangle (1,1);
    \path[yshift=10,
    postaction={
        decorate,
        decoration={
            markings,
            mark=between positions 0 and \pgfdecoratedpathlength step .01cm with {
                \pgfmathsetmacro\myval{multiply(divide(
                    \pgfkeysvalueof{/pgf/decoration/mark info/distance from start}, \pgfdecoratedpathlength),100)};
                \pgfsetfillcolor{col2!\myval!col1};
                \pgfpathcircle{\pgfpointorigin}{1.5};
                \pgfusepath{fill};}
    }}] 
    ([closed].075,.2)..(.2,.4)..(.8,0)..(.925,.2)..(.8,.4)..(.2,0);
\end{tikzpicture}

\end{document}

I did a little search on this problem, and it turns out it is neither caused by length>16384pt nor incorrect shift. The error sometimes disappear when the order of the points at last line changes, but I don't remember the exact order, and I think it is not very relevant to this problem.

How should I fix this problem?

1 Answer 1

2

This is a known problem. Somewhere on this site it has already been pointed out that a large fraction of these errors can be avoided by using a reciprocal from the fpu library. This fixes the problem also in your case. Per request by Henri Menke here is a version that works with the newest pgf version, v3.1.6. You can read about this in section 50.2 Handling “Dimension too large” errors of pgfmanual v3.1.6.

\documentclass[tikz]{standalone}

\usetikzlibrary{decorations.markings}
\usetikzlibrary{hobby}
\usetikzlibrary{fpu}

\definecolor{col1}{RGB}{24,127,127}
\definecolor{col2}{RGB}{240,240,240}

\begin{document}

\begin{tikzpicture}[use Hobby shortcut,/pgf/fpu/install only={reciprocal}]
    \clip (0,0) rectangle (1,1);
    \path[yshift=10,
    postaction={
        decorate,
        decoration={
            markings,
            mark=between positions 0 and \pgfdecoratedpathlength step .01cm with {
                \pgfmathsetmacro\myval{multiply(divide(
                    \pgfkeysvalueof{/pgf/decoration/mark info/distance from start}, \pgfdecoratedpathlength),100)};
                \pgfsetfillcolor{col2!\myval!col1};
                \pgfpathcircle{\pgfpointorigin}{1.5};
                \pgfusepath{fill};}
    }}] 
    ([closed].075,.2)..(.2,.4)..(.8,0)..(.925,.2)..(.8,.4)..(.2,0);
\end{tikzpicture}

\end{document}

If you have an older TeX installation use the original code that appeared here before this was added to pgf.

\documentclass[tikz]{standalone}

\usetikzlibrary{decorations.markings}
\usetikzlibrary{hobby}
\usetikzlibrary{fpu}
\makeatletter
\tikzset{use fpu reciprocal/.code={%
\def\pgfmathreciprocal@##1{%
    \begingroup
    \pgfkeys{/pgf/fpu=true,/pgf/fpu/output format=fixed}%
    \pgfmathparse{1/##1}%
    \pgfmath@smuggleone\pgfmathresult
    \endgroup
}}}%
\makeatother

\definecolor{col1}{RGB}{24,127,127}
\definecolor{col2}{RGB}{240,240,240}

\begin{document}

\begin{tikzpicture}[use Hobby shortcut,use fpu reciprocal]
    \clip (0,0) rectangle (1,1);
    \path[yshift=10,
    postaction={
        decorate,
        decoration={
            markings,
            mark=between positions 0 and \pgfdecoratedpathlength step .01cm with {
                \pgfmathsetmacro\myval{multiply(divide(
                    \pgfkeysvalueof{/pgf/decoration/mark info/distance from start}, \pgfdecoratedpathlength),100)};
                \pgfsetfillcolor{col2!\myval!col1};
                \pgfpathcircle{\pgfpointorigin}{1.5};
                \pgfusepath{fill};}
    }}] 
    ([closed].075,.2)..(.2,.4)..(.8,0)..(.925,.2)..(.8,.4)..(.2,0);
\end{tikzpicture}

\end{document}

enter image description here

5
  • 2
    Use /pgf/fpu/install only={reciprocal} instead of use fpu reciprocal. Oct 31, 2020 at 15:40
  • @HenriMenke Done. But now it complains "Package PGF Math Warning: The key `/pgf/fpu/install only' is experimental and m ight change or disappear at any point! on input line 12.".
    – user227987
    Oct 31, 2020 at 15:53
  • Also it appears that the linked post was one of the first to point out that these errors can be avoided by using the reciprocal from fpu.
    – user227987
    Oct 31, 2020 at 23:03
  • @anonymous There are still 12 "dimension too large" error, and there's also Package pgfkeys: Choice 'orthogonal' unknown in choice key '/pgf/fpu'. I am going to ignore this key.
    – Jinwen
    Nov 1, 2020 at 1:04
  • @Jinwen It seems that you are using an older version of pgf. I therefore added a version that works for older version. In fact, this was the code I had posted originally. Only per request by Henri Menke I had changed it. Now there are both versions, and hopefully everyone is happy...
    – user227987
    Nov 1, 2020 at 1:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .