{ 
  \def\lastedit{2005-07-16 14:08:23 by stolfi}
  \typeout{ic-letter-macros \lastedit} 
  \typeout{Based on `letterunicamp.sty' by Pedro J. de Rezende <12 Feb 92>.}
}

\input{ic-abacus.tex}

\makeatletter
\advance\endlinechar by -256\relax

\def\ds@draft{\overfullrule 5pt}  % Causes overfull hboxes to be marked.

\newsavebox{\letterhe@dbox}
\newsavebox{\letterf@@tbox}
\newlength{\headb@xwidth}
\newlength{\l@gohang}

% Letter environment

  % Usage:
  %   \input{ic-letter-macros}
  %   \input{my-letter-data}
  %   \begin{letter}
  %     \english % or \portugues
  %     \placedate{St. Anford, \today}
  %     \sendto{Mr. Bean//Jellybean Corp.//Candytown, NM}
  %
  %     Dear Mr. Bean,
  %     ...
  %     Sincerely,
  %     \signed{C. Rice\\Site Coordinator\\CandyExpo 2001}
  %     \writtenby{CR/ms}
  %   \end{letter}

  \newenvironment{letter}
    {
      \bgroup
        \newpage
        \c@page\@ne
        \raggedbottom

        \def\portugues{
          \let\senderaddress=\portsenderaddress\relax
          \def\today{
            \number\day\space de \ifcase\month\or
            janeiro\or fevereiro\or {mar\c co}\or abril\or maio\or junho\or
            julho\or agosto\or setembro\or outubro\or novembro\or dezembro\fi
            \space de \number\year
          }
          \makehe@df@@t
        }

        \def\english{
          \let\senderaddress=\englsenderaddress\relax
          \def\today{
            \ifcase\month\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\number\day, \number\year
          }
          \makehe@df@@t
        }
        \english

        \pagestyle{plain}
        \thispagestyle{letterfirst} 

        \normalsize\rm
        \parskip=1.0ex
        \lineskip=1pt 
        \normallineskip=1pt
        \def\baselinestretch{1}
        \topsep=0.5ex \partopsep=0pt \itemsep=0.5ex
        \rightskip=0pt \leftskip=0pt
        \rightmargin=0pt \leftmargin=0pt
        \marginparwidth=0pt \marginparsep=0pt
        \parindent=2em
        \def\insertfoot{\usebox{\letterf@@tbox}}
    }
    {
        \vfill
        \pagebreak
      \egroup
    }

  \def\placedate#1{%
    \begin{raggedleft}
      #1\par
    \end{raggedleft}
    \vspace{2\parskip}
  }

  \def\sendto#1{
    \begin{raggedright} 
      \noindent #1\par
    \end{raggedright}
    \nobreak
    \vspace{2\parskip}
  }

  \def\signaturebox#1#2{
    \begin{tabular}{c}
      \vrule height 3.75\baselineskip depth 0.25\baselineskip width 0pt
      \vrule height 1pt depth 0pt width #1\\
      #2
    \end{tabular}
  }

  \def\signed#1{
    \par\nobreak
    \begin{raggedleft}
      ${}$
      \signaturebox{0pt}{#1}
      \quad\quad\quad\quad
      ${}$
      \par
    \end{raggedleft}
  }
  
  % Requires macros-epsbox
  \def\epssigned#1#2#3{
    \par\nobreak
    \vspace{1\baselineskip}
    \nobreak
    \begin{raggedleft}
      ${}$
      \begin{tabular}{c}\epsbox{#1}{#2}\\[5pt]#3\end{tabular}
      \quad\quad\quad\quad
      \par
    \end{raggedleft}
  }
  
  \def\writtenby#1{
    \vfill
    \begin{raggedright}
      \normalsize\tt #1
    \end{raggedright}
    \vspace{0pt plus -1fill}
  }

% Page styles:

  % First page of letter
  %
  \def\ps@letterfirst{
    \setlength{\topmargin}{0.75in}
      \addtolength{\topmargin}{-\ht\letterhe@dbox}
    \setlength{\headheight}{12pt}
      \addtolength{\headheight}{\ht\letterhe@dbox}
    \headsep=20pt
    \footskip=25pt
      \addtolength{\footskip}{\ht\letterf@@tbox}
    \textheight=\paperheight\relax
      \addtolength{\textheight}{-1.0in}
      \addtolength{\textheight}{-\topmargin}
      \addtolength{\textheight}{-\headheight}
      \addtolength{\textheight}{-\headsep}
      \addtolength{\textheight}{-\footskip}
    \vsize=\textheight
    \def\@oddhead{\usebox{\letterhe@dbox}}
    \def\@evenhead{}
    \def\@oddfoot{\usebox{\letterf@@tbox}}
    \def\@evenfoot{}
  }

% Letterhead/letterfoot elements:

  % These definitions are used to build the letterhead 
  % at the bottom of the first page. 

  \def\sendername{}
  \def\portsenderaddress{}
  \def\englsenderaddress{}
  \def\sendertel{}
  \def\senderfax{}
  \def\senderemail{}
  \def\senderwww{}
  \def\sendertelex{}

% Logos

  % Institute of Computing:

  \def\iclogowidth{60pt}    % Nominal width of IC logo
  \def\icl@go{
    \hbox to \iclogowidth{
      \hss
      \Abacus{1}{9}{9}{6}{\iclogowidth}
      \hss
    }
  }

  % Unicamp:

  \def\ueclogowidth{92pt}    % Nominal width of Unicamp logo
  \def\ueclogoheight{100pt}  % Nominal height of Unicamp logo
  \def\uecl@go{
    \hbox to \ueclogowidth{
      \hss
      \vrule height \ueclogoheight width 0pt
      \special{psfile=/home/staff/stolfi/tex/inputs/unicamp-logo-js.ps voffset=0 hoffset=-46}
      \hss
    }
  }

% Letterhead and letterfoot 

  \ifx\xpt\undefined
    % (LaTeX 2e)
    \newcommand{\h@dfont}{
      \baselineskip 12pt
      \def\ss{\usefont{T1}{cmss}{m}{n}} 
      \let\rm=\ss\relax
      \def\tt{\usefont{T1}{cmtt}{m}{n}}
      \ss
    }
  \else
    % (LaTeX 2.09)
    \font\h@dfontss cmss10 at 10pt\relax
    \font\h@dfonttt cmtt10 at 10pt\relax
    \newcommand{\h@dfont}{
      \baselineskip 12pt
      \def\ss{\h@dfontss} 
      \let\rm=\ss\relax
      \def\tt{\h@dfonttt}
      \ss
    }
  \fi

  \def\makehe@df@@t{
    \setlength{\headb@xwidth}{7.0in}
    \setlength{\l@gohang}{\headb@xwidth}
    \addtolength{\l@gohang}{-\textwidth}
    \divide \l@gohang by 2\relax
    \savebox{\letterhe@dbox}{\vbox{\parindent 0pt\hrule height 0pt\letterheadbox\hrule height 0pt}}
    \savebox{\letterf@@tbox}{\vbox{\parindent 0pt\hrule height 0pt\letterfootbox\hrule height 0pt}}
  }

  \def\letterheadbox{
    \vbox to \ueclogoheight{
      \hrule height 0pt width 0pt
      \vss
      \hbox to \headb@xwidth{
        \vrule width 0pt
        \kern -\l@gohang
        \uecl@go
        \hss
      }
    }
  }

  \def\letterfootbox{
    \hbox to \textwidth{
      \vrule height 0pt width 0pt
      \hss
      \vtop to \footskip{
        \parindent 0pt
        \hrule height 0pt width 0pt
        \vspace{5pt}
        \hrule
        \vspace{5pt}
        \hbox to\headb@xwidth{
          \hbox{
            \vbox{
              \parindent 0pt
              % \leftskip 0pt \rightskip 0pt
              \hbox{
                \begin{minipage}{2.6in}
                  \begin{raggedright}
                    \parindent=0pt
                    \h@dfont\ss
                    \sendername\\
                    \senderaddress\par
                  \end{raggedright}
                \end{minipage}
              }
              \hrule height 0pt width 0pt
            }
          }
          \hss
          \lower 1mm \icl@go
          \hss
          \hbox{
            \vbox{
              \parindent 0pt
              % \leftskip 0pt \rightskip 0pt
              \hbox{
                \begin{minipage}{2.6in}
                  \begin{raggedleft}
                    \h@dfont\ss
                    \senderemail\\
                    \senderwww\\
                    \sendertel\\
                    \senderfax\\
                    \sendertelex\par
                  \end{raggedleft}
                \end{minipage}
              }
              \hrule height 0pt width 0pt
            }
          }
        }
        \vss
        \hrule height 0pt width 0pt
      }
      \hss
    }
  }

\advance\endlinechar by 256
\makeatother 
