Sorting cross-referenced items in writer

I am using LO 7.1.2.2. In a WRITER document I have a number of songs. At the beginning of the document I have a list of the song titles (an index). These are cross-referenced to the lyrics later in the document. Currently the list of titles is not in alphabetical order and some of them are not yet cross-referenced. Each title is concluded by a carriage return (enter). When I select the list of titles and try to sort them it will not sort the cross-referenced titles and the uncross-referenced titles are sorted but placed after the cross-referenced titles. Am I doing something wrong or is this a bug?

EDIT 2021-05-30 by ajlittoz: transfer of attached file from 306904/sorting-cross-referenced-items-in-writer-continuation

Lyrics - Sorted NEW Copy.odt

Your specification calls for an alphabetical index.

Don’t make it yourself. Writer provides an alphabetical index feature without the fuss of cross-references.

(You can have a step 0 where you remove your cross-references)

  • Step 1: preparation

    Select a song title and Insert>TOC & Index>Index Entry, Insert

  • Step 2: index creation

    • Where you want your index to appear, Insert>TOC & Index>TOC, Index or Bibliography.

    • Choose Alphabetical Index from the Type drop-down menu.

When you add a new song, repeat step 1. To update the index, right-click in it and Update Index/Table.

EDIT 2021-04-30

In this Lyrics demo.odt, I created an outline of your document based on Heading 1 and Heading 2 paragraph styles:

  • Heading 1 is used to create a separator page with a centered capital letter
  • Heading 2 is the song title with supplementary information to enter into the TOC
  • below the song title, you can have as many Text Body paragraphs as you need for artists, lyrics, duration, … I recommend you use one paragraph style per meaning (one for lyrics, one for artists, …) so that you can format them independently

Page breaks are added to the Heading n paragraph styles so that there is no need to type them manually.

TOC is inserted with Insert>TOC & Index>TOC, Index or Bibliography. TOC is formatted by Contents n family. You can tune these styles to fit your taste. Hyperlinks are generated: Ctrl+click to jump to the song title. However, I have not coded the return link to the TOC in the Heading 2 paragraphs (because the link word would also appear in the TOC). You can as quickly return to the TOC with a fast scroll.

I noticed that all your document is Default Paragraph Style with direct formatting. This is wrong. Read the Writer Guide and learn how to work with styles.

##Sorting your songs

Once your document is structured with Heading n outline, use the Navigator (compass icon or F5). Expand the Headings section. Click on a heading to select it and use one of the arrows in the Navigator toolbar to move it. Depending on the UI widgets, these arrows may be difficult to identify visually, so hover your mouse over the icons to spot the Promote Chapter and Demote Chapter arrows. They move the corresponding Heading n (and all Heading m with m>n and non-Heading m below the selected heading) one position up or down in the outline.

This is not as handy as a global sort but you can arrange your “chapters” as you like.

To show the community your question has been answered, click the ✓ next to the correct answer, and “upvote” by clicking on the ^ arrow of any helpful answers. These are the mechanisms for communicating the quality of the Q&A on this site. Thanks!

Thanks for the response. Your answer works fine for simply creating an index but the advantage I wanted with the cross-referencing was to be able to click on the title in the index and then be taken to the cross-referenced item. In other words by clicking on the title it would take me to the lyrics further down in the document

This is a limitation of an alphabetical index compared to a TOC: an entry in the Index may reference several occurrences (as a consequence of merging). Therefore there is no unique destination and Writer does not generate links.

The links can only be generated with a Table of Contents (which is an automated form of cross-references) but entries are sorted in page order. You can’t change this order.

Give more information on your procedure of creating your present cross-references. Ideally, edit your question and attach a 2-page sample file (with the paperclip tool). Depending on the type of the cross-references, there may be an alternate solution.

Not sure how I can edit my question as it essentially remains the same. The procedure I have followed was initially to type in the list of titles and then add the lyrics late in the document. It was only once I had added a large number of entries that I thought about automating it and I settled on the cross-referencing. At the time I had not always added the titles in alphabetical order and would have sorted them once I had finished. I then started with the cross-referencing, highlighting the target tile with the lyrics then adding the ‘set reference’. Then going to the list of titles and selecting the correct title and selecting ‘insert reference’. It was only once I had done a large number of entries like this and then tried to sort the list of titles that I realised I had a problem. This system works well for me other than the sorting. If it came to the crunch I could always just do the sort manually. A sample document is attached. Thanks for your help (I can’t see the paperclip to

The paperclip tool is only available in a question, not in a comment (thus the suggestion to edit your question).

I’m thinking of a solution based on Heading 1 style for the song titles and using the Navigator to reorder the songs. Waiting for the sample file to describe the procedure.

What I would do is to use a Heading x paragraph style for the titles and then create a table of contents (which is clickable).

The tricky part is to sort the songs. You can do it manually, the Navigator will help you move each chapter/song with the Promote/Demote chapter buttons. It will move the whole chapter, that is the title and the text after (until the next heading of the same level).

You may also be able to sort all the songs. Not tested but the strategy would be to put each song in a single cell of a table (as many cells as songs). Then, sort the table, it should take the first paragraph only for criterion, that is the title. Switch to the web layout view so that you can see the whole table. Then, you need to select each song/cell and copy it out of the table. Note that after all songs have been sorted, you can change the Heading x style used so that it adds a page break before (Text Flow tab). Thus, each song will be on a new page.

To show the community your question has been answered, please tag the best answer (), and/or vote for any helpful answer. Else, please edit your question to add information (answers are for solutions only).