# [NTG-context] interfaces.definecommand fails with brackets inside string arguments

Hans Hagen j.hagen at xs4all.nl
Tue Jul 9 12:29:57 CEST 2019

On 7/9/2019 10:37 AM, Taco Hoekwater wrote:
>
>
>> On 8 Jul 2019, at 17:18, mf <massifr at fastwebnet.it> wrote:
>>
>> Hello list,
>> i've played a bit with interfaces.definecommand, that lets you define TeX macros from lua (see the "ConTeXt Lua Documents", 7.3 User interfacing).
>>
>> I found that the commands defined by interfaces.definecommand fail when you pass string arguments that contain brackets.
>>
>> I think cldf-int.lua needs a patch to support those kind of arguments.
>
> FYI, it fails because definecommand() creates a \myCommand that is equivalent to this:
>
>    \def\myCommand#1{\ctxlua {_clmm_('myCommand',[[#1]])}}
>
> The [[…]] is the lua multi-line string syntax, like /* */ in C.
>
> So if the #1 expands into \blank[line], that produces [[\blank[line]]] resulting in a trailing extra ‘]’, which is a lua syntax error.
>
>
>>
>> In the meantime it's possible to bypass the problem passing arguments with brackets inside double braces, as in the MWE attached.
>
> Adding a space at the end also works, but a core patch makes sense to me.
i'll re-implment it in a more modern way

Hans

-----------------------------------------------------------------