Re: [NTG-context] printing tab in lua: print('a\tb') fails

2008-11-27 Thread Hans Hagen
Mojca Miklavec wrote:
 Hello,
 
 Here's a tiny question. The following command complains about
 undefined control sequence.
 
 \starttext
 \startluacode
 print('a\tb')

print('a\\tb')

 \stopluacode
 hello
 \stoptext

-
   Hans Hagen | PRAGMA ADE
   Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
  tel: 038 477 53 69 | fax: 038 477 53 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  : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] printing tab in lua: print('a\tb') fails

2008-11-27 Thread Mojca Miklavec
On Wed, Nov 26, 2008 at 8:28 PM, Wolfgang Schuster wrote:

 Am 26.11.2008 um 20:07 schrieb Mojca Miklavec:

 Hello,

 Here's a tiny question. The following command complains about
 undefined control sequence.

 \starttext
 \startluacode
 print('a\tb')

 print('a\t b')

But then I get some unwanted space.

 \stopluacode
 hello
 \stoptext

 There is a workaround:
print(string.format('a\t%s', 'b'))
 but I find it weird. Even if the line above gets commented out with
 two dashes it still complains.

 I understand approximately why this happens, but is that intended?
 Should I be using something else than \startluacode in the plethora of
 different lua triggering commands?

 \start/stopluacode is defined as \startluacode#1\stopluacode
 (simplified) and you should take care of TeXs parsing rules.

 If you want Lua comments and format command (\n, \t ...) use
 a external file for your Lua code.

OK, I will use external files next time. In this quick-and-dirty
approach I just added string.format since it was easier than
restructuring everything.

I thought that \startluacode should be behaving the same way as
verbatim environments where commands inside verbatim have no
influence, but apparently I was wrong.

Thanks,
  Mojca
___
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] printing tab in lua: print('a\tb') fails

2008-11-27 Thread luigi scarso
 OK, I will use external files next time. In this quick-and-dirty
 approach I just added string.format since it was easier than
 restructuring everything.

 I thought that \startluacode should be behaving the same way as
 verbatim environments where commands inside verbatim have no
 influence, but apparently I was wrong.

I also think so.
Can be strange, but inside a \startluacode\stopluacode I have no problems to
think at -- as comment
while I have problems to think to % as comment

And put lua code in a separate  file not always  is a good solution


-- 
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] printing tab in lua: print('a\tb') fails

2008-11-27 Thread Wolfgang Schuster
On Thu, Nov 27, 2008 at 9:29 AM, Mojca Miklavec
[EMAIL PROTECTED] wrote:
 On Wed, Nov 26, 2008 at 8:28 PM, Wolfgang Schuster wrote:

 Am 26.11.2008 um 20:07 schrieb Mojca Miklavec:

 Hello,

 Here's a tiny question. The following command complains about
 undefined control sequence.

 \starttext
 \startluacode
 print('a\tb')

 print('a\t b')

 But then I get some unwanted space.

print('a\string\tb')

 \stopluacode
 hello
 \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] printing tab in lua: print('a\tb') fails

2008-11-27 Thread Wolfgang Schuster
On Thu, Nov 27, 2008 at 9:42 AM, luigi scarso [EMAIL PROTECTED] wrote:



 OK, I will use external files next time. In this quick-and-dirty
 approach I just added string.format since it was easier than
 restructuring everything.

 I thought that \startluacode should be behaving the same way as
 verbatim environments where commands inside verbatim have no
 influence, but apparently I was wrong.

 I also think so.
 Can be strange, but inside a \startluacode\stopluacode I have no problems to
 think at -- as comment
 while I have problems to think to % as comment

 And put lua code in a separate  file not always  is a good solution

This would be really great, \start/stoplua with % for comments like \ctxlua
and \start/stopluacode with -- as comment, the first is used for longer settings
in macros and the second for inline functions.

@Luigi: You could try to parse the luacode content with Lpeg and with
the result back to \directlua.

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] printing tab in lua: print('a\tb') fails

2008-11-27 Thread luigi scarso
On Thu, Nov 27, 2008 at 10:02 AM, Wolfgang Schuster 
[EMAIL PROTECTED] wrote:

 On Thu, Nov 27, 2008 at 9:42 AM, luigi scarso [EMAIL PROTECTED]
 wrote:
 
 
 
  OK, I will use external files next time. In this quick-and-dirty
  approach I just added string.format since it was easier than
  restructuring everything.
 
  I thought that \startluacode should be behaving the same way as
  verbatim environments where commands inside verbatim have no
  influence, but apparently I was wrong.
 
  I also think so.
  Can be strange, but inside a \startluacode\stopluacode I have no problems
 to
  think at -- as comment
  while I have problems to think to % as comment
 
  And put lua code in a separate  file not always  is a good solution

 This would be really great, \start/stoplua with % for comments like \ctxlua
 and \start/stopluacode with -- as comment, the first is used for longer
 settings
 in macros and the second for inline functions.

 @Luigi: You could try to parse the luacode content with Lpeg and with
 the result back to \directlua.


Better to study
luat-ini.tex
first

-- 
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] printing tab in lua: print('a\tb') fails

2008-11-27 Thread Hans Hagen
luigi scarso wrote:
 
 Correction:
 
 -- works as comments in luacode
 % is used to format strings
 
 
 
 It's a bit different: code below is ok, and TeX comment is seen before 
 lua comment .
 Only Hello! is print on pdf
 
 %%
  \def\Foo{%
 \startluacode
 -- this is a lua comment
 %%  this is a TeX comment
 \stopluacode
 }

sure, since you use a \def which then stores catcodes as they are in tex 
mode

\startluacode
function document.luigishouldknowbetter(whatever)
for i=1,100 do
print(whatever) -- this is a lua comment
end
end
\stopluacode

\def\Foo
   {\ctxlua{document.luigishouldknowbetter(Hello world!)}}


-
   Hans Hagen | PRAGMA ADE
   Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
  tel: 038 477 53 69 | fax: 038 477 53 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  : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] printing tab in lua: print('a\tb') fails

2008-11-27 Thread luigi scarso
On Thu, Nov 27, 2008 at 1:03 PM, Hans Hagen [EMAIL PROTECTED] wrote:

 luigi scarso wrote:
 
  Correction:
 
  -- works as comments in luacode
  % is used to format strings
 
 
 
  It's a bit different: code below is ok, and TeX comment is seen before
  lua comment .
  Only Hello! is print on pdf
 
  %%
   \def\Foo{%
  \startluacode
  -- this is a lua comment
  %%  this is a TeX comment
  \stopluacode
  }

 sure, since you use a \def which then stores catcodes as they are in tex
 mode

 \startluacode
function document.luigishouldknowbetter(whatever)
for i=1,100 do
print(whatever) -- this is a lua comment
end
end
 \stopluacode

 \def\Foo
   {\ctxlua{document.luigishouldknowbetter(Hello world!)}}


Exactly.
In my opinion, this is better than my example, because I don't like to mix
things  (and also for namespace document).


-- 
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] printing tab in lua: print('a\tb') fails

2008-11-27 Thread luigi scarso


 Correction:

 -- works as comments in luacode
 % is used to format strings



It's a bit different: code below is ok, and TeX comment is seen before lua
comment .
Only Hello! is print on pdf

%%
 \def\Foo{%
\startluacode
-- this is a lua comment
%%  this is a TeX comment
\stopluacode
}

\starttext
Hello !
\Foo
\stoptext
%%%




This is wrong

%%
\starttext
Hello !
\startluacode
-- this is a lua comment
%%  this is a TeX comment
\stopluacode
\stoptext
%%%



! LuaTeX error main ctx instance:3: unexpected symbol near '%'.
\@@expanded ... comment
%% this is a TeX comment
}

l.6 \stopluacode

?




-- 
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] printing tab in lua: print('a\tb') fails

2008-11-27 Thread Hans Hagen
Mojca Miklavec wrote:

 I thought that \startluacode should be behaving the same way as
 verbatim environments where commands inside verbatim have no
 influence, but apparently I was wrong.

no, more like MPcode where one can mix things

if the luacode would not expand macros, then we'd need rather tricky 
code when we'd like to have tex put stuff in there


\startluacode
 print('a\string\tb')
\stopluacode

Hans

-
   Hans Hagen | PRAGMA ADE
   Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
  tel: 038 477 53 69 | fax: 038 477 53 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  : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] printing tab in lua: print('a\tb') fails

2008-11-26 Thread Wolfgang Schuster

Am 26.11.2008 um 20:07 schrieb Mojca Miklavec:

 Hello,

 Here's a tiny question. The following command complains about
 undefined control sequence.

 \starttext
 \startluacode
 print('a\tb')

print('a\t b')

 \stopluacode
 hello
 \stoptext

 There is a workaround:
print(string.format('a\t%s', 'b'))
 but I find it weird. Even if the line above gets commented out with
 two dashes it still complains.

 I understand approximately why this happens, but is that intended?
 Should I be using something else than \startluacode in the plethora of
 different lua triggering commands?

\start/stopluacode is defined as \startluacode#1\stopluacode
(simplified) and you should take care of TeXs parsing rules.

If you want Lua comments and format command (\n, \t ...) use
a external file for your Lua code.

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
___