% Karnaugh style - R. French 10/11/88
%
% Made for 12 pt, but should work for 10 pt OK

\typeout{Karnaugh style (rfrench)}

\newlength{\karnunitlength}
\setlength{\karnunitlength}{20pt}

\def\karngetfirst#1#2#3#4{#1}
\def\karngetsecond#1#2#3#4{#2}
\def\karngetthird#1#2#3#4{#3}
\def\karngetfourth#1#2#3#4{#4}

\def\karnfourbox{
	\put(0,0){\line(0,1){4}}
	\put(1,0){\line(0,1){4}}
	\put(2,0){\line(0,1){4}}
	\put(3,0){\line(0,1){4}}
	\put(4,0){\line(0,1){4}}
	\put(0,0){\line(1,0){4}}
	\put(0,1){\line(1,0){4}}
	\put(0,2){\line(1,0){4}}
	\put(0,3){\line(1,0){4}}
	\put(0,4){\line(1,0){4}}
}

\def\karnfourcontents#1#2#3#4{
	\put(0,0){\makebox(1,1){\karngetfirst#4}}
	\put(1,0){\makebox(1,1){\karngetsecond#4}}
	\put(2,0){\makebox(1,1){\karngetthird#4}}
	\put(3,0){\makebox(1,1){\karngetfourth#4}}
	\put(0,1){\makebox(1,1){\karngetfirst#3}}
	\put(1,1){\makebox(1,1){\karngetsecond#3}}
	\put(2,1){\makebox(1,1){\karngetthird#3}}
	\put(3,1){\makebox(1,1){\karngetfourth#3}}
	\put(0,2){\makebox(1,1){\karngetfirst#2}}
	\put(1,2){\makebox(1,1){\karngetsecond#2}}
	\put(2,2){\makebox(1,1){\karngetthird#2}}
	\put(3,2){\makebox(1,1){\karngetfourth#2}}
	\put(0,3){\makebox(1,1){\karngetfirst#1}}
	\put(1,3){\makebox(1,1){\karngetsecond#1}}
	\put(2,3){\makebox(1,1){\karngetthird#1}}
	\put(3,3){\makebox(1,1){\karngetfourth#1}}
}

\def\karnfoursidelabel{
	\put(-1,3){\makebox(1,1){\footnotesize 00}}
	\put(-1,2){\makebox(1,1){\footnotesize 01}}
	\put(-1,1){\makebox(1,1){\footnotesize 11}}
	\put(-1,0){\makebox(1,1){\footnotesize 10}}
	\put(0,4){\makebox(1,1){\footnotesize 00}}
	\put(1,4){\makebox(1,1){\footnotesize 01}}
	\put(2,4){\makebox(1,1){\footnotesize 11}}
	\put(3,4){\makebox(1,1){\footnotesize 10}}
}

\def\karnfourvarlabel#1#2{
	\put(-2,0){\makebox(0,4){\footnotesize #1}}
	\put(0,5.25){\makebox(4,0){\footnotesize #2}}
}

\def\karncircleone#1#2{
	\put(#1.5,#2.5){\circle{.8}}
}

\def\karncirclegroup#1#2#3#4#5#6{
	\put(#1.5,#2.5){\oval(.8,.8)[bl]}
	\put(#1.5,#4.5){\oval(.8,.8)[tl]}
	\put(#3.5,#2.5){\oval(.8,.8)[br]}
	\put(#3.5,#4.5){\oval(.8,.8)[tr]}
	\put(#1.1,#2.5){\line(0,1){#6}}
	\put(#3.9,#2.5){\line(0,1){#6}}
	\put(#1.5,#2.1){\line(1,0){#5}}
	\put(#1.5,#4.9){\line(1,0){#5}}
}

\def\karncirclecorners{
	\put(.5,.5){\oval(.8,.8)[tr]}
	\put(.5,.9){\line(-1,0){.8}}
	\put(.9,.5){\line(0,-1){.8}}

	\put(.5,3.5){\oval(.8,.8)[br]}
	\put(.5,3.1){\line(-1,0){.8}}
	\put(.9,3.5){\line(0,1){.8}}

	\put(3.5,3.5){\oval(.8,.8)[bl]}
	\put(3.5,3.1){\line(1,0){.8}}
	\put(3.1,3.5){\line(0,1){.8}}

	\put(3.5,.5){\oval(.8,.8)[tl]}
	\put(3.5,.9){\line(1,0){.8}}
	\put(3.1,.5){\line(0,-1){.8}}
}

\def\karncirclevertwrap#1#2#3{
	\put(#1.5,3.5){\oval(.8,.8)[bl]}
	\put(#2.5,3.5){\oval(.8,.8)[br]}
	\put(#1.5,.5){\oval(.8,.8)[tl]}
	\put(#2.5,.5){\oval(.8,.8)[tr]}

	\put(#1.5,3.1){\line(1,0){#3}}
	\put(#1.1,3.5){\line(0,1){.8}}
	\put(#2.9,3.5){\line(0,1){.8}}

	\put(#1.5,.9){\line(1,0){#3}}
	\put(#1.1,.5){\line(0,-1){.8}}
	\put(#2.9,.5){\line(0,-1){.8}}
}

\def\karncirclehorwrap#1#2#3{
	\put(.5,#1.5){\oval(.8,.8)[br]}
	\put(.5,#2.5){\oval(.8,.8)[tr]}
	\put(3.5,#1.5){\oval(.8,.8)[bl]}
	\put(3.5,#2.5){\oval(.8,.8)[tl]}

	\put(.9,#1.5){\line(0,1){#3}}
	\put(.5,#1.1){\line(-1,0){.8}}
	\put(.5,#2.9){\line(-1,0){.8}}

	\put(3.1,#1.5){\line(0,1){#3}}
	\put(3.5,#1.1){\line(1,0){.8}}
	\put(3.5,#2.9){\line(1,0){.8}}
}

\def\beginkarnfour#1#2#3#4#5#6{
	\setlength{\unitlength}{\karnunitlength}
	\begin{picture}(7,6)(-2.5,0)
	\karnfourbox
	\karnfourcontents{#1}{#2}{#3}{#4}
	\karnfoursidelabel
	\karnfourvarlabel{#5}{#6}
}

\def\endkarnfour{
	\end{picture}
}

\def\karnfoursimple#1#2#3#4{
	\setlength{\unitlength}{\karnunitlength}
	\begin{picture}(5,5)(1,0)
	\karnfourbox
	\karnfourcontents{#1}{#2}{#3}{#4}
	\end{picture}
}

\def\karnfour#1#2#3#4#5#6{
	\beginkarnfour{#1}{#2}{#3}{#4}{#5}{#6}
	\endkarnfour
}

% Usage:
%
% \karnfour{xxxx}{xxxx}{xxxx}{xxxx}{left}{top}
%	Draws 4x4 map with left and top as variable labels.  Includes
%	00-01-11-10 labelling.
%
% \karnfoursimple{xxxx}{xxxx}{xxxx}{xxxx}
%	Draws 4x4 map with 00-01-11-10 labelling.
%
% \beginkarnfour{xxxx}{xxxx}{xxxx}{xxxx}{left}{top}
%	Same as \karnfour, but doesn't close the environment so groupings
%	can be done.
%
% \endkarnfour
%	End a \beginkarnfour
%
% \karncircleone{x}{y}
%	Circle the single element at (x,y)  (0,0) is bottom left
%
% \karncirclegroup{x1}{y1}{x2}{y2}{wid}{ht}
%	Circle the group at (x1,y1) (lower-left) to (x2,y2) (upper-right)
%	with width wid and height ht (wid = x2-x1, ht=y2-y1)
%
% \karncirclecorners
%	Circle the corners
%
% \karncirclevertwrap{x1}{x2}{wid}
%	Circle a verticle wrap from x1 to x2 of width wid (height is
%	always 1 on top and bottom)  x1<x2
%
% \karncirclehorwrap{y1}{y2}{ht}
%	Circle a horizontal wrap from y1 to y2 of height ht (width
%	is always 1 on left and right)  y1<y2
