Using Filter Notation in code for Table of Contents

69 views
Skip to first unread message

Jarosław Szyc

unread,
Jan 26, 2023, 6:32:33 PM1/26/23
to TiddlyWiki
Hello! I am new user of TiddlyWiki, I work on Windows, Google Chrome and have a problem when creating Table of Contents. 

The following code works for me:

<<toc-selective-expandable 'ML' sort[created]>>

I obtain list of tiddlers tagged ML, which is sorted by creation date. Amazing!

But.......  2 things:

1) I want to be able to customize this list e.g. ''tiddlers with tag ML, but without tag Todo'' etc. So filter notation would be awesome
2) I run into a problem when name of tag tiddler has apostrophe e.g. Cauchy's Integral, then I am unable to create list of this tag using standard Table of Contents notation (hence again need of filter notation)

So what also works for me is that:

<<toc-selective-expandable [[ML]]>>

but I don't seem to be able to do anything else to that. What code lines do not work for me:

  • <<toc-selective-expandable [tag[ML]]>>
  • <<toc-selective-expandable [[ML]sort[title]]>>
  • <<toc-selective-expandable [tag[ML]sort[title]]>>
  • <<toc-selective-expandable  [tag[ML]!tag[Todo]  >>
  • <<toc-selective-expandable [tag[ML]tag[Todo]>>
All of the above commands don't produce a thing and I really wish they worked.

I would be really really thankful for help, because I love TiddlyWiki. And also I'm sorry if that's stupid thing to ask or wrong place to post such quesion - I am absolute begginer. If that's the case please tell me what should I do instead. 

Have a great day!







Eric Shulman

unread,
Jan 26, 2023, 7:34:38 PM1/26/23
to TiddlyWiki
For the first problem (excluding items tagged with "Todo"), try this:
```
<$set name="todo" filter="[tag[Todo]]">
<div class="tc-table-of-contents">
<$macrocall $name="toc-selective-expandable" tag="ML" sort="sort[created]" exclude=<<todo>> />
</div>
</$set>
```
Notes:
* The `$set` widget gets the list of all tiddlers tagged with "Todo" and stores it in the "exclude" variable
* `<div class="tc-table-of-contents">` applies the TWCore pre-defined styles to suppress the "numbered bullet item" display
* Using the `$macrocall` widget instead of the `<<toc-selective-expandable ... >>` macro syntax allows you to pass the value of the "exclude" variable as a parameter

To fix the second problem (where the root tag contains an apostrophe), enclose the root tag in double quotes:
```
<<toc-selective-expandable "Cauchy's Integral">>
```
* The `$macrocall` syntax will also handle the second problem , since all the parameter values are already enclosed in double quotes.

Let me know how it goes...

enjoy,
-e

Jarosław Szyc

unread,
Jan 26, 2023, 8:09:48 PM1/26/23
to TiddlyWiki
Woooow!!! 

Everything you described worked like a charm! ^^

thank you very much!

springer

unread,
Feb 10, 2023, 7:15:39 PM2/10/23
to TiddlyWiki
So, it turns out this solution does NOT work for toc-tabbed-internal-nav and toc-tabbed-external-nav

Adding this point here (in addition to at talk.tiddlywiki.org) because this thread is newer, AND someone hitting their head against the wall wondering why it's not working might feel a bit more sane if the issue is flagged.

Eric, if you happen to have a workaround ;) ...

Eric Shulman

unread,
Feb 10, 2023, 9:24:47 PM2/10/23
to TiddlyWiki
I've submitted a `[BUG]` issue on GitHub: https://github.com/Jermolene/TiddlyWiki5/issues/7261

The writeup for this issue includes some minor code changes to `$:/core/macros/toc` that will enable support for the use of the `exclude` parameter with `toc-tabbed-internal-nav` and `toc-tabbed-external-nav`.

Attached is a JSON file containing the modified `$:/core/macros/toc`, which I have tested on https://TiddlyWiki.com
$__core_macros_toc.json

PMario

unread,
Apr 25, 2023, 7:47:50 AM4/25/23
to TiddlyWiki
On Saturday, February 11, 2023 at 3:24:47 AM UTC+1 Eric Shulman wrote:
I've submitted a `[BUG]` issue on GitHub: https://github.com/Jermolene/TiddlyWiki5/issues/7261


Please test and give feedback.
have fun!
Mario

springer

unread,
Apr 25, 2023, 11:40:38 AM4/25/23
to TiddlyWiki
On the demo site, this kind of simple thing now works:

```
<$macrocall
$name="toc-tabbed-external-nav"
tag="TableOfContents"
    exclude="HelloThere"
/>
```
But this does not work:
```
<$macrocall
$name="toc-tabbed-external-nav"
tag="Common Operators"
    exclude="all Operator"
/>
```
As best I can tell, it fails when BOTH the tag and the exclude string have spaces.

This seems to be have been true (all along) for the toc-selective-expandable as well (which I never use, except now in testing).

Of course, I could make a workaround described earlier in this thread --  setting a variable called excluded so that `exclude=<<excluded>>` could do the work in the toc macro. 

But it seems the exclude parameter is of very limited use if it can't be used on the fly (without framing a variable beforehand) for something as simple as excluding a tiddler that has spaces in the title, when the tag title also has spaces in it.

Am I missing something?

-Springer

Eric Shulman

unread,
Apr 25, 2023, 12:14:42 PM4/25/23
to TiddlyWiki
On Tuesday, April 25, 2023 at 8:40:38 AM UTC-7 springer wrote:
```
<$macrocall
$name="toc-tabbed-external-nav"
tag="Common Operators"
    exclude="all Operator"
/>
```
As best I can tell, it fails when BOTH the tag and the exclude string have spaces.

Before the TOC code change, the `excluded` variable contained a ***list of tiddlers titles*** that had already been "visited" and was applied internally using `-[enlist<excluded>]` to prevent infinite "loops" in the tree.  In v5.3.0-prerelease, this variable can now also use filter syntax to generate a list of tiddler titles to be excluded (applied internally using `-[subfilter<excluded>]`).  The TOC code changes also now permit this parameter to be passed in to `toc-tabbed-external-nav`.  Since the value has always operated on a LIST, the correct usage to pass a specified title containing a space would be `exclude="[[all Operator]]"`

Note also that the `tag` parameter (used to specify the starting "root tag" for the tree) is NOT a list, and CAN contain spaces, since it is used internally via `tag<__tag__>`.

This DOES work as before:
```
<$macrocall
$name="toc-tabbed-external-nav"
tag="Common Operators"
    exclude="[[all Operator]]"
/>
```

-e

PMario

unread,
Apr 25, 2023, 2:28:40 PM4/25/23
to TiddlyWiki
Please have a look at the docs. [[title with spaces]]

toc-exclude-param.png

-m

springer

unread,
Apr 25, 2023, 7:47:14 PM4/25/23
to TiddlyWiki
Many apologies for posting before trying more things! 

(I had quickly tried some variant ways, but somehow tried all kinds of variants other than filter notation *with* quote-marks. I won't bore you further with explaining why I got confused. Thanks for the prompt clarification!)

-Springer

Reply all
Reply to author
Forward
0 new messages