TOC question

191 views
Skip to first unread message

David Gifford

unread,
Feb 6, 2019, 6:43:02 PM2/6/19
to TiddlyWiki
Hi all

How would I tweak $:/core/macros/toc (or something else) so that each tab in the toc would show the caption field of the tiddler, but the title within the tab contents would show the longer title field of the tiddler?

TonyM

unread,
Feb 6, 2019, 7:24:32 PM2/6/19
to TiddlyWiki
David,

You can modify the shadow tiddler or build a new toc macro for this purpose, which TOC do you expect to use?
  • toc
  • toc-expandable
  • toc-selective-expandable
  • toc-tabbed-internal-nav
  • toc-tabbed-external-nav
and I would be happy to have a look

Regards
Tony

David Gifford

unread,
Feb 6, 2019, 7:31:49 PM2/6/19
to TiddlyWiki
Thanks Tony

It is toc-tabbed-internal-nav

TonyM

unread,
Feb 6, 2019, 7:32:47 PM2/6/19
to TiddlyWiki
PS

All the macros are defined in $:/core/macros/toc and call a macro called toc-caption

To clarify 
  1. the index will have the title, and the selected tiddlers display their caption?
  2. the index will have the caption, and the selected tiddlers display their title?
The First will need manipulate the view template's display of the caption instead of the title and you may not want this for all tiddlers
The Second is I believe the default behaviour

The view template Question from a technical futures has being raided here 

Regards
Tony


On Thursday, February 7, 2019 at 10:43:02 AM UTC+11, David Gifford wrote:

S. S.

unread,
Feb 6, 2019, 11:32:59 PM2/6/19
to TiddlyWiki

David,

Open the shadow tiddler: $:/core/macros/toc
Find this line : \define toc-tabbed-external-nav
Yes, this is the correct line for modifying the toc-tabbed-internal-nav - as that macro calls it.

Find this line:
<h1><<toc-caption>></h1>

Change it to this :
<h1><$view field="title"/></h1>

Should work!
Regards

Jeremy Ruston

unread,
Feb 7, 2019, 6:29:01 AM2/7/19
to tiddl...@googlegroups.com
I’m not sure if it will let you do exactly what you want in this situation, but the reason that the toc-caption macro is separated out is so that it can be redefined for a particular instantiation of the TOC. For example, here we have a tabbed internal navigation TOC where the toc-caption macro has been modified to put a percentage sign before each caption. The toc-caption macro defined in this tiddler will override the one in the core.

\define toc-caption()
<$set name="tv-wikilinks" value="no">
  % <$transclude field="caption">
    <$view field="title"/>
  </$transclude>
</$set>
\end

<$macrocall
$name="toc-tabbed-internal-nav"
tag="TableOfContents"
selectedTiddler="$:/temp/toc/selectedTiddler"
unselectedText="<p>Select a topic in the table of contents. Click the arrow to expand a topic.</p>"
missingText="<p>Missing tiddler.</p>"
/>

Best wishes

Jeremy.


--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/e3fc8dd3-8791-4db0-9860-3ca129fcf26d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mohammad

unread,
Feb 7, 2019, 7:26:04 AM2/7/19
to TiddlyWiki
Hi Jeremy,
 This question may be off topic here.

You said, the toc-caption here will override the one in the core! Can I conclude that:

If a macro is called in a scope of a tiddler and it calls a macro internally say maymac, then if the  maymac is existed in the scope of calling tiddler, it will override the core or other scope macros! Is this kind of overloading?

--Mohammad 

Jeremy Ruston

unread,
Feb 7, 2019, 7:28:34 AM2/7/19
to tiddl...@googlegroups.com
You said, the toc-caption here will override the one in the core! Can I conclude that:

If a macro is called in a scope of a tiddler and it calls a macro internally say maymac, then if the  maymac is existed in the scope of calling tiddler, it will override the core or other scope macros! Is this kind of overloading?


Yes, exactly that.

It’s the same mechanism by which the following example renders “Ringo”:

<$set name="foo" value="John">
<$set name="foo" value="Paul">
<$set name="foo" value="George">
<$set name="foo" value="Ringo">
<$text text=<<foo>>/>
</$set>
</$set>
</$set>
</$set>


Best wishes

Jeremy



Mohammad

unread,
Feb 7, 2019, 7:35:22 AM2/7/19
to tiddl...@googlegroups.com
WOW,
 This is amazing Jeremy!

As mush as I go deeper in Tiddlywiki, I found more amazing things.
This gives us a lot of flexibility. I gonna to make some examples in TW-Scripts for this.

By now I understood

* I can have macro overloading in TW
* I can send a macro name like a pointer from scope 1 to another macro.
* I can define variables and constants
* I can have decision making
* I can loop over items
* ....

This is amazing!

--Mohammad

Dave Gifford - http://www.giffmex.org/

unread,
Feb 7, 2019, 8:27:28 AM2/7/19
to TiddlyWiki
Thank you to everyone who posted. S.S.'s solution was exactly what I needed. Thanks Jeremy for the explanation, too!

Dave

Jeremy Ruston

unread,
Feb 7, 2019, 8:30:00 AM2/7/19
to tiddl...@googlegroups.com
Hi Dave

Thank you to everyone who posted. S.S.'s solution was exactly what I needed. Thanks Jeremy for the explanation, too!

The disadvantage of SS’s solution is that it requires you to override a core tiddler. The correct way to do it is to use a custom template parameter for the TOC macro. The default template contains:

          <h1><<toc-caption>></h1>
          <$transclude mode="block">$missingText$</$transclude>

So, you’d want to add a template parameter pointing to a tiddler containing:


          <h1><$text text=<<currentTiddler>>/></h1>
          <$transclude mode="block">$missingText$</$transclude>

Best wishes

Jeremy.



Dave

On Wednesday, February 6, 2019 at 5:43:02 PM UTC-6, David Gifford wrote:
Hi all

How would I tweak $:/core/macros/toc (or something else) so that each tab in the toc would show the caption field of the tiddler, but the title within the tab contents would show the longer title field of the tiddler?

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.

John

unread,
Feb 7, 2019, 3:08:06 PM2/7/19
to TiddlyWiki
Yes. It's called dynamic scoping. Very unusual in languages. It's because JavaScript is a protype oriented language rather than class oriented.

TonyM

unread,
Feb 7, 2019, 7:56:00 PM2/7/19
to TiddlyWiki
Folks,

I will add to Jeremys post that the value of foo is changed as you expect, when displayed as I have below. In a way you are reusing the variable name, giving it a new value.

<$set name="foo" value="John">

<<foo>>

<$set name="foo" value="Paul">
<<foo>>


<$set name="foo" value="George">
<<foo>>


<$set name="foo" value="Ringo">
<$text text=<
<foo>>/>

</$set>
</$set>
</$set>
</$set>

However lets use this
\define mymacro()
<$set name="foo" value="Tony">
In macro: <<foo>><br>
</$set>
\end
<$set name="foo" value="John">
Before Macro: <<foo>><br>
<<mymacro>>
After Macro: <<foo>><br>
</$set>

The result will be 
Before Macro: John
In macro: Tony
After Macro: John


  • Basically foo is set to john between the first <$set and </$set> 
  • Then when you call the macro foo is set between <$set and </$set> in the macro
  • Because the value for foo does not continue outside the macro given its </$set>
  • When we return to the calling wiki text the value of foo that is returned is the value set previously.
The following has the same results, for the same reason, your are "nesting the set widgets"
<$set name="foo" value="John">
Before nested set: <<foo>><br>
<$set name="foo" value="Tony">
In nested set: <<foo>><br>
</$set>
After nested set: <<foo>><br>
</$set>
The result will be 
Before nested set: John
In nested set: Tony
After nested set::John

So Jeremy's example is also nesting set widgets, it is just clearer now.

Using a macro call forces the nesting because if the macro does not close its <$set widgets an error occurs.

This illustrates the way variable names can be reused, or overidden, some would imagine this is like css, others would think of this as a stack, last in first out.

Understanding this is of particular value when considering list widgets that change the current tiddler, they are changing the current tiddler inside the list but the current tiddler outside the list retains its original value. Lists within lists do this as well. However each list filter will determine if it takes account of its current context, or generates a totally new one.


Regards
Tony

S. S.

unread,
Feb 7, 2019, 8:07:57 PM2/7/19
to tiddl...@googlegroups.com

David,

It was not obvious to me what Tony & Jeremy meant by "using a template parameter" as I was not aware of how it is used!

If you look on the last line on the documentation for Table-of-Contents Macros, it says:

template
         Optionally, the title of a tiddler to use as a template for transcluding the selected tiddler into the right-hand panel

So the correct way is to create a template tiddler, say named : CustomTocTemplate

Put the following in that tiddler:

<h1><$text text=<<currentTiddler>>/></h1>
<$transclude mode="block">$missingText$</$transclude>

Then when you define your Table if Contents, you do it similar to this:

<$macrocall
    $name="toc-tabbed-internal-nav"
    tag="TableOfContents"
    template="CustomTocTemplate"

    selectedTiddler="$:/temp/toc/selectedTiddler"
    unselectedText="
<p>Select a topic in the table of contents. Click the arrow to expand a topic.</p>"
    missingText="
<p>Missing tiddler.</p>"
/>

Don't forget to undo the changes you made earlier by simply deleting the edited shadow tiddler : $:/core/macros/toc

Apologies for the earlier not so hot quick fix!

Edited to correct mistaken paste. Changed:

<h1><<toc-caption>></h1>
to

Dave Gifford - http://www.giffmex.org/

unread,
Feb 7, 2019, 9:02:58 PM2/7/19
to TiddlyWiki
Hi S.S.

I have made the changes. And it works great! Thanks for both solutions.

On Thursday, February 7, 2019 at 7:07:57 PM UTC-6, S. S. wrote:

David,

It was not obvious to me what Tony & Jeremy meant by "using a template parameter" as I was not aware of how it is used!

If you look on the last line on the documentation for Table-of-Contents Macros, it says:

template
         Optionally, the title of a tiddler to use as a template for transcluding the selected tiddler into the right-hand panel

So the correct way is to create a template tiddler, say named : CustomTocTemplate

Put the following in that tiddler:

<h1><<toc-caption>></h1>

<$transclude mode="block">$missingText$</$transclude>

Then when you define your Table if Contents, you do it similar to this:

<$macrocall
    $name="toc-tabbed-internal-nav"
    tag="TableOfContents"
   
template="CustomTocTemplate"
    selectedTiddler="$:/temp/toc/selectedTiddler"
    unselectedText="
<p>Select a topic in the table of contents. Click the arrow to expand a topic.</p>"
    missingText="
<p>Missing tiddler.</p>"
/>


Don't forget to undo the changes you made earlier by simply deleting the edited shadow tiddler : $:/core/macros/toc

Apologies for the earlier not so hot quick fix!

Edits were just to clean up the line spacing

Dave Gifford - http://www.giffmex.org/

unread,
Feb 7, 2019, 9:17:01 PM2/7/19
to TiddlyWiki
I should add that you meant to put <h1><$view field="title"/></h1> not <h1><<toc-caption>></h1>

Dave Gifford - http://www.giffmex.org/

unread,
Feb 7, 2019, 9:21:57 PM2/7/19
to TiddlyWiki
oops actually it was the text Jeremy suggested in the beginning...

Dave Gifford - http://www.giffmex.org/

unread,
Feb 7, 2019, 10:23:40 PM2/7/19
to TiddlyWiki
If anyone wants to see what I have been up to, here is a sample

Mohammad

unread,
Feb 7, 2019, 11:17:10 PM2/7/19
to TiddlyWiki
Thank you John and Tony for clarification.

--Mohammad

S. S.

unread,
Feb 8, 2019, 6:48:58 AM2/8/19
to TiddlyWiki
Edited my previous post to correct the mistaken paste. Corrected the template tiddler code to:

<h1><$text text=<<currentTiddler>>/></h1>
Reply all
Reply to author
Forward
0 new messages