I have a list of almost 300 items in an enumerate environment
\documentclass{article}
\begin{document}
\begin{enumerate}
\item This is the second item.
\item This is the third item.
\item This is the first item.
\end{enumerate}
\end{document}
that I want to list in a different order (the third item should be first, the first item should be second, and the second item should be third.) I want the output to look like this:
Is there a way I can pass the argument [3, 1, 2] to some function and have the list typeset in the order automatically instead of doing so manually ? Thank you.
EDIT: I see that we use xpatch
to use the old item. However, in my document I have redefined item as follows:
\newcounter{myenumi}
\renewcommand{\themyenumi}{\textbf{Example \thesection.\arabic{myenumi}.}}
\newenvironment{exenumerate}{%
% stuff for beginning of environment goes here
\setlength{\parindent}{0pt}% don't indent paragraphs
\setcounter{myenumi}{0}% restart numbering
\bigskip% skip a line
\renewcommand{\item}{% new definition of item
\par %start a new line
\medskip
\refstepcounter{myenumi}% advance counter
\noindent \makebox[8em][l]{\themyenumi}% print counter to width of 3em, aligned to left
}% end of definition of item
}{% at end of environment
\par% start new paragraph
\bigskip% skip a line
\noindent% don't indent new paragraph
\ignorespacesafterend% ignore spaces after environment
}
Will Werner's solution still work?
Best Answer
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.Then, we define a command that will store the list items.
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.
These commands are used as in the following:
Alternatively, if you want to specify the order after storing the items:
These commands are used as in the following: