inluding macros

50 views
Skip to first unread message

Jean-Pierre Rivière

unread,
Apr 8, 2021, 6:57:40 AM4/8/21
to TiddlyWiki
Macro should be at the beginning of a tiddler before anything else.

IMHO there could be an exception: including macros.

Here is my use case: I'm writing a tutorial/how-to about difficulties in TW programming. I illustrate my points with sample macros. I want to show the code within my articles and expose the output of invoicing the macros there as well.

I don't want to copy-paste the code. This is not pedagogic and prone to errors.

I know how to do this for code which does not include macros.

For code with macro definitions, my how-to tiddler would begin by

{{my-sample-macros]]

which would be replaced by

\define foo() bar

which would be OK as far as macro definitions is concerned IF my exception was an implemented feature.

Now' There could be a way around if there is a mean to dynamically create a new tiddler with the include already done, a tiddler that I would use for viewing, keeping the tiddler with the macro-including-start as a source of my tiddler. I have not yet explored that way as I am deeply ignorant about dynamic creation of tiddlers yet.

-- 
Jean-Pierre

Jean-Pierre Rivière

unread,
Apr 8, 2021, 7:09:59 AM4/8/21
to TiddlyWiki
On solution to my problem is to tag my sample macro tiddler as a system macro.

But this has the problems that its macros are now public and their names must now be made unique.

I can do that by calling my macro as demo-for-this-and-that instead of just macros (including helpers macros, which would clutter my main macro code).

and at the beginning of my how to tiddler I would add:

\define  demo(foo:bar etc) <<demo-for-this-and-that foo etc>>

not very nice neither very practical but the best I could do so far.

-- 
Jean-Pierre

Eric Shulman

unread,
Apr 8, 2021, 7:15:58 AM4/8/21
to TiddlyWiki
On Thursday, April 8, 2021 at 4:09:59 AM UTC-7 jn.pierr...@gmail.com wrote:
On solution to my problem is to tag my sample macro tiddler as a system macro.
But this has the problems that its macros are now public and their names must now be made unique.

To avoid creating global macros, you can use the \import pragma at the start of the tiddler,
or use <$importvariables filter="...">...</$importvariables> widget surrounding the desired content.


-e

Jean-Pierre Rivière

unread,
Apr 8, 2021, 7:55:23 AM4/8/21
to TiddlyWiki
Many thanks Eric. \import works fine here.

I'll be using it for helper macros required by system-wide true macros. That will help clean things. a declaration akin to private for a macro would be a lot better though.

Also, when I looked at pragma, it mentions \rules which is used in https://tiddlywiki.com/static/Using%2520Stylesheets.html with arguments. It's still not much documentation although it's worthwhile reading. Where could I fetch some more information about \rules (its grammar, its parameters, its use cases)  ?
Reply all
Reply to author
Forward
0 new messages