# How to automate a dictionary (sorting, headers)?

1. Here is a piece of solution to automate a dictionary using the links given in the first following comments.

There are two problems to solve :

• When one definition starts on one page and finishes on another, the words in the headinga are not the good ones. In my example below, take a look at the page 1 where the last word must be adhesive and not adhesion, and in the page 2, the first word must be adjacent and not adhesive. Is there a way to solve this problem ?
• Secundly, I would like the letter A of the section to be centerd using \textbf{\textsf{...}} for formatting.

Here is the code that I've wanted to improve.

% Sources :
%    1) http://tex.stackexchange.com/questions/30392/how-could-one-setup-a-layout-for-a-dictionary-if-possible
%    2) http://tex.stackexchange.com/questions/26122/indexing-an-interval-of-words-on-top-of-every-page

\documentclass[twoside]{article}
\usepackage{multicol}
\usepackage{ifthen}
\usepackage{fancyhdr}
\usepackage{enumerate}
\usepackage{lipsum}

% Empty \sectionmark
\renewcommand{\sectionmark}[1]{}

\fancyfoot[C]{\textbf{\textsf{\thepage}}}

% Entry command : \dict{<word>}{<gender>}{<text>}
\newcommand{\dict}[3]{%
\par\vspace{0.25\baselineskip} %
\textbf{\textsf{#1}} \textit{#2} #3 %
\markboth{#1}{#1}
}

\pagestyle{fancy}

\begin{document}

\section*{A}

\begin{multicols}{2}
\end{multicols}

\end{document}

2. The solution found is the following one even if there is one remaining disturbing behavior, even if it is logical : in the last page of the output of the following code, zero appears in both headers...

% Sources :
%    1) http://tex.stackexchange.com/questions/30392/how-could-one-setup-a-layout-for-a-dictionary-if-possible
%    2) http://tex.stackexchange.com/questions/26122/indexing-an-interval-of-words-on-top-of-every-page

\documentclass[twoside]{article}
\usepackage{multicol}
\usepackage{fancyhdr}
\usepackage[bf,sf,center]{titlesec}

\fancyfoot[C]{\textbf{\textsf{\thepage}}}

\renewcommand{\footrulewidth}{1.4pt}

% Entry command : \dict{<word>}{<gender>}{<text>}
\newcommand{\dict}[3]{%
\markboth{#1}{#1}%
\par\vspace{0.25\baselineskip}%
\textbf{\textsf{#1}} \textit{- #2 -} #3%
}

\pagestyle{fancy}

% For testing
\usepackage{lipsum}

\begin{document}

\section*{A}

\begin{multicols}{2}
\end{multicols}

\section*{M}

\begin{multicols}{2}
\dict{main}{n}{\lipsum[3]}
\dict{material}{n}{\lipsum[1]}
\dict{mathematic}{n}{\lipsum[2]}
\dict{more}{n}{\lipsum[2]}
\end{multicols}

\section*{Z}

\begin{multicols}{2}
\dict{zebra}{n}{\lipsum \lipsum \lipsum}
\dict{zero}{n}{\lipsum[4]}
\end{multicols}

\end{document}

-
Does this post help: tex.stackexchange.com/questions/26122/… –  cmhughes Oct 8 '11 at 18:34
There's no need to edit the question title with (SOLVED). You already "marked" the question this way by accepting an answer. –  lockstep Oct 9 '11 at 12:42
I reverted your question to version 3, the one before your problem was solved. This way, other users can see what the original problem was and what you were looking for. If the solution you eventually used differs decisively from lockstep's, you're welcome to add an answer of your own. If you just want to comment on the way you used it, add a comment to lockstep's answer. –  doncherry Oct 9 '11 at 12:47
With regard to your latest question: You need to figure out what your requirements exactly are. If zebra should replace zero on the last page, why shouldn't adhesive replace adjacent on the second page? –  lockstep Oct 9 '11 at 13:21
Thank you for being so patient in dealing with this site's habits in terms of what belongs where. You'll soon get the hang of it, as I hope you'll stick around -- I really like your question and the dictionary looks great! –  doncherry Oct 9 '11 at 13:23

With regard to your first question (wrong header entries): In your \dict macro, use \markboth before typesetting the entry text.

\newcommand{\dict}[3]{%
\markboth{#1}{#1}%
\par\vspace{0.25\baselineskip}%
\textbf{\textsf{#1}} \textit{#2} #3%
}


With regard to your second question (formatting the sectioning heading): Use, e.g.,

\usepackage[bf,sf,center]{titlesec}

-
Thanks for all ! –  projetmbc Oct 9 '11 at 12:32