
% GMACRO.TEX
% WRITTEN OCTOBER 24, 1987
% REVISED OCTOBER 19, 1988 -- CHANGED FOOTNOTE FORMAT

\newif\ifapple  \applefalse

\ifdim\hsize>0pt \magnification=1200 \fi
% Alternatives: 1000, 1095, 1152.  When an alternative is desired,
% specify it before inputting gmacro, and THEN set \hsize=0pt
\hsize=6.4 truein \vsize=8.9 truein
\hoffset=1 truein \voffset=1 truein
\baselineskip 12pt plus 1 pt minus 1pt
\parskip=\medskipamount
\tolerance=10000
%Implement following macro for printing with the Appleprinter at
%   the CFA
\def\applewriter{\advance\hoffset by-1truein\advance\voffset
    by-1truein}
\ifapple \applewriter \fi

%Redefinition of \alloc@ and \newinsert, to avoid writing of
%   counter numbers to output .lis file
% We make @ signs act like letters, temporarily.
\catcode`@=11
\def\alloc@#1#2#3#4#5{\global\advance\count1#1by\@ne
  \ch@ck#1#4#2% make sure there's still room
  \allocationnumber=\count1#1%
  \global#3#5=\allocationnumber
  \writelog{#5}{#2}}
\outer\def\newinsert#1{\global\advance\insc@unt by\m@ne
  \ch@ck0\insc@unt\count
  \ch@ck1\insc@unt\dimen
  \ch@ck2\insc@unt\skip
  \ch@ck4\insc@unt\box
  \allocationnumber=\insc@unt
  \global\chardef#1=\allocationnumber
  \writelog{#1}{\insert}}
\def\writelog#1#2{}

%Following macro is used for gboxit, to allow it to know when it
%  is working inside \eqalign.
  \def\openup{\openedtrue\afterassignment\@penup\dimen@=}

%Modification of format for footnotes:
 \def\vfootnote#1{\insert\footins\bgroup
    \interlinepenalty\interfootnotelinepenalty
    \splittopskip\ht\strutbox % top baseline for broken footnotes
    \splitmaxdepth\dp\strutbox \floatingpenalty\@MM
    \leftskip\z@skip \rightskip\z@skip \spaceskip\z@skip
    \xspaceskip\z@skip \footformat \footfont
    \textindent{#1}\footstrut\futurelet\next\fo@t}
 \def\footformat{}
 %To change the linespacing in footnotes:
        \def\footformat{\baselineskip=10pt plus 1pt}
 %To change the space between text and footnotes on a page:
        \skip\footins=18pt
 %To make the footnote rule the same width as the page:
        \def\footnoterule{\kern-3pt
        \hrule width \the\hsize \kern 2.6pt}

\catcode`@=12 % at signs are no longer letters

%\new declarations
\newdimen\topspace \newinsert\topspaceinsert
\skip\topspaceinsert=0pt \count\topspaceinsert=1000
\dimen\topspaceinsert=\maxdimen \newcount\headskip
\newif\ifopened  \openedfalse  \headskip=1
%End of \new declarations

%Restore original meaning to \alloc@ and \newinsert
\def\writelog#1#2{\wlog{\string#1=\string#2\the\allocationnumber}}

%HEADINGS:  For a one or two line heading, on pages after the
%   first one can use the following macros.  These macros create
%   headlines which begin at the usual top margin, causing the
%   rest of the page to be shorter than normal.
% Example:
%   \headline{LECTURE NOTES 1: THE DOPPLER EFFECT AND SPECIAL
%      RELATIVITY, \hfill p.~\folio}
%   \nopagenumbers
%  Other instructions are \headlineb{xxx}, \nextheadline{xxx},
%      \nextheadlineb{xxx}, \headstart{n}, \pageset{n}.

\def\nulltest{}    %Used in comparison tests
\def\headlinetext{}  %Headline initialized as null
\def\headlinetextb{}   %2nd headline initialized as null
\def\nextheadlinetext{}  %Headline for next page initialized
\def\nextheadlinetextb{} %2nd headline for next page initialized
\topspace=0pt
\def\topline#1{{\setbox1=\line{#1\hfil} \ifdim\ht1<10pt
    \vbox to 10pt{\vfill \box1}
   \else \box1 \fi}}
\def\makeheadline{\vbox to 0pt{\baselineskip 12pt
    \ifnum\pageno > \headskip
      \ifx \headlinetext \nulltest \else \topline{\headlinetext}
          \fi
      \ifx \headlinetextb \nulltest \else
          \line{\headlinetextb\hfil} \fi
    \fi \vss} \nointerlineskip}
\def\headline#1{\let\headlinetextold=\headlinetext
    \gdef\headlinetext{#1} \gdef\nextheadlinetext{#1}
  \ifx \headlinetextold \nulltest
    \ifx \headlinetext \nulltest \else
       \toks1=\expandafter{\headlinetext}
          \immediate\write16{Headline set: \the\toks1}
       \global\advance\topspace by 26pt
       \ifnum\pageno > \headskip \insert\topspaceinsert{\vskip
          26pt} \fi
    \fi
  \else
    \ifx \headlinetext \nulltest
       \global\advance\topspace by -26pt
       \ifnum\pageno>\headskip \insert\topspaceinsert{\vskip
          -26pt} \fi
       \immediate\write16{Headline cancelled.}
    \else \toks1=\expandafter{\headlinetext}
       \immediate\write16{Headline changed to: \the\toks1}
    \fi
  \fi}
\def\headlineb#1{\let\headlinetextbold=\headlinetextb
    \gdef\headlinetextb{#1} \gdef\nextheadlinetextb{#1}
  \ifx \headlinetextbold \nulltest
    \ifx \headlinetextb \nulltest \else
       \toks1=\expandafter{\headlinetextb}
       \immediate\write16{Headlineb set: \the\toks1}
       \global\advance\topspace by 12pt
       \ifnum\pageno > \headskip \insert\topspaceinsert{\vskip
          12pt} \fi
    \fi
  \else
    \ifx \headlinetextb \nulltest
       \global\advance\topspace by -12pt
       \ifnum\pageno>\headskip \insert\topspaceinsert{\vskip
          -12pt} \fi
       \immediate\write16{Second headline cancelled.}
    \else \toks1=\expandafter{\headlinetextb}
       \immediate\write16{Headlineb changed to: \the\toks1}
    \fi
  \fi}
\def\nextheadline#1{\gdef\nextheadlinetext{#1}}
\def\nextheadlineb#1{\gdef\nextheadlinetextb{#1}}
\def\headstart#1{\count255=\headskip \global\headskip = #1
  \global\advance \headskip by -1
  \ifnum\pageno > \count255
    \ifnum\pageno > \headskip \else
      \insert\topspaceinsert{\vskip -\topspace} \fi
  \else
    \ifnum\pageno > \headskip
      \insert\topspaceinsert{\vskip \topspace} \fi
  \fi}
% Use \headstart{3} to start headlines on page 3.  Default is 2.

\def\pageset#1{\count255=\pageno \global\pageno = #1
  \ifnum\count255 > \headskip
    \ifnum\pageno > \headskip \else
      \insert\topspaceinsert{\vskip -\topspace} \fi
  \else
    \ifnum\pageno > \headskip
      \insert\topspaceinsert{\vskip \topspace} \fi
  \fi}
% Use \pageset{3} to set pageno to 3.

%Redefinition of \pagecontents and \plainout:
% We make @ signs act like letters, temporarily.
\catcode`@=11
\def\pagecontents{
  \ifvoid\topspaceinsert\else\unvbox\topspaceinsert\fi
    %Line above added to allow space for headline(s).
  \ifvoid\topins\else\unvbox\topins\fi
  \dimen@=\dp\@cclv \unvbox\@cclv % open up \box255
  \ifvoid\footins\else % footnote info is present
    \vskip\skip\footins
    \footnoterule
    \unvbox\footins\fi
  \ifr@ggedbottom \kern-\dimen@ \vfil \fi}
\def\processnextheadline{
   \ifx \nextheadlinetext \headlinetext \else
      \edef\tem{{\nextheadlinetext}}
      \toks1=\expandafter{\tem}
      \expandafter\headline\the\toks1 \fi
   \ifx \nextheadlinetextb \headlinetextb \else
      \edef\tem{{\nextheadlinetextb}}
      \toks1=\expandafter{\tem}
      \expandafter\headlineb\the\toks1 \fi}
\def\plainoutput{
 \shipout\vbox{\makeheadline\pagebody
  \makefootline}
  \advancepageno
  \ifnum\outputpenalty>-\@MM
    \ifnum\pageno>\headskip
      \insert\topspaceinsert{\vskip\topspace} \fi
  \else\dosupereject\fi
  %Insert above added to allow space for headline at top of each
    %page.
  \processnextheadline}
  %Above command added to check if \nextheadline or
    %\nextheadlineb have been set

\catcode`@=12 % at signs are no longer letters

%FONT PACKAGE:
\input gfont_0.tex % Add correct directory here

\def\pagenumbers{\footline={\hss\normal\ifnum\pageno>\headskip
   \folio\fi\hss}}
\pagenumbers

% Simplequotes macros-- causes " to alternate meanings between ``
%   and ''
\def\quote{"}
\catcode`"=\active
\def\simplequotes{\def\openquote{``\def"{\closequote}}
  \def\closequote{''\def"{\openquote}} \def"{\openquote}}
\def\nosimplequotes{\def"{\quote}}
\simplequotes

\def\showall{\showboxdepth=\maxdimen \showboxbreadth=\maxdimen}

%GBOXIT MACROS: RESULT IS IS ONE MACRO, \gboxit{}, WHICH WORKS
%  FOR ALL PURPOSES.  MOST OF THE COMPLICATION IS TO ALLOW IT TO
%  WORK INSIDE \eqalign, ETC.
\def\boxdisp#1{\vcenter{\boxgen{\hbox{$\displaystyle #1$}}{10pt}}}
\def\boxtext#1{\boxgen{#1}{3pt}}
\def\boxeq#1{\boxgen{\hbox{$#1$}}{3pt}}
\def\boxgen#1#2{\hbox{\vrule\vbox{\hrule\kern#2\vtop{
   \hbox{\kern#2#1\kern#2}\kern#2\hrule}}\vrule}}
\def\gboxit#1{\ifopened\boxdisp{#1}\else\ifmmode
   \ifinner\boxeq{#1}\else\boxdisp{#1}\fi
  \else\boxtext{#1}\fi\fi}

\def\period{{.\spacefactor=3000} }    %Period with long space.
\def\shortperiod{\sfcode`.=1000} %Gives short spaces following periods.
\def\normalperiod{\sfcode`.=3000} %Undoes \shortperiod

%HEADING MACROS
%IF HEADINGS AND SUBHEADINGS FOLLOW, PUT ON ADJACENT LINES TO
%   AVOID EXTRA SPACE BETWEEN THEM
%EXAMPLES:
%   \superhead{II. PROJECT DESCRIPTION}
%   \head{A. INTRODUCTION}
%   \subhead{1. Phase Transitions in the Early Universe}
%   \subsubhead{a)}{Formation of Large Scale Structure/Dark
%   Matter in the Universe:}

% Meaning of inputs to following macro:
%   #1  Text of headline
%   #2  Used to pass along next instruction, to avoid double
%       skips.
%   #3  Skip above, in addition to parskip
%   #4  Skip below, in addition to parskip
%   #5  Font type
%   #6  Hanging indentation for continuation line, if headline
%       does not fit on one line.
%   #7  Minimum baselineskip for continuation line.  Will use
%       normal baselineskip if it exceeds this value.

\long\def\centerhead#1#2#3#4#5#6#7{
   \par \ifnum \lastpenalty < 10000 \goodbreak \fi
   #3  %Skip above, in addition to \parskip
   \setbox1=\hbox{#5#1} %#5 is font type
   \ifdim \wd1 > \hsize
     {\ifdim \baselineskip < #7 \baselineskip = #7 \fi
     \hangindent=#6 {\noindent {#5#1}} \par \hangindent=0pt}
   \else
     \vskip \parskip \centerline{#5#1} \fi
   \nobreak
   {\let\next=#2
      \ifx \next \superhead \else
      \ifx \next \head \else
      \ifx \next \subhead \else
      \ifx \next \subsubhead \else
           #4          %Skip below, in addition to parskip
           \nobreak    %Unless followed by another heading
      \fi\fi\fi\fi}
   #2}

% Meaning of inputs to following macro:
%   #1  Text of first part of headline, set in font specified by
%       #6.
%   #2  Text of second part of headline, set in text font.
%   #3  Used to pass along next instruction, to avoid double
%       skips.
%   #4  Skip above, in addition to parskip.
%   #5  Skip below, in addition to parskip.
%   #6  Font type.
%   #7  Hanging indentation for continuation line, if headline
%       does not fit on one line.
%   #8  Minimum baselineskip for continuation line.  Will use
%       normal baselineskip if it exceeds this value.

\long\def\lefthead#1#2#3#4#5#6#7#8{
   \par \ifnum \lastpenalty < 10000 \goodbreak \fi
   #4  %Skip above, in addition to \parskip
     {\ifdim \baselineskip < #8 \baselineskip = #8  \fi
     \hangindent=#7 {\noindent {#6#1} #2} \par \hangindent=0pt}
   \nobreak
   {\let\next=#3
      \ifx \next \superhead \else
      \ifx \next \head \else
      \ifx \next \subhead \else
      \ifx \next \subsubhead \else
           #5          %Skip below, in addition to parskip
           \nobreak    %Unless followed by another heading
      \fi\fi\fi\fi}
   #3}

\long\def\superhead#1#2{\centerhead{#1}{#2}{\bigskip}
     {\medskip}{\bigbf}{30pt}{15pt}}

\long\def\head#1#2{\centerhead{#1}{#2}{\medskip}{\smallskip}
      {\bf}{30pt}{12pt}}

\long\def\subhead#1#2{\lefthead{#1}{}{#2}{\smallskip}{}
      {\bf}{30pt}{12pt}}

\long\def\subsubhead#1#2#3{\lefthead{#1}{#2}{#3}{}{}{\bf}
      {30pt}{12pt}}

%ITEMIZE MACRO: USED TO TURN ALL PARAGRAPHS INTO
%   "ITEM" FORMAT, WITH FIRST WORD AS LABEL.

\long\def\itemize#1{{
   \def\entry ##1 {\hang\llap{##1\enspace}\ignorespaces}
   \everypar={\entry} \par #1\par
}}


