# Tikz style conflicting with clip command

Below is my example. I'd like to use a global style for all my tikz pictures to set up the line width. It is working well until I use a clip. I guess that it is not possible to pass some style option to clip. The code below gives the error msg

Package tikz Error: Extra options not allowed for clipping path command. \clip (2,0) circle (2cm);


Here is the MWE.

\documentclass{article}
\usepackage{tikz}
\tikzset{every path/.style={line width=2pt}}
\begin{document}
\begin{tikzpicture}
\clip (2,0) circle (2cm);
\draw (0,0) circle (3cm);
\end{tikzpicture}
\end{document}


Any help?

Here are three solutions.

1) If you necessarily need every path/.style, choose this excellent answer from Matthew Leingang (but the TeX group around \clip prevents the propagation of the bounding box):

\documentclass{article}
\usepackage{tikz}

\tikzset{every path/.style={draw=blue,line width=2pt}}
\begin{document}
\begin{tikzpicture}
{
\tikzset{every path/.style={}}
\clip (2,0) circle (2cm);
}
\draw (0,0) circle (3cm);
\end{tikzpicture}
\end{document}


2) Most of the time, you can avoid to use every path/.style. Here, you can use every picture/.style instead of every path/.style:

\documentclass{article}
\usepackage{tikz}
\tikzset{every picture/.style={line width=2pt}}
\begin{document}
\begin{tikzpicture}
\clip (2,0) circle (2cm);
\draw (0,0) circle (3cm);
\end{tikzpicture}
\end{document}


3) The third solution redefines the clip option :

\documentclass{article}
\usepackage{tikz}

\makeatletter
\tikzset{clip/.code={%
\let\tikz@mode=\pgfutil@empty%
\let\tikz@preactions=\pgfutil@empty%
\let\tikz@postactions=\pgfutil@empty%
\let\tikz@options=\pgfutil@empty%
},
}
\makeatother

\tikzset{every path/.style={line width=2pt}}
\begin{document}
\begin{tikzpicture}
\clip (2,0) circle (2cm);
\draw (0,0) circle (3cm);
\end{tikzpicture}
\end{document}

• Well, if you’re proposing the second solution, do \tikzset{clip/.code={\tikz@addmode{\tikz@mode@cliptrue}\let\tikz@options=\pgfutil@empty}} and you can use the original \path[clip] and \clip. – Qrrbrbirlbel Dec 26 '12 at 18:44
• @Qrrbrbirlbel Thanks for your suggestion: I edited my answer. – Paul Gaborit Dec 26 '12 at 18:58
• Of these three, Matthew's is the most reliable and robust. It really should be the first version given. – Loop Space Dec 26 '12 at 23:13
• @AndrewStacey The first solution is simpler: every picture can replace every path in the majority of cases! – Paul Gaborit Dec 26 '12 at 23:20
• Disagree. In simple cases, maybe, but it's not difficult to come up with examples where the behaviour is radically different. every scope comes in between, for example. – Loop Space Dec 26 '12 at 23:32

This is a crude method. Instead of changing the path style, you can define a my path and use it.

\documentclass{article}
\usepackage{tikz}
\tikzset{my path/.style={line width=2pt}}
\begin{document}
\begin{tikzpicture}
\clip (2,0) circle (2cm);
\draw [my path] (0,0) circle (3cm);
\end{tikzpicture}
\end{document}


Or define tikzset after clip (if needed put it inside a scope):

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\clip (2,0) circle (2cm);
\begin{scope}
\tikzset{every path/.style={line width=2pt}}
\draw  (0,0) circle (3cm);
\end{scope}
\end{tikzpicture}
\end{document}

• Thanks for your help. But with you suggestion I would have to use the my style on every picture. I'd like to set up global line width to change on the whole document. – Sigur Dec 26 '12 at 12:29
• @Sigur Unfortunately yes. But second option is somewhat less brutal. For using it globally, one has to patch the \clip command. Let us wait for tikz gurus. :-) – user11232 Dec 26 '12 at 12:41