Create a list of tiddler titles using filters and a hierarchy of tags

207 views
Skip to first unread message

AndrewMc

unread,
Aug 8, 2019, 2:49:55 AM8/8/19
to TiddlyWiki
Hi All

While I have been using TW for some years (mainly TWc) my usage of TW5 is rather basic and I am having difficulty with what I think is a filter problem.
I have some book text arranged in tiddlers, tagged with the chapter number, section number, and paragraph number of the text.

For example, all text from Chapter 7 is tagged with [C07].
The first Section of the chapter is a tiddler named [C07S01], containing just the section title, and is tagged with [C07] and [S01].
This section may contain several paragraphs.
The first Paragraph is a tiddler named [C07S01P01], and is tagged with [C07], [S01] and [P01].
The second paragraph is a tiddler named [C07S01P02], and is tagged with [C07], [S01] and [P02].

The second section in chapter 7 is [C07S02] (tagged with [C07] and [S02]).
and this has paragraphs [C07S02P01] and [C07S02P02] etc.

I am wanting to create a list of the tiddlers that make up this chapter.
I have created a [Chapter 7] tiddler containing the list-links macro:
<<list-links [tag[C07]]>>

This is a good start, and gets me the equivalent of:
* [[C07S01]]
* [[C07S01P01]]
* [[C07S01P02]]
* [[C07S02]]
* [[C07S02P01]]
* [[C07S02P02]]

However, I am wondering if there is a way to get the following:
{{C07S01}}
* [[C07S01P01]]
* [[C07S01P02]]
{{C07S02}}
* [[C07S02P01]]
* [[C07S02P02]]

That is, I would like to know if there is a way that I can transclude all of the Section tiddlers of a chapter, in numerical order, each followed by a list of the paragraphs within each section. Is this a task for a macro?

For a start, I am struggling to create a filter to obtain just the section tiddlers. I want to get only those tiddlers tagged with a chapter tag [C07] and with a tag beginning with [S], and  without a tag beginning with [P]. Is it possible to do this? Or, should I just add some more tags, [Section] for each section tiddler, and [Paragraph] for each paragraph tiddler?

Any suggestions and ideas appreciated.

Cheers
Andrew Mc

TonyM

unread,
Aug 8, 2019, 8:36:17 AM8/8/19
to TiddlyWiki
Andrew,

All of this is possible, but a full answer will take time. You may want to consider the existing TOC macros to see if you can leverage them. However I expect if you built your own TOC macro you would get more control. I need to get to bed so can't answer in full now.

However I am developing some guides and this may be interesting as a start, it demonstrates recursion that makes a TOC work to an unlimited number of levels, but you could write one just to process your known number of levels and treat each level differently. One macr call the chapter, the next the sections the next the paragraphs.

Recursion
Like a toc macro, recursion drills down into a heirachical structure
A sophisticated combination of iteration and selection
This example uses the same filter for each level, it processes all "tagging[]" the current tiddler then moves on to the next tiddler in the previous list.
\define each-other-level(filter)
Start level $filter$ <$link to=<<currentTiddler>> ><$text text=<<currentTiddler>>/></$link><br>
<$list filter="$filter$">
   
<<each-other-level $filter$>>
</$list>
End level for "<$text text=<<currentTiddler>>/
>"<br>
\end
\define first-level(filter)
Start all<br>
<$list filter="
$filter$">
   <<each-other-level $filter$>>
</$list>
End all<br>
\end

Start in TableOfContents<br>
<$tiddler tiddler="
TableOfContents">

<<first-level "
[is[current]tagging[]]">>

</$tiddler>

Or the unfinished

Structured levels not finished Incomplete and untested
Process a fixed and limited set of levels in a heirachie
A combination of iteration and selection
Each town within state within country
See recursion for an indefinite tree
\define all-countries()
Start all countries<br>
<$list filter="[tag[country]]" variable=country>
   
<$macrocall $name=country country-name=<<country>> />
</
$list>
Start all countries<br>
</$list>
\end

\define country{country-name}
Start $country-name$<br>
<$set name=country value="$country-name$">
<!-- <<country>> will stay set until you return here -->
<$list filter="[####tag[state]country<country>]" variable=state
   <$macrocall $name=state country-name=<<country>> state=<<state>>/
>
</$list>
End $country-name$<br>
</
$set>
\end

\define state{state}
Start $state$<br>
<$set name=state value="$state$">
<!-- <<state>>will stay set until you return here -->
<$list filter="[#####tag[country]]" variable=state
   
<$macrocall $name=town state=<<state>>/>
</
$list>
End $country-name$<br>
</$set>
\end

\define town(town}
Start $town$<br>
<$set name=state value="$town$">
<!-- <<town>>will stay set until you return here -->
<$list filter="[$$$$tag[country]]" variable=state
   <$macrocall $name=state state=<<state>>/
>
</$list>
End $town$<br>
</
$set>
\end
<<all-countries>>

Regards
Tony

AndrewMc

unread,
Aug 10, 2019, 3:13:50 AM8/10/19
to TiddlyWiki
Hi Tony

Thank you for response. I had not thought of using the TOC macros and have been trying them out to see what they do.
Also, thank you very much for the code. I am slowly working through it, figuring out what it is doing, and experimenting to see what happens when I make changes.

Cheers
Andrew Mc
Reply all
Reply to author
Forward
0 new messages