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
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to