2

I am coming from this answer of mine:

https://tex.stackexchange.com/a/394628/120578

The code is:

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{calc}
%opening
\title{}
\author{}
\def\tikzmark#1{\begin{tikzpicture}[remember picture]\node(#1){};\end{tikzpicture}}


\makeatletter
\renewcommand\vec[1]{\ifdefined\xsh\relax\else\pgfmathsetmacro\xs{\f@size/3}\def\xsh{\xs pt}\fi\ifdefined\ysh\relax\else\pgfmathsetmacro\ys{\f@size/1.3}\xdef\ysh{\ys pt}\fi\tikzmark{VecStart}#1\tikzmark{VecStop}\begin{tikzpicture}[remember picture,overlay]\draw[->,>=stealth]($(VecStart)+(\xsh,\ysh)$)--($(VecStop)+(-\xsh,\ysh)$);\end{tikzpicture}\let\xsh=\undefined\let\ysh=\undefined}
\makeatother
\begin{document}

$\vec{AB}$

\xdef\xsh{5pt}
\xdef\ysh{14pt}
$$\displaystyle\int\vec{\displaystyle\frac{AB}{3}}dx$$

\end{document}

As you can see in the picture:

enter image description here

there is white space before and after the tikzmark.

Where did that space came from? If I change my tikzmark to:

\def\tikzmark#1{\tikz[remember picture]\node(#1){};}

I get exactly the same result.

A boundy of 50 will be offered after the acception of the answer (I want an explanation for the spaces and how can be avoided... I don't really care for other methods of the same result. Just want to understand where these spaces came from).

koleygr
  • 20,105
  • 3
    The short answer is [inner sep] which defaults to 0.333em. – John Kormylo Oct 05 '17 at 02:48
  • Thank you @JohnKormylo... If you want you can make it an answer with some links or a command like \def\tikzmark#1{\tikz[inner sep=0,remember picture]\node(#1){};} that could solve the problem. I am already looking some things about this. But you gave me the help needed and I really would like an answer from you to accept. – koleygr Oct 05 '17 at 02:57
  • If I were doing it, I would abandon tikzmark and use a savebox instead. With extra effort you could even make it style sensitive. – John Kormylo Oct 05 '17 at 03:01
  • @JohnKormylo: Yes, I know that... But I don't really care about this specific problem's solution... I just wanted to know about that separators of tikzpictures like "inner sep" or "outer sep". I use tikzpictures in several cases and could not find this info about the dimensions added in a tikzpicture... Thanks! Please... make your comment a simple answer. Not much more wanted... – koleygr Oct 05 '17 at 03:06
  • BTW, see https://tex.stackexchange.com/questions/371715/fractions-stretch-and-shrink/371816?s=2|12.6349#371816 for the use of \sbox in math. – John Kormylo Oct 05 '17 at 03:14
  • I agree with John that using tikzmark here isn't the best way to do this since you actually want tikz to know about the size of the text that you are working with (that way you wouldn't have to calculate the separation manually). To do it properly would involve \mathchoice to deal with the different math styles. Regardless, please note that you are using a very old version of tikzmark in this code and the newest version (provided by the tikzmark tikz library) does not have the spacing issue. – Andrew Stacey Nov 05 '17 at 15:37

1 Answers1

7

By using \coordinate instead of \node you take up no space. I also checked to see if the \hbox{} created by tikz had any effect, but couldn't tell by eye.

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{calc}
%opening
\title{}
\author{}
\def\tikzmark#1{\begin{tikzpicture}[remember picture]\coordinate(#1);\end{tikzpicture}}


\makeatletter
\renewcommand\vec[1]{\ifdefined\xsh\relax
  \else
    \pgfmathsetmacro\xs{\f@size/3}%
    \def\xsh{\xs pt}%
  \fi
  \ifdefined\ysh\relax
  \else
    \pgfmathsetmacro\ys{\f@size/1.3}%
    \xdef\ysh{\ys pt}%
  \fi
  \tikzmark{VecStart}#1\tikzmark{VecStop}%
  \begin{tikzpicture}[remember picture,overlay]
    \draw[->,>=stealth]($(VecStart)+(\xsh,\ysh)$)--($(VecStop)+(-\xsh,\ysh)$);
  \end{tikzpicture}%
  \let\xsh=\undefined
  \let\ysh=\undefined}
\makeatother
\begin{document}

$\vec{AB}$

\xdef\xsh{0pt}%
\xdef\ysh{14pt}%
$$\displaystyle\int\vec{\displaystyle\frac{AB}{3}}dx$$
$$\displaystyle\int\null\frac{AB}{3}\null dx$$
$$\displaystyle\int\frac{AB}{3} dx$$

\end{document}
John Kormylo
  • 79,712
  • 3
  • 50
  • 120