Re: [NTG-context] Problem Passing \starttabulate into Lua

2009-01-01 Thread Wolfgang Schuster


Am 27.12.2008 um 12:20 schrieb Tad Ashlock:

I'm trying to create a ConTeXt macro (mkiv) that will manipulate the  
macro argument's text with Lua and then feed it back into ConTeXt  
with tex.print().  My approach worked correctly until I called the  
macro with \starttabulate ... \stoptabulate in the macro's  
argument.  So I started reducing the problem down to a minimum  
example which surprisingly turned out to have nothing to do with the  
manipulations I was performing.


\long\def\testmacro#1{\directlua0{d='\luaescapestring{#1}'}}
\starttext
Hello, world!
\testmacro{%
  testing
  \starttabulate
\NC 0 \NC testing tabulate. \NC \NR
  \stoptabulate}
\stoptext


\def\testmacro#1{\ctxlua{d='\luaescapestring{\normalunexpanded{#1}}'}}

\starttext

\testmacro{\starttabulate[|l|p|] \NC knuth \NC \input knuth \NC\NR  
\stoptabulate}


\ctxlua{tex.sprint(d)}

\stoptext

Wolfgang

___
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  : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Problem Passing \starttabulate into Lua

2008-12-30 Thread Wolfgang Schuster


Am 29.12.2008 um 14:28 schrieb Wolfgang Schuster:

When I changed '\starttabulate' to '\starttabulate[|l|p|]' in your  
solution above, it broke.


Try to escape the |, it's a active character in ConTeXt but this
could work (untested):

\def\testmacro
 {\bgroup
  \catcode`\\=12
  \catcode`\|=12
  \dotestmacro}


And now with a catcode table.

% redefined version of \startcatcodetable

\long\def\startcatcodetable#1#2\stopcatcodetable
  {\bgroup
   %\catcodetable\scratchcatcodetable
   \the\setdefaultcatcodes
   #2%
   \savecatcodetable#1\relax
   \egroup}

% the new catcode table

\newcatcodetable \testcatcodes

\startcatcodetable \testcatcodes
\catcode`\\ = 12
\catcode`\| = 12
\stopcatcodetable

\def\testmacro
  {\bgroup
   \setcatcodetable\testcatcodes
   \dotestmacro}

\def\dotestmacro#1%
  {\ctxlua{d='\luaescapestring{#1}'}
   \egroup}

\starttext

\testmacro{\starttabulate[|l|p|] \NC knuth \NC \input knuth \NC\NR  
\stoptabulate}


\ctxlua{tex.sprint(d)}

\stoptext

Wolfgang

___
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  : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Problem Passing \starttabulate into Lua

2008-12-29 Thread luigi scarso


 Thank you Wolfgang!  That's certainly a step in the right direction.  But
 what I (and others?) really need is a way of passing any chunk of ConTeXt
 code into Lua.


Maybe Nodes and attributes chapter
in
mk.pdf can help you .

(see http://www.pragma-ade.nl/dir?path=general/manualss=a)


-- 
luigi
___
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  : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Problem Passing \starttabulate into Lua

2008-12-29 Thread Ashlock, Tad A
On 2008-12-28 at 15:33, Wolfgang Schuster wrote:
Am 27.12.2008 um 12:20 schrieb Tad Ashlock:
 I'm trying to create a ConTeXt macro (mkiv) that will manipulate the
 macro argument's text with Lua and then feed it back into ConTeXt
 with tex.print().  My approach worked correctly until I called the
 macro with \starttabulate ... \stoptabulate in the macro's
 argument.  So I started reducing the problem down to a minimum
 example which surprisingly turned out to have nothing to do with the
 manipulations I was performing.
[snip]

\def\testmacro
   {\bgroup
\catcode`\\=12
\dotestmacro}

\def\dotestmacro#1
   {\ctxlua{d='\luaescapestring{#1}'}%
\egroup}

\starttext

\testmacro{\starttabulate \NC text \NC text \NC\NR \stoptabulate}

%\ctxlua{tex.sprint(d)}

\stoptext

Wolfgang

Thank you Wolfgang!  That's certainly a step in the right direction.  But what 
I (and others?) really need is a way of passing any chunk of ConTeXt code into 
Lua.

When I changed '\starttabulate' to '\starttabulate[|l|p|]' in your solution 
above, it broke.

Thanks again,
Tad
___
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  : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Problem Passing \starttabulate into Lua

2008-12-29 Thread Wolfgang Schuster


Am 29.12.2008 um 13:56 schrieb Ashlock, Tad A:


On 2008-12-28 at 15:33, Wolfgang Schuster wrote:

Am 27.12.2008 um 12:20 schrieb Tad Ashlock:

I'm trying to create a ConTeXt macro (mkiv) that will manipulate the
macro argument's text with Lua and then feed it back into ConTeXt
with tex.print().  My approach worked correctly until I called the
macro with \starttabulate ... \stoptabulate in the macro's
argument.  So I started reducing the problem down to a minimum
example which surprisingly turned out to have nothing to do with the
manipulations I was performing.

[snip]


\def\testmacro
 {\bgroup
  \catcode`\\=12
  \dotestmacro}

\def\dotestmacro#1
 {\ctxlua{d='\luaescapestring{#1}'}%
  \egroup}

\starttext

\testmacro{\starttabulate \NC text \NC text \NC\NR \stoptabulate}

%\ctxlua{tex.sprint(d)}

\stoptext

Wolfgang


Thank you Wolfgang!  That's certainly a step in the right  
direction.  But what I (and others?) really need is a way of passing  
any chunk of ConTeXt code into Lua.


Everything you pass to Lua is expanded and this did not work
with macros that contain \dosingleempty (or \dodoubleempty etc.).

\def\command
  {\dosingleempty\docommand}

\def\docommand[#1]{#1}

\def\testmacro#1%
  {\ctxlua{d='\luaescapestring{#1}'}}

\starttext

\testmacro{\docommand[text]} % works

\testmacro{\command[text]} % fails

\stoptext

When I changed '\starttabulate' to '\starttabulate[|l|p|]' in your  
solution above, it broke.


Try to escape the |, it's a active character in ConTeXt but this
could work (untested):

\def\testmacro
  {\bgroup
   \catcode`\\=12
   \catcode`\|=12
   \dotestmacro}

Wolfgang

___
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  : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Problem Passing \starttabulate into Lua

2008-12-28 Thread Wolfgang Schuster


Am 27.12.2008 um 12:20 schrieb Tad Ashlock:

I'm trying to create a ConTeXt macro (mkiv) that will manipulate the  
macro argument's text with Lua and then feed it back into ConTeXt  
with tex.print().  My approach worked correctly until I called the  
macro with \starttabulate ... \stoptabulate in the macro's  
argument.  So I started reducing the problem down to a minimum  
example which surprisingly turned out to have nothing to do with the  
manipulations I was performing.


Here is the working example (without \starttabulate):

\long\def\testmacro#1{\directlua0{d='\luaescapestring{#1}'}}
\starttext
Hello, world!
\testmacro{%
  testing}
\stoptext


Here is the broken example:

\long\def\testmacro#1{\directlua0{d='\luaescapestring{#1}'}}
\starttext
Hello, world!
\testmacro{%
  testing
  \starttabulate
\NC 0 \NC testing tabulate. \NC \NR
  \stoptabulate}
\stoptext


\def\testmacro
  {\bgroup
   \catcode`\\=12
   \dotestmacro}

\def\dotestmacro#1
  {\ctxlua{d='\luaescapestring{#1}'}%
   \egroup}

\starttext

\testmacro{\starttabulate \NC text \NC text \NC\NR \stoptabulate}

%\ctxlua{tex.sprint(d)}

\stoptext

Wolfgang

___
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  : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


[NTG-context] Problem Passing \starttabulate into Lua

2008-12-27 Thread Tad Ashlock
I'm trying to create a ConTeXt macro (mkiv) that will manipulate the 
macro argument's text with Lua and then feed it back into ConTeXt with 
tex.print().  My approach worked correctly until I called the macro with 
\starttabulate ... \stoptabulate in the macro's argument.  So I started 
reducing the problem down to a minimum example which surprisingly turned 
out to have nothing to do with the manipulations I was performing.


Here is the working example (without \starttabulate):

\long\def\testmacro#1{\directlua0{d='\luaescapestring{#1}'}}
\starttext
Hello, world!
\testmacro{%
   testing}
\stoptext


Here is the broken example:

\long\def\testmacro#1{\directlua0{d='\luaescapestring{#1}'}}
\starttext
Hello, world!
\testmacro{%
   testing
   \starttabulate
 \NC 0 \NC testing tabulate. \NC \NR
   \stoptabulate}
\stoptext

Here's the output:
=
MtxRun | loading configuration for C:/context/tex/texmf/web2c from 
C:/context/tex/texmf-cache/luatex-cache/context/2fea56f92e5267d7cc9662e4d5f52e1e/trees/53ad5f8b88994bdd02baa17501789699
MtxRun | run 1: luatex 
--fmt=C:/context/tex/texmf-cache/luatex-cache/context/2fea56f92e5267d7cc9662e4d5f52e1e/formats/cont-en 
--lua=C:/context/tex/texmf-cache/luatex-cache/context/2fea56f92e5267d7cc9662e4d5f52e1e/formats/cont-en.lua 
./test.tex

(test.tex

ConTeXt  ver: 2008.10.31 13:58 MKIV  fmt: 2008.12.24  int: english/english

language   : language en is active
system : cont-new loaded
(C:/context/tex/texmf-context/tex/context/base/cont-new.tex
systems : beware: some patches loaded from cont-new.tex
(C:/context/tex/texmf-context/tex/context/base/cont-new.mkiv) 
(C:/context/tex/texmf-context/tex/context/base/cont-mtx.tex))

system : cont-fil loaded
(C:/context/tex/texmf-context/tex/context/base/cont-fil.tex
loading: Context File Synonyms
)
system : cont-sys.rme loaded
(C:/context/tex/texmf-context/tex/context/user/cont-sys.rme 
(C:/context/tex/texmf-context/tex/context/base/type-tmf.tex) 
(C:/context/tex/texmf-context/tex/context/base/type-siz.tex) 
(C:/context/tex/texmf-context/tex/context/base/type-otf.tex))

bodyfont   : 12pt rm is loaded
specials   : pdftex loaded
system : test.top loaded
(test.top) (test.tuo) (test.tuo)
systems: begin file test at line 2
! Argument of \dodoubletestempty has an extra }.
inserted text
   \par
to be read again
  }
\doifnextcharelse ...token =#1\def \!!stringa {#2}
 \def \!!stringb 
{#3}\futur...

argument testing \starttabulate
 \NC 0 \NC testing tabulate. \NC \NR 
\stopt...

\testmacro ...\directlua 0{d='\luaescapestring {#1
 }'}
l.8 \stoptabulate}

?
=

I've tried all sorts of variations on the above example including using 
\ctxlua, \startlua, \startluacode, etc.  I tried using '[[...]]' and 
'[===[...]===]' instead of \luaescapestring.  I tried \def with and 
without \long.  I tried other \start* ... \stop* commands (different 
errors, but still broken).  Plus many more variations.


At this point I'm convinced that there's something fundamental that I'm 
not understanding.  What is the general method for taking any chunk of 
ConTeXt code and passing it into Lua so that it can be written back out 
with tex.print()?


Info: running on Windows XP, SP3 -- ConTeXt: 2008.10.31 -- LuaTeX, 
Version snapshot-0.31.2-2008121200, build 1659


(The older versions of ConTeXt and LuaTeX are necessary because of the 
problem the latest Windows versions are having.  See the Serious Bug? 
thread.)


Thank you,
Tad Ashlock




___
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  : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___