[Tex/LaTex] TikZ: Defining and reusing complex objects

diagramsmacrostikz-pgftikz-styles

(How) Is it possible to save some complex TikZ objects for reusing them (in the same and in different pictures)?

I know it's possible to define own styles, but I'm not sure if it's the right thing I'm looking for (styles seems to be only for properties not for complex and done objects). And that it's possible to save whole images with savebox, but can it be used to save portions of pictures?

Let's make an example: Someone's building several optical experiments. All experiments use the same kind of elements, like mirrors, lasers, polarizers, beam splitters and so on, but each experiment is in another configuration and setup. Each element has it's own picture (just like in electrical circuits where each type of element has it's own "icon").

How and where do I define my "kinds of elements" to be able to reuse them in my lots of TikZ pictures?

In the end I want ideally be able to draw my pictures similar (not neccerssarily exact) like

\begin{tikzpicture}
  \mirror at (0,0);
  \laser at (1,0);
  \draw (1,0) --(0,0) --(0,1);
\end{tikzpicture}

Best Answer

One way you could address this is to define your own node shapes as described in the PGF/TikZ manual in ยง 107.5 "Declaring New Shapes" and then define e.g. \mirror as \node [shape=mirror] (the shape= part is optional, but I would recommend it here). However, unfortunately you need to define node shapes using PGF not TikZ commands, which makes the creation of them difficult and doesn't allow you to simply convert an existing TikZ picture into a node shape.