0

I am attempting to add in some TikZ pictures as math symbols to represent some knot equations. Hence, I've created a couple of commands to create these images quickly.

\newcommand{\KA}[1]{
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
\draw [line width=1.5]    (100.4,110.6) .. controls (119.4,71.1) and (119.4,71.1) .. (99.9,30.6) ;
\draw [line width=1.5]    (150.9,110.1) .. controls (131.9,70.1) and (130.9,70.1) .. (150.4,30.1) ;
\end{tikzpicture}
}

\newcommand{\KB}[1]{ \begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1] \draw [line width=1.5] (207.02,45.05) .. controls (246.62,63.85) and (246.62,63.85) .. (287.02,44.15) ; \draw [line width=1.5] (207.78,95.55) .. controls (247.68,76.35) and (247.68,75.35) .. (287.78,94.65) ;

\end{tikzpicture} }

Then, I attempt to use this in a document. In a regular environment, this is fine. However, inside mathmode, where I need it, it throws an error. For something simple like:

$$
\KA + \KB
$$

, I get the error: enter image description here

Then, I attempted to use \mathord{} around each command. Still I get the error.

Here is the MWE:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}

\newcommand{\KA}[1]{ \begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1] \draw [line width=1.5] (100.4,110.6) .. controls (119.4,71.1) and (119.4,71.1) .. (99.9,30.6) ; \draw [line width=1.5] (150.9,110.1) .. controls (131.9,70.1) and (130.9,70.1) .. (150.4,30.1) ; \end{tikzpicture} }

\newcommand{\KB}[1]{ \begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1] \draw [line width=1.5] (207.02,45.05) .. controls (246.62,63.85) and (246.62,63.85) .. (287.02,44.15) ; \draw [line width=1.5] (207.78,95.55) .. controls (247.68,76.35) and (247.68,75.35) .. (287.78,94.65) ; \end{tikzpicture} }

\begin{document} $$\KA+\KB$$ \end{document}

  • 3
    Your newcommands are coded to require a parameter. Just get rid of the [1] after {\KA} and {\KB}. Also, you should use \[ .. \] instead of $$ .. $$. (https://tex.stackexchange.com/q/503/125871) – Sandy G Feb 05 '22 at 04:20

1 Answers1

1

I think this is the problem of Adding tikz plot in equation (maybe a duplicate). This can be done by modify the newcommand to fit for equation.

Reference: TikZ figure inside equation?

Instead of using the tikzpicture environment, you can just use \tikz command.

\documentclass{article}
\usepackage{tikz}
\usepackage{adjustbox}

\newcommand{\KA}{\raisebox{-0.3mm}{ \tikz[x=0.075pt,y=0.075pt,yscale=-1,xscale=1]{ \draw [line width=0.3] (100.4,110.6) .. controls (119.4,71.1) and (119.4,71.1) .. (99.9,30.6) ; \draw [line width=0.3] (150.9,110.1) .. controls (131.9,70.1) and (130.9,70.1) .. (150.4,30.1);}} }

\newcommand{\KB}{ \tikz[x=0.075pt,y=0.075pt,yscale=-1,xscale=1]{ \draw [line width=0.3] (207.02,45.05) .. controls (246.62,63.85) and (246.62,63.85) .. (287.02,44.15) ; \draw [line width=0.3] (207.78,95.55) .. controls (247.68,76.35) and (247.68,75.35) .. (287.78,94.65) ;} }

\begin{document} % make it larger to see (x10) \scalebox{10}{ $$\KA+\KB$$ } \end{document}

So far, no error is produced, but the size of the plot should be adjusted. I made some changes and now it looked like: Result

EDIT

As Sandy G pointed out, the use of tikzpicture is no problem. It is just my habit to use the simple \tikz command in maths equation.

  • FYI, the issue has nothing to do with the command \tikz. In LaTeX you can use \begin{tikzpicture} ... \end{tikzpicture} interchangeably with \tikz{ ... }. – Sandy G Feb 05 '22 at 17:48
  • @SandyG Yes indeed, a matter of habit In maths equation I have the preference of using \tikz command. – Teddy van Jerry Feb 06 '22 at 02:59