Include <<< in a macro call

This macro call:

<<copy-to-clipboard-above-right '''awk '{print tolower($0)}' <<<"$VAR"'''>>

does not display or operate correctly. The cause of the problem is the <<< because removing it fixes the problem. (I can provide further details about the macro and how it misbehaves if ‘<<<’ is present, but I don’t see how it would help since the cause of the problem is known.) Using triple double quotes instead of the triple single quotes does not fix the problem. Using the macrocall widget instead results in the exact same problem occurring.

Is there any way to include a triple less-than string (<<<) in a macro call?

1 Like

Using tripled single-quotes surrounding the macro parameter value is not supported syntax for macro calls.

You CAN use tripled double-quotes around the macro parameter value; however, because the value in your example ends with a double-quote, you need to include an extra trailing space to separate it from the tripled double-quotes, like this:

<<copy-to-clipboard-above-right """awk ‘{print tolower($0)}’ <<<"$VAR" """>>

Alternatively, to avoid the extra trailing quote in the clipboard contents, you can use doubled square brackets to enclose the macro parameter value, like this:

<<copy-to-clipboard-above-right [[awk ‘{print tolower($0)}’ <<<"$VAR"]]>>

enjoy,
-e

1 Like

Hi David,
Welcome. There is some info in the linked thread below, how to use inline code and code blocks.

Thanks, Eric. I was sure in my experimenting that I’d started with tripled double quotes (with trailing space) and they had not worked, but on testing again I see it does work.

The use of doubled square brackets to avoid the trailing space appeals to my sense of neatness. I did find that you cannot include single square brackets inside a macro parameter value if you use doubled square brackets. For example, this:

<<copy-to-clipboard-above-right [[tr '[:upper:]' '[:lower:]' <<<"$VAR"]]>>

results in an abnormal appearance to the copy button and only ‘[[tr’ being copied.

Using tripled double quotes with a trailing space does work:

<<copy-to-clipboard-above-right """tr '[:upper:]' '[:lower:]' <<<"$VAR" """>>

Is there a trick to including single square brackets within a macro parameter value enclosed in doubled square brackets?

Thanks for that tip, pmario. The linked thread was helpful.

Welcome @david_nebauer to the forums

Without giving a specific answer we often move “more difficult to handle strings”, those containing part of the tiddlyWiki script language, to macros/procedures and maybe functions.

  • Rather than use the short form to call <<macros p1>> /procedures consider using the long form $macrocall or $transclude $variable.
  • copy-to-clipboard-above-right is in the doc macros or is it a custom macro?, perhaps you can redesign/create the macro so the parameters need not have such parameters passed.
  • The New substitute operator may be another approach