ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Testing TeX macros through Lua
@ 2010-04-22 14:17 Jaroslav Hajtmar
  2010-04-22 19:15 ` Taco Hoekwater
  0 siblings, 1 reply; 3+ messages in thread
From: Jaroslav Hajtmar @ 2010-04-22 14:17 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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


___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Testing TeX macros through Lua
  2010-04-22 14:17 Testing TeX macros through Lua Jaroslav Hajtmar
@ 2010-04-22 19:15 ` Taco Hoekwater
  2010-04-23 17:23   ` Hans Hagen
  0 siblings, 1 reply; 3+ messages in thread
From: Taco Hoekwater @ 2010-04-22 19:15 UTC (permalink / raw)
  To: hajtmar, mailing list for ConTeXt users

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
___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Testing TeX macros through Lua
  2010-04-22 19:15 ` Taco Hoekwater
@ 2010-04-23 17:23   ` Hans Hagen
  0 siblings, 0 replies; 3+ messages in thread
From: Hans Hagen @ 2010-04-23 17:23 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Taco Hoekwater

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
-----------------------------------------------------------------
___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-04-23 17:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-22 14:17 Testing TeX macros through Lua Jaroslav Hajtmar
2010-04-22 19:15 ` Taco Hoekwater
2010-04-23 17:23   ` Hans Hagen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).