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.
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
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/