Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to create an environment (or any other command) for entering addresses. For example, I want something like this:

\newaddress
\home
\name{John Doe}
\phone{123-456-7890}
\address{100 1st Street, New York, NY}
\makeaddress

Then it prints following a certain format like:

\usepackage{wasysym} % Just for \XBox and \Square

\begin{description}
\item[Address Type:] \XBox Home, \Square Work
\item[Name:] John Doe
\item[Phone:] 123-456-7890
\item[Address:] 100 1st Street, New York, NY
\end{description}

How can I do this? I am open to any form of environment, command, or anything else.

share|improve this question

2 Answers 2

up vote 7 down vote accepted

Here's a quick implementation using xkeyval just to give an idea of what can be done using this approach:

enter image description here

\documentclass{article}
\usepackage{wasysym,xkeyval}% http://ctan.org/pkg/{wasysym,xkeyval}
\makeatletter
\define@cmdkey{address}{type}{}
\define@cmdkey{address}{name}{}
\define@cmdkey{address}{phone}{}
\define@cmdkey{address}{address}{}
\newcommand{\makeaddress}[1][]{%
  {\setkeys{address}{type=,name=,phone={555-555-5555},address=,#1}%
  \begin{description}
    \item[Address Type:] %\cmdKV@address@type
      \def\addresschoice@type{home}\ifx\addresschoice@type\cmdKV@address@type\relax\XBox Home%
      \else\def\addresschoice@type{work}\ifx\addresschoice@type\cmdKV@address@type\relax\Square Work
      \else None\fi\fi
    \item[Name:] \cmdKV@address@name
    \item[Phone:] \cmdKV@address@phone
    \item[Address:] \cmdKV@address@address
  \end{description}
}}
\makeatother
\begin{document}
\makeaddress[name={John Doe},address={100 1st Street, New York, NY},phone={123-456-7890},type=home]
\bigskip
\makeaddress[name={Jane Doe},address={Unknown}]
\end{document}

The main advantage would be that you can specify defaults for keys if they're not supplied, limit certain inputs to specific values and mix them in any order you like. You'll have to peruse the xkeyval documentation to view all the possibilities. I don't think my code is the most optimal or uses all the benefits of xkeyval, but at least it shows a proof of concept that should fit your use case.

share|improve this answer

You can use the directory package (see the example provided with the package at CTAN or from Christophe Geuzaine):

\documentclass[12pt]{article}
\usepackage[break,longdates]{directory} 
\directorystyle{address}
\begin{document}
\nodir{*}
\directory{family,business} 
\end{document}

The package also allows introducing information from an address book into a document, for instance to generate a letterhead.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.