1

I am trying to understand how it works the decoration pgf module, in order to solve the unanswered question Fiber-Optic-Style decoration.

I am having an hard time with some macros, for example \pgfdecoratedpathlength. Look the following MWE, from what I read on the pgfmanual version 2.10, the options (1), (2) and (3) should be equivalent, but only (2) works, while I get 100 errors for the others.

\documentclass[a4paper]{article}

\usepackage{pgf,pgfsys,pgffor}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{tikz}
\usepgfmodule{decorations}
\usetikzlibrary{intersections,arrows,decorations,snakes}


\pgfdeclaredecoration{fiber}{initial}
{
    \state{initial}[
        switch if less than=\pgfdecoratedpathlength/2 to final %% (1)
        %width=\pgfdecoratedpathlength/2 %% (2)
        %width=.5\pgfdecoratedpathlength %% (3)
        ]{
        \pgflineto{\pgfpoint{5pt}{15pt}}
        \pgflineto{\pgfpoint{5pt}{-15pt}}
    }
    \state{final}{
        \pgfpathlineto{\pgfpointdecoratedpathlast}
    }
}

\begin{document}
\begin{tikzpicture}[decoration={fiber, amplitude=1cm}, draw=red]
\draw[->,decorate] (3, 5mm) -- ++(4,0); %% ERROR! Undefined control sequence. <argument> \pgf@decorate@width
\draw[->,decorate] (3,0)    -- ++(3,0);
\draw[->,decorate] (3,-5mm) -- ++(2,0);
\draw[->,decorate] (3,-1cm) -- ++(1,0);
\draw[->,decorate] (3,-1.5cm) -- ++(0.5,0);
\end{tikzpicture}

\end{document}

The first error is Undefined control sequence. <argument> \pgf@decorate@width , in the first draw. Any ideas?

2
  • That is not a TeX length but just a macro hence 0.5*\dimen should work instead of .5\dimen (not tested) – percusse Dec 17 '13 at 23:39
  • width=.5*\pgfdecoratedpathlength works for (3) in place of width=.5\pgfdecoratedpathlength. But why (1) does not work? By the manual, (1) and (2) should be completely equivalent. – Nicola Dec 18 '13 at 7:52
1

You forgot the comma after final. So width=\pgfdecoratedpathlength/2 is dropped and TikZ questioned that how come the width is not defined???

The following code works fine.

\documentclass[border=9,tikz]{standalone}
\usetikzlibrary{decorations}
\pgfdeclaredecoration{fiber}{initial}{
    \state{initial}[
        switch if less than=\pgfdecoratedpathlength/2 to final, %% (1)
        width=\pgfdecoratedpathlength/2 %% (2)
        ]{
        \pgflineto{\pgfpoint{5pt}{15pt}}
        \pgflineto{\pgfpoint{5pt}{-15pt}}
    }
    \state{final}{
        \pgfpathlineto{\pgfpointdecoratedpathlast}
    }
}

\begin{document}
    \begin{tikzpicture}[decoration={fiber, amplitude=1cm}, draw=red]
        \draw[->,decorate] (3, 5mm) -- ++(4,0);
    \end{tikzpicture}
\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.