ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* TeX expansion within lua
@ 2012-09-04 15:12 Marco Patzer
  2012-09-04 15:28 ` Aditya Mahajan
  2012-09-04 17:06 ` Martin Schröder
  0 siblings, 2 replies; 11+ messages in thread
From: Marco Patzer @ 2012-09-04 15:12 UTC (permalink / raw)
  To: context

Hi,

please have a look at the following example:

\starttext

\def\cmd{%
  \def\mymacro{Foobar}
  \newtoks\mytoks
  \mytoks={mytoks}}

\startluacode
  context.cmd()
  context.mymacro()
  -- this fails
  -- context(tex.toks.mytoks)
\stopluacode

-- this works
\startluacode
  context(tex.toks.mytoks)
\stopluacode

\stoptext

Why does the first call to tex.toks.mytoks fail?

Apparently the luacode environment has to be closed for cmd to be
expanded. I guess that the call to mymacro() succeeds is a quirk due
to the face that the macro is expanded later, in contrast to tokens,
dimens and counters.

Is there a command I can use within Lua to expand a macro
immediately or to expand the pending macros to be able to access the
values like the token register in the example?


Another question which is related:

Is there a way to access the contents of the macro from within Lua
like counters and token registers?

\starttext

\newtoks\mytoks
\mytoks={Foobar}

\startluacode
  local tok = tex.toks.mytoks

  -- something like this is what I have in mind
  -- local mac = tex.macros.somemacro
\stopluacode

\stoptext

I am just interested in a text string, not a box with typeset
material. I guess that's more difficult, since macros are expanded
and not just simply read.


Marco

___________________________________________________________________________________
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] 11+ messages in thread

end of thread, other threads:[~2012-09-05  9:42 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-04 15:12 TeX expansion within lua Marco Patzer
2012-09-04 15:28 ` Aditya Mahajan
2012-09-04 16:54   ` Marco Patzer
2012-09-04 17:06 ` Martin Schröder
2012-09-04 17:40   ` Marco Patzer
2012-09-04 17:53     ` Wolfgang Schuster
2012-09-04 18:11       ` Marco Patzer
2012-09-04 18:25         ` Wolfgang Schuster
2012-09-04 18:58           ` Marco Patzer
2012-09-05  9:18     ` Hans Hagen
2012-09-05  9:42       ` Marco Patzer

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).