[tw5] Using Filter Notation in code for Table of Contents

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!

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

Woooow!!!

Everything you described worked like a charm! ^^

thank you very much!

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 :wink:

I’ve submitted a [BUG] issue on GitHub: [BUG] toc-tabbed-* macros should accept initial `exclude` parameter · Issue #7261 · Jermolene/TiddlyWiki5 · GitHub

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 (10.9 KB)

1 Like

Hi folks,

There is a preview version https://tiddlywiki5-4elmgaims-jermolene.vercel.app/
created by the PR table-of-content macros -- make "exclude" an official macro parameter by pmario · Pull Request #7417 · Jermolene/TiddlyWiki5 · GitHub … which may be included into the next TW version.

docs: TiddlyWiki — a non-linear personal web notebook

Please test and give feedback.

have fun!
Mario

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

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

1 Like

Please have a look at the docs. [[title with spaces]]

-m

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