# Indexing an interval of words on top of every page

Friends, I'm curious on how to do the following in LaTeX:

Dictionaries have two words on the top of each page, meaning the interval of words to be found on that specific page, e.g.,

In the figure, analyst refers to the lower bound (the first word), and ancillary refers to the upper bound (the last word) in this page.

I was wondering of how we could achieve something similar in LaTeX. Let's say we have the following document:

\documentclass{article}
\usepackage{multicol}
\usepackage{enumerate}
\usepackage{lipsum}

\begin{document}
\begin{multicols}{2}
\begin{description}
\end{description}
\end{multicols}
\end{document}


For this page, I expect to see both adequate and adhesive in the top of the page (first and last items on the page, respectively). The same rule applies to the rest of the pages. Update: I should've mentioned that I'm curious of an "automatic" way of choosing which words will be set in the page headers. =)

Any ideas?

-
Section 10 of the fancyhdr documentation shows how to do this. –  Alan Munn Aug 19 '11 at 19:07
@Alan: Interesting, thanks for mentioning. In fact, I was looking for something like an automatic procedure to look which words are the first and last in the current page and then set them in the header. fancyhdr solves the second part (how to put them in there), I wonder how could we solve the first one. =) –  Paulo Cereda Aug 19 '11 at 19:16
It's all in there. See my posted answer. –  Alan Munn Aug 19 '11 at 21:19
@Alan: my bad, I probably misread the documentation. ;-) –  Paulo Cereda Aug 19 '11 at 21:34

Here's a worked up example based on section 10 of the fancyhdr documentation:

\documentclass[twoside]{article}
\usepackage{multicol}
\usepackage{ifthen}
\usepackage{fancyhdr}
\usepackage{enumerate}
\usepackage{lipsum}
% empty \sectionmark
\renewcommand{\sectionmark}[1]{}
% create a command to create marks and collapse them if they are identical
\newcommand{\mymarks}{%
\ifthenelse{\equal{\leftmark}{\rightmark}}
{\rightmark} % if equal
{\rightmark--\leftmark}} % if not equal
% define a wrapper on the description environment to add the marks
% this part is quick and dirty; it would be better to define one's own
% environment to do this, but the basic idea is the same: you need
% to add the \markboth command to each dictionary entry
\def\ditem[#1]{\markboth{#1}{#1}\item[#1]}
\pagestyle{fancy}
\begin{document}
\begin{multicols}{2}
\begin{description}

Absolutely fantastic, Alan! Thanks a million! =) –  Paulo Cereda Aug 19 '11 at 21:31