ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* ctxlua percentage format escape
@ 2021-05-29 12:32 Adam Reviczky
  2021-05-29 13:02 ` Jairo A. del Rio
  0 siblings, 1 reply; 4+ messages in thread
From: Adam Reviczky @ 2021-05-29 12:32 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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

Hi,

I was trying to use a quick calculation like the new mathfun in lmtx for an
older mkiv document.

MWE from the wiki:
https://wiki.contextgarden.net/Programming_in_LuaTeX#Examples

\starttext
$\pi = \ctxlua{context("\%.6f", math.pi)}$
\stoptext

But that gives an error (actually for both lmtx and mkiv): token call,
syntax: [ctxlua]:1: invalid escape sequence near '"\%'

Whereas

\starttext
$\pi = \startluacode context("%.6f", math.pi) \stopluacode$
\stoptext

Works fine as expected.

Is there a way to escape the percentage sign in ctxlua as a format value?

Adam

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

[-- Attachment #2: Type: text/plain, Size: 493 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: ctxlua percentage format escape
  2021-05-29 12:32 ctxlua percentage format escape Adam Reviczky
@ 2021-05-29 13:02 ` Jairo A. del Rio
  2021-05-29 13:09   ` Adam Reviczky
  2021-05-29 16:48   ` Hans Hagen
  0 siblings, 2 replies; 4+ messages in thread
From: Jairo A. del Rio @ 2021-05-29 13:02 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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

Hi, Adam. There are some ways to do it. I'm sure there are many more, but I
don't remember them right now. Hi, Hans. There's a bug (?) in syst-lua.lua
related to \expression in MkIV (xmath and xcomplex aren't defined). Please
fix that


%Temporary hack for MkIV

%Only use it in case \expression ... \relax doesn't work

\startmkivmode

\startluacode

xmath = xmath or math

xcomplex = xcomplex or {} --maybe math too???

\stopluacode

\stopmkivmode

\starttext

$\pi = \ctxlua{context("\letterpercent.6f", math.pi)}$


$\pi = \expression string.format("\letterpercent.6f", pi)\relax$


%Changing catcodes so $ and % are letter characters

\startasciimode

\m{\pi = \expression ("%.6f"):format(pi) \relax}


\m{\pi = \ctxlua{context("%.6f", math.pi)}}

\stopasciimode

\stoptext

Regards,


Jairo

El sáb, 29 de may. de 2021 a la(s) 07:32, Adam Reviczky (reviczky@gmail.com)
escribió:

> Hi,
>
> I was trying to use a quick calculation like the new mathfun in lmtx for
> an older mkiv document.
>
> MWE from the wiki:
> https://wiki.contextgarden.net/Programming_in_LuaTeX#Examples
>
> \starttext
> $\pi = \ctxlua{context("\%.6f", math.pi)}$
> \stoptext
>
> But that gives an error (actually for both lmtx and mkiv): token call,
> syntax: [ctxlua]:1: invalid escape sequence near '"\%'
>
> Whereas
>
> \starttext
> $\pi = \startluacode context("%.6f", math.pi) \stopluacode$
> \stoptext
>
> Works fine as expected.
>
> Is there a way to escape the percentage sign in ctxlua as a format value?
>
> Adam
>
> ___________________________________________________________________________________
> 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://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki     : http://contextgarden.net
>
> ___________________________________________________________________________________
>

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

[-- Attachment #2: Type: text/plain, Size: 493 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: ctxlua percentage format escape
  2021-05-29 13:02 ` Jairo A. del Rio
@ 2021-05-29 13:09   ` Adam Reviczky
  2021-05-29 16:48   ` Hans Hagen
  1 sibling, 0 replies; 4+ messages in thread
From: Adam Reviczky @ 2021-05-29 13:09 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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

Thank you Jairo!

I have tried playing around with letterpercent/catcodes as well, not sure
what I did wrong, but your examples work just fine, so thanks again.

Adam

On Sat, May 29, 2021 at 2:04 PM Jairo A. del Rio <jairoadelrio6@gmail.com>
wrote:

> Hi, Adam. There are some ways to do it. I'm sure there are many more, but
> I don't remember them right now. Hi, Hans. There's a bug (?) in
> syst-lua.lua related to \expression in MkIV (xmath and xcomplex aren't
> defined). Please fix that
>
>
> %Temporary hack for MkIV
>
> %Only use it in case \expression ... \relax doesn't work
>
> \startmkivmode
>
> \startluacode
>
> xmath = xmath or math
>
> xcomplex = xcomplex or {} --maybe math too???
>
> \stopluacode
>
> \stopmkivmode
>
> \starttext
>
> $\pi = \ctxlua{context("\letterpercent.6f", math.pi)}$
>
>
> $\pi = \expression string.format("\letterpercent.6f", pi)\relax$
>
>
> %Changing catcodes so $ and % are letter characters
>
> \startasciimode
>
> \m{\pi = \expression ("%.6f"):format(pi) \relax}
>
>
> \m{\pi = \ctxlua{context("%.6f", math.pi)}}
>
> \stopasciimode
>
> \stoptext
>
> Regards,
>
>
> Jairo
>
> El sáb, 29 de may. de 2021 a la(s) 07:32, Adam Reviczky (
> reviczky@gmail.com) escribió:
>
>> Hi,
>>
>> I was trying to use a quick calculation like the new mathfun in lmtx for
>> an older mkiv document.
>>
>> MWE from the wiki:
>> https://wiki.contextgarden.net/Programming_in_LuaTeX#Examples
>>
>> \starttext
>> $\pi = \ctxlua{context("\%.6f", math.pi)}$
>> \stoptext
>>
>> But that gives an error (actually for both lmtx and mkiv): token call,
>> syntax: [ctxlua]:1: invalid escape sequence near '"\%'
>>
>> Whereas
>>
>> \starttext
>> $\pi = \startluacode context("%.6f", math.pi) \stopluacode$
>> \stoptext
>>
>> Works fine as expected.
>>
>> Is there a way to escape the percentage sign in ctxlua as a format value?
>>
>> Adam
>>
>> ___________________________________________________________________________________
>> 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://context.aanhet.net
>> archive  : https://bitbucket.org/phg/context-mirror/commits/
>> wiki     : http://contextgarden.net
>>
>> ___________________________________________________________________________________
>>
>
> ___________________________________________________________________________________
> 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://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki     : http://contextgarden.net
>
> ___________________________________________________________________________________
>

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

[-- Attachment #2: Type: text/plain, Size: 493 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: ctxlua percentage format escape
  2021-05-29 13:02 ` Jairo A. del Rio
  2021-05-29 13:09   ` Adam Reviczky
@ 2021-05-29 16:48   ` Hans Hagen
  1 sibling, 0 replies; 4+ messages in thread
From: Hans Hagen @ 2021-05-29 16:48 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Jairo A. del Rio

On 5/29/2021 3:02 PM, Jairo A. del Rio wrote:
> Hi, Adam. There are some ways to do it. I'm sure there are many more, 
> but I don't remember them right now. Hi, Hans. There's a bug (?) in 
> syst-lua.lua related to \expression in MkIV (xmath and xcomplex aren't 
> defined). Please fix that

something

     local result = CONTEXTLMTXMODE > 0 and
         { "local xmath = xmath local xcomplex = xcomplex return " }
      or { "local xmath =  math local xcomplex = { }      return " }

you can test it

> %Temporary hack for MkIV
> 
> %Only use it in case \expression ... \relax doesn't work

kind of old (hacky experiment) that one ... i probably need to adapt it 
to lmtx anyway

\luaexpr and \mathexpr are probably better for this kind of stuff (no 
need for the % then when the optional format arg is used)

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 / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

end of thread, other threads:[~2021-05-29 16:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-29 12:32 ctxlua percentage format escape Adam Reviczky
2021-05-29 13:02 ` Jairo A. del Rio
2021-05-29 13:09   ` Adam Reviczky
2021-05-29 16:48   ` 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).