neuron
neuron copied to clipboard
Add a toc/table of contents option
I think at would be good to have the possibility, to set a flag to automatically generate a table of contents at the beginning of the zettel based on the headings in the zettel.
Alternative suggestion would be to have some custom query like <toc?for_zettels=...> That would be even more flexible e.g. giving the possibility to make one zettel with the table of contents of multiple others.
I was thinking a simple toc: true in the YAML frontmatter should do it.
Not sure if the case for a toc query type is strong enough (why would one want to generate ToC based on a different zettel?) ... although the idea (i.e., using query type to say 'i want toc here') is interesting.
I was thinking about something similar to the latter idea, which would behave like <z:tags?filter=...>, but instead of only showing the matching tags, zettels would also show up under the corresponding node in the tree.
Example:
- A is tagged my-book/part1
- B1 and B2 are tagged my-book/part1/chapter1
- C is tagged my-book/part1/chapter2
- D is tagged my-book/part2
<z:toc?filter=my-book/**>
==>
- my-book
- part1
- A
- chapter1
- B1
- B2
- chapter2
- C
- my-book
- part2
- D
There are some issues with this though, because we don't know how to order the zettels, and also because a single zettels can have multiple tags that match my-book/**.
why would one want to generate ToC based on a different zettel?
Well, the question is a bit, what use cases we assume valid for a zettelkasten.
But imagine you are writing a book. Every chapter is one zettel, which has multiple sections. Then as an entry point into the book one could create one zettel which displays the tocs of all chapters in a list. Thereby you can achieve to have one big table of content stretching over multiple zettels.
I am actually planing to collect theorems for my thesis in neuron. Right now if I want a linked toc, I need to put every section in one zettel. With a toc feature, I could just have everything in one zettel. With the fancy toc feature, I could go the middle ground. The toc could span multiple zettels but also the structure inside them.
I really like the idea the longer I think about it. Of course, as always, someone would need to implement it.
One second motivation, why a <z:toc> query or something like that would be useful is that it gives the possibility to have some introductory text before the toc, like the wikipedia does it.
I've written a little tool that accomplishes something similar to this using jq to parse Neuron's query output.
If I want a zettel to appear in my ToC (I call it an index, but it is really more of a ToC), I add a tag starting with index/ followed by the desired path within the ToC for that zettel, e.g. index/comp/linux/security. A zettel can have multiple of these index tags, and multiple zettels can have the same index tag. Zettels can also belong to any level of the hierarchy.
I have my tool configured to generate a new zettel for each level of the index hierarchy, with links to any leaf nodes (zettels) or sub-trees (deeper layers of the index hierarchy).
Here's an example of navigating the generated index/ToC pages:

It can be tweaked to use a 'sentinel' other than index/, and could also easily be used to generate multiple different ToCs, e.g. my-book/foo/bar and my-other-book/qux/spam.
It works pretty well for me so far, maybe it could help inspire the UI of a similar feature built in to Neuron.
P.s. be careful if you try to use my script, as it will rm $HOME/zettelkasten/index-*. It's only been written with my use case in mind thus far.
The suggestion to support Wikipedia style {{..}} templates in https://github.com/srid/neuron/issues/312#issuecomment-666313401 seems relevant here.