# Unknown origin of additional spaces in a glyph

I'm very sorry to open this topic again, but through the process of writing my paper, which includes Braid diagrams I bumped into another issue I can't resolve. This time my issue lies in unwanted spacing before and after a glyph:

\documentclass{article}
\usepackage{tikz}
\usepackage{braids}

\usetikzlibrary{intersections}
\usetikzlibrary{knots}

\newcommand{\correct}[1]{
\scalebox{0.3}{
\begin{tikzpicture}[#1]
\draw[xshift=5cm,ultra thick] (0,1) .. controls +(0,0) and +(0,0) .. (0,1) .. controls +(1,0) and +(-1,0) .. (2,0);
\draw[xshift=5cm,white,double=black,ultra thick,double distance=1.6pt] (0,0) .. controls +(0,0) and +(0,0) .. (0,0) .. controls +(1,0) and +(-1,0) .. (2,1);
\end{tikzpicture}}
}
\newcommand{\notcorrect}[1]{
\scalebox{0.3}{
\begin{tikzpicture}[#1]
\draw[ultra thick] (0,0) .. controls +(3,1) and +(-3,1) .. (1,0);
\end{tikzpicture}}
}

\begin{document}

This is a correct \correct{} input. This is not a correct \notcorrect{} input.

\end{document}


I have a hypothesis to why the unwanted spaces are showing. When I first confronted this problem I was using the knots environment provided by \usetikzlibrary{knots}. I speculated that knots was defined only in the display mode, so I switched to plain tikz to solve the problem. I was 100% confident in my solution, so you can imagine the shock I received when my change did absolutely nothing :

\documentclass{article}

\usepackage{tikz}
\usepackage{braids}

\usetikzlibrary{knots}

\newcommand{\firstnotcorrect}[1]{
\scalebox{0.4}{
\begin{tikzpicture}[#1]
\draw[ultra thick] (0,0) .. controls +(3,1) and +(-3,1) .. (1,0);
\end{tikzpicture}}
}
\newcommand{\secondnotcorrect}[1]{
\scalebox{0.4}{
\begin{tikzpicture}[#1]
\begin{knot}
\strand[ultra thick] (0,0) .. controls +(3,1) and +(-3,1) .. (1,0);
\end{knot}
\end{tikzpicture}}
}

\begin{document}

Braids diagram with \texttt{tikz} library \texttt{knots}: \secondnotcorrect{}

Braids diagram in plain \texttt{tikz}: \firstnotcorrect{}

\end{document}


Although I do think this similarity is present due to the fact that all the commands used in plain tikz are also included (in a reduced format of course) in knot environment.

What perplexes me is the fact that in the first source code the glyphs are defined in the exact same way, but the difference is still present. Please help me. This is without doubt one of the strangest mysteries I've encountered through years of using LaTeX.

• Could it be because the second box is wider, since it has to go from -3 to +3 on the x scale, while the other one only goes from -1 to 1? – Moriambar May 7 '17 at 15:06
• I think it is as Moriambar says. A quick fix probably would be to add something like \path[use as bounding box] (0, 0) rectangle (1,1); before drawing your incorrect braid. (untested) – Troy May 7 '17 at 15:16

Arcs create wider bounding boxes, because they include the control points. You can reset the bounding box in various ways, here I present one.

See https://tex.stackexchange.com/search?q=tikz+controls+bounding+box for other examples. I chose the method in Specific drawings with arrows and vertices in latex by Henri Menke.

\documentclass{article}

\usepackage{tikz}
\usepackage{braids}

\usetikzlibrary{knots}

\newcommand{\firstcorrect}{%
\begin{tikzpicture}[x=0.4cm,y=0.4cm]
\path[use as bounding box] (0,0) rectangle (1,0.7);
\draw[thin] (0,0) .. controls +(3,1) and +(-3,1) .. (1,0);
\end{tikzpicture}%
}
\newcommand{\secondcorrect}{%
\begin{tikzpicture}[x=0.4cm,y=0.4cm]
\path[use as bounding box] (0,0) rectangle (1,0.7);
\begin{knot}
\strand[thin] (0,0) .. controls +(3,1) and +(-3,1) .. (1,0);
\end{knot}
\end{tikzpicture}%
}

\begin{document}

Braids diagram with \texttt{tikz} library \texttt{knots}:
\secondcorrect; with box: \fbox{\secondcorrect}

Braids diagram in plain \texttt{tikz}: \firstcorrect;
with box: \fbox{\firstcorrect}

\end{document}


Note that you were including several spaces by not protecting the end of lines.

It's also not appropriate to draw the picture with a thick pen and then scale it: you get better control without scaling.

Maybe you want to set the bounding box slightly wider.

• Thank you so very much! An upvote and one big tick are indeed a proper reward for such a brilliant answer! – Gregor Perčič May 7 '17 at 16:00

Maybe not the best, but I propose some clipping of the second image; I think that the control points (or something like that) are far away:

\documentclass{article}
\usepackage{tikz}
\usepackage{braids}

\usetikzlibrary{intersections}
\usetikzlibrary{knots}

\newcommand{\correct}[1]{
\begin{tikzpicture}[#1]
\draw[xshift=5cm] (0,1) .. controls +(0,0) and +(0,0) .. (0,1) .. controls +(1,0) and +(-1,0) .. (2,0);
\draw[xshift=5cm] (0,0) .. controls +(0,0) and +(0,0) .. (0,0) .. controls +(1,0) and +(-1,0) .. (2,1);
\end{tikzpicture}
}
\newcommand{\notcorrect}[1]{
\begin{tikzpicture}[#1]
\clip (-3ex,-3ex) rectangle (4em,7ex);
\draw(0,0) .. controls +(3,1) and +(-3,1) .. (1,0);
\end{tikzpicture}
}

\begin{document}

This is a correct \correct{scale=0.3} input. This is not a correct \notcorrect{scale=0.3} input.

\end{document}


Result: