2

Question

Is zero-length line with an arrow in TikZ a bug?

\documentclass[tikz,border=12pt,12pt]{standalone}
\begin{document}
\begin{tikzpicture}
    \draw[->](1,1)--(1,1);
\end{tikzpicture}
\end{document}

enter image description here

Note: PSTricks behaves the same.

I am trying to find whether it is mathematically useful (at least for me) but in fact it is not.

The direction of the arrow does not converge. :-)

\documentclass[tikz,border=12pt,12pt]{standalone}
\begin{document}
\foreach \i in {6,5,...,1}{%
\begin{tikzpicture}
     \draw (0,0) grid (6,6);
     \draw[->,ultra thick,red](45:1)--(45:\i);
\end{tikzpicture}}
\end{document}

enter image description here

Display Name
  • 46,933
  • 6
    In what way would this be a bug? It seems reasonable to me. – Joseph Wright Jan 06 '19 at 18:34
  • @JosephWright: Why is it reasonable to you? Just a blank (nothing gets rendered) is reasonable to me. – Display Name Jan 06 '19 at 18:58
  • 1
    There are two steps: 'draw a line' and 'add an arrow at the end of the line'. Just because the line has length zero, doesn't make it vanish. – Joseph Wright Jan 06 '19 at 19:07
  • @JosephWright: That is the bug. What is an arrow for in this case? :-) – Display Name Jan 06 '19 at 19:11
  • 2
    It might be useful to be able to draw an arrow tip without any line. However, then one has the problem of pointing it in the desired direction! A couple notes: Just \draw[->](1,1); is enough to get the arrow tip. If you want to give it direction, there is this trick: \draw[->](1,1)--++(60:1000sp). Interestingly, if you shrink the second dimension to less than about 600sp, the arrow tip reverts to pointing up. The exact limit may depend on the overall scale of the picture. This seems to me more a useless feature than a bug, but this site is not supposed to be about opinions. – Harald Hanche-Olsen Jan 06 '19 at 19:40
  • @marmot: I think the author knew this bug but he/she left it as it is to speed up the compilation process. If he/she put a conditional statement before putting an arrow the compilation might take longer. :-) – Display Name Jan 06 '19 at 20:22

1 Answers1

9

In agreement with the comments by Joseph Wright and Harald Hanche-Olsen, I would say that the answer to your question is

no, it is not a bug.

Usually, a bug is some behavior that is different than what one expects from what is written in the manual. As pointed out by Paul Gaborit (Thanks!!!), on p. 183 of the pgfmanual there is a distinction between proper and non-proper tips. All you need to do is to add tips=proper to get

\documentclass[tikz,border=12pt]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[->](1,1)--(1,1);
\begin{scope}[tips=proper,xshift=1cm]
    \draw[->](1,1)--(1,1);
\end{scope}    
\end{tikzpicture}
\end{document}

enter image description here

As you can see, the second arrow gets suppressed completely, which is, judging from your question and comments, the behavior you feel is appropriate. So all you need to do in your TikZ pictures is to add this style. (If you want it for all your pictures, just do \tikzset{every picture/.append style={tips=proper}}.)

Naively, you may think that TikZ could produce an error if the information is not sufficient, as it is if one does not specify the direction of the arrow. However, there is no error message. Rather, if there is no well-defined direction, TikZ will find one for you. I'd call that a feature.

Also, I cannot see the point of the animation. Clearly, TikZ (nor any other tool I know of) has knowledge on what happened in the previous frame (without further ado) . The last frame of your animation shows an arrow of length 0, regardless of whether the previous frames had arrows or ducks in. How is there a limit?

  • Because this bug is not so dangerous, let me call it a useless feature. :-) – Display Name Jan 06 '19 at 22:21
  • 1
    @GodMustBeCrazy I dunno. What do you expect? You enter strange code and get a strange result. If you ask TeX to typeset $1=2$ it will also do that without complaining. Yet I would not blame it on TeX if the equation is wrong. –  Jan 06 '19 at 22:39
  • If you buy a fried chicken, you can optionally get a pepper powder. Now you don't buy a fried chicken, should you get a pepper powder? :-) – Display Name Jan 06 '19 at 22:55
  • @GodMustBeCrazy I am vegetarian. This is yet another example showing that it is good to be vegetarian. I do not have this problem. –  Jan 06 '19 at 23:00
  • If you buy salad, you can optionally get some dressing. Now you don't buy any salad, should you get some dressing? :-) – Display Name Jan 06 '19 at 23:04
  • @GodMustBeCrazy Marmots generally don't buy food. Believe it or not, it is very hard for us to get a credit card approved. ;-) –  Jan 06 '19 at 23:10
  • 1
    @marmot The new (since pgf v3.1) key /pgf/tips and its value on proper draw may help... – Paul Gaborit Jan 07 '19 at 15:25
  • @PaulGaborit Thanks! Do you want to post an answer or may I add this to mine? (I actually really do not see anything wrong with the behavior.) –  Jan 07 '19 at 15:31
  • @marmot You may complete your answer. – Paul Gaborit Jan 07 '19 at 16:00
  • 1
    @GodMustBeCrazy Imagine you just need dressing (maybe you already have the salad in your garden). Wouldn't it be annoyingly if the clerk at the supermarket would refuse to sell you dressing because you are not buying salad as well? Imagine you already have some image and just need to add an arrowhead, how would you do this if you are not allowed to draw an arrowhead without line? – samcarter_is_at_topanswers.xyz Jan 07 '19 at 16:29
  • Eventually the bug has been fixed by proper value to fix the improperly designed. The end of comment. – Display Name Jan 07 '19 at 16:38
  • @PaulGaborit and @ marmot Maybe it would be good to add an tips=proper answer to this question: https://tex.stackexchange.com/questions/70186/does-a-zero-length-line-with-an-arrow-make-sense-is-it-a-bug What do you think? – samcarter_is_at_topanswers.xyz Jan 07 '19 at 16:40