I'm new to TikZ/PGF (a week or so in), and am loving it. I've had good success making figures so far, but have a question about best practices for including multiple copies of a sub-circuit in a single figure. And doing so in a way that allows simple connections to the input/output nodes of the sub-circuit.
As a very rudimentary example (please excuse the free-handed drawing) in which I have a drawing with two repeated sub-circuits (contained within a rectangle).

So in this example, I'd like to define the amplifier circuit once, and then place it twice in the picture and connect wires to its input and output nodes. Does this require me to develop a library, or can the sub-circuit be written into the .tex file directly and then reused?
I did see the post about using a \newsavebox here, but I'm not sure how I would access the nodes in the circuit using that approach.
Any help is greatly appreciated. Many thanks.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{circuits.logic.US,circuits.ee.IEC,positioning,fit}
\begin{document}
\begin{tikzpicture}[circuit ee IEC,circuit logic US,x=3cm,y=2cm,semithick,
set resistor graphic=var resistor IEC graphic]
% Box on the left (non circuit stuff)
\draw (0,0) rectangle (2,2);
\draw (1,1) rectangle (1.8,1.8);
\draw (0.3,0.2) rectangle (0.5,0.5);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Begin the sub-circuit to be replicated
\node[contact] (A) at (2.5,0) {};
\node[contact] [right=1.5cm of A] (B) {};
\node[contact] [above=1.5cm of B] (C) {};
\node[contact] [right=1.0cm of B] (D) {};
\node[contact] [right=1.5cm of D] (E) {};
\node[buffer gate] [right=0.1 of D] (amp) {};
% Problem #1: there is whitespace between the amp output and the line to node E
\draw (A) to [resistor] (B) (B) to [capacitor] (D) (D) to (amp) (amp) to (E);
\draw (B) to [resistor] (C);
% Problem #2: had to tune 0.54 to get vertical line to node E. (output of amp)
% Must be a better way ...
\draw (D) -- ++(0,0.5) to [capacitor] ++(right:0.54) to (E);
\tikzset{black box/.style={draw=black, rectangle}};
\node(preampbox) [black box, fit=(A) (C) (E) (amp), inner sep=0.4cm] {};
%%%%%%%%%%%%%% end subcircuit %%%%%%%%%%%%%%%%%%
\end{tikzpicture}
\end{document}


savebox? Isn't afor loopeligible? – masu Sep 29 '13 at 18:55insert path. Then thefitlibrary can be used to draw the box around it. Could you add the the code for the sub-circuit as well as the whole picture? (I’m not so familiar with circuits and won’t look up all the shapes and things.) – Qrrbrbirlbel Sep 29 '13 at 22:12