0

Every time I try to clip a Tikzpicture within math environments (id est, \begin{equation}\end{equation}, [] or $$) I get the following error

Package tikz Error: Extra options not allowed for clipping path command.

Here is the exact code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{parskip}
\usepackage{tikz}
\usepackage{tikz-cd}
\usepackage{float}
\usepackage{makeidx}
\usepackage{enumerate}
\usepackage{bm}
\usepackage{fancyhdr}
\usepackage[top=2cm,bottom=2cm]{geometry}
\usepackage{framed}
\usepackage{mdframed}
\usepackage{graphicx}
\usepackage{pict2e}

\usetikzlibrary{knots,intersections,decorations.pathreplacing,hobby,arrows,patterns} \tikzset{every path/.style={black,thick}, every node/.style={transform shape, knot crossing, inner sep=2.5pt}}

\begin{document}

[ \epsilon\left(\begin{tikzpicture}[scale=0.4] \clip (-1.5,-0.7)--(-1.5,0.7)--(1.5,0.7)--(1.5,-0.7)--(-1.5,-0.7)--cycle; \begin{scope}[yshift=-0.3cm] \draw[->,thin] (-1,-1)--(1,1); \draw[ultra thick,double distance=0.4pt,double=black,white] (-1,1)--(1,-1); \draw[->,thin] (-1,1)--(1,-1); \end{scope} \end{tikzpicture}\right) ]

\end{document}

I saw Drawing the rules for the bracket polynomial and got some ideas on how to fix my code. More specifically, following @egreg's answer by defining macros for the picture. However, I have a lot of knot diagrams drawn in mathematical environments, and most are scaled differently. The answer given by @GuM looked useful, but I did not understand how to implement it.

tl;dr: what is the best method to clip tikzpictures that are surrounded by mathematical environments, given that most are scaled differently?

edit: I am assuming it has something to do with the following line of code I have \tikzset{every path/.style={black,thick}, every node/.style={transform shape, knot crossing, inner sep=2.5pt}}

edit2: When I try adding \tikzset{every path/.style={}} before the clip, and \tikzset{every path={black,thick}} after the clip, it does remove the error. However, it does not end up drawing all diagrams properly. For instance,

\begin{align*}
  \left\langle\begin{tikzpicture}[scale=0.005]
  \tikzset{every path/.style={}}
  \clip (0,0)--(150,0)--(150,100)--(0,100);
  \tikzset{every path={black,thick}}
   \begin{scope}[yshift=-70cm]
    \draw[thin]    (98.5,132) .. controls (48.07,199.48) and (-22.7,112.44) .. (13.82,70.28) .. controls (26.55,55.59) and (52.31,46.35) .. (96.5,51) ;
    \draw[thin]    (44.5,39) .. controls (78.5,-45) and (130.5,45) .. (114.5,102) ;
    \draw[thin]   (127.5,58) .. controls (195.69,97.4) and (107.74,133.35) .. (64.59,109.76) .. controls (50.78,102.21) and (41.56,88.57) .. (43.5,67) ;
   \end{scope}%
  \end{tikzpicture}\right\rangle 
\end{align*}

removes some curves. Not sure why.

  • I cannot get the same error. Could you make your example complete (starts with \documentclass{...} and ends with \end{document})? – muzimuzhi Z Jan 09 '21 at 14:13
  • @muzimuzhiZ Sorry about that, I added the complete code now! – tikzboi Jan 09 '21 at 14:20
  • As far as I can see, the issue is due to every path/.style={black,thick} – egreg Jan 09 '21 at 14:23
  • @egreg, yeah I assumed so. But how do I change my code now without messing up any other knot diagram I have? Also, if you do remove every path/.style={black,thick} the diagram looks a lot different. So, I am not really sure. – tikzboi Jan 09 '21 at 14:27
  • You could state \tikzset{every path/.style={}} inside the tikzpicture before doing \clip. I see no difference whether or not I reinstate \tikzset{every path={black,thick} after the \clip line. – egreg Jan 09 '21 at 14:41
  • @egreg I added an edit2 to the question, it's a reply to your suggestion! – tikzboi Jan 09 '21 at 15:02
  • In your edit2, \tikzset{every path={black,thick}} should be \tikzset{every path/.style={black,thick}}. – muzimuzhi Z Jan 09 '21 at 18:30
  • Why do you need clip in the first place? The line ends look better if the sloped lines are not clipped horizontally. – Heiko Oberdiek Jan 18 '21 at 13:19

2 Answers2

0

Not sure if that error is really helpful, or should it be changed to warning by applying following patch?

\usepackage{xpatch}
\makeatletter
\xpatchcmd\tikz@finish
  {\tikzerror{Extra options not allowed for clipping path command.}}
  {\PackageWarning{tikz}{Extra options not allowed for clipping path command.}}
  {}{\fail}
\makeatother

IMOH, discarding unused \tikz@options in clip mode won't cause severe problems.

muzimuzhi Z
  • 26,474
0

I completely forgot to answer my question. @egreg's comment fixed the mistake.

I first made a new command to use:

\newcommand{\knotsinmath}[1]{%
 \tikzset{every path/.style={}}
 \begin{tikzpicture}[baseline=-\dimexpr\fontdimen22\textfont2\relax]
  #1
 \end{tikzpicture}%
}

Then, this works perfectly fine. The problem I was facing back then happened to do with the clip itself, but this also makes the error go away.

\begin{align*}
  \left\langle\knotsinmath{\begin{scope}[scale=0.005,yshift=-70cm]
   \clip (0,0)--(160,0)--(160,160)--(0,160)--cycle;
   \draw[thin]    (98.5,132) .. controls (48.07,199.48) and (-22.7,112.44) .. (13.82,70.28) .. controls (26.55,55.59) and (52.31,46.35) .. (96.5,51) ;
   \draw[thin]    (44.5,39) .. controls (78.5,-45) and (130.5,45) .. (114.5,102) ;
   \draw[thin]   (127.5,58) .. controls (195.69,97.4) and (107.74,133.35) .. (64.59,109.76) .. controls (50.78,102.21) and (41.56,88.57) .. (43.5,67) ;
   \end{scope}}\right\rangle
\end{align*}