send multiple words to macro without quotes?

70 views
Skip to first unread message

Dave

unread,
Apr 14, 2020, 4:19:35 PM4/14/20
to TiddlyWiki
Here's a simple macro for highlighting text:
\define h(txt) <mark>$txt$</mark>
<<h text to highlight>>


but the way I have it, it just shows "text" highlighted.

If I do this <<h 'text to highlight,>> then it works fine.


But, seeing as I'm super lazy, I was wondering if there's a way to change the macro itself to accept all the text sent to is as one blob

I tried
 \define h(txt) <mark>"$txt$"</mark>
but it just showed "text" (with yellow highlight)

Any ideas?

Thanks,
- Dave



Mark S.

unread,
Apr 14, 2020, 5:07:24 PM4/14/20
to TiddlyWiki
Here's a version that will highlight up to ten words. Just make appropriate adjustments to the macro definition and the filter to make it work for as many words as you think you'll need.

\define h(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10)
<$vars un="__">
<mark>
<$list filter="t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 +[addprefix<un>addsuffix<un>getvariable[]]" variable="myvar">
<<myvar>>
</$list>
</
mark>
</$vars>
\end


Dave

unread,
Apr 14, 2020, 5:58:38 PM4/14/20
to TiddlyWiki
Awesome, thanks!

I don't understand *exactly* how that works, especially the +[addprefix<un>addsuffix<un>getvariable[]] part, but I'm sure once I do understand it, that might be useful for other things too!!


Thanks,
- Dave

Mat

unread,
Apr 14, 2020, 6:07:58 PM4/14/20
to TiddlyWiki
I would think even this is enough:

\define h(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10) <mark>$t1$ $t2$ $t3$ etc </mark>

<:-)

Mark S.

unread,
Apr 14, 2020, 6:19:53 PM4/14/20
to TiddlyWiki
Sure, but then you have to construct a new substitution variable for each argument. With this approach, you can just copy the parameters into the filter.

Mat

unread,
Apr 14, 2020, 6:26:22 PM4/14/20
to TiddlyWiki
Mark S. wrote:
Sure, but then you have to construct a new substitution variable for each argument. With this approach, you can just copy the parameters into the filter.

...That must either be a pretty funny joke OR I have no idea what you're talking about :-)

<:-)

Mark S.

unread,
Apr 14, 2020, 7:22:11 PM4/14/20
to TiddlyWiki
\define h(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10)
<$vars un="__">
<mark>
<$list filter="t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 +[addprefix<un>addsuffix<un>getvariable[]]" variable="myvar">
<<myvar>>
</$list>
</mark>
</$vars>
\end

Notice the parts in bold blue are identical. You don't have to decorate each parameter with $dollarSigns$.
This may seem unnecessary, but you might feel differently if you wanted to highlight a two hundred word
citation.

Mat

unread,
Apr 14, 2020, 7:35:18 PM4/14/20
to TiddlyWiki
OK, you have a point!

I have a feeling the range operator should be usable here but not sure how.

<:-)

TonyM

unread,
Apr 14, 2020, 8:58:53 PM4/14/20
to TiddlyWiki
Dave,

I have gone down this path before. In various batch/command languages there is a reference for all parameters in a macro but not in tiddlywiki, but I do not see what you gain with your laziness, other than more complexity, thus work. Here are a few ways to call a macro with multiple words; I could possibly come up with half  dozen more if you want.

\define h(txt) <mark>$txt$</mark>
\define hvar() <mark>$(text)$</
mark>
\define hfield(fieldname) <mark>{{!!$fieldname$}}</mark>


<<h text to highlight>>
<<h "text in quotes">>
<<h 'text in single quotes'>>
<<h """text in triple quotes""">>
<<h txt:"text as named parameter">>
<$macrocall $name=h txt="text as named parameter in macrocall"/>


<<h """
This allows even sentences
to be passed across<br>
multiple lines in one parameter
"""
>>


<$macrocall $name=h
txt
="text as named parameter in macrocall"/>


<<hfield caption>>


<$set name=text value="Text in a specific variable name">
<<hvar>>
</$set>


Regards
Tony

Mark S.

unread,
Apr 14, 2020, 11:26:10 PM4/14/20
to TiddlyWiki


On Tuesday, April 14, 2020 at 4:35:18 PM UTC-7, Mat wrote:
I have a feeling the range operator should be usable here but not sure how.


You're right. The range operator can make the second part of the macro even simpler:

\define h(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10)
<$vars un="__">
<mark>
<$list filter="[range[10]] +[addprefix[t]addprefix<un>addsuffix<un>getvariable[]]" variable="myvar">

<<myvar>>
</$list>
</
mark>
</$vars>
\end

So now if you want to add parameters, you just need to add parameters and adjust the "range" operator to match.


TonyM

unread,
Apr 14, 2020, 11:44:32 PM4/14/20
to TiddlyWiki
Mark,

Nifty code. I still think it should be trivial for the macro code to provide an all params parameter? Then it could be enlisted.

eg; \define h(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10)

Use $t1$ $t6$ etc or $allparams$ to get every parameter in the order listed with or without a name.
Arguably if it has a name as a name="value" pair, or just "value"

But I could not raise an interest in this when I last tried. It would open up a set of possible algorithms currently a little more dificult even impossible in some cases.

Regards
Tony 

Mark S.

unread,
Apr 14, 2020, 11:50:51 PM4/14/20
to TiddlyWiki


On Tuesday, April 14, 2020 at 8:44:32 PM UTC-7, TonyM wrote:
Mark,

Nifty code. I still think it should be trivial for the macro code to provide an all params parameter? Then it could be enlisted.


You mean like in the core? Yeah that might be fun. Maybe even useful. That makes me think of another filter wish. A "tee" filter. Maybe I'll start a thread.

TonyM

unread,
Apr 15, 2020, 8:35:28 AM4/15/20
to TiddlyWiki
Tee filter?
Reply all
Reply to author
Forward
0 new messages