Hello everybody. Is there any possibility discover through Lua in ConTeXt whether it has been defined in ConTeXt source any regular TeX macros? Be enough for me any simple example or relevant link. Thanx J.Hajtmar
Jaroslav Hajtmar wrote:
Hello everybody.
Is there any possibility discover through Lua in ConTeXt whether it has been defined in ConTeXt source any regular TeX macros?
\starttext \directlua{print(token.command_name(token.create('starttext')))} \directlua{print(token.command_name(token.create('starttextx')))} \stoptext In short: if the result of command_name is "undefined_cs", the corresponding identifier is undefined (at this moment at this level). What command_name returns is a string representation of the internal command, of which there are some 140. normal macros are "call", conditionals are "if_test", box commands are "box_set", etc. There is no list of returned names in the manual, but you can generate one by something like this: \directlua{ i=0 while i<200 do v = token.command_name({i,0,0}) if not v then break end print(i, v) i=i+1 end} Alternatively, you can do this: \directlua{print(token.csname_name(token.create('starttext')))} if the returned string is empty, the command was undefined, otherwise you get the string back that you gave yourself (but with this option you don't know what kind of command it was). Best wishes, Taco
On 22-4-2010 9:15, Taco Hoekwater wrote:
Jaroslav Hajtmar wrote:
Hello everybody.
Is there any possibility discover through Lua in ConTeXt whether it has been defined in ConTeXt source any regular TeX macros?
\starttext \directlua{print(token.command_name(token.create('starttext')))} \directlua{print(token.command_name(token.create('starttextx')))} \stoptext
In short: if the result of command_name is "undefined_cs", the corresponding identifier is undefined (at this moment at this level).
What command_name returns is a string representation of the internal command, of which there are some 140. normal macros are "call", conditionals are "if_test", box commands are "box_set", etc. There is no list of returned names in the manual, but you can generate one by something like this:
\directlua{ i=0 while i<200 do v = token.command_name({i,0,0}) if not v then break end print(i, v) i=i+1 end}
Alternatively, you can do this:
\directlua{print(token.csname_name(token.create('starttext')))}
if the returned string is empty, the command was undefined, otherwise you get the string back that you gave yourself (but with this option you don't know what kind of command it was).
\starttext \startluacode function interfaces.valid_command(str) return (str and str ~= "" and token.csname_name(token.create(str)) ~= "") or false end print(interfaces.is_command()) print(interfaces.is_command("")) print(interfaces.is_command("interesting")) print(interfaces.is_command("starttext")) \stopluacode \stoptext ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
participants (3)
-
Hans Hagen
-
Jaroslav Hajtmar
-
Taco Hoekwater