% REQUIRES standard verbatim package for verbatim stuff below.
% REQUIRES color package for \shadow and \highlight.

\makeatletter  % in effect for duration of this file, then undone

%  MISCELLANEOUS GENERAL COMMANDS

\newcommand{\myurl}[1]{\url{http://rig.cs.luc.edu/~rig/#1}}
\newcommand{\smallurl}[1]{{\small\url{#1}}}

\let\@originput=\input
\def\input{\typeout{}\@originput} % just to ensure file names not split across a line in the log file

\newcommand{\comm}[1]{}
 % Name changed from \comment to \comm to avoid conflict with comment
 % environment of the verbatim package.

\newcommand{\todo}[1]{\typeout{To Do: #1}{\quad\em To Do: #1\quad}}

\def\dropsuffix#1-#2.{#1}
\def\basename{\expandafter\dropsuffix\jobname-.}

\def\uncompactdate#1#2#3#4#5#6#7#8{\ifcase#5#6\or January\or February\or March\or April\or May\or June\or July\or August\or September\or October\or November\or December\fi \space#7#8, #1#2#3#4}
 % Converts date in YYYYMMDD format to Monthname DD, YYYY.

\newcommand{\twodig}[1]{\ifcase#1 00\or01\or02\or03\or04\or05\or06\or07\or08\or09\else#1\fi}
 % Converts one digit (nonneg.) nos. to have a leading 0; other nos. unchanged.

%\newcommand{\ie}{{\it i.e., }}
%\newcommand{\eg}{{\it e.g., }}

\newcommand{\inputitems}[1]{\begin{itemize}\input{#1}\end{itemize}}

\newcommand{\shadow}{\color{cyan}} % Command name \shade used by eepic.sty
\newcommand{\highlight}{\color{red}}


%  HYPHENATION

\hyphenation{mas-sa-chu-setts di-men-sion di-men-sion-al}


%  LINE SPACING COMMANDS

\newcommand{\mysinglespace}{\setlength{\baselineskip}{16pt}}
% (for a 12pt document)

\newcommand{\mydoublespace}{\setlength{\baselineskip}{24pt}}
% (for a 12pt document)

\newcommand{\mylinespacing}[1]{\setlength{\baselineskip}{#1}}

% Set baselinestretch and make it go into effect
\newcommand{\stretchset}[1]{\renewcommand{\baselinestretch}{#1}\@normalsize}


%  STRUTS

\newcommand{\Hugestrut}{{\Huge\strut}}
\newcommand{\hugestrut}{{\huge\strut}}
\newcommand{\LARGEstrut}{{\LARGE\strut}}
\newcommand{\Largestrut}{{\Large\strut}}
\newcommand{\largestrut}{{\large\strut}}


%  PAGE TWIDDLING

% Do clearpage and make an empty page with plain pagestyle.
\newcommand{\emptypage}{\clearpage\thispagestyle{plain}\mbox{}\newpage}

% Get to an odd numbered page, with any blank pages in plain style
\renewcommand{\cleardoublepage}{\clearpage\if@twoside \ifodd\c@page\else
    \hbox{}\thispagestyle{plain}\newpage\if@twocolumn\hbox{}\newpage\fi\fi\fi}


%  SECTIONING

\newcommand{\modestsections}{
    \let\part=\section
    \let\section=\subsection
        \renewcommand{\thesubsection}{\arabic{subsection}}
    \let\subsection=\subsubsection  % nos. def. in terms of section as before
    \let\subsubsection=\paragraph
    \let\paragraph=\subparagraph
    \renewcommand{\subparagraph}[1]{\paragraph{##1}
        \typeout{You've used the subparagraph command, which is the same as
                 the paragraph command since you're using modest sections.}}
    \renewcommand\appendix{\par
        \setcounter{subsection}{0}%
        \setcounter{subsubsection}{0}%
        \renewcommand\thesubsection{\@Alph\c@subsection}}
}

\newcommand{\modestmaketitle}{
\def\@maketitle{\newpage
 \null
 \vskip 1.5em
 \begin{center}%
  {\Large \@title \par}%
  \vskip 1em
  {\large
   \lineskip .5em
   \begin{tabular}[t]{c}\@author
   \end{tabular}\par}%
  \vskip .7em
  {\large \@date}%
 \end{center}%
 \par
 \vskip 1em}
}

\newcommand{\verymodestmaketitle}{
 \newpage
 {\centering
  {\large \@title \par}%
  \vskip 1em
  {
   \lineskip .5em
   \begin{tabular}[t]{c}\@author
   \end{tabular}\par}%
  \vskip .7em
  {\@date}%
 }%
 \par
 \vskip 1em
}


%  COUNTERS, ESP. FOOTNOTES

\newcommand{\arabicifpos}[1]{\@arabicifpos{\@nameuse{c@#1}}}
\newcommand{\@arabicifpos}[1]{\ifnum #1>0 \number #1\fi}

%  MAKE 0 FOOTNOTE COUNTER NOT PRINT.  USEFUL FOR FRONT PAGE GRANT INFO.
\renewcommand{\thefootnote}{\arabicifpos{footnote}}


%  PICTURES

% sets basic length unit for picture environment
\setlength{\unitlength}{1in}

% useful shorthands for some linethickness changes
\newcommand{\extrathinlines}{\linethickness{.05ex}}
\newcommand{\medthicklines}{\linethickness{.2ex}}
\newcommand{\extrathicklines}{\linethickness{.5ex}}

% Commands analogous to \circle and \circle* for rectangles/squares
% and filled ones.  As with \circle, reference points are at center.

\def\rect{\@ifstar{\@blackrect}{\@rect}}

\def\square{\@ifstar{\@blacksquare}{\@square}}

\def\@square#1{\@rect(#1,#1)}

\def\@blacksquare#1{\@blackrect(#1,#1)}

\def\@rect(#1,#2){\makebox(0,0)%
{\begin{picture}(#1,#2)\put(0,0){\framebox(#1,#2){}}\end{picture}}}

\def\@blackrect(#1,#2){\makebox(0,0){\rule{#1\unitlength}{#2\unitlength}}}

% Following two commands are useful for easily using pictures from xfig
% but substituting black rectangles or circles for unfilled ones.

% Another command for a black rectangle but completely analogous to
% framebox (without optional argument).
% The reference point is at lower left as for framebox.

\def\blackbox(#1,#2)#3{\makebox(#1,#2){\rule{#1\unitlength}{#2\unitlength}}}

% An alternative command name for circle* with no @ in the name

\let\blackcircle=\@dot

% two dimensional multiput for pictures
% \arrayputs(x,y)(deltax,deltay){xnum}{ynum}{object}
% modeled on \multiput(x,y)(deltax,deltay){num}{object}
% Content processed once; i.e., exact copies at every array position.
\newsavebox{\object}
\newsavebox{\arrayputsrow}
\long\def\arrayputs(#1,#2)(#3,#4)#5#6#7{
   \savebox{\object}{#7}
   \savebox{\arrayputsrow}{\multiput(#1,0)(#3,0){#5}{\usebox{\object}}}
   \sbox{\object}{}
   \multiput(0,#2)(0,#4){#6}{\usebox{\arrayputsrow}}
   \sbox{\arrayputsrow}{}}
% New variations:
% reprocess content going row major
\long\def\arrayputxy(#1,#2)(#3,#4)#5#6#7{
   \multiput(#1,#2)(0,#4){#6}{\multiput(0,0)(#3,0){#5}{#7}}
   }
% reprocess content going column major
\long\def\arrayputyx(#1,#2)(#3,#4)#5#6#7{
   \multiput(#1,#2)(#3,0){#5}{\multiput(0,0)(0,#4){#6}{#7}}
   }

% Rectangular grid of lines (graph paper).  Uses \unitlength for grid
% spacing and arguments for grid size
\newcommand{\graphpap}[2]{
\noindent
\begin{picture}(#1,#2)
\put(0,0){\line(1,0){#1}}
\put(0,0){\line(0,1){#2}}
\multiput(0,1)(0,1){#2}{\line(1,0){#1}}
\multiput(1,0)(1,0){#1}{\line(0,1){#2}}
\end{picture}}

% Add grid to existing picture to help with visualization when developing drawing
\newcommand{\addgrid}[4]{
\put(0,0){\line(1,0){#1#3}}
\put(0,0){\line(0,1){#2#4}}
\multiput(0,1#4)(0,1#4){#2}{\line(1,0){#1#3}}
\multiput(1#3,0)(1#3,0){#1}{\line(0,1){#2#4}}
}

% Switching fbox/framebox to only draw the horizontal lines:

\def\horizonly@frameb@x#1{%
  \@tempdima\fboxrule
  \advance\@tempdima\fboxsep
  \advance\@tempdima\dp\@tempboxa
  \hbox{%
    \lower\@tempdima\hbox{%
      \vbox{%
        \hrule\@height\fboxrule
        \hbox{%
          #1%
          \vbox{%
            \vskip\fboxsep
            \box\@tempboxa
            \vskip\fboxsep}%
          #1}%
        \hrule\@height\fboxrule}%
                          }%
        }%
}

\newcommand{\horizonlyfboxes}{\let\@frameb@x=\horizonly@frameb@x}


%  TABBING ENVIRONMENTS (USE FOR AUTOMATIC CORRECT WIDTH BOXES)

\newcommand{\standardtabs}{MMMM\=MMMM\=MMMM\=MMMM\=MMMM\=
                           MMMM\=MMMM\=MMMM\=MMMM\=MMMM\=\kill}

\newenvironment{boundedtabpackage}[1]%
{\begin{minipage}{#1}\begin{tabbing}}%
{\end{tabbing}\end{minipage}}

\newenvironment{tabpackage}%  LIKE BOUNDEDTABPACKAGE BUT W. \columnwidth WIDTH
{\begin{minipage}{\columnwidth}\begin{tabbing}}%
{\end{tabbing}\end{minipage}}

\newenvironment{positionedtabpackage}[1]%  LIKE TABPACKAGE BUT t or b for vertical positioning
{\begin{minipage}[#1]{\columnwidth}\begin{tabbing}}%
{\end{tabbing}\end{minipage}}

%  VERBATIM

% My old \inputverb command needed to be followed by an \endverbatim
% Better is the one here that requires the verbatim package.  It
% differs from \verbatiminput in the verbatim package only by printing
% left parend, the file name, and `` (verbatim)'' before the
% \verbatiminput and right parend afterwards.
% And now have a version for fancyvrb package.

\newcommand{\inputverb}[1]% for verbatim package
{\typeout{(#1 (verbatim)}\verbatiminput{#1}\typeout{)}}
\newcommand{\inputVerb}[1]% for fancyvrb package
{\typeout{(#1 (verbatim)}\VerbatimInput{#1}\typeout{)}}

%  DOING REPETITIONS OF SOMETHING

\newcount\n
\def\repetition#1#2{\n=0\loop\ifnum\n<#2\advance\n by 1 #1\repeat}

\def\fewreps#1#2{\ifcase#2\or % up to 35 repetitions
#1\or
#1#1\or
#1#1#1\or
#1#1#1#1\or
#1#1#1#1#1\or
#1#1#1#1#1#1\or
#1#1#1#1#1#1#1\or
#1#1#1#1#1#1#1#1\or
#1#1#1#1#1#1#1#1#1\or
#1#1#1#1#1#1#1#1#1#1\or
#1#1#1#1#1#1#1#1#1#1#1\or
#1#1#1#1#1#1#1#1#1#1#1#1\or
#1#1#1#1#1#1#1#1#1#1#1#1#1\or
#1#1#1#1#1#1#1#1#1#1#1#1#1#1\or
#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1\or
#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1\or
#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1\or
#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1\or
#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1\or
#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1\or
#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1\or
#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1\or
#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1\or
#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#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