Source

cover-letter / cover-letter.sty

Full commit
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{cover-letter}[2011/6/18 v1.0 Package `cover-letter.sty']
\typeout{Package `cover-letter' version 1.0 by Panagiotis Mavrogiorgos}

% cover-letter is a package for typesetting letters.
% A key - value model is used for the input through pgfkeys package
% The symbols are provided by the marvosym package

\RequirePackage{pgfkeys}
\RequirePackage{etoolbox}
\RequirePackage{xcolor}
\RequirePackage{xspace}
\RequirePackage{marvosym}
\RequirePackage{paralist}
\RequirePackage{fancyhdr}
\RequirePackage{totcount}
\RequirePackage{hyperref}
\RequirePackage{url}

%===============================================================================
% Page numbering
%===============================================================================
% By default we don't have page numbers,
%
% In order to use a "Page N of M" numbering style we need the `totcount` package
% and we need to declare `page` as a counter (to be added at the aux file.

\regtotcounter{page}

% Command `\showpagenumbers` must be given immediately after `\begin{document}`.
% It changes the page numbering scheme to "Page N of M".  The document needs at
% least 2 subsequent compilations in order to display the correct page numbers.
\newrobustcmd*{\ShowPageNumbers}{%
    \pagestyle{fancy}
    \fancyhf{}
    \renewrobustcmd*{\headrulewidth}{0pt}
    \renewrobustcmd*{\footrulewidth}{0pt}
    \cfoot{%
        \small%
        \itshape%
        \color{\SecondaryColor}%
        \textbf{\thepage/\total{page}}
    }
}

% Set the default page numbering scheme.
\pagestyle{empty}

%===============================================================================
% Colors
%===============================================================================
% Define `\SetColors` command.
\newrobustcmd*{\SetColors}[1]{
    % Create keys
    \pgfqkeys{/Colors}{
        Primary/.store in = \PrimaryColor,
        Secondary/.store in = \SecondaryColor,
    }
    % Set key values
    \pgfqkeys{/Colors}{#1}%
}

%  Set the default colors.
\SetColors{
    Primary=blue,
    Secondary=gray,
}

%===============================================================================
% Personal Data
%===============================================================================
% Firstname and Lastname are necessary
\newrobustcmd*{\SetPersonal}[1]{%
    % Create keys
    \pgfqkeys{/Personal}{
        Firstname/.store in =\PersonalFirstname,
        Lastname/.store in = \PersonalLastname,
        Title/.store in = \PersonalTitle,
        AddressA/.store in = \PersonalAddressA,
        AddressB/.store in = \PersonalAddressB,
        AddressC/.store in = \PersonalAddressC,
        Email/.store in = \PersonalEmail,
        Mobile/.store in = \PersonalMobile,
        Phone/.store in = \PersonalPhone,
        fax/.store in = \PersonalFax,
        Homepage/.store in = \PersonalHomepage,
    }%
    % Set key values
    \pgfqkeys{/Personal}{#1}%
}

%===============================================================================
% Recipient
%===============================================================================
\newrobustcmd*{\SetRecipient}[1]{%
    % Create keys
    \pgfqkeys{/Recipient}{%
        Firstname/.store in = \RecipientFirstname,
        Lastname/.store in = \RecipientLastname,
        AddressA/.store in = \RecipientAddressA,
        AddressB/.store in = \RecipientAddressB,
        AddressC/.store in = \RecipientAddressC,
    }%
    % Set key values
    \pgfqkeys{/Recipient}{#1}%
}

%===============================================================================
% Enclosures
%===============================================================================
\newrobustcmd*{\SetEnclosures}[1]{%
    \pgfqkeys{/Enclosure}{
        Name/.store in = \EnclosureName,
        ItemA/.store in = \EnclosureA,
        ItemB/.store in = \EnclosureB,
        ItemC/.store in = \EnclosureC,
        ItemD/.store in = \EnclosureD,
        ItemE/.store in = \EnclosureE,
    }
    \pgfqkeys{/Enclosure}{#1}
}

\SetEnclosures{
    Name = Enclosures,
}

%===============================================================================
% Utilities
%===============================================================================
\newrobustcmd*{\PersonalFullname}{\PersonalFirstname\xspace\PersonalLastname\xspace}
\newrobustcmd*{\RecipientFullname}{\RecipientFirstname\xspace\RecipientLastname\xspace}

%===============================================================================
% Styles
%===============================================================================
% TODO
\newrobustcmd*{\NameStyle}[1]{}
\newrobustcmd*{\AddressStyle}[1]{}

%===============================================================================
% Typeset Personal data
%===============================================================================
\newrobustcmd{\TypesetPersonal}{
    \begin{minipage}[t]{\textwidth}
        \raggedleft
        \textbf{\PersonalFullname}\\[.35ex]
        \small\itshape\color{\SecondaryColor}%
        \hfill
        % address lines
        \ifdefvoid{\PersonalAddressA}{}{\hfill \PersonalAddressA \\}
        \ifdefvoid{\PersonalAddressB}{}{\hfill \PersonalAddressB \\}
        \ifdefvoid{\PersonalAddressC}{}{\hfill \PersonalAddressC \\}
        % rest
        \ifdefvoid{\PersonalMobile}{}{\Mobilefone~\PersonalMobile \\}
        \ifdefvoid{\PersonalPhone}{}{\Telefon~\PersonalPhone \\}
        \ifdefvoid{\PersonalFax}{}{\Fax~\PersonalFax \\}
        \ifdefvoid{\PersonalEmail}{}{\Letter~\href{mailto:\PersonalEmail}{\PersonalEmail} \\}
        %\ifdefvoid{\PersonalHomepage}{}{\Homepage~\url{\PersonalHomepage} \\}
    \end{minipage}\newline
}

% Typeset Recipient data
\newrobustcmd{\TypesetRecipient}{
    \begin{minipage}[t]{.4\textwidth}
        \raggedright%
        \textbf{\RecipientFullname}\\[.35ex]
        \small\itshape\color{\SecondaryColor}%
        % address line
        \ifdefvoid{\RecipientAddressA}{}{\RecipientAddressA \hfill \\}
        \ifdefvoid{\RecipientAddressB}{}{\RecipientAddressB \hfill \\}
        \ifdefvoid{\RecipientAddressC}{}{\RecipientAddressC \hfill \\}
    \end{minipage}\newline
}

% Typeset Date
\newrobustcmd{\TypesetDate}{
    \begin{minipage}[t]{\textwidth}
        \raggedleft \hfill \today
    \end{minipage}%\newline
}

% Typeset Signature
\newrobustcmd{\TypesetSignature}{%
    \textbf{\PersonalFullname}\newline
    \ifdefvoid{\PersonalTitle}
        {}
        {\small\itshape\color{\SecondaryColor} \PersonalTitle}
}

% Typeset Enclosures
% Enclosures are typeset only if `EnclosureA` has been set.
\newrobustcmd{\TypesetEnclosures}{
    \ifdefvoid{\EnclosureA}{}{%
        \vfill
        \small\itshape\color{\SecondaryColor}%
        \textbf{\EnclosureName}:
        \begin{compactitem}
            \item \EnclosureA
            \ifdefvoid{\EnclosureB}{}{\item \EnclosureB}
            \ifdefvoid{\EnclosureC}{}{\item \EnclosureC}
            \ifdefvoid{\EnclosureD}{}{\item \EnclosureD}
            \ifdefvoid{\EnclosureE}{}{\item \EnclosureE}
        \end{compactitem}
    }
}