Although LaTeX is not the best language for this sort of thing, here is a potential solution. It uses the pgffor
package.
First, we load the pgffor
package and define a counter that will keep track of how many items there are in our list.
\usepackage{pgffor}
\newcounter{SortListTotal}
Then, we define a command that will store the list items.
\newcommand{\sortitem}[2]{\expandafter\def\csname SortListItem#1\endcsname{#2}\stepcounter{SortListTotal}}
The first argument of \sortitem
is the item's number; the second is the item text.
Now, we define a command to print out the list. This command also resets the counter, ready for a new sorted list.
\newcommand{\printsortlist}{\foreach\currentlistitem in{1,2,...,\value{SortListTotal}}{\item[\currentlistitem]\csname SortListItem\currentlistitem\endcsname}\setcounter{SortListTotal}{0}}
These commands are used as in the following:
\begin{enumerate}
\sortitem{3}{This is the third item.}
\sortitem{4}{This is the fourth item.}
\sortitem{1}{This is the first item.}
\sortitem{2}{This is the second item.}
\printsortlist
\end{enumerate}
Alternatively, if you want to specify the order after storing the items:
\makeatletter
\newcounter{SortListTotal}
\newcommand{\sortitem}[1]{\stepcounter{SortListTotal}\expandafter\def\csname SortItem\arabic{SortListTotal}\endcsname{#1}}
\newcommand{\printsortlist}[1]{\@for\currentitem:=#1\do{\item\csname SortItem\currentitem\endcsname}\setcounter{SortListTotal}{0}}
\makeatother
These commands are used as in the following:
\begin{enumerate}
\sortitem{This is the third item.}
\sortitem{This is the fourth item.}
\sortitem{This is the first item.}
\sortitem{This is the second item.}
\printsortlist{3,4,1,2}
\end{enumerate}
The backref
option to hyperref
can take a value. By default it is section
, but this does not seem to be giving the correct output, as it picks up the item number instead inside an enumerate. On the other hand you are requesting a page ref, and passing the page
option does work:
![Sample output](https://i.stack.imgur.com/LehF8.png)
\documentclass{article}
\usepackage[backref=page]{hyperref}
\begin{document}
\begin{enumerate}
\item A
\item B
\item C~\cite{art}
\end{enumerate}
\bibliographystyle{plain}
\bibliography{test}
\end{document}
with test.bib
@Article{art,
author = {Author, A. N.},
title = {On\dots},
journal = {J. Jour.},
year = 2004
}
Best Answer
The following example defines colors
enum1
,enum2
, ... using\colorlet
of packagexcolor
. Then it hooks into\labelenumi
to add the color command with the color that consists of the value of counterenumi
. For deeper nesting levels of theenumerate
environment,\labelenumii
upto\labelenumiv
can also be changed accordingly.Extension for nested lists: