3

Georges Dupéron's solution of the question "Tikz: Shading a path without any filling" is definitely what I need and it's an excellent solution. Since the spath package has had an improve version (spath3 package) and been released on CTAN, I want to change Georges Dupéron's solution to use spath3 instead. However, I'm a beginner in LaTeX from China and can't understand the source code of spath3, especially the ExplSyntax in the code. So I just changed the line

\usepackage{spath}% for "use path", from the TeX.SX 

in the file fade-no-fill.sty to

\usepackage{spath3}% for "use path", from the TeX.SX 

then run the main.tex with pdflatex main.tex, and I got this error message:

! Package pgf Error: Unknown class 'spath'.

I only figured out that this line

\pgfoonew \thepathsav=new spath(\tmppath)

in the file fade-no-fill.sty cause this error.

Now I don't know what to do!

Can someone help me to do this?

Some explanation on how to use the spath3 package would be greatly appreciated as well.

  • Where did you get the spaht3.sty from? Appearantly you have to get the spath3.dtx, run pdflatex spath3.dtx to get the spath3.sty. Have you done that? – Guilherme Zanotelli Nov 22 '16 at 11:04
  • Yes,I download the spath3.dtx then run pdflatex spath3.dtx to get the spath3.sty.Got the error mentioned in the question. When I use \usepackage{spath} It works very well.I wonder how to use \usepackage{spath3} to do the same thing as use \usepackage{spath} – Cong Yang Nov 30 '16 at 8:44
5

Firstly, spath3 is on CTAN and is part of TeXLive so doesn't need to be separately downloaded.

Secondly, it does feel slightly overkill to be using it in this context, but I don't know enough about how fadings work to be able to extract only the needed parts. What is needed is the facility to save and restore a path (which is easy enough to do without spath3) but also to restore the bounding box of that path (which ought to be doable without spath3, but my initial experiments dismally failed).

So here's the original code modified to use spath3. It works on the code from the original answer, but I haven't tested it on anything else. I've also removed some unnecessary code from the original.

The original document is unchanged:

\documentclass[tikz,border=5mm]{standalone}
%\url{https://tex.stackexchange.com/q/134283/86}
\usepackage{tikz}
\usepackage{fade-no-fill}
\begin{document}

\begin{tikzpicture}
  \draw[style=help lines] (0,-2) grid[step=1cm] (2,0);
  \path[
    fade path but don't fill={
      very thick,
      transparent!20,
      ->
    }{
      top color=blue!80,
      bottom color=green!80,
    },
  ] (0cm,0cm) .. controls +(0cm,-1cm) and +(0cm,1cm) .. (1cm,-2cm);


  \begin{scope}[x=0.5cm,y=0.5cm]
    % Circles, each with a distinct fading
    \foreach \i in {1,...,5}{
      \pgfmathsetmacro{\j}{18*\i}
      \path[
        fade path but don't fill={
          very thick,
          transparent!\j,
        }{
          top color=green!80,
          bottom color=blue!80,
          shading angle=45,
        },
      ] (1+\i,-\i) circle (\i mm);
    }

    % Circles, with a global fading
    \path[
      fade path but don't fill={
        very thick,
        transparent!60,
      }{
        top color=blue!80,
        bottom color=green!80,
      },
    ] foreach \i in {1,...,5}{
      (\i-1,-\i-3) circle (\i mm)
    };
  \end{scope}
\end{tikzpicture}

\end{document}

and fade-no-fill.sty is now:

%\url{https://tex.stackexchange.com/a/327713/86}
\usetikzlibrary{math}%
\usetikzlibrary{fadings}%
\usepackage{spath3}
\usetikzlibrary{arrows.meta}% needed so that bounding boxes correctly include arrows.

\ExplSyntaxOn
\cs_if_exist:NF \spath_set_current_softpath:n {

\cs_new_protected_nopar:Npn \spath_set_current_softpath:n #1
{
  \spath_get:nnN {#1} {min bb} \l__spath_tmpa_tl
  \exp_last_unbraced:NV \pgf@protocolsizes\l__spath_tmpa_tl

  \spath_get:nnN {#1} {max bb} \l__spath_tmpa_tl
  \exp_last_unbraced:NV \pgf@protocolsizes\l__spath_tmpa_tl

  \spath_get:nnN {#1} {path} \l__spath_tmpa_tl
  \pgfsyssoftpath@setcurrentpath\l__spath_tmpa_tl
}
}
\tikzset{restore~ soft~ path/.code={%
    \spath_set_current_softpath:n {#1}
  }
}
\ExplSyntaxOff

\tikzset{
  fade path but don't fill/.style 2 args={
    preaction={save spath=fadingpath,},
    postaction={
      /utils/exec={
        \coordinate (oldbb-ne) at (current bounding box.north east);
        \coordinate (oldbb-sw) at (current bounding box.south west);
        \pgfresetboundingbox
        \begin{tikzfadingfrompicture}[name=tempfade]%
        \pgfresetboundingbox
        \draw[restore soft path=fadingpath,#1];
        \coordinate (temp-fade-bb-ne) at (current bounding box.north east);
        \coordinate (temp-fade-bb-sw) at (current bounding box.south west);
        \coordinate (temp-fade-bb-center) at (current bounding box.center);
        \end{tikzfadingfrompicture}
        %
        \useasboundingbox (oldbb-ne) rectangle (oldbb-sw);
        %
        \tikzmath{
          coordinate \ctempfadebbcenter;
          \ctempfadebbcenter = (temp-fade-bb-center);
        }
        \tikzset{tempstyle/.style/.expand once={#2}}
        \path[
          path fading=tempfade,
          fit fading=false,
          fading transform={
            yshift=\ctempfadebbcentery,
            xshift=\ctempfadebbcenterx,
          },
          tempstyle,
        ] (temp-fade-bb-ne) rectangle (temp-fade-bb-sw);
      },
    },
  },
}

Interestingly, I had to add a new command \spath_set_current_softpath:n to ensure that the fading picked up the arrow heads. This will make its way into spath3 at some point which is why I've wrapped it in a \cs_if_exist:NF.

  • @CongYang No worries. It's been a while since you asked your question so I wouldn't expect you to be eagerly awaiting an answer. – Loop Space Aug 4 '17 at 11:33

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.