TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a database full of names, addresses, etc.. We use them at my work to make sure only people in the database are allowed inside (or denied entry, if they've ever done something wrong). I created a document with pdflatexdb, and by using longtable, I now have a 'working' document that I can live with if I have to.

However, as we add people to the database everyday, the "list" gets larger and less manageable as far a scanning for a name or id number and the like. What I'd like to figure out is how to create an "index" that will show which pages last names (a field in the DB) start with... IE - names that start with A are on page one, B page 50, C page 60, and so forth. Here is a working example:


\usepackage[left=.5in, right=.5in, top=1cm, bottom=.8in]{geometry}

\fancyfoot[RE, RO]{\thepage}
\fancyfoot[C]{Generated: \today}

\texdbconnection{CONNECTION STUFF}

\texdbdef{##query}{select lname, fname, license_no, comments from visitors where redsheet='Allow' order by lname}{##lname,##fname,##license,##comments}

%% EHD TeXDBdef

\begin{center}\section*{These people are allowed inside the building.}\end{center}
\begin{center}\Large{Ordered by name}\end{center}
    \Large{Name} & \Large{License \#} & \Large{Comments} \vspace{1em} \\     \hline \vspace{.2em}
    \texdbfor{##query}{\texttt{##lname,} \texttt{##fname} & \texttt{##license} & \texttt{\textit{##comments}} \\ \vspace{.5em}}


I am a relative n00b to LaTeX, so please be gentle if my document has glaring errors (I'm assuming some of my code is redundant or even useless).


share|improve this question
FYI, I'm working on a PHP frontend for this, so please don't comment on the uselessness of a paper list... – jmd9qs Apr 13 '13 at 11:29
up vote 2 down vote accepted

It's not possible to run the code without the connection package and something to connect to however

\Large{Ordered by name}

size commands like \Large don't take an argument so if you use in that form the {} are not delimiting an argument but making a group which is harmless in this case but confusing, better to leave out the braces.

But I would guess that you can replace




where \labelname gets the first letter and does a \label if it is new, something like


then at the end you just need to use \pageref on each letter in turn:







\section{Name index}

\expandafter\ifx\csname r@letter-#1\endcsname\relax\else
\par\noindent#1: \pageref{letter-#1}\par
\if Z#1\else\expandafter\refnameletter\fi}



enter image description here

enter image description here

share|improve this answer
thanks! I know this isn't testable on your end, but I'll give it a go and get back to you later on today. – jmd9qs Apr 13 '13 at 12:16
I should probably comment for the record that there are letters other than A-Z and this will silently ignore them, but it saved worrying about encodings and stuff. – David Carlisle Apr 13 '13 at 12:18
I figured that, but it suits my needs as I don't need to worry about special characters or anything... Thanks again! – jmd9qs Apr 13 '13 at 13:02
Thanks for your solution David! As of now it's not gonna work for me, I think I'm going to have to give in and write a perl script... probably a cleaner solution, and more maintainable. – jmd9qs Apr 13 '13 at 16:10

Your Answer


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.