[Tex/LaTex] How to sort a list numerically

#enumeratedescriptionlistssorting

Basically, I want to create a summary for a history class. Therefore a lot of years occur throughout the lectures.

Does LaTeX allow to sort a list if I set it up like in the following example?

\begin{description}
  \item[1912] Something good happened
  \item[1923] Something bad happened
  \item[1901] Something terrible happened
\end{description}

Is it possible that LaTeX recognizes the number and reorders it correctly?

Desired output:

1901 Something terrible happened

1912 Something good happened

1923 Something bad happened

LaTeX is able to do so in the bib, so can it be extended somehow?

Best Answer

This approach automatically orders the items by year or any other number, by using an external list on an .csv file.

\documentclass{article}
\usepackage{filecontents} % To create an external .csv file
\begin{filecontents}{\jobname.csv}
Order, Text
1912, Something good happened.
1923, Something bad happened.
1901, Something terrible happened.
\end{filecontents}

\usepackage{datatool}
\DTLloaddb{externalcsv}{\jobname.csv}

\begin{document}

\begin{enumerate}
\DTLsort{Order=ascending}{externalcsv}%
\DTLforeach{externalcsv}{\myorder=Order, \mytext=Text}{\item[\myorder.]\mytext}
\end{enumerate}

\end{document}

Output

enter image description here

Related Question