# Penrose graphical notation with TikZ

How can I draw a tensor network like this using TikZ? Perhaps adding some words on them. I'm very comfortable with LaTeX, but still a noob to TikZ. I will draw these kinds of shape extensively, and hope to know a template on them. Thanks!

EDIT

This is what I've done so far. I'm not sure how to connect line at specified border, the correct way of placing node (relative position or coordinate?), and how to put tokens at the specified positions.

\documentclass[tikz,multi,border=10pt]{standalone}
\usetikzlibrary{shapes.geometric,positioning}
\begin{document}
\begin{tikzpicture}
[
triangle/.style = {regular polygon, regular polygon sides=3, draw=black, fill=green!60!black, inner sep=0pt, minimum size=2cm},
border rotated/.style = {shape border rotate=180},
rectangular/.style={fill=brown!80!black, rectangle, rounded corners = 5pt, draw=black, inner sep=0pt, minimum width=4.5cm, minimum height=1cm},
square/.style={fill=blue!60!black, rectangle, draw=black, inner sep=0pt, minimum size = 1cm}
]

\node[square] (1) {};
\node[triangle, border rotated] (2) [below left = 1cm  of 1] {};
\node[triangle, border rotated] (3) [below right = 1cm  of 1] {};
\node[rectangular] (4) [below=3cm of 1] {};
\node[square] (7) [below = 7cm of 1]{};
\node[triangle] (5) [above left = 1cm  of 7] {};
\node[triangle] (6) [above right = 1cm  of 7]{};

\draw (2.35) -- +(0,0.2) -- (1);
\draw (2.145) to [bend right=45] (5.215);
\draw (3.145) -- +(0,0.2) -- (1);

\end{tikzpicture}
\end{document}

• Welcome! TikZ has extensive documentation and there are copious examples available. What have you got so far? You are more likely to get useful help if you post something and ask about a specific problem. It isn't clear what you have in mind by a template but right now this looks like a do-all-these-for-me question. You may or may not get lucky and somebody answers, but the question is not really a fair one. You might look at tikz-cd or at the chains library, for example. And why are you so set on TikZ if you don't know anything about it anyway? Why not an alternative? – cfr Mar 24 '16 at 3:19
• If you don't want to take the time to learn how to draw images, you can always include them as external images using graphicx. Or you can export TikZ code from Inkscape, for example. (It isn't very editable, but if you don't need to modify it, it should be fine.) – cfr Mar 24 '16 at 3:20
• Is this related? – cfr Mar 24 '16 at 3:26
• I'm sorry, but I'm just kind of intimated by the 880 page of TikZ manual. If you know what chapters to look into for these functionality, I will be very grateful. – Witty Viper of Hidden Glen Mar 24 '16 at 3:29
• However, if your copy has 'only' 880 pages, you have an outdated TeX installation and probably TikZ 2.1. You would be well advised to update. Then maybe look at tutorials 1 and 5 in part I. – cfr Mar 24 '16 at 3:35

I'm not entirely certain I understand all of the 3 points you've asked about. For example, I'm not sure what 'tokens' refers to, though I'm guessing the filled black circles.

Generally, relative positioning makes it easier to modify code later. For example, it is easier to add new things into the diagram and have other things auto-adjust. But it is really a question of what works best in a particular case. Often, absolute positioning is quicker to do for a one-off, for example, although it makes the code less flexible.

I've renamed triangle to triangular to avoid overwriting the triangle shape.

The code below shows one way to:

• connect the triangles from the appropriate points;
• connect the triangles to the rectangle from/to appropriate points;
• add black circles to the rectangle;
• add a curved arrow with the label s'.

Hopefully, this should enable you to build further on what you have already.

\documentclass[tikz,multi,border=10pt]{standalone}
\usetikzlibrary{shapes.geometric,positioning}
\begin{document}
\begin{tikzpicture}
[
triangular/.style = {regular polygon, regular polygon sides=3, draw=black, fill=green!60!black, inner sep=0pt, minimum size=2cm},
border rotated/.style = {shape border rotate=180},
rectangular/.style={fill=brown!80!black, rectangle, rounded corners = 5pt, draw=black, inner sep=0pt, minimum width=4.5cm, minimum height=1cm},
square/.style={fill=blue!60!black, rectangle, draw=black, inner sep=0pt, minimum size = 1cm}
]

\node[square] (1) {};
\node[triangular, border rotated] (2) [below left = 1cm  of 1] {};
\node[triangular, border rotated] (3) [below right = 1cm  of 1] {};
\node[rectangular] (4) [below=3cm of 1] {};
\node[square] (7) [below = 7cm of 1]{};
\node[triangular] (5) [above left = 1cm  of 7] {};
\node[triangular] (6) [above right = 1cm  of 7]{};

\draw (2.35) -- +(0,0.2) -- (1);
\draw (2.145) .. controls +(-7.5mm,35mm) and +(-7.5mm,-35mm) .. (5.215);
\draw (3.145) -- +(0,0.2) -- (1);
\draw (5.-35) -- +(0,-0.2) -- (7);
\draw (6.-145) -- +(0,-0.2) -- (7);
\draw (3.35) .. controls +(7.5mm,35mm) and +(7.5mm,-35mm) .. (6.-35);
\draw (2.south) -- (4.north -| 2.south) (3.south) -- (4.north -| 3.south) (4.south -| 5.north) -- (5.north) (4.south -| 6.north) -- (6.north);

\path (2.south) -- node [fill, circle] {} (5.north);
\path (3.south) -- node [fill, circle] {} (6.north);
\draw [<-] (4.north west) [bend right] to ++(-10mm,10mm) node [anchor=south] {$s'$};

\end{tikzpicture}
\end{document} • Thanks a bunch! I can see why the code or the syntax work. But without you telling me how exactly, I would now know them at all. – Witty Viper of Hidden Glen Apr 1 '16 at 16:03