(new here …) count the number of non-system fields

136 views
Skip to first unread message

Martin

unread,
Feb 18, 2020, 7:26:54 AM2/18/20
to TiddlyWiki
Hello,

I'm working a while with TiddlyWiki, mostly for note-taking. For this, I need the text of the bible. I have organised this text by chapters, so each chapter is a tiddler, for example named "Gen 1" for Genesis 1. I use the fields of such a tiddler to list the verses of a chapter – in the case of Gen 1 I have fields from 1 to 31. So, in each chapter, the number of verses can be up to 176 (in the case of Psalm 119).

The advantage of this approach is that I can transclude each verse in my notes, writing {{Gen 1!!1}} for Genesis Chapter 1 Verse 1.

But now I want to get a readable list of each chapter. For this, I wrote a macro:

\define show_all(verse_start,verse_end)
{{!!title}}, $verse_start$ $verse_end$
<p>
   
<$tiddler tiddler={{!!title}}>
       
<$list variable="line" filter="[all[tiddlers]fields[]nsort[title]]+[range[$verse_start$,$verse_end$]]">
           
<tr style="background-color:Moccasin;">
               
<td style="color:blue;width:2em;text-align:center"><<line>> </td><td><$transclude field=<<line>> /></td>
           
</tr>
        </
$list>
   
</$tiddler>
</
p>
\end

This works. But now my question: I want to replace ma parameter $verse_end$ by an automatic detection of the highest existing value in this chapter. And I tried for some time, but I didn't manage to solve this.

How can I get the highest existing numeric field name and put it into a variable? Or how can I count the total number of fields in the current tiddler, excluding the system fields (and some other fields)? 

Mat

unread,
Feb 18, 2020, 7:38:50 AM2/18/20
to TiddlyWiki
Welcome Martin
 
How can I get the highest existing numeric field name and put it into a variable?

 
Or how can I count the total number of fields in the current tiddler, excluding the system fields (and some other fields)? 


[fields[]] -created -text -draft.title -tags -title -draft.of -modified +[count[]]

<:-)

Martin

unread,
Feb 18, 2020, 8:00:12 AM2/18/20
to TiddlyWiki
Thanks, Mat.

But your proposition counts all the fields in every tiddler, and gets a result of 93 in my case. The same is when I use the maxall-operator.

How can I manage to count only the fields of the current tiddler?

Mat

unread,
Feb 18, 2020, 8:03:37 AM2/18/20
to TiddlyWiki
You can make another list, inside the first, that counts the data for the current tiddler, e.g

{{{ [<currentTiddler>fields[].......] }}}

Does this answer your need?

<:-)

Martin

unread,
Feb 18, 2020, 9:01:32 AM2/18/20
to TiddlyWiki
No, this doesn't help, I'm afraid.

In my code, I have a range to cover, and the second value of this range should be equal to the number of fields I have in the tiddler.

filter="[all[tiddlers]fields[]nsort[title]]+[range[$verse_start$,$verse_end$]]"

When I make another list with your filter expression, this will not change the range. I need a way to replace $verse_end$ by the correct number of fields.

I think you proposed a filter like this:

filter="{{{ [<currentTiddler>[fields[]] -created -text -draft.title -tags -title -draft.of -modified +[count[]] }}}

As result I get "1" in the current tiddler. But even if I would get a correct number, I still have to get the range-command to work with that number.


Mark S.

unread,
Feb 18, 2020, 10:18:39 AM2/18/20
to TiddlyWiki
Without a copy of one of your chapters, its very hard to help much.

Often people get fixated on one particular approach, without looking at the bigger picture.

Why do you need a range? Is it because you want to list all the verses?

The following will find all fields that start with a number, order them, and output the contents (assuming
it's tagged as a template tiddler and that Bible chapters are tagged as "Bible" :

<$list filter="[all[current]tag[Bible]]">
<$list filter="[
<currentTiddler>fields[]regexp[^\d+$]nsort[]]" variable=versenum>
<$transclude field=<
<versenum>>/><br/>
</$list>
</$list>

BTW, I have a version of the KJV on tiddlyspace somewhere, It has all the verses broken down into their own tiddlers.
This is probably the most "Tiddlyesque" way of doing things, because it allows you to annotate by verse, which
you will have problems doing with your approach.

For my own usage, I have a modern language Bible broken down by chapter. When I want to annotate, I use the
excision tool and a template that highlights the passage. Then I use the TW comment feature to make the
by-passage commentary. This is probably the most compact way of doing things. It also works with the
indexing that TW has had since vsn 5.1.20. I don't think numbered fields get indexed for searching, but I could
be wrong. In any event, it's only 6 megs, which means it's still usable on a cheap Kindle tablet.

HTH

Martin

unread,
Feb 19, 2020, 12:28:43 PM2/19/20
to TiddlyWiki
Thanks, Mark! Your code helped me. I combined it to this:

\define testverse()
<$tiddler tiddler={{!!title}}>

<$list filter="[<currentTiddler>fields[]regexp[^\d+$]nsort[]]" variable=versenum>

           
<tr style="background-color:Moccasin;">
               
<td style="color:blue;width:2em;text-align:center"><<versenum>> </td><td><$transclude field=<<versenum>> /></td>
           
</tr>
</
$list>
</$tiddler>
\end

As you can see in the tiddlers I join to this posting, I am working in German.

You asked why I choose to store the bible-verses in the fields of the tiddlers: When I started with TiddlyWiki, I saw there were fields, and I thought they where meant to store information inside. And, as I wrote in an earlier posting, it is easy to transclude a verse using something like {{Gen 3!!15}}. In the beginning, I used TiddlyWiki because of his ability of transclusion.

You mentioned the use of an "excision tool" – I didn't know this exists, and I still don't know how to use ist. Same with the "TW comment feature", and with indexing. Is there a place to find all these possibilities, and perhaps more? I've read a lot on TiddlyWiki.com, but often I find the documentation very short and with only some examples about Tiddly-titles, Tiddly-text and tags, if any. It is difficult to find out how to work with fields. Sometimes it is even difficult to understand how to use the different tools – there is a lack of "real world examples" in my opinion. It would be helpful to have an article describing in depth how to break down a large text to work with in a TiddlyWiki-way: linking, transclusion, annotation, citation, import and export, finding text, counting words, taging, import, export, printing, making PDF-files or HTML-pages etc. There are a few videos on youtube, and there are hour-long hangout-videos – I started to view some of these, but I didn't find them very helpful for my situation.

Would it be possible to see how you use TiddlyWiki to work with the text of the bible?

My idea is to have for each chapter of the bible a kind of loop: take one verse, retrieve cross-references, comments, annotations etc.; go to the next verse, retrieve everything related to this verse; go to the next etc. But this will take some time to develop, and a lot of try and error.

Martin
Gen 3.tid
testverse.tid

Mark S.

unread,
Feb 19, 2020, 3:24:30 PM2/19/20
to tiddl...@googlegroups.com
For the moment, you can learn about excision here:

,
To get the comment plugin, go to the control panel, click on "Plugins", get More plugins, open plugin library, then type "comments" into the search field. You can then click on and install the comments plugin.

Here's how the process goes. Open the chapter, highlight the verse you want, and use the excision button:



And here's the excision in process


This is what you end up with. You may want to change line breaks.
For my use, I use a template to change presentation:


I can post the template and stylesheet changes if you're interested. Here's how it looks in view mode:




Click on the asterisk to go to the new verse tiddler:


Click on the "add comment" button to add a comment.


HTH

Mark S.

unread,
Feb 19, 2020, 3:26:57 PM2/19/20
to TiddlyWiki
Rats. I pointed at the wrong thing in the first image. Why do I always spot the error after I post?
This is the excision button:

Martin

unread,
Feb 21, 2020, 4:59:55 AM2/21/20
to TiddlyWiki
Thanks, Mark, for the example and the explanations.

I'd like to leave the tiddlers with the text of the bible untouched — this gives me the possibility to change to another bible version, without loosing my annotations. So I work with a system of index numbers to weave everything together: each book of the bible has his number, and chapters and verses are already numbered as well. This is kind of a database-approach — perhaps you will say this isn't the tiddlywiki-way of doing things. But at the moment I think the underlaying system gives everything I need, and I will progress — slowly, because I cannot take too much time for this.

Martin


Mark S.

unread,
Feb 21, 2020, 10:57:25 AM2/21/20
to TiddlyWiki
I think the approach that is both database-driven and tiddlywiki-friendly is tiddlers by verse. The tools for filtering and editing are tiddler-oriented. Verses in fields will be somewhat opaque.

Good luck!
Reply all
Reply to author
Forward
0 new messages