[tw5] Railroad plugin: one way to setup a tiddler transclusion template

I’m documenting two BASIC Anywhere Machine functions: MIN and MAX .

I’m using the railroad plugin to describe syntax.

MIN and MAX having identical syntax (and I’ve got many other cases like this), I wanted to define the railroad diagram once for both the MIN and MAX tiddlers.

I created a template tiddler called “Syntax MIN MAX” that has the following text:

!! Syntax

<$railroad text={{{
[<currentTiddler>addprefix["]addsuffix["]]
[["("<"numValue1">]]
[[","]]
[[<"numValue2">]]
[[")"]]
+[join[]]
}}}>

Both my MIN and my MAX tiddlers have the following in their text:

{{||Syntax MIN MAX}}

I could have kept things simple by defining the one railroad diagram with it displaying required choice of MIN or MAX, but I did not like the look of that at all.

If you have an approach you think is simpler than the one described above, please let everybody know about it.

Aside: I do not much like the CSS styling of the diagrams, so I’ve started dabbling with some easy customisation (colour and font weight):

Screenshot 2023-06-18 6.52.35 PM.png

Here is one I find simpler (YMMV):

<$railroad text={{{
[["]addsuffix<currentTiddler>addsuffix["]]
[["(" <"numValue1"> "," <"numValue2"> ")"]]
+[join[]]
}}}/>

and a slight variation:

<$railroad text={{{
[["]] [<currentTiddler>] =[["]]
[["(" <"numValue1"> "," <"numValue2"> ")"]]
+[join[]]
}}}/>

For me the first line in each of the above read slightly easier than that addprefix/addsuffix combination since I don’t need to mentally re-order anything. And having all the quoting together in a single line (2nd line in each of the above) I found it easier to read since at a glance I can tell everything on that line is part of one static string.

Maybe these small tweaks aren’t what you had in mind, but I thought I’d share in case it helps.

Also, the future 5.3 version of Tiddlywiki might introduce substitution within attribute values: https://tiddlywiki5-git-fork-saqimtiaz-textsubstitution-jermolene.vercel.app/#Substituted%20Attribute%20Values. With that feature, you could do this:

<$railroad text=`"$(currentTiddler)$" "(" <"numValue1"> "," <"numValue2">")"`/>

I know Charlie has a self-imposed policy not to upgrade past 5.2.3, so this last one is for others who might be interested.

Definitely more concise with fewer square brackets going on.

My challenge is it makes it harder to make a one-to-one relationship between the “bubbles” in the diagram and the pieces related to the bubbles. Kind of like I’m playing a game of “Where’s Waldo”.

But that’s part and parcel of my cognitive disability.

I think loads of folk would appreciate your less verbose approach. Thanks !

Looking back at my OP, it became a game of Where’s Waldo because of a mismatch between the number of lines in the macrocall and number of nodes in the railroad diagram.

The fix:

!! Syntax

<$railroad text={{{
[<currentTiddler>addprefix["]addsuffix["]]
[["("]]
[[<"numValue1">]]
[[","]]
[[<"numValue2">]]
[[")"]]
+[join[]]
}}}>

1 Like

Delayed reaction:

I do very much like this, though:

[["]] [<currentTiddler>] =[["]]

I rarely run into de-duplication issues, so I keep forgetting about that “x-nay de-duplication, eh?” prefix.

I’ve got to figure out a way to remember that.

1 Like

The only way for me to remember that “=” prefix, I think, is by applying it often.

Taking Brian’s approach to simplify things by dumping addsuffix and addprefix:

<$railroad text={{{
=[["]] =[<currentTiddler>] =[["]]
=[["("]]
=[[<"numValue1">]]
=[[","]]
=[[<"numValue2">]]
=[[")"]]
+[join[]]
}}}>
1 Like

Incrementally and iteratively, getting to Railroad Diagram ZEN.

A barebones-beginning railroad diagram editor tagged as $:/tags/ViewTemplate, with one edit text field to enter the railroad diagram text, and the other edit field to describe the bits in the diagram.

The macros to transclude the diagram, to transclude the description, and to transclude a “Syntax” documentation block:

\define myRdg()
<div style="width:96%; height:88px;border:1px solid black;overflow:auto;resize:horizontal;">
<div style="width:800px;">
<$wikify name=this_text text={{!!rdg}}>
<$railroad text=<<this_text>>/>
</$wikify>
</div>
</div>
\end
\define myRdgDesc()
{{!!rdg_desc}}
\end
\define myRdgAll()
!! Syntax
<<myRdg>>
<<myRdgDesc>>
\end

The result: