directory: address books with LaTeX and BibTeX

Christophe Geuzaine

Download

The current distribution of directory is directory-1.20.tgz. This distribution contains both a PostScript and a PDF version of the documentation. The separate files are also available through the CTAN sites in the biblio/bibtex/contrib/directory/ subdirectory. Older versions are still available here. Any questions, comments or suggestions? Send me an e-mail.

Contents

1  Introduction
2  General description
    2.1  Package inclusion and options
    2.2  Making a citation
    2.3  The bst styles
    2.4  The bib file fields
3  Customization
    3.1  Dimensions
    3.2  Flags and formats
4  Using both directory and bibliography
5  Generating directories with hypertext links
6  Generating HTML, vCard or LDIF directories
7  Example
    7.1  Source file
    7.2  Output
8  Contributors
9  Versions

1  Introduction

directory1 is a macro package for LaTeX and BibTeX that facilitates the construction, the maintenance and the exploitation of an address book like database. It consists of five BibTeX style files (address.bst, phone.bst, email.bst, birthday.bst and letter.bst) designed to be used in conjunction with the LaTeX style file directory.sty. Depending on the bibliographical style used, the package has two main applications:
  1. the construction of a list of information (address, phone number, etc.) about selected persons, companies or places;
  2. the inclusion of a selected piece of information concerning a person, a place or a company at a desired location in a document.
In the first case, directory behaves just like standard bibliographical styles: while standard bibliographical styles handle data concerning books, articles, proceedings, etc., directory handles data relative to people, companies or places. For example, the name in the title of this guide refers to the corresponding entry in the directory listed in section 7.2. The first four BibTeX files provide several ways to handle this data.
In the second case, the package enables bits of the database to be put in your document. It can for example be used to put the address of your correspondent in the address field of a letter.
Four special BibTeX style files (address-html.bst, email-html.bst, address-vcard.bst and address-ldif.bst) are also provided for an easy generation of HTML, vCard and LDIF versions of your directories.

2  General description

2.1  Package inclusion and options

The package is included by the usual \usepackage{directory} command at the top of the document. Four options are available:
break:
allows the directory fields to be broken across pages;
german:
creates directories in German;
french:
creates directories in French;
longdates:
prints birthday dates using month names instead of numbers.
The old (before version 1.10) formatting options are now handled by the same command mechanism as all other customization options (see section 3).
The directory is produced by the \directory[extension]{filename} command, where filename stands for the name of the bib file (without the bib extension) and where the optional argument extension gives, if necessary, the extension of the file output by BibTeX (see section 4). As usual, multiple bib files can be included, a comma separating the different file names.

2.2  Making a citation

An entry is cited in the text by a \dir{key}, \pdir{key}, \rdir{key} or \wdir{key} command, equivalent to the standard \cite{key} command, where key is used in the same way as ever (referring to an entry in a bib file). The differences between the four citation commands will be explained in the next section. A \nodir{key} command exists and acts exactly like \nocite{key} for standard bibliographies.

2.3  The bst styles

The style of the directory is chosen by a \directorystyle{style} command, where style is one of the following:
address:
full listing in the directory of all fields corresponding to the key entry. The \dir{key} command also prints the name field of the entry in the document;
phone:
only the phone, cellular and fax fields corresponding to the cited entry are displayed in the directory. The \dir{key} command acts in the same way as with the address style, except that the names are abbreviated;
email:
only e-mail addresses are displayed in the directory. The \dir{key} command acts in the same way as with the address style;
birthday:
only the birthdays are displayed, sorting the entries in chronological order. The \dir{key} command acts in the same way as with the address style;
letter:
acts in a slightly different way than the four preceding styles. No directory is produced with the \directory command. The \dir{key} command results in the name field of the key entry to be printed in the document. The \pdir{key} (respectively \rdir{key} or \wdir{key}) command prints the name and the private (respectively residence or work) address in the document in a tabulated way.

2.4  The bib file fields

directory defines three entry types: @person{}, @company{} and @place{}. In all these types, name is the only mandatory field, since it serves as a key for sorting the entries. Here are all the available fields that can be defined for each entry:
@person{key,
  name = "Full name(s), in standard BibTeX format",
  nickname = "Nickname(s)",
  birthday = "Birthday date(s), in numeric 'day month' format",
  birthyear = "Birth year(s)",

  p.street = "Street of private residence",
  p.city = "City of private residence",
  p.zip = "ZIP code of private residence",
  p.state = "State of private residence",
  p.country = "Country of private residence",
  p.phone = "Private phone number",
  p.cellular = "Private mobile phone number",
  p.fax = "Private fax number",
  p.email = "Private e-mail address",
  p.url = "Private home page",
  p.account = "Private bank account",

  r.street = "Street of alternative residence",
  r.city = "City of alternative residence",
  r.zip = "ZIP code of alternative residence",
  r.state = "State of alternative residence",
  r.country = "Country of alternative residence",
  r.phone = "Alternative phone number",
  r.cellular = "Alternative mobile phone number",
  r.fax = "Alternative fax number",
  r.email = "Alternative e-mail address",
  r.url = "Alternative home page",
  r.account = "Alternative bank account",

  w.name = "Work organization name",
  w.title = "Job title",
  w.street = "Street of work organization",
  w.city = "City of work organization",
  w.zip = "ZIP code of work organization",
  w.state = "State of work organization",
  w.country = "Country of work organization",
  w.phone = "Work phone number",
  w.cellular = "Work mobile phone number",
  w.fax = "Work fax number",
  w.email = "Work e-mail address",
  w.url = "Work home page",
  w.account = "Work bank account",

  note = "Additional notes about the person",
}

@company{key,
  name = "Company name",
  street = "Company street",
  city = "Company city",
  zip = "Company ZIP code",
  state = "Company state",
  country = "Company country",
  phone = "Company phone number",
  cellular = "Company mobile phone number",
  fax = "Company fax number",
  email = "Company e-mail address",
  url = "Company home page",
  account = "Company bank account",
  note = "Additional notes about the company",
}

@place{key,
  name = "Place name",
  street = "Place street",
  city = "Place city",
  zip = "Place ZIP code",
  state = "Place state",
  country = "Place country",
  phone = "Place phone number",
  cellular = "Place mobile phone number",
  fax = "Place fax number",
  note = "Additional notes about the place",
}

Multiple names, nicknames or birthday dates should be be separated with "and". For backward compatibility, or if an unconventional address formatting is needed, the street, city, state, zip and country fields (and their p., r. and w. equivalents) can be replaced by generic address, p.address, r.address or w.address fields. As soon as an address field is defined, any street, city, state, zip or country field definition is ignored, and the formatting in the address field is kept as is.

3  Customization

3.1  Dimensions

Three new dimensions defining the indentation of the fields (\dirindent and \dirparindent) and the amount of space between two entries (\dirsep) have been introduced. The default values are:
\setlength{\dirindent}{3em}
\setlength{\dirparindent}{0em}
\setlength{\dirsep}{3ex}

If you want to explicitly introduce a new paragraph in a field, you should use the \dirbreak command.
A fourth dimension (\dirtablewidth) sets the width of the table used to display fields in when the letter style is selected. The default value is:
\setlength{\dirtablewidth}{0.5\textwidth}

3.2  Flags and formats

Each field of a directory is easily customizable by redefining one of the commands summarized in table 1 at the end of this user's guide (page pageref).
For example, to produce nicely formatted address booklets, you could redefine the \Dirheader command as
\pagestyle{headings}
\renewcommand{\Dirheader}[1]
 {\newpage\markboth{\MakeUppercase{#1}}{\MakeUppercase{#1}}}

(which will split the directory across pages, with the first letter used in the sorting algorithm in the header of each page) or
\renewcommand{\Dirheader}[1]
  {\item\hspace{-\dirindent}\textbf{\MakeUppercase{#1}}}

(which will produce inline headings).
When a field type appears multiple times in an entry, the default settings assume the same formatting for each one. For example, there are three instances of a phone type field in a full person entry, i.e. p.phone, r.phone and w.phone, and the \dirphone and \Dirphone customization commands apply to these three instances in the same way.
To particularize the formatting of one of these instances, you can use special versions of the customization commands, constructed by inserting p, r or w after the \dir or \Dir prefix of the original commands. For example, to customize only the phone field in the work part, you should use \dirwphone and \Dirwphone.
To change the formatting of names, you have to edit the BibTeX style files. For example, the default name format "Christophe von Geuzaine, Jr." can be changed into "von Geuzaine C., Jr." in your address books by replacing the line
s nameptr "{ff }{vv }{ll}{, jj}" format.name$ 't :=

in the file address.bst by the line
s nameptr "{vv }{ll}{ f.}{, jj}" format.name$ 't :=

4  Using both directory and bibliography

Since BibTeX always produces an output file of the form 'filename.bbl', it is necessary-in order to use both directory and bibliography entries-, after generating the bbl file corresponding to the directory, to rename it with a new extension (for example dir), and to give this new extension as an optional argument to the \directory command. The normal procedure can then be followed during the rest of the bibliography processing. Remember that changing the directory (adding an entry or suppressing one) forces you to restart from the beginning.

5  Generating directories with hypertext links

You can use the hyperref package along with directory. For example, adding the following lines in the preamble of your document and using pdflatex will produce a PDF version of your directory, with working links for the email and url fields.
\ifx\pdfoutput\undefined\else
  \usepackage{hyperref}
  \newcommand\MyURL{\begingroup\Url}
  \renewcommand{\Diremail}[1]{\href{mailto:#1}{\MyURL{#1}}}
  \renewcommand{\Dirurl}[1]{\href{#1}{\MyURL{#1}}}
\fi

6  Generating HTML, vCard or LDIF directories

Four special BibTeX style files (address-html, email-html, address-vcard and address-ldif) allow the easy generation of HTML, vCard and LDIF versions of your directories:
address-html:
full listing in the HTML directory of all fields corresponding to the key entry. The output formatting is similar to that produced by LaTeX with the address style;
email-html:
only e-mail addresses are displayed in the HTML directory;
address-vcard:
full listing in the vCard directory of all fields corresponding to the key entry.
address-ldif:
full listing in the LDIF directory of all fields corresponding to the key entry.
Since BibTeX directly outputs a bbl file in HTML, vCard or LDIF format, no additional program is needed to make the HTML/vCard/LDIF conversion. The bbl file directly contains the HTML/vCard/LDIF code, ready to be included in a HTML document or to be imported in a vCard/LDIF-aware application (Apple Address Book, Microsoft Outlook, Mozilla Mail, etc.).
This method presents nevertheless a little drawback: after BibTeX'ing your LaTeX file, running LaTeX on the same file (even with another \directorystyle) will produce errors, since the bbl file is not understandable by LaTeX. You have to either delete the bbl file or to override the error messages (and to change the \directorystyle) before any subsequent successful LaTeX run.
The handling of special characters in the HTML/vCard/LDIF directories is also somewhat problematic: any special LaTeX character sequence is output the way it is in the bib file. This implies for example that {\'e} is printed in the HTML document as {\'e}, and not as é. The vCard style assumes an ISO Latin 1 encoding of the directory. If a special encoding is used in the bib file, the LDIF output will need to be converted to UTF8. See the comments in the BibTeX style files for more information.

7  Example

Despite the option described in section 4, one of the most interesting way of using directory is to build a separate address book, including several bib files referring to several categories of people, companies or places, as in the example shown in this document:
\nodir{*}
\directory{family,business}
A second interesting way of using directory is to use it in your faxes or letters. Using the standard LaTeX class letter.cls with the directory style letter, you may for example begin a letter by the following command (\wdir must be protect'ed since the argument of the letter environment is a moving argument):
\begin{letter}{\protect\wdir{c.geuzaine}}
Take a look at the example tex and bib files (directory.tex, family.bib and business.bib) and try the options out. The source files are commented and easy to customize. I would be very happy to get your suggestions to improve this package.

7.1  Source file

Here are four bib entries (taken from family.bib and business.bib):
@Person{c.geuzaine,
  name       = "Christophe Geuzaine",
  birthday   = "06 02",
  birthyear  = "1973",
  p.email    = "geuz@geuz.org",
  p.url      = "http://www.geuz.org",
  w.title    = "Postdoctoral Scholar",
  w.name     = "Caltech, Applied and Computational Mathematics",
  w.url      = "http://www.acm.caltech.edu",
  w.street   = "1200 E California Blvd",
  w.city     = "Pasadena",
  w.state    = "CA",
  w.zip      = 91125,
  w.country  = "USA",
  w.phone    = "1 626 395 4552",
}

@Person{d.d.knu,
  name       = "Knudson, Daffy Duck and Bunny, Bugs and Mr. Pluto",
  nickname   = "gnat and gnu and pluto",
  birthday   = "10 02 and 05 11 and 01 01",
  p.phone    = "+01-(0)2-765.43.21",
  p.cellular = "+01-(0)5-555.55.55",
  p.account  = "010-1234567-05",
  r.street   = "Haight Street 512",
  r.zip      = 80214,
  r.city     = "Novosibirsk",
  r.country  = "Gnuland",
  r.phone    = "+01-(0)2-876.54.32",
  w.name     = "University of Novosibirsk, 
                Department of Octopus Parthenogenesis",
}

@Company{knudsoft,
  name   = "The Knudsoft Company",
  email  = "knud@knudsoft.com", 
  url    = "http://knudsoft.com/hole/gates.htm", 
}

@Place{knudsoft:rs.2,
  name   = "Knudsoft (RS.2 Computer Room)",
  phone  = "+01-(0)2-434.23.23",
}

7.2  Output

The output resulting from the \directory{family,business} command is shown below (all entries are listed, thanks to the \nodir{*} command):
directory generated with address-html.bst, email-html.bst, address-vcard.bst and address-ldif.bst.

8  Contributors

Many thanks to Bernd Schandl, Robert Walker Sumner, Thomas Ruedas and Jürgen Göbel for their suggestions and corrections.

9  Versions

0.95
(Jan 8, 1998) First distributed version.
0.96
(Jan 9, 1998) New documentation. Introduction of customization commands. New alignment mechanism in the addressbook and phonebook environments.
0.97
(Jan 26, 1998) Entries ccp and p.ccp changed to account and p.account.
0.98
(Feb 9, 1998) New style letter.bst. New commands \pdir, \rdir and \wdir to produce in-text addresses when used with the letter.bst style. New internal key generation.
0.99
(Feb 12, 1998) Name change of old customization flags (\nameflag becomes \dirname). New flags introduced: \dirnickname, \dirphone, \dirfax, \diremail, \dirurl, \diraccount and \dirand.
1.00
(Mar 26, 1998) New HTML styles (address-html.bst and email-html.bst).
1.01
(Oct 26, 1998) Minor corrections.
1.10
(May 6, 1999) Major rewriting of bst files (suppression of direct LaTeX formatting). Definition of new customization commands. New package global options to split directories across pages and allow page breaks inside directory fields. The url.sty package is now required.
1.11
(May 7, 1999) Introduction of \dirparindent.
1.12
(May 11, 1999) Formatting commands can be particularized to each subfield by adding p, r or w after the \dir or \Dir prefix of the original customization command. Many simplifications and small corrections in the page breaking mechanism and in the list environments.
1.13
(Jun 21, 1999) Fixed bug for long entries without blank spaces (e.g. in url fields).
1.14
(Jun 21, 2000) More flexible definition of \Dirheader.
1.15
(Aug 28, 2000) Added fields for cellular phones (suggested by Stefano Ferrari). Added section explaining how to use hyperref to generate PDF documents with hyperlinks. Updated web site address.
1.16
(Feb 5, 2002) Added \dirtablewidth to set the width of the fields when the letter style is selected. Suppressed the split option (redefining the \Dirheader command makes it possible to achieve the same result: see section 3.2).
1.17
(Dec 15, 2002) Revised documentation.
1.18
(Sep 13, 2003) Added vCard and LDIF support.
1.19
(Sep 15, 2003) Split address into street, city, state, zip and country.
1.20
(Sep 22, 2004) Fixed small vcard export bug when using the old address fields; new german, french and longdates options.
Table 1: Summary of customization commands
Command  Arg.  Explanation Default
\dirsymbol  0   In-text symbol produced after a directory citation
\dirand  0  "anding" string \normalfont{and}
\dirbirthday  0  Birthday field flag $\star$~
\dirprivate  0  Private field flag \emph{p}~
\dirresidence  0  Residence field flag \emph{r}~
\dirwork  0  Work field flag \emph{w}~
\dirnote  0  Note field flag $\triangleright$~
\dirnickname  0  Nickname field flag
\diraddress  0  Address fields flag
\dirphone*  0  Phone fields flag tel:
\dircellular*  0  Cellular phone fields flag mobile:
\dirfax*  0  Fax fields flag fax:
\diremail*  0  E-mail fields flag
\dirurl*  0  Url fields flag
\diraccount*  0  Account fields flag acc:
\dirtitle  0  Title field flag
\dirname  0  Name field flag
\Dirlabel  1  Label format {\textbf{#1}}
\Dirheader  1  Command issued for each new starting letter in the directory (the arg. is the first letter used in the sorting algorithm) {}
\Dirbirthday  2   Birthday format (the first arg. is the day, the second is the month) {\number#2}/{\number#1}
\Dirbirthyear  1   Birth year format when a birthday field exists /{#1}
\DirbirthyearAlone  1   Birth year format when no birthday field exists {#1}
\Dirnickname  1  Nickname format (aka \emph{#1})
\Diraddress*  1  Address format {#1}
\Dirphone*  1  Phone format {#1}
\Dircellular*  1  Cellular phone format {#1}
\Dirfax*  1  Fax format {#1}
\Diremail*  1  E-mail format \url{#1}
\Dirurl*  1  Url format \url{#1}
\Diraccount*  1  Account format \url{#1}
\Dirtitle  1  Title format {#1}
\Dirname  1  Name format {#1}
\Dirnote  1  Note format {#1}
* The commands marked with an asterisk also exist in three other versions, controlling independently the private, residence and work parts (e.g. \dirphone can be particularized to \dirpphone, \dirrphone and \dirwphone).

Footnotes:

1directory is distributed under the LaTeX Project Public License (LPPL) since version 1.11.