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
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
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
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
On Thu, Nov 27, 2008 at 9:42 AM, 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
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
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
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
On Thu, Nov 27, 2008 at 10:02 AM, Wolfgang Schuster
On Thu, Nov 27, 2008 at 9:42 AM, luigi scarso
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
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
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 -----------------------------------------------------------------
On Thu, Nov 27, 2008 at 1:03 PM, 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!")}}
Exactly. In my opinion, this is better than my example, because I don't like to mix things (and also for namespace document). -- luigi
On Thu, Nov 27, 2008 at 9:29 AM, 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.
print('a\string\tb')
\stopluacode hello \stoptext
Wolfgang
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 -----------------------------------------------------------------
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 -----------------------------------------------------------------
participants (4)
-
Hans Hagen
-
luigi scarso
-
Mojca Miklavec
-
Wolfgang Schuster