Commits

Panagiotis Mavrogiorgos committed 22de969

[Major]. Changes in the API.

Data are given through special `\Set*` commands.
All commands and macros are now CamelCase.

  • Participants
  • Parent commits a8394c6

Comments (0)

Files changed (3)

File cover-letter-example.pdf

Binary file modified.

File cover-letter-example.tex

 %%----------------------------------------------------
 % Cover letter
 %%----------------------------------------------------
-\usepackage[
-    %/general/SecondaryColor=black,
-    %
-    /sender/Firstname=Charis,
-    /sender/Lastname=Papadopoulos,
-    /sender/Title={Civil Engineer, M.Sc.},
-    /sender/AddressA={Syntagma Sqr.\ 1},
-    %/sender/AddressB={AddressB},
-    /sender/AddressC={99999 Athens, Greece},
-    /sender/Email={email@example.com},
-    /sender/Mobile={+30 6969.666.999},
-    /sender/Phone={+30 210.123.4567},
-    %/sender/Homepage={www.google.com},    % currently not active
-    %
-    /recipient/Firstname=John,
-    /recipient/Lastname=Doe,
-    /recipient/AddressA={You may use up to 3 lines},
-    /recipient/AddressB={for the Addresses.},
-    /recipient/AddressC={Don't forget the braces!},
-    %
-    /enclosures/name=Enclosures,
-    /enclosures/itemA={Curriculum Vit\ae},
-    /enclosures/itemB={You may use up to 5 items},
-    /enclosures/itemC={Item 3},
-    /enclosures/itemD={Item 4},
-    %/enclosures/itemE={Item 5},
-]{cover-letter}
+\usepackage{cover-letter}
+
+\SetColors{
+    Primary = black,    % Currently inactive
+    Secondary = darkgray,
+}
+
+\SetPersonal{%
+    Firstname = Charis,
+    Lastname = Papadopoulos,
+    Title = {Civil Engineer, M.Sc.},
+    AddressA = {Syntagma Sqr.\ 1},
+    AddressB = {Address second line},
+    AddressC = {Address third line},
+    Email = {email@example.com},
+    Mobile = {+30 6969.666.999},
+    Phone = {+30 210.123.4567},
+    Homepage = {www.google.com},    % currently not active
+}
+
+\SetRecipient{%
+    Firstname = John,
+    Lastname = Doe,
+    AddressA = {You may use up to 3 lines},
+    AddressB = {for the Addresses.},
+    AddressC = {Don't forget the braces!},
+}
+
+\SetEnclosures{%
+    Name=Enclosures,
+    ItemA={Curriculum Vit\ae},
+    ItemB={Item 2},
+    ItemC={Item 3},
+    ItemD={Item 4},
+    ItemE={You may use up to 5 items},
+}
 
 \begin{document}
 
 % By default the footer is empty. If you uncomment the following line, the
 % footer will display the message "Page N of M".
 % If it is active, the document must be compiled twice.
-\showpagenumbers
+\ShowPageNumbers
 
-\typesetSender
-\typesetRecipient
-\typesetDate
+\TypesetPersonal
+\TypesetRecipient
+\TypesetDate
 
 %----------------------------------
 % This is where your letter starts!
 
 % And this is where it ends...
 %----------------------------------
-\typesetSignature
-\typesetEnclosures
+\TypesetSignature
+\TypesetEnclosures
 
 \end{document}

File 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 pgfopts package
+% A key - value model is used for the input through pgfkeys package
 % The symbols are provided by the marvosym package
 
-\RequirePackage{pgfopts}
+\RequirePackage{pgfkeys}
 \RequirePackage{etoolbox}
 \RequirePackage{xcolor}
 \RequirePackage{xspace}
 \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}
 
-\newcommand{\showpagenumbers}{%
-    \newcounter{totalpages}
-    \setcounter{totalpages}{\totvalue{page}}
-    \pagestyle{fancy}
-    \fancyhead[RCL]{}
-    \fancyfoot[RL]{}
-    \fancyfoot[C]{
-        \small\itshape\color{\secondaryColor}%
-        Page \textbf{\thepage}\ of \textbf{\thetotalpages}
+%===============================================================================
+% Colors
+%===============================================================================
+% Define `\SetColors` command.
+\newrobustcmd*{\SetColors}[1]{
+    % Create keys
+    \pgfqkeys{/Colors}{
+        Primary/.store in = \PrimaryColor,
+        Secondary/.store in = \SecondaryColor,
     }
-    \renewcommand{\headrulewidth}{0pt}
-    \renewcommand{\footrulewidth}{0pt}
+    % Set key values
+    \pgfqkeys{/Colors}{#1}%
 }
 
-% Key definition
-\pgfqkeys{/general}{
-    SecondaryColor/.initial = darkgray,}
-
-\pgfqkeys{/recipient}{
-    Firstname/.store in = \recipFirstname,
-    Lastname/.store in = \recipLastname,
-    AddressA/.store in = \recipAddressA,
-    AddressB/.store in = \recipAddressB,
-    AddressC/.store in = \recipAddressC,
+%  Set the default colors.
+\SetColors{
+    Primary=blue,
+    Secondary=gray,
 }
 
-\pgfqkeys{/sender}{
-    Firstname/.store in = \senderFirstname,
-    Lastname/.store in = \senderLastname,
-    Title/.store in = \senderTitle,
-    AddressA/.store in = \senderAddressA,
-    AddressB/.store in = \senderAddressB,
-    AddressC/.store in = \senderAddressC,
-    Email/.store in = \senderEmail,
-    Mobile/.store in = \senderMobile,
-    Phone/.store in = \senderPhone,
-    Fax/.store in = \senderFax,
-    Homepage/.store in = \senderHomepage,
+%===============================================================================
+% 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}%
 }
 
-\pgfqkeys{/enclosures}{
-    name/.store in = \enclosureName,
-    itemA/.store in = \enclosureA,
-    itemB/.store in = \enclosureB,
-    itemC/.store in = \enclosureC,
-    itemD/.store in = \enclosureD,
-    itemE/.store in = \enclosureE,
+%===============================================================================
+% Recipient
+%===============================================================================
+\newrobustcmd*{\SetRecipient}[1]{%
+    % Create keys
+    \pgfqkeys{/Recipient}{%
+        Firstname/.store in = \RecipFirstname,
+        Lastname/.store in = \RecipLastname,
+        AddressA/.store in = \RecipAddressA,
+        AddressB/.store in = \RecipAddressB,
+        AddressC/.store in = \RecipAddressC,
+    }%
+    % Set key values
+    \typeout{before}
+    \pgfqkeys{/Recipient}{#1}%
+    \typeout{before}
 }
 
+%===============================================================================
+% 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}
+}
 
-\ProcessPgfOptions{/general}
-\ProcessPgfOptions{/sender}
-\ProcessPgfOptions{/recipient}
-\ProcessPgfOptions{/enclosures}
+\SetEnclosures{
+    Name = Enclosures,
+}
 
-% store default value into macros.
-\pgfkeysgetvalue{/general/SecondaryColor}{\secondaryColor}
+%===============================================================================
+% Utilities
+%===============================================================================
+\newrobustcmd*{\PersonalFullname}{\PersonalFirstname\xspace\PersonalLastname\xspace}
+\newrobustcmd*{\RecipientFullname}{\RecipientFirstname\xspace\RecipientLastname\xspace}
 
-% Typeset Sender data
-\newcommand{\typesetSender}{
-    \hfill%
+%===============================================================================
+% Styles
+%===============================================================================
+% TODO
+\newrobustcmd*{\NameStyle}[1]{}
+\newrobustcmd*{\AddressStyle}[1]{}
+
+%===============================================================================
+% Typeset Personal data
+%===============================================================================
+\newrobustcmd{\TypesetPersonal}{
     \begin{minipage}[t]{\textwidth}
         \raggedleft
-        \textbf{\senderFirstname \xspace \senderLastname}\\[.35ex]
-        \small\itshape\color{\secondaryColor}%
+        \textbf{\PersonalFirstname \xspace \PersonalLastname}\\[.35ex]
+        \small\itshape\color{\SecondaryColor}%
         \hfill
         % address lines
-        \ifdefvoid{\senderAddressA}{}{\hfill \senderAddressA \\}
-        \ifdefvoid{\senderAddressB}{}{\hfill \senderAddressB \\}
-        \ifdefvoid{\senderAddressC}{}{\hfill \senderAddressC \\}
+        \ifdefvoid{\PersonalAddressA}{}{\hfill \PersonalAddressA \\}
+        \ifdefvoid{\PersonalAddressB}{}{\hfill \PersonalAddressB \\}
+        \ifdefvoid{\PersonalAddressC}{}{\hfill \PersonalAddressC \\}
         % rest
-        \ifdefvoid{\senderMobile}{}{\Mobilefone~\senderMobile \\}
-        \ifdefvoid{\senderPhone}{}{\Telefon~\senderPhone \\}
-        \ifdefvoid{\senderFax}{}{\Fax~\senderFax \\}
-        \ifdefvoid{\senderEmail}{}{\Letter~\href{mailto:\senderEmail}{\senderEmail} \\}
-        %\ifdefvoid{\senderHomepage}{}{\Homepage~\url{\senderHomepage} \\}
+        \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
-\newcommand{\typesetRecipient}{
+\newrobustcmd{\TypesetRecipient}{
     \begin{minipage}[t]{.4\textwidth}
         \raggedright%
-        \textbf{\recipFirstname \xspace \recipLastname}\\[.35ex]
-        \small\itshape\color{\secondaryColor}%
+        \textbf{\RecipFirstname \xspace \RecipLastname}\\[.35ex]
+        \small\itshape\color{\SecondaryColor}%
         % address line
-        \ifdefvoid{\recipAddressA}{}{\recipAddressA \hfill \\}
-        \ifdefvoid{\recipAddressB}{}{\recipAddressB \hfill \\}
-        \ifdefvoid{\recipAddressC}{}{\recipAddressC \hfill \\}
+        \ifdefvoid{\RecipAddressA}{}{\RecipAddressA \hfill \\}
+        \ifdefvoid{\RecipAddressB}{}{\RecipAddressB \hfill \\}
+        \ifdefvoid{\RecipAddressC}{}{\RecipAddressC \hfill \\}
     \end{minipage}\newline
 }
 
 % Typeset Date
-\newcommand{\typesetDate}{
+\newrobustcmd{\TypesetDate}{
     \begin{minipage}[t]{\textwidth}
         \raggedleft \hfill \today
-    \end{minipage}\newline
+    \end{minipage}%\newline
 }
 
 % Typeset Signature
-\newcommand{\senderFullname}{\senderFirstname \xspace \senderLastname}
-\newcommand{\typesetSignature}{%
-    \textbf{\senderFullname}\newline
-    \ifdefvoid{\senderTitle}
+\newrobustcmd{\TypesetSignature}{%
+    \textbf{\PersonalFullname}\newline
+    \ifdefvoid{\PersonalTitle}
         {}
-        {\small\itshape\color{\secondaryColor} \senderTitle}
+        {\small\itshape\color{\SecondaryColor} \PersonalTitle}
 }
 
 % Typeset Enclosures
-\newcommand{\typesetEnclosures}{
-    \ifdefvoid{\enclosureA}{}{%
+\newrobustcmd{\TypesetEnclosures}{
+    \ifdefvoid{\EnclosureA}{}{%
         \vfill
-        \small\itshape\color{\secondaryColor}%
-        \textbf{\enclosureName}:
+        \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}
+            \item \EnclosureA
+            \ifdefvoid{\EnclosureB}{}{\item \EnclosureB}
+            \ifdefvoid{\EnclosureC}{}{\item \EnclosureC}
+            \ifdefvoid{\EnclosureD}{}{\item \EnclosureD}
+            \ifdefvoid{\EnclosureE}{}{\item \EnclosureE}
         \end{compactitem}
     }
 }