ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* printing tab in lua: print('a\tb') fails
@ 2008-11-26 19:07 Mojca Miklavec
  2008-11-26 19:28 ` Wolfgang Schuster
  2008-11-27  8:13 ` Hans Hagen
  0 siblings, 2 replies; 13+ messages in thread
From: Mojca Miklavec @ 2008-11-26 19:07 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hello,

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

\starttext
\startluacode
print('a\tb')
\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?

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
___________________________________________________________________________________


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

* Re: printing tab in lua: print('a\tb') fails
  2008-11-26 19:07 printing tab in lua: print('a\tb') fails Mojca Miklavec
@ 2008-11-26 19:28 ` Wolfgang Schuster
  2008-11-27  8:29   ` Mojca Miklavec
  2008-11-27  8:13 ` Hans Hagen
  1 sibling, 1 reply; 13+ messages in thread
From: Wolfgang Schuster @ 2008-11-26 19:28 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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
___________________________________________________________________________________


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

* Re: printing tab in lua: print('a\tb') fails
  2008-11-26 19:07 printing tab in lua: print('a\tb') fails Mojca Miklavec
  2008-11-26 19:28 ` Wolfgang Schuster
@ 2008-11-27  8:13 ` Hans Hagen
  1 sibling, 0 replies; 13+ messages in thread
From: Hans Hagen @ 2008-11-27  8:13 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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
___________________________________________________________________________________


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

* Re: printing tab in lua: print('a\tb') fails
  2008-11-26 19:28 ` Wolfgang Schuster
@ 2008-11-27  8:29   ` Mojca Miklavec
  2008-11-27  8:42     ` luigi scarso
                       ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Mojca Miklavec @ 2008-11-27  8:29 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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
___________________________________________________________________________________


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

* Re: printing tab in lua: print('a\tb') fails
  2008-11-27  8:29   ` Mojca Miklavec
@ 2008-11-27  8:42     ` luigi scarso
  2008-11-27  9:02       ` Wolfgang Schuster
  2008-11-27  8:50     ` Wolfgang Schuster
  2008-11-27 10:04     ` Hans Hagen
  2 siblings, 1 reply; 13+ messages in thread
From: luigi scarso @ 2008-11-27  8:42 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 577 bytes --]

> 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

[-- Attachment #1.2: Type: text/html, Size: 870 bytes --]

[-- Attachment #2: Type: text/plain, Size: 487 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

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

* Re: printing tab in lua: print('a\tb') fails
  2008-11-27  8:29   ` Mojca Miklavec
  2008-11-27  8:42     ` luigi scarso
@ 2008-11-27  8:50     ` Wolfgang Schuster
  2008-11-27 10:04     ` Hans Hagen
  2 siblings, 0 replies; 13+ messages in thread
From: Wolfgang Schuster @ 2008-11-27  8:50 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Thu, Nov 27, 2008 at 9:29 AM, Mojca Miklavec
<mojca.miklavec.lists@gmail.com> 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
___________________________________________________________________________________


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

* Re: printing tab in lua: print('a\tb') fails
  2008-11-27  8:42     ` luigi scarso
@ 2008-11-27  9:02       ` Wolfgang Schuster
  2008-11-27  9:28         ` luigi scarso
  2008-11-27 10:17         ` Wolfgang Schuster
  0 siblings, 2 replies; 13+ messages in thread
From: Wolfgang Schuster @ 2008-11-27  9:02 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Thu, Nov 27, 2008 at 9:42 AM, luigi scarso <luigi.scarso@gmail.com> 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
___________________________________________________________________________________


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

* Re: printing tab in lua: print('a\tb') fails
  2008-11-27  9:02       ` Wolfgang Schuster
@ 2008-11-27  9:28         ` luigi scarso
  2008-11-27 10:17         ` Wolfgang Schuster
  1 sibling, 0 replies; 13+ messages in thread
From: luigi scarso @ 2008-11-27  9:28 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 1174 bytes --]

On Thu, Nov 27, 2008 at 10:02 AM, Wolfgang Schuster <
schuster.wolfgang@googlemail.com> wrote:

> On Thu, Nov 27, 2008 at 9:42 AM, luigi scarso <luigi.scarso@gmail.com>
> 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

[-- Attachment #1.2: Type: text/html, Size: 1730 bytes --]

[-- Attachment #2: Type: text/plain, Size: 487 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

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

* Re: printing tab in lua: print('a\tb') fails
  2008-11-27  8:29   ` Mojca Miklavec
  2008-11-27  8:42     ` luigi scarso
  2008-11-27  8:50     ` Wolfgang Schuster
@ 2008-11-27 10:04     ` Hans Hagen
  2 siblings, 0 replies; 13+ messages in thread
From: Hans Hagen @ 2008-11-27 10:04 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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
___________________________________________________________________________________


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

* Re: printing tab in lua: print('a\tb') fails
  2008-11-27  9:02       ` Wolfgang Schuster
  2008-11-27  9:28         ` luigi scarso
@ 2008-11-27 10:17         ` Wolfgang Schuster
  2008-11-27 11:48           ` luigi scarso
  1 sibling, 1 reply; 13+ messages in thread
From: Wolfgang Schuster @ 2008-11-27 10:17 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Thu, Nov 27, 2008 at 10:02 AM, Wolfgang Schuster
<schuster.wolfgang@googlemail.com> wrote:
> On Thu, Nov 27, 2008 at 9:42 AM, luigi scarso <luigi.scarso@gmail.com> 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.

Correction:

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

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
___________________________________________________________________________________


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

* Re: printing tab in lua: print('a\tb') fails
  2008-11-27 10:17         ` Wolfgang Schuster
@ 2008-11-27 11:48           ` luigi scarso
  2008-11-27 12:03             ` Hans Hagen
  0 siblings, 1 reply; 13+ messages in thread
From: luigi scarso @ 2008-11-27 11:48 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 690 bytes --]

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

[-- Attachment #1.2: Type: text/html, Size: 1557 bytes --]

[-- Attachment #2: Type: text/plain, Size: 487 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

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

* Re: printing tab in lua: print('a\tb') fails
  2008-11-27 11:48           ` luigi scarso
@ 2008-11-27 12:03             ` Hans Hagen
  2008-11-27 13:00               ` luigi scarso
  0 siblings, 1 reply; 13+ messages in thread
From: Hans Hagen @ 2008-11-27 12:03 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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
___________________________________________________________________________________


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

* Re: printing tab in lua: print('a\tb') fails
  2008-11-27 12:03             ` Hans Hagen
@ 2008-11-27 13:00               ` luigi scarso
  0 siblings, 0 replies; 13+ messages in thread
From: luigi scarso @ 2008-11-27 13:00 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 1002 bytes --]

On Thu, Nov 27, 2008 at 1:03 PM, Hans Hagen <pragma@wxs.nl> 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

[-- Attachment #1.2: Type: text/html, Size: 1740 bytes --]

[-- Attachment #2: Type: text/plain, Size: 487 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

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

end of thread, other threads:[~2008-11-27 13:00 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-26 19:07 printing tab in lua: print('a\tb') fails Mojca Miklavec
2008-11-26 19:28 ` Wolfgang Schuster
2008-11-27  8:29   ` Mojca Miklavec
2008-11-27  8:42     ` luigi scarso
2008-11-27  9:02       ` Wolfgang Schuster
2008-11-27  9:28         ` luigi scarso
2008-11-27 10:17         ` Wolfgang Schuster
2008-11-27 11:48           ` luigi scarso
2008-11-27 12:03             ` Hans Hagen
2008-11-27 13:00               ` luigi scarso
2008-11-27  8:50     ` Wolfgang Schuster
2008-11-27 10:04     ` Hans Hagen
2008-11-27  8:13 ` 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).