Customizing Levels of TOC

762 views
Skip to first unread message

michaelha...@gmail.com

unread,
Oct 3, 2018, 5:36:18 PM10/3/18
to TiddlyWiki

I have been using TiddlyWiki 5 for a few years now, and I have always used a hierarchal structure of tags. I am now coming to the point where I have enough sub-levels of tags, it feels like I have to scroll more horizontally than vertically.


One of the things I really like about TiddlyWiki is that tags can be just another level of tiddlers, and I would quite like to retain that ability to click on a tag and jump to the parent tiddler right away. Unfortunately, this system has resulted in an ungainly table of contents.


I would like to ask if there is any way to hide or deactivate parts of the right bar table of contents after a certain level, or hide certain tags specifically.


For example, if my TOC looked like this:


  • Item 1

    • Subitem 1

      • Extra 1

      • Extra 2

      • Extra 3

  • Item 2

    • Subitem 2

  • Item 3

    • Subitem 3


And so on.


Would there be a way to hide the list under Section 1, so instead my TOC looked like this:


  • Item 1

    • Subitem 1

  • Item 2

    • Subitem 2

  • Item 3

    • Subitem 3


Would something like this be doable?


Thank you.

Mark S.

unread,
Oct 3, 2018, 8:12:20 PM10/3/18
to TiddlyWiki
If the "extra" items have something in common (tag, prefix, field, etc.) then you can sneak extra criteria into the "sort" parameter to suppress their display.

e.g. sort:"!tag[Goats]"

Good luck!
-- Mark

michaelha...@gmail.com

unread,
Oct 3, 2018, 8:40:46 PM10/3/18
to tiddl...@googlegroups.com
Mark, please forgive my ignorance, but how would I implement sort:"!tag[Example]" in my table of contents?

As I said in my first message, everything is tagged, so I think your suggestion should work. But I do not use "sort" anywhere in the structure. My table of contents is made up of continuing levels of sub-tags. Where I have used code, I have used: <div class="tc-table-of-contents"> and the List field.

Am I explaining myself poorly?

TonyM

unread,
Oct 3, 2018, 8:45:47 PM10/3/18
to TiddlyWiki

A project you may wish to start.

The TOC macros use recursion to find every possible member of the resulting tree. Recursion is one macro "A" calls another "B" which calls itself "B

If you only want three levels displayed perhaps make you own set of macros eg in one tiddler -
\define top()
\define middle()
\define bottom()

The meaning of current tiddler changes for each level.

Top lists the items tagging the current tiddler and calls middle for each of these tiddlers,  Middle then list all items tagging the current tiddler, and calls bottom for each of them. Bottom then list all items tagging the current tiddler but does not call any deeper level.

I can give a full solution later if you do not want to use this as a learning opportunity.

Regards
Tony

michaelha...@gmail.com

unread,
Oct 3, 2018, 9:04:18 PM10/3/18
to TiddlyWiki
Tony, that is certainly something I might try. I am a bit worried it might be too inflexible though.

Clarification: Would that be three levels for everything? Could I set differing levels for different sets of tags? And how much maintenance would the new macros need as I edited and tweaked my table of contents over time?

I am always interested in learning more about TiddlyWiki, and while this might be something to play around with, I am not sure I have the skill that I could manage to get it to do what I would like it to do.

What would you suggest?

Thank you.

TonyM

unread,
Oct 3, 2018, 9:20:52 PM10/3/18
to TiddlyWiki
The solution I suggested was to meet your implied 3 levels deep. You would use this set of macros when your required 3 levels deep and the normal toc for unlimited levels.

You could easily make 4 - 5 level alternatives, however we would like to set a number of levels deep. I have looked at doing this and while it is possible, it is currently a little convoluted.

The macros simply use the tags of tiddlers to list members, managing your tags is all you need to do, the macros are used to list them in a toc and you use the one you need where you want the list to appear. Calling the macros would usually be in fairly static unchanging tiddlers, but the listing will respond to which tiddler tags which. ie maintaining your table of contents does not change.

barro...@gmail.com

unread,
Oct 3, 2018, 9:23:03 PM10/3/18
to TiddlyWiki
I Mark S' suggection suppress display of items in the other "item #" branches and you don't want that, you can break up your table of contents using multiple ToC macros in the page for your table of contents like so

<div class="tc-table-of-contents">
<<toc-selective-expandable 'Item 1 tag name' exclude:"-[prefix[Extra]]-[tag[any tags you don't want to display]]">>

<<toc-selective-expandable 'Item 2 tag name'>>

<<toc-selective-expandable 'Item 3 tag name'>>

</div>

This will show Items 1, 2 & 3 as separate TOC's un the same page with a empty line/space between them
Item 1 will not display anything bearing the title prefix of Extra or other criteria that the Extra tiddlers may have

I use this trick for creating basic table of contents of more expansive versions showing all cross linked pages.  This also allows you break up long table of contents into smaller sections

michaelha...@gmail.com

unread,
Oct 3, 2018, 9:34:19 PM10/3/18
to TiddlyWiki
Tony, thank you for explaining. Just to make sure I have understood your explanation, your idea with the macros was that I have a set of different table of contents to display different levels of information? That is certainly not something I had considered, and I will probably need to spend some time exploring the idea at a later date.

Before I get too distracted though, do you think there is any way I might be able just to stop chosen tags from appearing in my table of contents?

I am beginning to suspect I may have asked for something much more complex than I realized.

michaelha...@gmail.com

unread,
Oct 3, 2018, 9:46:32 PM10/3/18
to TiddlyWiki
barro, I am sorry, but could I ask two more questions?

First, how exactly would I write the table of contents to include multiple tags? Like this:

<<toc-selective-expandable "Contents" exclude:"-[tag[Tag1][Tag2][Tag3]]">>

Second, after removing the items listed beneath, my TOC headers still show the expandable arrows, though they no longer do anything. How might I get rid of these?

Thank you.

Mark S.

unread,
Oct 3, 2018, 10:36:00 PM10/3/18
to TiddlyWiki
The table of contents macro has a "sort" parameter. But it can be used for more than sorting. You can use it to put in additional filtering. e.g. <<toc tag:"Root" sort:"!tag[Example]">>

michaelha...@gmail.com

unread,
Oct 4, 2018, 8:08:16 AM10/4/18
to TiddlyWiki
Okay, so my current table of contents looks like this;

<div class="tc-table-of-contents">
<
<toc-selective-expandable "Contents" exclude: "-[tag[Tag1]]-[tag[Tag2]]">>
</div>

I assume I can continue adding the tags I want to keep hidden in the same way?

And after removing the items listed beneath each tag in the TOC, the text still shows the expandable arrows, though they no longer reveal any content. Is there a way a get rid of the arrows, or are they to be a permanent fixture?

Thank you.

Mark S.

unread,
Oct 4, 2018, 10:02:17 AM10/4/18
to TiddlyWiki

Where is the "exclude" option coming from? It's not listed in the documentation at tiddlywiki.com.

-- Mark

michaelha...@gmail.com

unread,
Oct 4, 2018, 10:08:08 AM10/4/18
to TiddlyWiki
Mark, see barro's comment above. 

His example is as follows:

Mark S.

unread,
Oct 4, 2018, 10:16:59 AM10/4/18
to TiddlyWiki
Perhaps Barro has a customized version of the toc-selective-expandable macro. The standard macro doesn't include the exclude option. You can use the "sort" option, but the syntax would be more like:

<<toc-selective-expandable 'Root" sort:"!tag[badtag]!tag[otherbadtag]">>

-- Mark

michaelha...@gmail.com

unread,
Oct 4, 2018, 10:30:05 AM10/4/18
to TiddlyWiki
Mark,

Here is my TOC after trying to add the sort option as you suggested:

<div class="tc-table-of-contents">
<
<toc-selective-expandable "Contents" sort:"!tag[Tag1]!tag[Tag2]">>
</div>

As far as I can tell, that seems to be working. The expandable arrows are still present however. Is there a method by which I might remove them, or will they stick around even though the content they would have shown has been hidden?

Thank you.

Mark S.

unread,
Oct 4, 2018, 10:35:18 AM10/4/18
to TiddlyWiki
It turns out there is an undocumented "exclude" option, so if you can try that method if you want and see if it works better.

michaelha...@gmail.com

unread,
Oct 4, 2018, 10:44:18 AM10/4/18
to TiddlyWiki
Both the sort and the exclude options seem to meet my needs, so I think I will err on the side of caution and go with the choice that is properly documented on the site.

I take it the expandable arrows are non-negotiable?

Thank you.

Eric Shulman

unread,
Oct 4, 2018, 12:30:23 PM10/4/18
to TiddlyWiki
On Thursday, October 4, 2018 at 7:35:18 AM UTC-7, Mark S. wrote:
It turns out there is an undocumented "exclude" option, so if you can try that method if you want and see if it works better.

Some years ago, when the TOC macros were first written, they had a problem with infinite recursion if a tiddler was tagged with the tag of a "parent node" in the tree.

To address this, I added an *internal* variable, "exclude", that is used during the recursion to automatically keep track of which tiddlers have already been listed in the tree, so that they won't get displayed more than once and create circular references.  The value of the exclude param is a "negative filter"... that is, it uses TW filter syntax to remove matching titles from consideration, like this: "-[[SomeTitle]]".  As the recursion progresses, more titles are added...e.g., "-[[Foo]] -[[Bar]] -[[Baz]]".

Normally, when invoking a TOC macro, the "exclude" filter value defaults to blank, so that all tiddlers in the tree will be shown.  However, if you DO provide an initial filter value for the exclude param, any titles matching that filter will be suppressed without being displayed even once.  Thus, you can use exclude="-[tag[Gronk]]".

Important note: every term in the exclude filter MUST be a negated term (with the "-" prefix) or it will CAUSE infinite recursion.  For example, if you write exclude="[tag[Foo]]" instead of exclude="-[tag[Foo]]", then all tiddlers tagged "Foo" will be treated as matching tiddlers at *every* level of the tree and the code will recurse until the browser crashes.

It's just too easy to break things just by missing a single leading "-" on any filter term.  Perhaps for this reason more than anything else, the variable -- while necessary for internally preventing infinite recursion -- is not documented for general use as an input param.

-e

Mark S.

unread,
Oct 4, 2018, 1:56:47 PM10/4/18
to TiddlyWiki
Hi Eric,

Thanks for the backgrounder. The problem with using the exclude filter (or the sort parameter) is that although the child tiddlers are snipped away, the "branch" is still left with it's open/close arrow, which is a bit distracting. I remember that this has come up in other threads, so "pruning" the branch (making it into a standard link) seems to be a recurring request. I'm looking at the code, trying to see where it might be possible to introduce a list of branches to be pruned (e.g. "Learning [[Customise TiddlyWiki]]") but it's easy to get lost in the code ;-)

Thanks!
-- Mark

Mark S.

unread,
Oct 4, 2018, 6:11:47 PM10/4/18
to TiddlyWiki
The expandable arrows can only be changed by changing the code.

If you want to experiment, put the following contents in a tiddler, and tag it as $:/tags/Macro :

\define toc-linked-selective-expandable-body(tag,sort:"",itemClassFilter:" ",exclude,path,prune:"")
<$set name="toc-state" value=<<qualify """$:/state/toc$path$-$(currentTiddler)$""">>>
 
<$set name="toc-item-class" filter="""$itemClassFilter$""" emptyValue="toc-item" value="toc-item-selected" >
<$set name="prune" value="""$prune$""">
   
<li class=<<toc-item-class>>>
     
<$link>
         
<$list filter="[all[current]]  -[enlist<prune>] +[tagging[]limit[1]]" variable="ignore" scratch="-[enlist<prune>]" emptyMessage="<$button class='tc-btn-invisible'>{{$:/core/images/blank}}</$button>">
         
<$reveal type="nomatch" state=<<toc-state>> text="open">
           
<$button set=<<toc-state>> setTo="open" class="tc-btn-invisible tc-popup-keep">
             
{{$:/core/images/right-arrow}}
           
</$button>
          </
$reveal>
         
<$reveal type="match" state=<<toc-state>> text="open">
           
<$button set=<<toc-state>> setTo="close" class="tc-btn-invisible tc-popup-keep">
             
{{$:/core/images/down-arrow}}
           
</$button>
          </
$reveal>
       
</$list>
        <<toc-caption>>
      </
$link>
     
<$reveal type="match" state=<<toc-state>> text="open">
       
<$macrocall $name="toc-selective-expandable" tag=<<currentTiddler>> sort="""$sort$""" itemClassFilter="""$itemClassFilter$""" exclude="""$exclude$""" path="""$path$""" prune="""$prune$"""/>
     
</$reveal>
    </
li>
</$set>
  </
$set>
</$set>
\end


\define toc-selective-expandable-empty-message()
<<toc-linked-selective-expandable-body tag:"""$(tag)$""" sort:"""$(sort)$""" itemClassFilter:"""$(itemClassFilter)$""" exclude:"""$(excluded)$""" path:"""$(path)$""" prune:"""$(prune)$""">>
\end

\define toc-selective-expandable(tag,sort:"",itemClassFilter,exclude,path,prune)
<$vars tag="""$tag$""" sort="""$sort$""" itemClassFilter="""$itemClassFilter$""" excluded="""$exclude$ -[[$tag$]]""" path="""$path$/
$tag$""" prune="""$prune$""" >
  <ol class="
tc-toc toc-selective-expandable">
    <$list filter="""
[all[shadows+tiddlers]tag[$tag$]!has[draft.of]$sort$] -[[$tag$]] $exclude$""">
      <$list filter="
[all[current]toc-link[no]]" variable="ignore" emptyMessage=<<toc-selective-expandable-empty-message>> >
        <$macrocall $name=toc-unlinked-selective-expandable-body tag="""
$tag$""" sort="""$sort$""" itemClassFilter="""$itemClassFilter$""" exclude=<<excluded>> path=<<path>> prune="""$prune$""" >
      </$list>
    </$list>
  </ol>
</$vars>
\end

This code will override the existing core code. Now you can "prune" branches by their tiddler name. For instance:

<div class="tc-table-of-contents">
<
<toc-selective-expandable "TableOfContents" prune:"Learning [[Drag and Drop]]">>
</div>

If used at TiddlyWiki.com will show the standard table of contents, but "Learning" and "Drag and Drop" (under Features) will both be links -- not expandable branches.

Oh, before dropping in this code be sure to close all existing branches or the existing branch state will force the contents to display even without an expansion "parent".

This applies only to the toc-selective-expandable macro.

Be sure to make a backup of your work before trying this -- you never know.

HTH
-- Mark

michaelha...@gmail.com

unread,
Oct 4, 2018, 6:53:04 PM10/4/18
to TiddlyWiki
Don't hope. That helped.

Mark, thank you very much. I have added your suggested code to my TiddlyWiki, and touch wood, everything seems to be working fine. Will hold on to the back up for a while yet, but I do believe this is my issue resolved.

Thank you again, Mark, for taking the time to explain what I should be doing, and even more so for taking the time to come up with a custom bit of code to meet my needs.

Thank you to everyone else who commented as well. Your suggestions were enlightening, and I certainly will have to try playing around with multiple TOCs at some point to see how I can better organize my information.

Best,

Michael

Mohammad

unread,
Oct 5, 2018, 11:16:09 AM10/5/18
to tiddl...@googlegroups.com
Great job Mark!

Is it possible to raise the issue and solution at github with the hope of Jeremy adds this to the core!

-Mohammad

Mark S.

unread,
Oct 5, 2018, 11:31:10 AM10/5/18
to TiddlyWiki
I think we would need to prove that more than two people find it useful! ;-)

Mohammad

unread,
Oct 5, 2018, 11:43:29 AM10/5/18
to TiddlyWiki
So, I would ask people here to like your post! :-)

- Mohammad

barro...@gmail.com

unread,
Oct 5, 2018, 1:44:10 PM10/5/18
to TiddlyWiki
Mark



Where is the "exclude" option coming from? It's not listed in the documentation at tiddlywiki.com.


The "exclude" feature I learned here in th TW Group, it was cited as an undocumented feature of the toc macro-- it seems to work.

barro...@gmail.com

unread,
Oct 5, 2018, 1:53:44 PM10/5/18
to TiddlyWiki
Micheal,


barro, I am sorry, but could I ask two more questions?

no problem, this group is all about asking questions and I ask questions all the time, so ask away-- if I don't have the answer, perhaps more knowledgeable members will see your question and stepin with an answer...
 
First, how exactly would I write the table of contents to include multiple tags? Like this:

<<toc-selective-expandable "Contents" exclude:"-[tag[Tag1][Tag2][Tag3]]">>

kk I see in a later post you figured how to do multiple excludes, each excluded tag has its own exclude.
 
Second, after removing the items listed beneath, my TOC headers still show the expandable arrows, though they no longer do anything. How might I get rid of these?

The arrow I hadn't been able to get rid of

barro...@gmail.com

unread,
Oct 5, 2018, 2:06:47 PM10/5/18
to TiddlyWiki
Mark,

Nope, using it with the standard toc macro.

Your sorting ! exclude looks good, do they go before or after the usual field sorting such as
sort:"[field]![bad tag]"

Perhaps Barro has a customized version of the toc-selective-expandable macro. The standard macro doesn't include the exclude option. You can use the "sort" option, but the syntax would be more like:

Also I'm probably also confusing things cause I haven't seen anywhere else, anyone using multiple toc macros in the same same toc div/sidebar tiddler.

barro...@gmail.com

unread,
Oct 5, 2018, 3:14:19 PM10/5/18
to TiddlyWiki
Eric,

Thank you for the info about, the exclude option.  I agree with the reason it isn't shown in the documentation and will follow suit with being cautious about suggesting its use to others because of the potential disastrous results if it's no used incorrectly.  The ! exclude ability of the sort function is much safer.

TonyM

unread,
Oct 5, 2018, 7:51:17 PM10/5/18
to TiddlyWiki
Folks,

The questions discussed here with toc and filtered tocs etc... Is all about heirachies represented in tiddlywiki. Out of the box tiddlywiki handles this very well.

There are a number of threads here that cover this and extending functionality like the exclude tiddlers.

I can recomend playing with and building your own toc macro because its a great way to learn about recursion ie call a macro that calls a second macro that calls itself. and of course you can customise it. True avoiding infinite loops may be nessasary if your data was not structured.

I am posting here, as heirachical organisation and going beyond simple heirachies, is an interest of mine. I intend to build some grand solutions based on this in time, but you can expect a trickle of macros.

I see the ability to increment a variable to count how deep in the heirachy is an importiant feature we need.

Otherwise I want sophisticated solutions that will ultimately meet most user requirements in a simplified way, potentialy hiding the real complexity.

I am allways open to collaboration.

Regards
Tony

TonyM

unread,
Oct 5, 2018, 11:31:19 PM10/5/18
to TiddlyWiki
Michael,

Extending the concepts shared by others I have built a TOC that you can set the number of levels deep on so you do not need to exclude items.

It does require Evans formulae plugin to work just to increment a value, this is just an experiment but it provides a simpler macro to modify for include excludes and alternate output formatting. In this case it uses the heading level of the levels deep and block quotes to indent.

\define toc-levels(root-tiddler max)
<$set name=level value="1">
<$set name=max value="$max$" emptyValue="100">
<blockquote>
$root
-tiddler$ (Max levels deep <<max>>)<br>
<$list filter="[tag[$root-tiddler$]]" variable=name>
 
<$macrocall $name=loopme tiddlername=<<name>> level=<<level>> max=<<max>>/><br>
</
$list>
</blockquote>
</
$set></$set>
\end
\define loopme(tiddlername level max)
<blockquote>
<h$level$>$level$. <$link to="$tiddlername$" tooltip="Click to open $tiddlername$"><$view tiddler="$tiddlername$" field="caption" format=text><$view tiddler="$tiddlername$" field="title" format=text></$view></$view></$link></h$level$>
<$formula-vars
   
next-level=add($level$,1)>
<$list filter="[[$max$]] -[[$level$]]">
<$list filter="[tag[$tiddlername$]]" variable=loop-name>
 
<$macrocall $name="loopme" tiddlername=<<loop-name>> level=<<next-level>> max="$max$"/>
</$list>
</
$list>
</$formula-vars>
</
blockquote>
\end


<<toc-levels TableOfContents 3>>

Regards
Tony

On Thursday, October 4, 2018 at 7:36:18 AM UTC+10, michaelha...@gmail.com wrote:

I have been using TiddlyWiki 5 for a few years now, and I have always used a hierarchal structure of tags. I am now coming to the point where I have enough sub-levels of tags, it feels like I have to scroll more horizontally than vertically.


One of the things I really like about TiddlyWiki is that tags can be just another level of tiddlers, and I would quite like to retain that ability to click on a tag and jump to the parent tiddler right away. Unfortunately, this system has resulted in an ungainly table of contents.


I would like to ask if there is any way to hide or deactivate parts of the right bar table of contents after a certain level, or hide certain tags specifically.


For example, if my TOC looked like this:


  • Item 1

    • Subitem 1

      • Extra 1

      • Extra 2

      • Extra 3

  • Item 2

    • Subitem 2

  • Item 3

    • Subitem 3


And so on.


Would there be a way to hide the list under Section 1, so instead my TOC looked like this:


  • Item 1

    • Subitem 1

  • Item 2

    • Subitem 2

  • Item 3

    • Subitem 3


Would something like this be doable?


Thank you.

barro...@gmail.com

unread,
Oct 6, 2018, 1:01:15 AM10/6/18
to TiddlyWiki
Tony,

I am definitely interested in what others know or have done with various things in TW cause I plan on putting my applications of TW through some serious tests for world building/video game development.

Like me replaced my exclude usage with sort![] once I saw Mark S suggesting a more stable method-- I didn't want to pass on a potentional disaster to my users if they decided to duplicate what I did and made a mistake doing it.

I intend on tinkering with the toc macro cause I want to put "new from here" buttons to toc entries for quick and easy creation of tagged tiddlers from the toc.

and I have been studying what you and Mark have shown in this thread-- it was quite fruitful sparking a discussion in this thread.
Reply all
Reply to author
Forward
0 new messages