Graphics, Figures & Tables ⇒ List alphabetization in LaTeX
List alphabetization in LaTeX
Personally i suddenly find there ought to be an alphabetical variant or option to i.e. the \description itemize environment.
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
List alphabetization in LaTeX
Code: Select all
\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}
Nicola Talbot
Creating a Minimal Example: http://www.dickimaw-books.com/latex/minexample/
Re: List alphabetization in LaTeX
Re: List alphabetization in LaTeX
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
List alphabetization in LaTeX
You need to update your version of datatool. (\DTLcleardb was new to version 2.03)./test.tex:37: Undefined control sequence.
<argument> \DTLcleardb
{list}
l.37 \begin{sortedlist}
Regards
Nicola Talbot
Creating a Minimal Example: http://www.dickimaw-books.com/latex/minexample/