In some document I have some long bullet lists (numbered or not numbered), for instance:

  1. 2001: ...
  2. 2002: ....
  3. 2003: .....

but I would just like to have the list reordered in just its inverse order, so that it ends up like:

  1. 2003: ...
  2. 2002: ....
  3. 2001: .....

this trivial example is easy, but I have lists with 200 entries. How can I do this?

  • 1
    I'm not sure how it would be effected in LyX-world, but this is certainly an interesting LaTeX problem :) – Sean Allred Jul 18 '15 at 5:20
  • no, just on item and one line – Open the way Jul 18 '15 at 6:18
  • plyx might be able to do this. There is a section on sorting tables and lists. see wiki.lyx.org/Examples/PLyXSystem – scottkosty Jul 18 '15 at 13:43
  • Have you heard of sort? It can sort things in a number of different ways. There's also a similar command for Windows.... – jon Jul 18 '15 at 22:07

Using some techniques from Order items in enumerate environment automatically, you can reverse the list on the LaTeX side. It will still display in sequential order as you place them within LyX, but will be reversed in the output.

Add the following to your Document > Settings... > Local Layout:

Format 60

Style Reverse_Enumerate
Category              List
Margin                Static
LatexType             Item_Environment
LatexName             reverseenum
NextNoIndent          1
ToggleIndent          Never
LeftMargin            MMN
LabelSep              xx
ParSkip               0.0
ItemSep               0.2
TopSep                0.7
BottomSep             0.7
ParSep                0.3
Align                 Block
AlignPossible         Block, Left
LabelType             Enumerate
LabelCounter          "enum"
HTMLTag               ol
HTMLItem              li
HTMLLabel             NONE
RefPrefix             enu

The above defines a new environment Reverse Enumerate that you can choose from your paragraph drop-down:

enter image description here

It is virtually similar to the Enumerate construction, only with a different name and associated with a different LaTeX environment reverseenum as well as the removal of the Insert > Custom Item option. Now add the definition of the reverseenum environment to your Document > Settings... > LaTeX Preamble:

% Using some ideas from
%   https://tex.stackexchange.com/q/128297/5764

\let\olditem\item% Store regular \item macro
  \stepcounter{reverseenum}% New reverseenum environment (also resets listcount)
  \g@addto@macro{\BODY}{\item\relax\item}% Used to delimit the items; last item identified by \item\relax\item
  \def\item##1\item{% Redefine \item to capture contents
    \expandafter\ifx\optarg\relax\else% Last item not reached
      \stepcounter{listcount}% Next item being processed
      \global\@namedef{reverseenum@\thereverseenum @\thelistcount}{##1}% Store item in control sequence
      \expandafter\item% Recursively continue processing items
  \BODY% Process environment (save items)
  \def\reverselist{% How to reverse list, recursively
      \olditem \csname reverseenum@\thereverseenum @\thelistcount\endcsname
  \enumerate\reverselist\endenumerate% Process items

The above definition processes the list once, storing each \item in a specially-named macro. Once the entire environment is processed and the \items stored, it re-processes the list by setting the now-stored \items in reverse order, stepping backward through the list of specially-named macros.

To that end, consider the following LyX input:

enter image description here

The first list is set under Enumerate. The second list is set under Reverse Enumerate. It produces the following PDF output:

enter image description here

It would be trivial to modify the above to work for an Itemize list as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.