I'm looking for suggestions on how to sort entries for songbook entries made with the songs package. The package documentation covers how to sort index entries, but appears silent on the issue of sorting the song entries themselves. It would seem there would be a way to sort them by song title, author, or any other key value created with \newsongkey, but the manual is silent on it (as far as I have found).

Will songs only print in the order typed? If so, does anyone have suggestions on how to build a macro that sorts by keyvals or some other parameter? As an example, the following songs print as typed, but could I make them sort by song title, i.e. first letters A,B,C = current song numbers 3,2,1?

\beginsong{Crown Him With Many Crowns}[
by={George J. Elvey, Godfrey Thring and Matthew Bridges},
sr={Revelation 4:9-11,5:13},
cr={Public domain.}]
\[C]Crown Him with \[Am]many \[F]crowns,
The \[C]Lamb up\[F]on His \[Gsus]throne. \[G]
Hark! \[C]How the \[F]heav'nly \[D]anthem \[G]drowns
All music \[D]but its \[G]own! \[G7]
A\[C]wake, my soul, and \[F]sing \[F/E]
Of \[D]Him Who died for \[G]thee \[G7/F]
And \[C/E]hail Him \[F]as thy \[G7]matchless \[C]King
Through \[F]all e\[G]terni\[C]ty.
\beginsong{Blessed Assurance}[
by={Fanny Crosby and Phoebe Knapp},
sr={Philippians 1:21},
cr={Public domain}
\beginverse \memorize
\[C]Blessed assurance, \[F]Jesus is \[C]mine!
\[(C)]O what a fore\[G]taste of \[D]glory \[G]divine!
\[C]Heir of salvation, \[F]purchase of \[C]God,
\[(C)]Born of his \[Dm]Spirit, \[G]washed in his \[C]blood.
\[C]This is my story, \[F]this is my \[C]song,
\[(C)]Praising my \[F]Sav\[C]ior \[G]all the \[D]day \[G]long;
\[G7]This is my \[C]story, \[F]this is my \[C]song,
\[(C)]Praising my \[Dm]Savior \[G]all the day \[C]long.
\beginsong{Amazing Grace}[
  by={John Newton},
  sr={Luke 15:4; 2 Corinthians 4:8,9; Ephesians 2:8; Revelation 14:3},
  cr={Public domain.}]
A\[E]mazing \[E/D#]grace! How \[A/C#]sweet the \[E/B]sound
That \[E]saved a \[E/C#]wretch like \[B7]me!
I \[E]once was \[E/D#]lost, but \[A/C#]now am \[E/B]found;
Was \[E]blind, but \[B]now I \[E]see.

  • Interesting question. I guess it will not be possible without significant modifications to the code however. The contents of LaTeX environments (or semi-enviroments such as \beginsong...\endsong in the songs package are usually added to the output as soon as they are encountered in the source code, which means the output order is necessarily the same as the input order. There are ways to work around this, like putting each song fully processed inside a 'box' until it is ready to be added to the document, or collecting the source code for the songs in temporary files,
    – Marijn
    Dec 2, 2021 at 12:57
  • but this is difficult to do and has various disadvantages - the easiest is to sort the songs in advance outside of LaTeX and then input them in order I'm afraid.
    – Marijn
    Dec 2, 2021 at 12:59


You must log in to answer this question.

Browse other questions tagged .