Help needed to create a cloze macro

I have been playing with the sticky macro of stobot and ToDo macro of JanJo to create a cloze macro based on a similar concept. It is little more complicated than those two. So I need someone to help me out (I had posted regarding this before also, but that thread didn’t get much response. Must be because I was unable to convey clearly what I was trying to do. Hope someone can help me this time. I have tried to make the concept more clearer this time).

Here is what I am trying to do.

Based on the sticky <<sticky "" >> macro and ToDo <<ToDo "" "" "" >> macro, I am making a cloze macro (Clozes are a type of flashcards used for learning purpose). I wrap some portions of the tiddler text in the cloze macro and using some CSS, I am keeping this wrapped text hidden (although there will be a red underline which act as a marker for the clozes). Also this hidden text gets revealed while hovering over it. This is the concept of clozes I am trying. This much I can do without much fuss by just swapping the names in the code for sticky or ToDo macro.

This is how it looks in edit mode.

This is how it looks in view mode.

Now coming to the complicated part. I want to add answer buttons for these clozes. Answer buttons I am taking directly from anwiki - see this example question and answer from anwiki and this is the code for those answer buttons from anwiki. This include some complex calculations which I don’t understand fully, so I am using it without any modifications.

On clicking the clozes in viewmode, a modal appears (like in JanJo’s ToDo) which show these answer buttons (easy, good, hard, again).

image

In Anwiki the answer response is stored in tiddler fields of the question answer tiddler- see the fields of this example tiddler. But in cloze macro I am trying to save these as dynamic parameters of the cloze macro whose values change with the type of answer response. quality, ef, repetiton, due are the macro parameters used and are again taken from anwiki - see this macro.

My concept is more based on JanJo’s ToDo more than stobot’s sticky macro since mine involves more macro parameters.

Now coming to the roadblocks I am encountering.

I am able to apply the cloze macro to selected text (I use context menu plug in for easily applying the macro in view mode). Then I try to answer them by clicking on the answer buttons in the modal (modal is invoked by clicking on the hidden text). The dynamic parameters will get first stored in the fields of a temporary tiddler called $:/temp/clozeinfos when an answer button is clicked- which works. The problem I am facing is that although the values for dynamic parameters are getting saved in the fields of a temporary tiddler called $:/temp/clozeinfos , they are not getting saved in as macro parameters in the cloze macro wrapped around each text.

This macro uses search-replace operator. The input or output for the search-replace operator is also supposed to be saved in the fields of the $:/temp/clozeinfos I guess (I am not sure though), but this is not happening. Also the search and replace function is not happening in the cloze macro.

Can someone help me out. I have been working on this for the last one week , but couldn’t find a solution. I am almost exhausted.

@EricShulman When I saw the development thread of sticky macro by stobot, I fiound that it was you who gave him the suggestion to use the search replace operator. Can you check what is going wrong ? This is the demo I made. Most of the code related to this macro is in these two tiddlers - macro and modal.
This the temp tiddler which stores the parameter values and this is an example cloze

The relevant code in the cloze macro tiddler lies in the bottom half of that tiddler.

Somehow I was able to get the search and replace working with the macro parameters changing with the change in the type of answer response. I don’t know when it will fail. The culprit was the list filter used.

<$tiddler tiddler="$:/temp/clozeinfos" >

I changed it to

<$tiddler tiddler=<<object>> >

And some more modifications were made in the macro and modal code. Here is the wiki.

Now I have to work on a flashcard home.

1 Like

I was trying to create separate state tiddlers to save the spaced repetition related data of each cloze.

I defined the title of these state tiddler as shown below ( txt is the selected text )

\define clozestate()  $:/state/cloze/info/$(currentTiddler)$/$(txt)$

and its working.

Now I want to use the spaced repetition parameters stored in the fields of this state tiddler (like quality, ef, repetition, due) in another macro.

The previously used macro definition is given below

\define outcloze() <<cloze "{{$:/temp/clozeinfos!!txt}}" "quality={{!!quality}}" "ef={{!!ef}}" "repetition={{!!repetition}}" "due={{!!due}}">>

Instead I want to use the fields (quality, ef, repetition, due) of the new state tiddlers $:/state/cloze/info/$(currentTiddler)$/$(txt)$ aka <<clozestate>> in the above given macro. This is what I tried

\define clozestatetxt() {{<<clozestate>>!!txt}}
\define clozestatequality() {{<<clozestate>>!!quality}}
\define clozestateef() {{<<clozestate>>!!ef}}
\define clozestaterepetition() {{<<clozestate>>!!repetition}}
\define clozestatedue() {{<<clozestate>>!!due}}
\define outcloze() <<cloze "<<clozestatetxt>>" "<<clozestatequality>>" "<<clozestateef>>" "<<clozestaterepetition>>" "<<clozestatedue>>">>

Is this the way to do it?

\define againQuality() 0
\define hardQuality() 2
\define goodQuality() 4
\define easyQuality() 5
\define updateEasynessFactor()
    IF(gt(<<quality>>,<<againQuality>>), clamp({{!!ef}}-0.8+0.28*<<quality>>-0.02*<<quality>>*<<quality>>,1.3,2.5), {{!!ef}})
\end
\define updateRepetitionCount()
    IF(gt(<<quality>>,<<againQuality>>),{{!!repetition}} + 1, 1)
\end
\define updateDueDate()
    to_tw_date(add_days(now(),<<repetition>>))
\end
\define updateActions()
<!-- UPDATE question parameters -->
<$formula-vars ef=<<updateEasynessFactor>>>
    <$action-setfield $field="ef" $value=<<ef>>/>
    <$formula-vars repetition=<<updateRepetitionCount>>>
        <$action-setfield $field="repetition" $value=<<repetition>>/>
        <$formula-vars due=<<updateDueDate>>>
            <$action-setfield $field="due" $value=<<due>>/>
        </$formula-vars>
    </$formula-vars>
</$formula-vars>

This is a macro taken from anwiki to update the spaced repetion parameters stored in the tiddler fields.
I want to modify this code in such a way that the fields quality,ef,repetition,due of the $:/state/cloze/info/$(currentTiddler)$/$(txt)$ aka <<clozestate>> is updated instead of the currentTiddler as shown in the code given above

I modified it like given below, but its not working.

\define againQuality() 0
\define hardQuality() 2
\define goodQuality() 4
\define easyQuality() 5
\define clozestate()  $:/state/cloze/info/$(currentTiddler)$/$(txt)$
\define clozestatequality() {{<<clozestate>>!!quality}}
\define clozestateef() {{<<clozestate>>!!ef}}
\define clozestaterepetition() {{<<clozestate>>!!repetition}}
\define clozestatedue() {{<<clozestate>>!!due}}
\define updateEasynessFactor()
    IF(gt(<<quality>>,<<againQuality>>), clamp(<<clozestateef>>-0.8+0.28*<<quality>>-0.02*<<quality>>*<<quality>>,1.3,2.5), <<clozestateef>>)
\end
\define updateRepetitionCount()
    IF(gt(<<quality>>,<<againQuality>>),<<clozestaterepetition>> + 1, 1)
\end
\define updateDueDate()
    to_tw_date(add_days(now(),<<clozestaterepetition>>))
\end
\define updateActions()
<!-- UPDATE question parameters -->
<$formula-vars ef=<<updateEasynessFactor>>>
    <$action-setfield tiddler=<<clozestate>> $field="ef" $value=<<ef>>/>
    <$formula-vars repetition=<<updateRepetitionCount>>>
        <$action-setfield tiddler=<<clozestate>> $field="repetition" $value=<<repetition>>/>
        <$formula-vars due=<<updateDueDate>>>
            <$action-setfield tiddler=<<clozestate>> $field="due" $value=<<due>>/>
        </$formula-vars>
    </$formula-vars>
</$formula-vars>

All the field references you want to change are pointing at the currentTiddler (e.g., {{!!qualify}}, {{!!ef}}, etc.).
Instead of changing all those references, just wrap the relevant code inside a $tiddler widget, like this:

\define updateActions()
<$tiddler tiddler=<<clozestate>>>
<$formula ...>
...etc..
1 Like
\define outend() "{{$:/temp/clozeinfos!!txt}}" "quality={{!!quality}}" "ef={{!!ef}}" "repetition={{!!repetition}}" "due={{!!due}}">>
\define outcloze() <<cloze "{{$:/temp/clozeinfos!!txt}}" "quality={{!!quality}}" "ef={{!!ef}}" "repetition={{!!repetition}}" "due={{!!due}}">>
\define outdone() <<cloze-done "{{$:/temp/clozeinfos!!txt}}" "quality={{!!quality}}" "ef={{!!ef}}" "repetition={{!!repetition}}" "due={{!!due}}">>

This code also I want to point to the tiddler=<<clozestate>>
Can this code also be wrapped in the tiddler widget ?
How to do it ?

\define updateEasynessFactor()
    IF(gt(<<quality>>,<<againQuality>>), clamp({{!!ef}}-0.8+0.28*<<quality>>-0.02*<<quality>>*<<quality>>,1.3,2.5), {{!!ef}})
\end
\define updateRepetitionCount()
    IF(gt(<<quality>>,<<againQuality>>),{{!!repetition}} + 1, 1)
\end
\define updateDueDate()
    to_tw_date(add_days(now(),<<repetition>>))
\end

Each of these also should be wrapped in the tiddler widget?

All of these macros are called from within updateActions(). Thus, they should all automatically be applied to whatever the currentTiddler title is set to by the $tiddler macro.

1 Like

I will test it out when I am back on my desktop. Thankyou for your help @EricShulman

I was not able to get everything working due to the large no of complex codes involved. I am stopping this project temporarily. I wasted many days working for a solution. Will re try after some gap. Thanks for the help you provided.