ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* cld questions
@ 2021-09-05 10:01 Henning Hraban Ramm via ntg-context
  2021-09-05 11:01 ` Hans Hagen via ntg-context
  0 siblings, 1 reply; 6+ messages in thread
From: Henning Hraban Ramm via ntg-context @ 2021-09-05 10:01 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Henning Hraban Ramm

Hi again,
I’m converting a few macros into Lua (LMTX), but couldn’t find some answers in the docs:


* How translates \ifodd\realpageno ?

This doesn’t work:
if ((tex.getcount("realpageno") mod 2) == 1) then
 a = 1
end

I found tex.ifodd but don’t know how to use it either.


* How to access my \def’d macros?

Is this supposed to work?:

TeX:
\def\Something{1cm}

Lua:
context.Something()

(It doesn’t in my case, but if it should, I can investigate.)


* TeX primitives
Is tex.strut and tex.par supposed to work? Or how should I access these?


* interface definitions:

Lua:
interfaces.implement {
    name      = "MyFun",
    public    = true,
    --permanent = false, -- what does this mean?
    arguments = { "string", "string", "string", "string" },
    actions   = function(reference, y, text, filename)
	-- a lot
    end,
}

TeX:
\MyFun{ref:some}{1cm}{bla}{hacker}

0) I don’t understand what “permanent” does and why I should maybe disable it. (cld-mkiv, p.146)

1) The parameter y is actually supposed to be a dimension, but if I declare it "dimen", ConTeXt says there wasn’t a number at "1cm".
   Or is a measure like that not a dimension?

2) The original interface of \MyFun had two optional parameters. I couldn’t find how to do that with interfaces.implement.
   cld-mkiv, p.151 (12.7) shows how to do lists or key=value, but not single optional args.


I’d be glad to get a few hints.

Hraban
___________________________________________________________________________________
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] 6+ messages in thread

* Re: cld questions
  2021-09-05 10:01 cld questions Henning Hraban Ramm via ntg-context
@ 2021-09-05 11:01 ` Hans Hagen via ntg-context
  2021-09-05 14:27   ` Henning Hraban Ramm via ntg-context
  0 siblings, 1 reply; 6+ messages in thread
From: Hans Hagen via ntg-context @ 2021-09-05 11:01 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Hans Hagen

On 9/5/2021 12:01 PM, Henning Hraban Ramm via ntg-context wrote:
> Hi again,
> I’m converting a few macros into Lua (LMTX), but couldn’t find some answers in the docs:
> 
> 
> * How translates \ifodd\realpageno ?
> 
> This doesn’t work:
> if ((tex.getcount("realpageno") mod 2) == 1) then
>   a = 1
> end

we're talking lua: 9 % 2 == 0

> TeX:
> \def\Something{1cm}
> 
> Lua:
> context.Something()

yes (assuming you're in scope)

  * TeX primitives
> Is tex.strut and tex.par supposed to work? Or how should I access these?

\strut is not is primitive

context.strut() and context.par() should just work

> 0) I don’t understand what “permanent” does and why I should maybe disable it. (cld-mkiv, p.146)

overload protection

\permanent\def\Whatever{?}
\overloadmode=0
%\overloadmode=3
%\overloadmode=4
\def\Whatever{!}

try 3 and 4 (actually, try to run your documents with overloadmode set 
and you might see where you replace core macros)

%enabledirectives[overloadmode=warning]
\enabledirectives[overloadmode=error]

btw, you can temporary do

\pushoverloadmode
potentially risky definitions
\popoverloadmode

> 1) The parameter y is actually supposed to be a dimension, but if I declare it "dimen", ConTeXt says there wasn’t a number at "1cm".
>     Or is a measure like that not a dimension?

if you want to use {} around it use "dimenargument"

> 2) The original interface of \MyFun had two optional parameters. I couldn’t find how to do that with interfaces.implement.
>     cld-mkiv, p.151 (12.7) shows how to do lists or key=value, but not single optional args.

there is "optional"

and ... cld is not yet updated to lmtx in this respect so some newer 
features are missing

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] 6+ messages in thread

* Re: cld questions
  2021-09-05 11:01 ` Hans Hagen via ntg-context
@ 2021-09-05 14:27   ` Henning Hraban Ramm via ntg-context
  2021-09-06 16:20     ` Henning Hraban Ramm via ntg-context
  0 siblings, 1 reply; 6+ messages in thread
From: Henning Hraban Ramm via ntg-context @ 2021-09-05 14:27 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Henning Hraban Ramm


> Am 05.09.2021 um 13:01 schrieb Hans Hagen <j.hagen@xs4all.nl>:
> 
> On 9/5/2021 12:01 PM, Henning Hraban Ramm via ntg-context wrote:
>> * How translates \ifodd\realpageno ?
>> This doesn’t work:
>> if ((tex.getcount("realpageno") mod 2) == 1) then
>>  a = 1
>> end
> 
> we're talking lua: 9 % 2 == 0

Oops. Too many languages...

>> TeX:
>> \def\Something{1cm}
>> Lua:
>> context.Something()
> 
> yes (assuming you're in scope)

Then I’m out of scope.

\def is in my environment, directly before I load the Lua functions with \loadluafile.
How can I access the macros from the environment there?


>> Is tex.strut and tex.par supposed to work? Or how should I access these?
> 
> \strut is not is primitive
> 
> context.strut() and context.par() should just work

It does. I thought I had tried that...

> 0) I don’t understand what “permanent” does and why I should maybe disable it. (cld-mkiv, p.146)
> 
> overload protection
> 
> \permanent\def\Whatever{?}
> \overloadmode=0
> %\overloadmode=3
> %\overloadmode=4
> \def\Whatever{!}
> 
> try 3 and 4 (actually, try to run your documents with overloadmode set and you might see where you replace core macros)
> 
> %enabledirectives[overloadmode=warning]
> \enabledirectives[overloadmode=error]
> 
> btw, you can temporary do
> 
> \pushoverloadmode
> potentially risky definitions
> \popoverloadmode

Thank you, I’ll try. (While I’m quite sure I never overload core macros.)


>> 1) The parameter y is actually supposed to be a dimension, but if I declare it "dimen", ConTeXt says there wasn’t a number at "1cm".
>>    Or is a measure like that not a dimension?
> 
> if you want to use {} around it use "dimenargument"
> 
>> 2) The original interface of \MyFun had two optional parameters. I couldn’t find how to do that with interfaces.implement.
>>    cld-mkiv, p.151 (12.7) shows how to do lists or key=value, but not single optional args.
> 
> there is "optional"
> 
> and ... cld is not yet updated to lmtx in this respect so some newer features are missing

Thank you!

Must I then declare "string optional" etc.?



Hraban


___________________________________________________________________________________
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] 6+ messages in thread

* Re: cld questions
  2021-09-05 14:27   ` Henning Hraban Ramm via ntg-context
@ 2021-09-06 16:20     ` Henning Hraban Ramm via ntg-context
  2021-09-06 18:00       ` Hans Hagen via ntg-context
  0 siblings, 1 reply; 6+ messages in thread
From: Henning Hraban Ramm via ntg-context @ 2021-09-06 16:20 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Henning Hraban Ramm

Another question:

I think I understood the need for function arguments.
My macro, defined with interfaces.implement, works while I call "Image" below,
but if I call "ClippedImage" (one level of indirection more), I get:

"""
tex error       > tex error on line 28 in file virtual://page.nopage.1: Missing { inserted
...(no helpful output here)...
A left brace was mandatory here, so I've put one in.
"""

I can’t imagine where to put that brace.



function Image(Width, Height, filename)
	context.externalfigure(
		{ filename },
		{
			width = todimen(Width),
		}
	)
end

function ClippedImage(Width, Height, filename)
	context.clip(
		{
			width = todimen(Width),
			height = todimen(Height),
		},
		Image(Width, Height, filename)
	)
end



Am 05.09.2021 um 16:27 schrieb Henning Hraban Ramm via ntg-context <ntg-context@ntg.nl>:

>> TeX:
>> \def\Something{1cm}
>> Lua:
>> context.Something()
> 
> yes (assuming you're in scope)

Then I’m out of scope.

\def is in my environment, directly before I load the Lua functions with \loadluafile.
How can I access the macros from the environment there?


>> 2) The original interface of \MyFun had two optional parameters. I couldn’t find how to do that with interfaces.implement.
>>   cld-mkiv, p.151 (12.7) shows how to do lists or key=value, but not single optional args.
> 
> there is "optional"
> 
> and ... cld is not yet updated to lmtx in this respect so some newer features are missing

Must I then declare "string optional" etc.?

___________________________________________________________________________________
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] 6+ messages in thread

* Re: cld questions
  2021-09-06 16:20     ` Henning Hraban Ramm via ntg-context
@ 2021-09-06 18:00       ` Hans Hagen via ntg-context
  2021-09-06 19:16         ` Henning Hraban Ramm via ntg-context
  0 siblings, 1 reply; 6+ messages in thread
From: Hans Hagen via ntg-context @ 2021-09-06 18:00 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Hans Hagen

On 9/6/2021 6:20 PM, Henning Hraban Ramm via ntg-context wrote:
> Another question:
> 
> I think I understood the need for function arguments.
> My macro, defined with interfaces.implement, works while I call "Image" below,
> but if I call "ClippedImage" (one level of indirection more), I get:
> 
> """
> tex error       > tex error on line 28 in file virtual://page.nopage.1: Missing { inserted
> ...(no helpful output here)...
> A left brace was mandatory here, so I've put one in.
> """
> 
> I can’t imagine where to put that brace.
> 
> 
> 
> function Image(Width, Height, filename)
> 	context.externalfigure(
> 		{ filename },
> 		{
> 			width = todimen(Width),
> 		}
> 	)
> end
> 
> function ClippedImage(Width, Height, filename)
> 	context.clip(
> 		{
> 			width = todimen(Width),
> 			height = todimen(Height),
> 		},
> 		Image(Width, Height, filename)

function() Image(Width, Height, filename) end

> 	)
> end
> 
> 
> 
> Am 05.09.2021 um 16:27 schrieb Henning Hraban Ramm via ntg-context <ntg-context@ntg.nl>:
> 
>>> TeX:
>>> \def\Something{1cm}
>>> Lua:
>>> context.Something()
>>
>> yes (assuming you're in scope)
> 
> Then I’m out of scope.
> 
> \def is in my environment, directly before I load the Lua functions with \loadluafile.
> How can I access the macros from the environment there?
> 
> 
>>> 2) The original interface of \MyFun had two optional parameters. I couldn’t find how to do that with interfaces.implement.
>>>    cld-mkiv, p.151 (12.7) shows how to do lists or key=value, but not single optional args.
>>
>> there is "optional"
>>
>> and ... cld is not yet updated to lmtx in this respect so some newer features are missing
> 
> Must I then declare "string optional" etc.?
> 
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________
> 


-- 

-----------------------------------------------------------------
                                           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] 6+ messages in thread

* Re: cld questions
  2021-09-06 18:00       ` Hans Hagen via ntg-context
@ 2021-09-06 19:16         ` Henning Hraban Ramm via ntg-context
  0 siblings, 0 replies; 6+ messages in thread
From: Henning Hraban Ramm via ntg-context @ 2021-09-06 19:16 UTC (permalink / raw)
  To: Hans Hagen; +Cc: Henning Hraban Ramm, mailing list for ConTeXt users


> Am 06.09.2021 um 20:00 schrieb Hans Hagen <j.hagen@xs4all.nl>:
> 
> function() Image(Width, Height, filename) end

Oh, of course. Me stupid. I was looking at the code for too long...

Hraban
___________________________________________________________________________________
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] 6+ messages in thread

end of thread, other threads:[~2021-09-06 19:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-05 10:01 cld questions Henning Hraban Ramm via ntg-context
2021-09-05 11:01 ` Hans Hagen via ntg-context
2021-09-05 14:27   ` Henning Hraban Ramm via ntg-context
2021-09-06 16:20     ` Henning Hraban Ramm via ntg-context
2021-09-06 18:00       ` Hans Hagen via ntg-context
2021-09-06 19:16         ` Henning Hraban Ramm via ntg-context

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