[comp.text.tex] Digital circuits in LaTeX.

raja@silver.ucs.indiana.edu (Raja Sooriamurthi) (07/11/90)

For a manual that I'm preparing I need some digital circuits (made up
of AND, NAND, OR, NOR and XOR gates) interspersed with text. I gave it
a shot using the picture environment of LaTeX and produced quite
pleasant circuits using AND and NAND gates. But producing OR and XOR is
complicated because of the arcs required.  

My questions are:

	1. Have you included circuits with LaTeX text before
and if so what did you use. Information on  other packages/macros is
welcome. 

	2. I felt METAFONT might help in producing an 'alphabet' of
gates which I could then use to construct the circuits. I haven't done
any METAFONT programming before, but have recently acquired the book.
Would it be feasible to construct such a 'gate alphabet'. Better still,
has anyone done similar things before.

Thanks for any help and advice.

- Raja

---------------------------------------------------------------------------
Raja Sooriamurthi                              Computer Science Department
raja@silver.ucs.indiana.edu                       Indiana University
---------------------------------------------------------------------------

duchier@cs.yale.edu (Denys Duchier) (07/11/90)

I can't remember where I got this font, but here goes anyway. There
are two files: milstd.mf and milstd.tex.

------------------------------begin milstd.mf--------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       "milstd" font by Rick Simpson
%       (published in UKTeX 1988, issue 30 (23 Sept. 1988))

%       Contains a collection of special characters for
%       use in logic diagrams


%       To create the "milstd" font, use command:
%               makefont milstd

%       To use the characters in a PLAIN TeX document:
%               \font\milstd=milstd         % define the font
%               . . .
%               {\milstd\char0}             % typeset the character

%       To use the characters in a LaTeX document:
%               \newfont{\milstd}{milstd}   % define the font
%               . . .
%               {\milstd\char0}             % typeset the character

%       See "milstd.tex" for definitions to be used with TeX and LaTeX


mode_setup;
font_size 10pt#;

picture pic;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       Slanting line at 45-degree angle for marking
%       busses in logic diagrams.

slwd#:=7pt#;
define_pixels(slwd);

beginchar(0,slwd#,slwd#,0);  "Slanted line for buss widths";

x1 = 0;
y1 = 0;

x2 = slwd;
y2 = slwd;

pickup pencircle scaled 1pt;
draw z1--z2;

labels (range 1 thru 2);

endchar;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       AND gate, facing to the right
%

gateunit# := 6pt#;

gatea# := 2   * gateunit#;
gateb# := 4   * gateunit#;
gatec# := 2.5 * gateunit#;
gated# := 2   * gateunit#;

define_pixels(gatea,gateb,gatec,gated);

beginchar(1,gatec#+gated#,gateb#,0);  "AND gate, right";

x1 = x2 = 0;
x3 = x5 = gatec;
x4 = gatec + gated;

y1 = y5 = 0;
y2 = y3 = gateb;
y4 = gatea;

pickup pencircle scaled 1pt;
draw z1--z2--z3{right}..z4..{left}z5--z1;

pic := currentpicture;

labels (range 1 thru 5);

endchar;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       AND gate, facing down
%

beginchar(2,gateb#,gatec#+gated#,0);  "AND gate, down";

currentpicture := pic rotated 270 shifted (0,gatec+gated);

endchar;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       AND gate, facing to the left
%

beginchar(3,gatec#+gated#,gateb#,0);  "AND gate, right";

currentpicture := pic rotated 180 shifted(gatec+gated,gateb);

endchar;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       AND gate, facing up
%

beginchar(4,gateb#,gatec#+gated#,0);  "AND gate, up";

currentpicture := pic rotated 90 shifted(gateb,0);

endchar;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       NAND gate, facing to the right
%

gatee# := gateunit#;

define_pixels(gatee);

beginchar(5,gatec#+gated#,gateb#,0);  "NAND gate, right";

x1 = x2 = 0;
x3 = x5 = gatec;
x4 = gatec + gated;
x6 = x4 + gatee/2;

y1 = y5 = 0;
y2 = y3 = gateb;
y4 = gatea;
y6 = y4;

pickup pencircle scaled 1pt;
draw z1--z2--z3{right}..z4..{left}z5--z1;
draw fullcircle scaled gatee shifted(z6);

pic := currentpicture;

labels (range 1 thru 6);

endchar;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       NAND gate, facing down
%

beginchar(6,gateb#,gatec#+gated#,0);  "NAND gate, down";

currentpicture := pic rotated 270 shifted (0,gatec+gated);

endchar;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       NAND gate, facing to the left
%

beginchar(7,gatec#+gated#,gateb#,0);  "NAND gate, right";

currentpicture := pic rotated 180 shifted(gatec+gated,gateb);

endchar;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       NAND gate, facing up
%

beginchar(8,gateb#,gatec#+gated#,0);  "NAND gate, up";

currentpicture := pic rotated 90 shifted(gateb,0);

endchar;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       OR gate, facing to the right
%

gatef# := .75 * gateunit#;
gateg# := 1.5 * gateunit#;
gateh# := 3   * gateunit#;

define_pixels(gatef,gateg,gateh);

beginchar(9,gateg#+gateh#,gateb#,0);  "OR gate, right";

x1 = x2 = 0;
x3 = x5 = gateg;
x4 = gateg + gateh;
x6 = gatef;

y1 = y5 = 0;
y2 = y3 = gateb;
y4 = y6 = gatea;

pickup pencircle scaled 1pt;
draw z1..z6..z2;
draw z2--z3;
draw z3{right}..{(1,-2)}z4;
draw z4{-1,-2}..z5{left};
draw z5--z1;

pic := currentpicture;

labels (range 1 thru 6);

endchar;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       OR gate, facing down
%

beginchar(10,gateb#,gateg#+gateh#,0);  "OR gate, down";

currentpicture := pic rotated 270 shifted (0,gateg+gateh);

endchar;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       OR gate, facing to the left
%

beginchar(11,gateg#+gateh#,gateb#,0);  "OR gate, left";

currentpicture := pic rotated 180 shifted(gateg+gateh,gateb);

endchar;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       OR gate, facing up
%

beginchar(12,gateb#,gateg#+gateh#,0);  "OR gate, up";

currentpicture := pic rotated 90 shifted(gateb,0);

endchar;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       NOR gate, facing to the right
%

beginchar(13,gateg#+gateh#,gateb#,0);  "NOR gate, right";

x1 = x2 = 0;
x3 = x5 = gateg;
x4 = gateg + gateh;
x6 = gatef;
x7 = x4 + gatee/2;

y1 = y5 = 0;
y2 = y3 = gateb;
y4 = y6 = gatea;
y7 = y4;

pickup pencircle scaled 1pt;
draw z1..z6..z2;
draw z2--z3;
draw z3{right}..{(1,-2)}z4;
draw z4{-1,-2}..z5{left};
draw z5--z1;
draw fullcircle scaled gatee shifted (z7);

pic := currentpicture;

labels (range 1 thru 7);

endchar;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       NOR gate, facing down
%

beginchar(14,gateb#,gateg#+gateh#,0);  "NOR gate, down";

currentpicture := pic rotated 270 shifted (0,gateg+gateh);

endchar;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       NOR gate, facing to the left
%

beginchar(15,gateg#+gateh#,gateb#,0);  "NOR gate, left";

currentpicture := pic rotated 180 shifted(gateg+gateh,gateb);

endchar;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       NOR gate, facing up
%

beginchar(16,gateb#,gateg#+gateh#,0);  "NOR gate, up";

currentpicture := pic rotated 90 shifted(gateb,0);

endchar;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       Buffer, facing to the right
%

gatei# := 3    * gateunit#;
gatej# := .866 * gatei#;
gatek# := 1.5  * gateunit#;

define_pixels(gatei,gatej,gatek);

beginchar(17,gatej#,gatei#,0);  "Buffer, right";

x1 = x2 = 0;
x3 = gatej;

y1 = 0;
y2 = gatei;
y3 = gatek;

pickup pencircle scaled 1pt;
draw z1--z2--z3--z1;

pic := currentpicture;

labels (range 1 thru 3);

endchar;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       Buffer, facing down
%

beginchar(18,gatei#,gatej#,0);  "Buffer, down";

currentpicture := pic rotated 270 shifted (0,gatej);

endchar;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       Buffer, facing to the left
%

beginchar(19,gatej#,gatei#,0);  "Buffer, left";

currentpicture := pic rotated 180 shifted(gatej,gatei);

endchar;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       Buffer, facing up
%

beginchar(20,gatei#,gatej#,0);  "Buffer, up";

currentpicture := pic rotated 90 shifted(gatei,0);

endchar;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       Inverter, facing to the right
%

beginchar(21,gatej#,gatei#,0);  "Inverter, right";

x1 = x2 = 0;
x3 = gatej;
x4 = x3 + gatee/2;

y1 = 0;
y2 = gatei;
y3 = y4 = gatek;


pickup pencircle scaled 1pt;
draw z1--z2--z3--z1;
draw fullcircle scaled gatee shifted (z4);

pic := currentpicture;

labels (range 1 thru 4);

endchar;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       Inverter, facing down
%

beginchar(22,gatei#,gatej#,0);  "Inverter, down";

currentpicture := pic rotated 270 shifted (0,gatej);

endchar;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       Inverter, facing to the left
%

beginchar(23,gatej#,gatei#,0);  "Inverter, left";

currentpicture := pic rotated 180 shifted(gatej,gatei);

endchar;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       Inverter, facing up
%

beginchar(24,gatei#,gatej#,0);  "Inverter, up";

currentpicture := pic rotated 90 shifted(gatei,0);

endchar;

end;
------------------------------end  milstd.mf--------------------

------------------------------begin milstd.tex------------------
%  milstd.tex
%
%       Special characters for logic diagrams (as in MIL-STD 806)
%
\newfont{\milstd}{milstd}
%
\def\BusWidth{{\milstd\char0}}  % '/' for bus width notation
\def\ANDr{{\milstd\char1}}      % AND gate facing right
\def\ANDd{{\milstd\char2}}      %                 down
\def\ANDl{{\milstd\char3}}      %                 left
\def\ANDu{{\milstd\char4}}      %                 up
\def\NANDr{{\milstd\char5}}     % NAND gate facing right
\def\NANDd{{\milstd\char6}}
\def\NANDl{{\milstd\char7}}
\def\NANDu{{\milstd\char8}}
\def\ORr{{\milstd\char9}}       % OR gate facing right
\def\ORd{{\milstd\char10}}
\def\ORl{{\milstd\char11}}
\def\ORu{{\milstd\char12}}
\def\NORr{{\milstd\char13}}     % NOR gate facing right
\def\NORd{{\milstd\char14}}
\def\NORl{{\milstd\char15}}
\def\NORu{{\milstd\char16}}
\def\BUFr{{\milstd\char17}}     % Buffer facing right
\def\BUFd{{\milstd\char18}}
\def\BUFl{{\milstd\char19}}
\def\BUFu{{\milstd\char20}}
\def\INVr{{\milstd\char21}}     % Inverter facing right
\def\INVd{{\milstd\char22}}
\def\INVl{{\milstd\char23}}
\def\INVu{{\milstd\char24}}
------------------------------end  milstd.tex------------------

--Denys