3

Background: I am trying to apply multiple decorations to a path in a TikZ picture. In this particular case, my attempts fail as the maximum dimension PGF can calculate with is exceeded.

This is not exactly the path I had trouble with (as that path is very deeply embedded in a complex tikzpicture), but it is similar and illustrates the problem in response to a request in the comments. I'm not sure if what I'm trying to do is just somewhat crazy but anyway:

\documentclass[tikz]{standalone}
\usepackage{fp}
\usetikzlibrary{calc,decorations.pathmorphing,decorations.text,fixedpointarithmetic}
\begin{document}

  \begin{tikzpicture}
    [
    nant/.append style={draw=#1, double=#1!25, double distance between line centers=5.5pt, line width=.5pt, decorate, decoration={snake, segment length=10pt, amplitude=.5pt}},
    ]
    \node (n1) [draw] {Some Information};
    \node (n2) [anchor=south east, yshift=7.5pt, draw] at (n1.north east) {Terminology};
    \node (n3) [anchor=north east, draw, xshift=-25mm] at (n1.south west) {Something};
    \coordinate (nant4) at ($(n1.north east |- n2.south)!1/2!(n1.north east)$);
    \coordinate (nant3) at ($(n1.north west |- nant4) + (5pt,0)$);
    \coordinate (nant2) at ($(n3.east) + (35pt,10pt)$);
    \coordinate (nant1) at ($(n3.east |- nant2) + (10pt,-7.5pt)$);
    \path [nant=blue,postaction={decoration={text along path, text={|\scriptsize\scshape|the flow of stuff ||}, text color=blue, raise=-.5pt}, decorate}] (nant1) to [out=0, in=-135] (nant2) to [out=45, in=180] (nant3) -- (nant4);
%   \path [nant=blue] (nant1) to [out=0, in=-135] (nant2) to [out=45, in=180] (nant3) -- (nant4);
%   \path [postaction={decoration={text along path, text={|\scriptsize\scshape|the flow of stuff ||}, text color=blue, raise=-.5pt}, decorate}] ($(nant2) + (0,-4pt)$) to [out=45, in=180] ($(nant3) + (0,-1.25pt)$) -- ($(nant4) + (0,-1.25pt)$);
  \end{tikzpicture}

\end{document}

The commented lines show the method I'm using to approximate the result I want, just in case it isn't clear what the intended result is, and to save somebody the trouble of suggesting it.

Guided by Alain Matthes's answer, I tried to use the fixedpointarithmetic library for the particular path in the picture. However, this seems to cause pdflatex to hang indefinitely. (I know this library slows things down but I don't think it should take quite this long. At least, when it doesn't hang, it works in a reasonable time.)

Simplifying, I came up with this Minimum (non-)Working Example:

\documentclass[tikz]{standalone}
\usepackage{fp}
\usetikzlibrary{calc,decorations.pathmorphing,decorations.text,fixedpointarithmetic}
\begin{document}

  \begin{tikzpicture}
    [
    nant/.append style={draw=#1, double=#1!25, double distance between line centers=5.5pt, line width=.5pt, decorate, decoration={snake, segment length=10pt, amplitude=.5pt}},
    ]
    \path [nant=red] (0,5) -- (10,10);
    \path [nant=blue] (0,0) to [out=190, in=30] (10,5);
    \path [fixed point arithmetic, nant=green] (0,10) -- (10,15);
    \path [fixed point arithmetic, nant=black] (0,0) to [out=190, in=30] (10,5);
  \end{tikzpicture}

\end{document}

The first three paths are drawn fine if I comment out the fourth but the fourth causes the hang. Given that PGF's maths parser can cope with this path without resorting to the used of fixed point, it presumably cannot be a capacity issue. So there is something about trying to draw the curved path, it seems, as opposed to the straight line.

What am I doing wrong here? The manual doesn't say much about situations where you cannot use fixed point so I'm not sure what to look for or where to start. Any suggestions for diagnostics would be appreciated.

  • It compiles if you don't use fixedpointarithmetic though. so any reason to include it? – percusse Aug 5 '14 at 23:19
  • @percusse Yes. I know. That's why I said that PGF's parser can cope with this without resorting to fixed point. The blue path is identical to the black path except for the used of fixed point. However, in my original code, the numbers are too big for PGF's own parser which is why I was trying to use fixed point. The code in the question is just a minimal example ;). – cfr Aug 5 '14 at 23:22
  • But note that it is caused because of the sharp turns on the edges so fixed point arithmetic might not help there. I'll try fpu to see if it is so when I have chance. Can oyu include the problematic path? – percusse Aug 5 '14 at 23:25
  • @percusse Thanks for your help. Please see my edit. – cfr Aug 5 '14 at 23:52
2

Your text along path decoration is applied to the path morphed by the snake decoration (a line with many small segments). Draw both decorations separately (1st solution) or via a preaction and a postaction (2nd solution) and you get a good result without fixedpointarithmetic library.

Note: to use fixedpointarithmetic library in a tikzpicture, you must define /pgf/fixed point arithmetic (as my comments in the following code).

enter image description here

1st solution (two paths)

\documentclass[tikz]{standalone}
%\usepackage{fp}
\usetikzlibrary{calc,decorations.pathmorphing,decorations.text}%,fixedpointarithmetic}
\begin{document}

  \begin{tikzpicture}%[/pgf/fixed point arithmetic]
    \tikzset{
    nant/.append style={draw=#1, double=#1!25, double distance between line centers=5.5pt,
      line width=.5pt, decorate, decoration={snake, segment length=10pt, amplitude=.5pt}},
    }
    \node (n1) [draw] {Some Information};
    \node (n2) [anchor=south east, yshift=7.5pt, draw] at (n1.north east) {Terminology};
    \node (n3) [anchor=north east, draw, xshift=-25mm] at (n1.south west) {Something};
    \coordinate (nant4) at ($(n1.north east |- n2.south)!1/2!(n1.north east)$);
    \coordinate (nant3) at ($(n1.north west |- nant4) + (5pt,0)$);
    \coordinate (nant2) at ($(n3.east) + (35pt,10pt)$);
    \coordinate (nant1) at ($(n3.east |- nant2) + (10pt,-7.5pt)$);
    \path [nant=blue]
    (nant1) to [out=0, in=-135] (nant2) to [out=45, in=180] (nant3) -- (nant4);
    \path [decoration={text along path,text={|\scriptsize\scshape|the flow of stuff ||},
      text color=blue, raise=-.5pt}, decorate]
    (nant1) to [out=0, in=-135] (nant2) to [out=45, in=180] (nant3) -- (nant4);
  \end{tikzpicture}

\end{document}

2nd solution (single path with preaction and postaction)

\documentclass[tikz]{standalone}
%\usepackage{fp}
\usetikzlibrary{calc,decorations.pathmorphing,decorations.text}%,fixedpointarithmetic}
\begin{document}

  \begin{tikzpicture}%[/pgf/fixed point arithmetic]
    \tikzset{
    nant/.append style={draw=#1, double=#1!25, double distance between line centers=5.5pt,
      line width=.5pt, decorate, decoration={snake, segment length=10pt, amplitude=.5pt}},
    }
    \node (n1) [draw] {Some Information};
    \node (n2) [anchor=south east, yshift=7.5pt, draw] at (n1.north east) {Terminology};
    \node (n3) [anchor=north east, draw, xshift=-25mm] at (n1.south west) {Something};
    \coordinate (nant4) at ($(n1.north east |- n2.south)!1/2!(n1.north east)$);
    \coordinate (nant3) at ($(n1.north west |- nant4) + (5pt,0)$);
    \coordinate (nant2) at ($(n3.east) + (35pt,10pt)$);
    \coordinate (nant1) at ($(n3.east |- nant2) + (10pt,-7.5pt)$);
    \path[preaction={nant=blue},
    postaction={decoration={text along path,text={|\scriptsize\scshape|the flow of stuff ||},
        text color=blue, raise=-.5pt}, decorate}]
    (nant1) to [out=0, in=-135] (nant2) to [out=45, in=180] (nant3) -- (nant4);
  \end{tikzpicture}

\end{document}
  • Thanks! So is fixed point arithmetic something you either apply to a whole picture, or not at all? – cfr Dec 31 '14 at 20:39
  • @cfr The fixed point arihtmetic key is a key path. But, as the pgfmanual says (p.633) : "The best way to use this key is as an argument to a scope or picture." fp computations are very slow. – Paul Gaborit Jan 4 '15 at 7:57
2

I have no problem compiling your code when added, as you suggest, fixed point arithmetic. The compilation takes on my 5 years old PC :

  • 70 sec for XeLaTeX (pdf size 8Kb)
  • 72 sec for PDFLaTeX (pdf size 27Kb)
  • 94 sec for LuaLaTeX (pdf size 27Kb)

Probably on a modern phone it will be faster ;)

enter image description here

UPDATE: Here is the result of your MnWE (30 sec) :

enter image description here

  • Can you compile my MnWE without modification? If so, I am curious why I can't.... – cfr Jan 4 '15 at 15:08
  • @cfr Here it is. – Kpym Jan 4 '15 at 17:43
  • Weird. We must have different versions of something, I guess. Thanks for testing. – cfr Jan 4 '15 at 18:55
  • @cfr Are you using a Mac ? Just a joke ;) – Kpym Jan 4 '15 at 19:26
  • Why a joke? But, no. I'm not using a Mac. – cfr Jan 4 '15 at 19:29

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.