Perry Smith <[email protected]> writes:
> While playing with macros, I discovered that if the argument has a
> comma, the parser thinks there are two arguments which may not be the
> intentions. It appears that the comma can be quoted with a backslash

Yes, macro arguments are comma-separated, and that can play havoc with
string arguments if one is not careful to escape commas in the string.

> but on my experimentation, that led to other frustrations. e.g. the
> bold doesn’t come out bold in the HTML.

Well, it does work in an un-nested macro. E.g., with your bold macro
from another post,

  {{{bold(Tom\, Dick\, and Harry)}}}

is exported as *Tom, Dick, and Harry* in bold.

Nested inside another macro, like your include-if, the macro

  {{{include-if(blah, {{{bold(Tom\, Dick\, and Harry)}}})}}}

results only in *Tom*. So it appears that the escaping fails in this
corner case, but it turns out it actually doesn't. I suspect that the
escaped commas in the inner macro are processed twice and are un-escaped
by the lisp processing of the outer macro. So, in the Elisp way we all
know and love, they have to be quadruple-escaped. Try this; it actually
works:

   {{{include-if(blah, {{{bold(Tom\\\\, Dick\\\\, and Harry)}}})}}}

Maybe the parser could be changed to avoid this, but I don't think it's
a bug; it's an undocumented but somewhat predictable side effect of
nesting macros. Which is something I think is best avoided if possible.
Even without the matchsticks, nested macros are ugly and hard to read.

Actually, to judge by the syntax documentation
(https://orgmode.org/worg/org-syntax.html), macros should not be able to
contain macros (or other objects) at all, since it's not specified that
they can. The syntax documentation probably needs to be corrected. But
I'm not sure exactly what objects will be parsed inside a macro (e.g.:
inline babel calls will, inline src blocks apparently not).

Ihor, if you're following this, WDYT?

> Thus my question:
>
> Can arguments to macros be enclosed in quotes of some style?

No. The quotes will be interpreted as part of the string, and unescaped
commas will still be parsed as argument separators.

Regards,
Christian

Reply via email to