[Tex/LaTex] How to invert a ‘clip’ selection within TikZ

tikz-pgf

I wish to draw an arc for a reflex angle on the outside of a triangle with coordinates (A), (B) and (C).

If I wanted to draw the arc inside the triangle I could use something like

\begin{scope}
\path[clip] (A) -- (B) -- (C) -- cycle;
\draw (B) circle (2mm);    % this is the little angle marker
\end{scope}

Is there a straightforward way to exclude the part of the circle that's in the triangle, as in the pseudo-code below?

\begin{scope}
\path[magicalinverseclipcommand] (A) -- (B) -- (C) -- cycle;
\draw (B) circle (2mm);    % this is the little angle marker
\end{scope}

EDIT: Although I included the code above as a motivating example of what an inverse clip would do, I would prefer a general solution that works systematically with any closed path, and not just in the particular example of a triangle with a circle clipped out of it. Looking at my question, I realise this isn't clear, and I will be happy with the best solution to my particular problem, but wonder if there is a less ad hoc solution than those listed so far.

Best Answer

What you can do is add a rectangle to your clipping path that's larger than the current bounding box, and clip with that. Andrew Stacey suggested using the current page as the clipping rectangle, because that will catch all elements that follow. By using the pgfinterruptboundingbox environment when defining the clipping rectangle, the actual size of the tikzpicture will not be influenced.

Note that, in order to use the current page, the remember picture,overlay options need to be passed to the tikzpicture, and you need two compile runs to get the positioning of all the elements right. Furthermore, this doesn't work with the minimal documentclass.

\documentclass{article} % Has to be a proper class, not minimal
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[remember picture,overlay]

% A path that follows the edges of the current page
\tikzstyle{reverseclip}=[insert path={(current page.north east) --
  (current page.south east) --
  (current page.south west) --
  (current page.north west) --
  (current page.north east)}
]

\coordinate (A) at (0,0);
\coordinate (B) at (1,0);
\coordinate (C) at (1,1);

\begin{pgfinterruptboundingbox} % To make sure our clipping path does not mess up the placement of the picture
\path [clip] (A) -- (B) -- (C) -- cycle [reverseclip];
\end{pgfinterruptboundingbox}

\draw[thick] (A) circle (2mm);
\draw[thick] (B) circle (2mm);    
\draw[thick] (C) circle (2mm);   

\end{tikzpicture}
\end{document}


And just to show that it works for the general case:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[remember picture,overlay]

% A path that follows the edges of the current page
\tikzstyle{reverseclip}=[insert path={(current page.north east) --
  (current page.south east) --
  (current page.south west) --
  (current page.north west) --
  (current page.north east)}
]

\draw [step=0.1,red] (0,0) grid  (2,2);

\begin{pgfinterruptboundingbox} % To make sure our clipping path does not mess up the placement of the picture
\path [clip,rounded corners] (0,0) -- (.75,0) -- (1.2,.8) -- (2,1) -- (1.4,1) -- (1.2,2) -- (.3,.75) -- cycle [reverseclip];
\end{pgfinterruptboundingbox}

\draw [step=0.1,thick] (0,0) grid  (2,2);

\end{tikzpicture}
\end{document}

general path clipped