Ignoring caption field in table of contents

I think there must be an easy solution to the problem, but it eludes me.
I’m trying to make a table of contents that displays only the titles of the tiddlers and not their caption field. I know that the tables of contents looks for caption fields, but is there a way to make it ignore them? I need this change for one particular table of content only.

The TWCore table of contents (see https://tiddlywiki.com/#%24%3A%2Fcore%2Fmacros%2Ftoc) define a toc-caption macro, like this:

\define toc-caption()
\whitespace trim
<span class="tc-toc-caption tc-tiny-gap-left">
<$set name="tv-wikilinks" value="no">
  <$transclude field="caption">
    <$view field="title"/>
  </$transclude>
</$set>
</span>
\end

You can override this definition by adding a local macro within the same tiddler that you are using to invoke the TOC macro. Thus, to always use the title text, you would write:

\define toc-caption()
\whitespace trim
<span class="tc-toc-caption tc-tiny-gap-left">
<$view field="title"/>
</span>
\end

Because the modified toc-caption macro is defined locally, it will only affect the TOC rendered from that tiddler. All other uses of TOC will still apply the default toc-caption definition contained in the TWCore.

2 Likes

I believe that there is an oversight in the toc macro however:

Shouldnt the highlighted text be <<toc-caption>> instead ? There is no way to override the caption for toc items without a field toc-link set to no.

Thank you for your replies. I didn’t manage to make a good use for the solution proposed. (mainly because I only found out later that a ListWidget was more suitable for my purpose)
But anyway a big thanks to you

I think you are right. It’s the simple <<toc ...>> macro, which nobody seems to use. So we didn’t spot it. … IMO you could create a PR at GitHub

Done correction of the toc and toc-body macro by Telumire · Pull Request #7121 · Jermolene/TiddlyWiki5 · GitHub

3 Likes

I wonder if the TW 5.2.4 “Nested Macros” change offers a nice Code Pattern when overriding a macro called by another macro?

  • I have not Explored this yet but suspect something like this;
\define my-toc(tag)
\define toc-caption()
toc-caption redefined here
\end
<$macrocall $name=toc-tabbed-internal-nav tag="$tag$"/>
\end
  • The result being the redefined toc-caption only exists within my-toc

I expect within tw 5.3.0 we can easily pass all parameters given to my-toc through to toc-tabbed-internal-nav etc… and would look quite different.

I tried to nest the macros but when a macro is nested it become local to the macro, so you can’t redefine the nested macro after the fact : if you try to do that you will instead create a new macro.

To redefine B inside of A we would need to be able to access the B property of the A function and it’s not possible for now (AFAIK). It would be something like \define A.B() ..

Perhaps this behaviour needs documenting;

Looking at Nested Macro Definitions would imply what I thought to be the case, or do I miss understand something?

  • If in the example given, there was already a macro “actions” would it be used instead?
  • What if I set a variable instead with the macro content.

I reread this and “B” the macro inside of A has being redefined as “CONTENT B”, the next question is if the A macro calls another macro how does the B macro appear there?

I tested the redefinition of tag-pill in the following and confirmed its not redefined when calling tag as @telumire predicted.

  • In part this is because the redefinition needs to be a global macro?
\define A()
\define B()
CONTENT B
\end B
\define C()
CONTENT C
\end C
\define tag-pill(tag) 
redefined tag-pill for $tag$
\end tag-pill
CONTENT A and <<B>>
<<tag TableOfContents>> <<tag-pill>>
\end A

\define B()
this is NOT the B macro inside of A
\end

A: <<A>>

B: <<B>>

C: <<C>>