Graphics, Figures & TablesList alphabetization in LaTeX

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
christoi
Posts: 4
Joined: Mon May 24, 2010 5:57 pm

List alphabetization in LaTeX

Post by christoi »

Is there any way to alphabetize a list in LaTeX without using \makeindex?

Personally i suddenly find there ought to be an alphabetical variant or option to i.e. the \description itemize environment.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

nlct
Posts: 276
Joined: Thu Nov 06, 2008 11:15 am

List alphabetization in LaTeX

Post by nlct »

You could use the datatool package to create a database of your items and then sort it. For example:

Code: Select all

Code, edit and compile here:
\documentclass{article}
\usepackage{datatool}
\newcommand{\sortitem}[2]{%
\DTLnewrow{list}%
\DTLnewdbentry{list}{label}{#1}%
\DTLnewdbentry{list}{description}{#2}%
}
\newenvironment{sortedlist}%
{%
\DTLifdbexists{list}{\DTLcleardb{list}}{\DTLnewdb{list}}%
}%
{%
\DTLsort{label}{list}%
\begin{description}%
\DTLforeach*{list}{\theLabel=label,\theDesc=description}{%
\item[\theLabel] \theDesc
}%
\end{description}%
}
\begin{document}
\begin{sortedlist}
\sortitem{banana}{A yellow fruit}
\sortitem{pear}{An oddly shaped fruit}
\sortitem{apple}{A roundish fruit}
\end{sortedlist}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Regards
Nicola Talbot
christoi
Posts: 4
Joined: Mon May 24, 2010 5:57 pm

Re: List alphabetization in LaTeX

Post by christoi »

Magnificent! Thanks a lot!
christoi
Posts: 4
Joined: Mon May 24, 2010 5:57 pm

Re: List alphabetization in LaTeX

Post by christoi »

But, hey!

It seems i can only put one \sortedlist in my document. Using more than one i get an error message that says:

./test.tex:37: Undefined control sequence.
<argument> \DTLcleardb
{list}
l.37 \begin{sortedlist}

Do i need to clear the sorting prosess before starting a new \sortedlist or something?


Many thanks in advance.
christoi
User avatar
nlct
Posts: 276
Joined: Thu Nov 06, 2008 11:15 am

List alphabetization in LaTeX

Post by nlct »

./test.tex:37: Undefined control sequence.
<argument> \DTLcleardb
{list}
l.37 \begin{sortedlist}
You need to update your version of datatool. (\DTLcleardb was new to version 2.03)

Regards
Nicola Talbot
Post Reply