%\filename{TCmacros.tex}
%\edited{last by stolfi on Fri Jul  4 07:31:05 1986}

% Macros for the test-and-complement gates and circuits

\endlinechar=-1 % Ignore <return> at end-of-line

% TC arrays and boxes
 
  % Dimensions of cells:
  
  \newdimen\cellheightunit \cellheightunit=7pt
  \newdimen\cellwidthunit  \cellwidthunit=6pt
  \newdimen\cellheight \cellheight=2\cellheightunit
  \newdimen\cellwidth  \cellwidth=2\cellwidthunit

  % Say {\cellsize{<n>} <stuff>} to typeset <stuff> with cells <n> 
  % units big (default is 2 units)
  
  \def\cellsize#1{\cellwidth=#1\cellwidthunit\cellheight=#1\cellheightunit}

  \newdimen\eps \eps=0.2pt % Width of frames

  % Cells:
  
  \def\cellbox#1{\vbox to \cellheight{\null\vss
    \hbox to \cellwidth{\hss #1\hss}
    \vss\null}}
  
  % Cell symbols:
  
  \font\cellsymbolfont=cmssbx10 \relax

  \def\0{\hbox{\cellsymbolfont 0}}
  \def\1{\hbox{\cellsymbolfont 1}}
  \def\x{\hbox{\cellsymbolfont x}}
  \def\p{\hbox{\cellsymbolfont -}}
  
  % \TCarray{ 
  %   \0 & \1     & \0    & \x & \p \cr
  %   \0 & \sigma & \p    & \p & \x \cr
  %   }
  % produces a TC array with given cells and no border.

  \def\TCarray#1{\vbox{\tabskip=0pt \offinterlineskip
    % Must define \vdots, \ddots, \hdots here.
    \halign{\cellbox{$ ## $}&&\cellbox{$ ## $}\cr #1\crcr}
    \null
    }}
  
  % \TCbox 3 by 2{$\Lambda_{m,n}$} 
  % produces a box with the same size as a 3x2 TC array,
  % containing the given hmode stuff centered.
  % Doesn't put a border around the box.
  
  \def\TCbox#1by#2#{\TCboxxx{#1}{#2}}
  \def\TCboxxx#1#2#3{\vbox to #1\cellheight{\offinterlineskip
    \null\vss
    \hbox to #2\cellwidth{\hss #3\hss}
    \vss\null}}

  % \wires{ \w & \w & \w &  & \w} creates a box with 
  % input/output wires (half the cell height).
  % Leave out a \w to omit the corresponding wire segment.
  
  \def\wires#1{\vbox{
    \def\w{\vrule width 4\eps}
    \tabskip=0pt \offinterlineskip
    \halign{\wirebox{$ ## $}&&\wirebox{$ ## $}\cr #1\crcr}
    \null
    }}
  
  \newdimen\wireheight \wireheight=\cellheightunit
  
  % Say {\wirelength{n} \wires{...}} to set wires n units long
  
  \def\wirelength#1{\wireheight=#1\cellheight}
  
  \def\wirebox#1{\vbox to \wireheight{\null\vss
    \hbox to \cellwidth{\vrule height \wireheight depth 0pt width 0pt
      \hss #1\hss
    }
    \vss\null}}
  
  % \vstack{<boxes>} makes a vertical pile out of the
  % given boxes, without glue.
  % \hstack{<boxes>} strings them side by side (aligned by their bottoms).
  % Needs some hackery to ignore spaces and carriage returns between
  % boxes.
  
  \def\hstack{\bgroup\endlinechar=-1\hstackkk}
  \def\hstackkk#1{\hbox{#1}\egroup}
  \def\vstack#1{\vbox{\offinterlineskip #1\null}}

  % \frame{<hmode stuff>} produces a box out of the given stuff
  % and puts a thin border (half in and half out) around it.
  
  \def\frame#1{\hbox{\kern -\eps
    \vbox{
      \null\kern -\eps \hrule height 2\eps \kern -\eps
      \hbox{\vrule width 2\eps \kern-\eps #1\kern-\eps \vrule width 2\eps}
      \kern -\eps \hrule height 2\eps \kern -\eps \null
      }
    \kern -\eps
    }}
    
\endlinechar=`\^^M % <return> at end of line will not be ignored


