Sorting of second (and higher?) level entries in a table of contents is not preserved

The essence of the problem I bumped into is the following:

. Create three tiddlers (“notes”) with titles 1, 2, and 10, respectively (text not required) each tagged “note”.
. Create a toc tiddler “note” tagged “toc” with caption “Notes” and with the following content:

<div class="tc-table-of-contents">
<<toc "note" "nsort[]">>
</div>

The toc correctly sorts the notes numerically, as desired, due to the use of nsort, as illustrated below.

. Create a tiddler “toc” with the following content:

<div class="tc-table-of-contents">
<<toc-selective-expandable "toc">>
</div>

In the toc tiddler the second-level toc is not sorted correctly.

Try using 01 and 02 and 10 as tiddler titles or field values; I’m sure there is a better way to resolve the issue but that’s what I do.

//steve.

The simple titles in the example reduce the problem to its essence. Actual titles refer to text in books, as follows: “p. 25, construction of Table 3”, where the sorting is by page number. (The sorting in the actual toc is more complex then shown here.)

Both <<toc>> and <<toc-selective-expandable>> can use the “sort” parameter, and each macro generates it’s tree contents independently by following the tiddler tags at each level. Thus, the <<toc-selective-expandable>> macro doesn’t use the contents of the 2nd-level “note” tiddler (which has it’s own <<toc>> macro) to determine the next level of the tree.

To achieve the sorting you want, you need to provide the nsort[] sorting parameter directly in the <<toc-selective-expandable>> macro, like this:

<div class="tc-table-of-contents">
<<toc-selective-expandable "toc" "nsort[]">>
</div>

-e

I was going to try (without documentation) to move the sort parameter to the top level. It turns out that it is needed at both levels. If it is omitted at the second level, then the sorting is wrong when only this level is shown (the reverse of the above).
Thanks
Jan

@Jan there is some great work done to rewrite the TOC macro with 5.3.x features and enhance the toc macro by @pmario which has not yet moved into production, which provides even more control.

@TW_Tones Is there any documentation? Sounds interesting, I am very curious.

It is somewhat counterintuitive that the sorting specified for a table of contents is not used if it is made a sublevel of another table of contents.

As mentioned, I was going to try to move the sort parameter to the top, which Eric before I did explained is the solution. But this made me think: what if different levels or even entries within a level require different sorting, e.g., the top level is an alphabetical list of composers, for each composer the works are sorted either alphabetically or, where applicable, by opus number or by work ID (BWV, KV, etc.) or by date of composition and for each work the movements are sorted by sequence number?

@Jan Here is at least part of the discussion, TOC-macros Rewritten (+ a lot of new fuctionality) - Part 2 which @pmario just edited. Without reading the details today, at a minimum you can add a different sort in a field of a TOC item, that influences its children.

Of course a TOC is just one example of a hierarchical list. It is possible to write your own using nested $list widgets and impose your own sort order for the tiddlers at each level. This is of course dependant on your data as to how this may work and things such as how many levels deep you need to sort.

  • One approach may be to have an outer list widget, that acts on everything with the TableOfContents tag but invokes a TOC for each tiddler therein with that tag, and its own sort field.

This relates to an argument I put quite often, we are all inclined to try and push everything such as a multilevel sort into one filter, perhaps so it fits into a parameter of one lists widget or the TOC macros. But this is not necessary when one can write nested lists for which each level can have its own variable, sort order and display format etc… and if you have an indeterminate number of levels look into writing recursive filters and now functions.

@TW_Tones Thank you!