19

Release comparison

In version 2.10 of TikZ you could write:

\coordinate [label={[red] center:$P$}] (x) at (0,0);

but in the latest release (version 3.0.0) you'll get an error (unknown function 'center') unless you write it without any space between the [options] and the <angle>:

\coordinate [label={[red]center:$P$}] (x) at (0,0);

On the contrary, you can still write it as before if the <angle> is a number:

\coordinate [label={[red] 30:$P$}] (x) at (0,0);

Question

Is this a bug or a desired behaviour?

MWE

\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture}
%\coordinate [label={[red] center:$P$}] (a) at (0,0); % this doesn't work
\coordinate [label={[red]center:$P$}]  (b) at (1,0);
\coordinate [label={[red] 30:$P$}]     (c) at (2,0);
\end{tikzpicture}
\end{document}
Luigi
  • 6,325
  • I filed a bug report on Sourceforge. Even if this is not actually a bug, I think there is a compatibility issue with older codes that should be solved. – Luigi Feb 02 '14 at 10:29
  • All of these don't work for me, but maybe I'm missing a library you've loaded or some other setup/options you've configured. Could you please post a minimal working example (MWE) so the community can take a look at what might be going on? – Paul Gessler Mar 02 '14 at 15:08
  • @PaulGessler, you are right! I forgot the coordinate <name>. – Luigi Mar 02 '14 at 16:45
  • 1
    @Adam you are wrong. Please test the code by yourself before suggesting to close it as off topic. There is actually an issue. I forgot to include a particular element in the MWE only, but I fixed it almost one month ago. Please, give it a try and let me know if it works or not (you have to uncomment the first coordinate to see the wrong behaviour). – Luigi Mar 31 '14 at 09:03
  • Sorry, @Luigi! I misread the comments. I've voted to reopen. And you're right. In the future I'll be sure to test the code. :) Sorry! – Adam Liter Mar 31 '14 at 13:56
  • @Adam never mind! Maybe that comment was a bit misleading. – Luigi Mar 31 '14 at 14:15

1 Answers1

10

Amazingly finding the problem was much easier than using the \ignorespaces, thanks to David Carlisle on chat, realizing my stupid mistake that \zap@space should be utilized. More fun is here if you haven't yet I'm a cargo cult programmer ...

Anyway, the reason for the error is that the code is, with all respect, looking like unfinished there. The space gobbling is not performed so when you send a whitespace in front of center it is compared with a macro defined as

\def\tikz@on@text{center}

So when you \ifx them they don't match and TikZ thinks you sent an angle or an anchor. You know the rest. As a working example I tried to gobble the initial spaces for testing and David Carlisle fixed my gobble mechanism. The macro opening is the changed part that was originally located on line 701 of tikz.code.tex file.

\documentclass[]{article}
\usepackage{tikz}
\makeatletter

\tikzset{tikz@label@post/.code={% The code has 2 args here WHY? Line 701
  \edef\tikz@label@angle{\expandafter\expandafter\expandafter%
                         \zap@space%
                         \expandafter\tikz@label@angle\space \@empty}%
  \csname tikz@label@angle@is@\tikz@label@angle\endcsname%
  \ifx\tikz@label@angle\tikz@on@text%
    \def\tikz@node@at{\pgfpointanchor{\tikzlastnode}{center}}%
    \def\tikz@anchor{center}%
  \else%
    \iftikz@absolute%
      \pgftransformreset%
      \pgf@process{%
        \pgfpointshapeborder{\tikzlastnode}%
        {\pgfpointadd{\pgfpointanchor{\tikzlastnode}{center}}{\pgfpointpolar{\tikz@label@angle}{1pt}}}}%
      \edef\tikz@node@at{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
      \tikz@compute@direction{\tikz@label@angle}%
      \tikz@addtransform{\pgftransformshift{\pgfpointpolar{\tikz@label@angle}{#1}}}%  
    \else%
      \pgf@process{\pgfpointanchor{\tikzlastnode}{\tikz@label@angle}}%
      \edef\tikz@node@at{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
      \pgf@xb=\pgf@x%
      \pgf@yb=\pgf@y%
      \pgf@process{\pgfpointanchor{\tikzlastnode}{center}}%
      \pgf@xc=\pgf@x%
      \pgf@yc=\pgf@y%
      \tikz@label@simplefalse%
      \iftikz@fullytransformed%
        \tikz@label@simpletrue%
      \else
        \ifdim\pgf@xc=\pgf@xb\relax%
          \ifdim\pgf@yc=\pgf@yb\relax%
            \tikz@label@simpletrue%
          \fi%
        \fi%
      \fi%
      \iftikz@label@simple%  
        \tikz@compute@direction{\tikz@label@angle}%
        \tikz@addtransform{\pgftransformshift{\pgfpointpolar{\tikz@label@angle}{#1}}}%  
      \else%
        \pgf@process{\pgfpointnormalised{%
            \pgfpointdiff{\pgfpointtransformed{\pgfqpoint{\pgf@xc}{\pgf@yc}}}{\pgfpointtransformed{\pgfqpoint{\pgf@xb}{\pgf@yb}}}}}%
        \edef\pgf@marshal{%
          \noexpand\tikz@addtransform{\noexpand\pgftransformshift{\noexpand\pgfpointscale{#1}{
                \noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}}}}%
        \pgf@marshal%
        \pgf@xc=\pgf@x%
        \pgf@yc=\pgf@y%
        \pgf@x=\pgf@yc%
        \pgf@y=-\pgf@xc%
        \tikz@auto@anchor%
      \fi%
    \fi%
  \fi}
}
\makeatother

\begin{document}
\begin{tikzpicture}
\coordinate [label={[red]     center:$P$}] (a) at (0,0); % this works
\coordinate [label={[red]center:$P$}]  (b) at (1,0);
\coordinate [label={[red] 30:$P$}]     (c) at (2,0);
\end{tikzpicture}
\end{document}

enter image description here

percusse
  • 157,807