I'm trying to employ the extremely cool inverted clipping from this question in combination with reusage of named paths with the use path key I stole from this question. However, it seems like my cargo-cult skills of stealing TikZ code from stackexchange are insufficient here, because in the MWE I constructed, the inversion of the clipping does not work as expected:


\tikzset{invclip/.style={clip,insert path={{[reset cm]
      (-16383.99999pt,-16383.99999pt) rectangle (16383.99999pt,16383.99999pt)

  use path for main/.code={%
      \expandafter\pgfsyssoftpath@setcurrentpath\csname tikz@intersect@path@name@#1\endcsname
  use path for actions/.code={%
    \expandafter\def\expandafter\tikz@preactions\expandafter{\tikz@preactions\expandafter\let\expandafter\tikz@actions@path\csname tikz@intersect@path@name@#1\endcsname}%
  use path/.style={%
    use path for main=#1,
    use path for actions=#1,

\begin{tikzpicture}[outer sep=0mm]
  \coordinate (A) at (-1,-1);
  \coordinate (B) at (1,-1);
  \coordinate (C) at (1,1);
  \coordinate (D) at (-1,1);
  \path[draw=black,name path=P] (A) -- (B) -- (C) -- (D) --cycle;
    \begin{pgfinterruptboundingbox} % useful to avoid the rectangle in the bounding box
      \path[invclip] (A) -- (B) -- (C) -- (D); % works just fine
      %\path[invclip,use path=P]; % doesn't work at all
  \fill[orange!50] (-2,-2) rectangle (2,2);

This works just fine:

this works

But this doesn't work:

this doesn't work

How can I use inverted clipping with use path?

  • In this example, of course, you could draw what you need much more easily. But I assume your real case is not so simple. – cfr Jul 19 '17 at 19:58
  • Yes, my actual case involves very complicated paths instead of rectangles, but is conceptually the same (an inner shape, an outer shape, and I want to fill just the area between the two). – carsten Jul 19 '17 at 20:40
  • Then why not just use the even odd rule? – cfr Jul 20 '17 at 0:29
  • 1
    There is an unofficial package spath that helps you connect two or more paths into one. In this case, you are connecting a huge rectangle with whatever complicated path you used to have. After all this is a matter of softpath operation. – Symbol 1 Jul 20 '17 at 12:48
  • 1
    @cfr According to Loop Space's comment, it is distinct but the same. (What am I talking about...) – Symbol 1 Jul 23 '17 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.