Minor bug in Lua or ConTeXt
ConTeXt ver: 2023.01.04 The following MWE won't compile because of the \dummycommand line even though it is a comment. Not sure whether it's a minor bug or an unavoidable aspect of allowing embedded Lua. \startluacode -- \dummycommand \stopluacode \starttext Hello \stoptext — Bruce Horrocks Hampshire, UK
On 1/18/23 00:36, Bruce Horrocks via ntg-context wrote:
ConTeXt ver: 2023.01.04
The following MWE won't compile because of the \dummycommand line even though it is a comment. Not sure whether it's a minor bug or an unavoidable aspect of allowing embedded Lua.
Hi Bruce, I think your code should read: \startluacode -- \\dummycommand \stopluacode \starttext Hello \stoptext BTW, in pure Lua: a = "\a" b = "\\b" print(a..b) outputs "\b". Sorry, I lack the knowledge to explain this, but backslash seems to be an special char in pure Lua too. Just in case it might help, Pablo
On 1/18/2023 12:36 AM, Bruce Horrocks via ntg-context wrote:
ConTeXt ver: 2023.01.04
The following MWE won't compile because of the \dummycommand line even though it is a comment. Not sure whether it's a minor bug or an unavoidable aspect of allowing embedded Lua.
\startluacode -- \dummycommand \stopluacode \starttext Hello \stoptext
a bang-head-against-the-wall case: \let\dummycommand\relax \startluacode -- \dummycommand \stopluacode \starttext Hello \stoptext or: \ifdefined\dummycommand \else \let\dummycommand\relax \fi a document-on-the-wiki challenge for Pablo Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
Thanks Hans. Before Pablo spends too much effort on the wiki it's worth pointing out that this only happened because I was in-line documenting the Lua function that I had written and wanted to name the ConTeXT macro that would invoke it - so it's trivial for me to avoid this error. Perhaps the Wiki only needs to point out that if you get a Lua related error and the error log lists the entire contents of \startluacode ... \stopluacode then a possible source of the error is a \command somewhere in there? Regards,
On 18 Jan 2023, at 09:48, Hans Hagen via ntg-context
wrote: On 1/18/2023 12:36 AM, Bruce Horrocks via ntg-context wrote:
ConTeXt ver: 2023.01.04 The following MWE won't compile because of the \dummycommand line even though it is a comment. Not sure whether it's a minor bug or an unavoidable aspect of allowing embedded Lua. \startluacode -- \dummycommand \stopluacode \starttext Hello \stoptext
a bang-head-against-the-wall case:
\let\dummycommand\relax
\startluacode -- \dummycommand \stopluacode \starttext Hello \stoptext
or:
\ifdefined\dummycommand \else \let\dummycommand\relax \fi
a document-on-the-wiki challenge for Pablo
Hans
----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | 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 / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___________________________________________________________________________________
— Bruce Horrocks Hampshire, UK
On 1/18/23 14:41, Bruce Horrocks via ntg-context wrote:
[…] Perhaps the Wiki only needs to point out that if you get a Lua related error and the error log lists the entire contents of \startluacode ... \stopluacode then a possible source of the error is a \command somewhere in there?
Hi Bruce, from what I understand is that undefined TeX commands cannot be added to Lua comments. If I’m not wrong (in my previous statement), I think this is counterintuitive, since undefined commands are fine in TeX comments and undefined variables are fine inside \startluacode … \stopluacode. So I added https://wiki.contextgarden.net/Programming_in_LuaTeX#Undefined_Commands_in_L.... Let me know whether I missed something. Many thanks for your help, Pablo
On 1/18/2023 6:47 PM, Pablo Rodriguez via ntg-context wrote:
from what I understand is that undefined TeX commands cannot be added to Lua comments.
Indeed. Of course we could have some 'ignore undefined command' feature but that cripples the engine as well as then also never gives warning in the case you *do* want to expand.
If I’m not wrong (in my previous statement), I think this is counterintuitive, since undefined commands are fine in TeX comments and undefined variables are fine inside \startluacode … \stopluacode. I bet you'd complain if \the\scratchdimen would not expand. You cannot expect context to completely parse what goes into lua beforehand, unless you are willing to get a performance hit (apart from a waste of time).
And even if we'd make e.g. - active (with some lookahead magick) and then gobble till the end of the line we would get questions why it doesn't work in macros. It's a small price to pay. (I also bet that Bruce is willing to \relax the command.) Thanks for adding to the wiki, Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
On 1/18/23 19:07, Hans Hagen via ntg-context wrote:
On 1/18/2023 6:47 PM, Pablo Rodriguez via ntg-context wrote: [...]
If I’m not wrong (in my previous statement), I think this is counterintuitive, since undefined commands are fine in TeX comments and undefined variables are fine inside \startluacode … \stopluacode.
I bet you'd complain if \the\scratchdimen would not expand. You cannot expect context to completely parse what goes into lua beforehand, unless you are willing to get a performance hit (apart from a waste of time).
I’m starting to understand that one cannot have it all. I haven’t used so much Lua code to add an undefined TeX command in a comment. Different reply isn’t wrong, only it needs to be known in advance.
Thanks for adding to the wiki,
I have discovered after the addition that this was explained before (last paragraph from https://wiki.contextgarden.net/Programming_in_LuaTeX#Calling_Lua_from_TeX). To emphasize it visually, I abused the <blockquote> element. If any wiki wizard knows better, please tell. Many thanks for your help, Pablo
participants (4)
-
Bruce Horrocks
-
Hans Hagen
-
Hans Hagen
-
Pablo Rodriguez