Hello Hans, thank you for explanation and the nice how-to solution! Best regards, Lukas
Because the macro actually *is* defined: as soon as tex sees
\foo
it reserves the name and gives it the meaning undefined, so even \undefined is defined.
Anyway, that is why we have \ifdefined that does a different kind of checking. In retrospect, that is a better one, so I'll adapt that in lmtx.
\starttext \let\MyMacroA\undefined
\startluacode local function whatever(s) context.type("\\" .. s) context(" is " .. (tokens.defined(s,true) and "defined" or "undefined")) --% Hans' way context(" and has meaning " .. (tokens.defined(s) and "defined" or "undefined")) --% Hans' way context.par() end
whatever("MyMacroA") whatever("MyMacroB") \stopluacode
\stoptext
\MyMacroA is defined and has meaning undefined \MyMacroB is undefined and has meaning undefined
You can do this in current luatex/mkiv:
if CONTEXTLMTXMODE == 0 then
local d = tokens.defined local c = tokens.create
function tokens.defined(s,b) if b then return d(s) else return c(s).cmd_name == "undefined_cmd" end end
end
Hans