5

This code:

\pic[rotate=40, local bounding box=microfono] at (4.5,-5) {microph};
\draw[black, line width=2pt] (microfono.-45) -- ++(-.2,+.2) ++(.2,-.2) -- ++(0,-2);

works outside the scope but not inside (the line is not displayed). Why?

\documentclass[border=0pt]{standalone}
\usepackage{tikz}
\tikzset{
    pics/microph/.style={code={ 
        \draw[black, line width=.2em, rounded corners=1.7ex] 
            (-.85em,4.5ex) -- (-.85em,2ex) -- (.85em,2ex) -- (.85em,4.5ex);
        \fill[black] 
            (-.6em,5ex) to[rounded corners=1.2ex]  
            (-.6em,2.5ex) to[rounded corners=1.2ex] (.6em,2.5ex)
            -- (.6em,5ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)  
            -- (.6em,5.5ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
            -- (.6em,6ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
            -- (.6em,6.5ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
            to[rounded corners=1.2ex]
            (.6em,8ex) to[rounded corners=1.2ex]
            (-.6em,8ex) to cycle; 
    }},
}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip (-8.5,-6.5) rectangle (8.5,6.5);
\node[fill=cyan, draw=cyan, minimum width=17cm, minimum height=13cm](sky){};
\pic[rotate=40, local bounding box=microfono] at (4.5,-5) {microph};
\draw[black, line width=2pt] (microfono.-45) -- ++(-.2,+.2) ++(.2,-.2) -- ++(0,-2);
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

12
  • delete this line \clip (-8.5,-6.5) rectangle (8.5,6.5);
    – AndréC
    Commented Nov 30, 2019 at 8:26
  • 1
    @AndréC I did a scope just to clip, I cannot delete that line, it is what I need
    – CarLaTeX
    Commented Nov 30, 2019 at 8:40
  • 2
    @AndréC Yes, but that does not solve my problem
    – CarLaTeX
    Commented Nov 30, 2019 at 10:21
  • 3
    I think I get the desired result with: \path (4.5,-5) pic[rotate=40, pic type=microph] node(microfono){};, but I don't understant why the original code don't work.
    – vi pa
    Commented Nov 30, 2019 at 10:25
  • 1
    @CarLaTeX This does not solve the problem, but it shows that the problem may not be where you are looking for it.
    – AndréC
    Commented Nov 30, 2019 at 14:27

4 Answers 4

1

I had originally fixed this use of local bounding box in PGF 3.1.5 by executing the \pgf@path@size@hook in \pgf@protocolsizes unconditionally. However, this broke all other uses of local bounding box. Unfortunately, I could not think of another solution to make this admittedly very niche situation work. Nevertheless, I can propose a workaround for using local bounding box in a \clip context. Simply add overlay=false to the path or scope that you want to get the local bounding box of.

\documentclass[border=0pt]{standalone}
\usepackage{tikz}
\tikzset{
    pics/microph/.style={code={ 
        \draw[black, line width=.2em, rounded corners=1.7ex] 
            (-.85em,4.5ex) -- (-.85em,2ex) -- (.85em,2ex) -- (.85em,4.5ex);
        \fill[black] 
            (-.6em,5ex) to[rounded corners=1.2ex]  
            (-.6em,2.5ex) to[rounded corners=1.2ex] (.6em,2.5ex)
            -- (.6em,5ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)  
            -- (.6em,5.5ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
            -- (.6em,6ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
            -- (.6em,6.5ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
            to[rounded corners=1.2ex]
            (.6em,8ex) to[rounded corners=1.2ex]
            (-.6em,8ex) to cycle; 
    }},
}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip (-8.5,-6.5) rectangle (8.5,6.5);
\node[fill=cyan, draw=cyan, minimum width=17cm, minimum height=13cm](sky){};
\pic[rotate=40, overlay=false, local bounding box=microfono] at (4.5,-5) {microph};
\draw[black, line width=2pt] (microfono.-45) -- ++(-.2,+.2) ++(.2,-.2) -- ++(0,-2);
\end{scope}
\end{tikzpicture}
\end{document}
5

the description of \clip contains the sentence "the size of subsequent paths will not be important for the picture size." So I assume that local bounding box can't get the correct size.

A simple work around is to draw the micro twice:

\documentclass[border=0pt]{standalone}
\usepackage{tikz}
\tikzset{
    pics/microph/.style={code={
        \draw[black, line width=.2em, rounded corners=1.7ex]
            (-.85em,4.5ex) -- (-.85em,2ex) -- (.85em,2ex) -- (.85em,4.5ex);
        \fill[black]
            (-.6em,5ex) to[rounded corners=1.2ex]
            (-.6em,2.5ex) to[rounded corners=1.2ex] (.6em,2.5ex)
            -- (.6em,5ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
            -- (.6em,5.5ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
            -- (.6em,6ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
            -- (.6em,6.5ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
            to[rounded corners=1.2ex]
            (.6em,8ex) to[rounded corners=1.2ex]
            (-.6em,8ex) to cycle;
    }},
}
\begin{document}
\begin{tikzpicture}
%
\begin{scope}
\pic[rotate=40, local bounding box=microfono] at (4.5,-5) {microph};
\clip (-8.5,-6.5) rectangle (8.5,6.5);
\node[fill=cyan, draw=cyan, minimum width=17cm, minimum height=13cm](sky){};
\pic[rotate=40] at (4.5,-5) {microph};
\draw[line width=2pt] (microfono.-45) -- ++(-.2,+.2) ++(.2,-.2) -- ++(0,-2);
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

2
  • 1
    You are correct. The problem here is local bounding box which hooks into \pgf@protocolsizes but only \ifpgf@relevantforpicturesize which seems wrong to me. The hook should be executed unconditionally. Commented Dec 1, 2019 at 3:01
  • The microphone wire marks a break at the point where it is bent.
    – AndréC
    Commented Dec 1, 2019 at 7:31
5

You do not need a local bounding box here. You can just use some coordinate in the microphone. However, it is known that pics screw up the name prefixes. This bug has been only fixed partially, and according to Henri Menke it will be fixed completely in the next version of pgf. For the time being, let us use @cfr's solution to reset the name prefixing with name prefix ... This solution is what the pgf manual v3.1.4 recommends on p. 263

enter image description here

Then you can use the tricks from the pgfmanual to give a name to the pic, and to refer to one of its coordinates from outside. This has the additional benefit that you do not have to guess an angle like -45, which will change if you rotate the microphone.

\documentclass[border=0pt]{standalone}
\usepackage{tikz}
\tikzset{
    pics/microph/.style={code={ 
        \draw[black, line width=.2em, rounded corners=1.7ex] 
            (-.85em,4.5ex) -- (-.85em,2ex) -- (.85em,2ex) -- (.85em,4.5ex);
        \path (0,2ex) coordinate (-plug);   
        \fill[black,name prefix ..] % https://tex.stackexchange.com/a/194370 
            (-.6em,5ex) to[rounded corners=1.2ex]  
            (-.6em,2.5ex) to[rounded corners=1.2ex] (.6em,2.5ex)
            -- (.6em,5ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)  
            -- (.6em,5.5ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
            -- (.6em,6ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
            -- (.6em,6.5ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
            to[rounded corners=1.2ex]
            (.6em,8ex) to[rounded corners=1.2ex]
            (-.6em,8ex) to cycle; 
   }},
}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip (-8.5,-6.5) rectangle (8.5,6.5);
\node[fill=cyan, draw=cyan, minimum width=17cm, minimum height=13cm](sky){};
\pic[rotate=40] (microfono) at (4.5,-5) {microph};
\draw[black, line width=2pt] (microfono-plug)   -- ++(.2,-.2) -- ++(0,-2);
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

12
  • 1
    This has nothing to do with name prefix. Your “fix” was just a coincidence because you removed local bounding box. Commented Dec 1, 2019 at 3:04
  • @HenriMenke I am aware of this, and, as written in the answer, my, or more precisely cfr's, fix made the local bounding box unnecessary. It allows one to access the coordinates from outside. My understanding is that the local bounding box is only a tool that was introduced because of the fix it is not possible to do so.
    – user194703
    Commented Dec 1, 2019 at 3:20
  • I see. That name prefix thing is fixed on the latest master github.com/pgf-tikz/pgf/commit/…. I hope I can release 3.1.5 before Christmas. Commented Dec 1, 2019 at 3:24
  • 1
    The “nuke the complete TeX Live installation” switch is currently disabled ;-). The only thing it can break is TikZ, of course, but I try hard to not do that. If it does break you should open a bug report. I think I react relatively fast. Commented Dec 1, 2019 at 3:33
  • 1
    Then you should look at github.com/pgf-tikz/pgf#development. With the first three command you can switch to the development version in your active shell session. However, that does not update automatically. You will have to go to the directory where you cloned and perform git pull origin master when you want to update. See also tex.stackexchange.com/questions/448263/… Commented Dec 1, 2019 at 3:59
4

As I mentioned in my comments the problem arises with your pic {microph} and not with the first pic {seagull} defined on section 18 Pics: Small Pictures on Paths of the TikZ manual. This clearly shows that there is a bug in the source code of the pic operation. This bug makes the to operations in the code of a pic incompatible.

The problem comes from a bug in the pic operation that does not tolerate to operations. By replacing these operations with --, it works.

You do not need a local box because the pic allow you to place node accessible from the outside with the prefix name as shown on section 18.2 The Pic Syntax of the manual. So I added a coordinate called the (-milieu) to the right where the wire connects: in the middle of the bottom of the microphone.

\draw[black, line width=.2em, rounded corners=1.7ex,pic actions] 
            (-.85em,4.5ex) -- (-.85em,2ex) -- (.85em,2ex)coordinate[midway](-milieu) -- (.85em,4.5ex);

screenshot

\documentclass[border=0pt]{standalone}
\usepackage{tikz}
\tikzset{
    pics/microph/.style={code={ 
        \draw[black, line width=.2em, rounded corners=1.7ex,pic actions] 
            (-.85em,4.5ex) -- (-.85em,2ex) -- (.85em,2ex)coordinate[midway](-milieu) -- (.85em,4.5ex);
        \fill[black,pic actions]  
            (-.6em,5ex)[rounded corners=1.2ex]  --% 
            (-.6em,2.5ex)[rounded corners=1.2ex] --%to 
            (.6em,2.5ex)
            -- (.6em,5ex)[rounded corners=.2ex] --%to 
            ++(-.85em,0)[rounded corners=.2ex]  --%to
            ++(0,.35ex) -- ++(.85em,0)  
            -- (.6em,5.5ex)[rounded corners=.2ex] --%to 
            ++(-.85em,0)[rounded corners=.2ex] --%to 
            ++(0,.35ex) -- ++(.85em,0)
            -- (.6em,6ex)[rounded corners=.2ex] --%to 
            ++(-.85em,0)[rounded corners=.2ex]  --%to
            ++(0,.35ex) -- ++(.85em,0)
            -- (.6em,6.5ex)[rounded corners=.2ex] --%to 
            ++(-.85em,0)[rounded corners=.2ex] --%to 
            ++(0,.35ex) -- ++(.85em,0)
            [rounded corners=1.2ex]--%to
            (.6em,8ex) [rounded corners=1.2ex]--%to
            (-.6em,8ex) --%to
             cycle; 
    }},
}

\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip (-8.5,-6.5) rectangle (8.5,6.5);
\node[fill=cyan, draw=cyan, minimum width=17cm, minimum height=13cm](sky){};
\pic[rotate=40] (microfono) at (4.5,-5) {microph};
\draw[black, line width=2pt] (microfono-milieu) -- ++(.2,-.2) -- ++(0,-2);
\end{scope}

\end{tikzpicture}


\end{document}
4
  • @CarLaTeX Thank you. Do you want to report this bug to Henri Menke so he can fix it?
    – AndréC
    Commented Nov 30, 2019 at 18:17
  • I'll try to do it, thanks
    – CarLaTeX
    Commented Nov 30, 2019 at 18:39
  • That is a coincidence because you removed local bounding box. The to operation works just fine in pic. Commented Dec 1, 2019 at 3:03
  • @HenriMenke Indead, the manual say on page 259 Unlike nodes, pics cannot be referenced later on. You can reference nodes that are inside a pic, but not “the pic itself”. In particular, you cannot draw lines between pics the way you can draw them between nodes. In general, whenever it makes sense that some drawing could conceivably be connected to other node-like-things, then a node is better than a pic. So, the use of a local bounding box is in itself wrong.
    – AndréC
    Commented Dec 1, 2019 at 3:45

You must log in to answer this question.

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