7

Why the shape (sB) is unknown in the following code ? How to avoid this ?

\documentclass[]{standalone}
\usepackage{tikz,xparse}
\usetikzlibrary{calc}

\tikzset{pics/.cd,
    % Marque croix
    Cross/.style args={#1 and #2}{%
        code = {%
        \draw[#2,rotate=45,scale=1.4] (0,#1 pt) -- (0,-#1 pt) ;
        \draw[#2,rotate=-45,scale=1.4] (0,#1 pt) -- (0,-#1 pt) ;
        }
    },
    Cross/.default={2 and black}
}

\NewDocumentCommand{\Segment}{mO{}}{%
    \begin{scope}[#2]
    \path    (0,0) coordinate (sA) pic {Cross={1.5 and gray}}
        -- (#1,0) coordinate (sB) pic {Cross={1.5 and gray}} ;
    \draw (sA)--(sB) ; % Can't reuse (sB)
    \end{scope}
}


\begin{document}
    \begin{tikzpicture}
    \Segment{1.5}
    \end{tikzpicture}
\end{document}
5
  • 2
    For your second question on avoiding: \path (0,0) coordinate (sA) pic {Cross={1.5 and gray}}; \path (#1,0) coordinate (sB) pic {Cross={1.5 and gray}} ; in the definition of \Segment
    – user11232
    Commented Nov 11, 2014 at 7:55
  • @HarishKumar is not possible to use two or more pics on same path?
    – Ignasi
    Commented Nov 11, 2014 at 8:00
  • @Ignasi Why not? Try \draw (0,0) -- pic[pos=0] {Cross={1.5 and gray}} pic[pos=1] {Cross={1.5 and gray}} (#1,0); for example.
    – user11232
    Commented Nov 11, 2014 at 8:05
  • @HarishKumar Mixing your to remarks, on can do : ` \draw (0,0) coordinate (sA) -- (#3,0) coordinate (sB) \foreach \i in {0,1} {pic[pos=\i] {Cross={1.5 and gray}}}; `
    – Tarass
    Commented Nov 11, 2014 at 8:14
  • @HarishKumar OK, forget my question. Mark solved it.
    – Ignasi
    Commented Nov 11, 2014 at 8:23

1 Answer 1

5

This appears to be a bug. The internal command \iftikz@node@is@pic is not reset after a pic on a path so any subsequent nodes (coordinates are nodes) are parsed as pics and consequently nothing is done.

A temporary fix (and not guaranteed to work in every possible use case) is to put the following (with appropriate category code changes) in the preamble:

\def\tikz@do@after@node{\tikz@node@is@picfalse\tikz@scan@next@command}
2
  • I was not able to find a bug report, so I did it here : sourceforge.net/p/pgf/bugs/341
    – Kpym
    Commented Nov 27, 2014 at 17:56
  • There is another workaround to this bug that I have seen somwehre on TeX.SX (the author was @percusse I think), we can isolate the pic in a group like this {pic[..]{..}}. For exemple in OP we can do \path (0,0) coordinate (sA) {pic{Cross={1.5 and gray}}} -- (#1,0) coordinate (sB) pic{Cross={1.5 and gray}};.
    – Kpym
    Commented Jan 14, 2015 at 13:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .