[NTG-context] Re: Question about building an array of values with Lua

2023-08-24 Thread Wolfgang Schuster

Otared Kavian schrieb am 24.08.2023 um 12:50:


On 24 Aug 2023, at 06:03, Wolfgang Schuster 
> wrote:

[…]


I would drop the column check in this case.

    for i = 0,9 do
    context.startxrow()
    context.startxcell()
    context(i)
    context.stopxcell()
    context.startxcell()
    context(math.mod(i*i,10))
    context.stopxcell()
    context.startxcell()
    context(i)
    context.stopxcell()
    context.startxcell()
    context(math.mod(2*i*i,10))
    context.stopxcell()
    context.stopxrow()
    end

Wolfgang


Indeed this is much more elegant… It feels so good to be on this list 
and learn from such insights :-)


We don't even need the math.mod function because Lua added with version 
5.1 a modulo operator,

the loop to create the row can now be changed to

    for i = 0,9 do
    context.startxrow()
    context.startxcell()
    context(i)
    context.stopxcell()
    context.startxcell()
    context(i * i % 10)
    context.stopxcell()
    context.startxcell()
    context(i)
    context.stopxcell()
    context.startxcell()
    context(2 * i * i % 10)
    context.stopxcell()
    context.stopxrow()
    end

Wolfgang

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

[NTG-context] Re: xmldoif: checking for contents of attribute

2023-08-24 Thread Hans Hagen

On 8/24/2023 4:11 PM, denis.ma...@unibe.ch wrote:

Hi,

I'm trying to check whether an attribute contains (or, actually starts with) a 
given string.
I've tried a whole bunch of different combinations, but I've had no luck so 
far. Minimal example below. Anyone has a hint?

Best,
Denis


%
\startxmlsetups xml:test
 \xmlsetsetup{#1}{*}{-}
 \xmlsetsetup{#1}{doc|element}{xml:*}
\stopxmlsetups

\xmlregisterdocumentsetup{test}{xml:test}


\startxmlsetups xml:doc
\xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:element
\xmlfilter{#1}{./find(attribute('class'), 'abc')/command(xml:whatever)}

\xmldoifelse{#1}{./attribute('class')/contains('abc')} {Yes}{No}
\stopxmlsetups

\startxmlsetups xml:whatever
Yes
\stopxmlsetups

\startbuffer[test]


Yes
No

\stopbuffer

\starttext

\xmlprocessbuffer{test}{test}{}

\stoptext

\xmldoifelse{#1}{.[@class and contains(@class,'abc')]}{Yes}{No}
\xmldoifelse{#1}{.[@class and find(@class,"abc")]}{Yes}{No}


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


[NTG-context] Re: xmldoif: checking for contents of attribute

2023-08-24 Thread Thomas A. Schmitz
One way would be to do the search in Lua; when you have multiple searches to 
perform, that may be the easiest way to go. For example:

\startxmlsetups xml:test
\xmlsetsetup{#1}{*}{-}
\xmlsetsetup{#1}{doc|element}{xml:*}
\stopxmlsetups
 
\xmlregisterdocumentsetup{test}{xml:test}
 
\startxmlsetups xml:doc
\xmlflush{#1}
\stopxmlsetups
 
\startxmlsetups xml:element
 \xmlfunction {#1} {element}
\stopxmlsetups
 
\startluacode
function xml.functions.element (t)
 if t.at.class and t.at.class:find ("abc") then
context.startcolor { "blue" }
lxml.flush (t)
context.stopcolor ()
 else
context.startcolor { "red" }
lxml.flush (t)
context.stopcolor ()
 end
end
\stopluacode 
 
\startbuffer[test]


Yes
No

\stopbuffer
 
\starttext
 
\xmlprocessbuffer{test}{test}{}
 
\stoptext

Hope that gets you started.

Thomas

> On 24. Aug 2023, at 16:11, denis.ma...@unibe.ch wrote:
> 
> Hi,
>  I’m trying to check whether an attribute contains (or, actually starts with) 
> a given string.
> I’ve tried a whole bunch of different combinations, but I’ve had no luck so 
> far. Minimal example below. Anyone has a hint?
>  Best,
> Denis
>   %
> \startxmlsetups xml:test
> \xmlsetsetup{#1}{*}{-}
> \xmlsetsetup{#1}{doc|element}{xml:*} \stopxmlsetups
>  \xmlregisterdocumentsetup{test}{xml:test}
>   \startxmlsetups xml:doc
> \xmlflush{#1}
> \stopxmlsetups
>  \startxmlsetups xml:element
> \xmlfilter{#1}{./find(attribute('class'), 'abc')/command(xml:whatever)}
>  \xmldoifelse{#1}{./attribute('class')/contains('abc')} {Yes}{No}
> \stopxmlsetups
>  \startxmlsetups xml:whatever
> Yes
> \stopxmlsetups
>  \startbuffer[test]
> 
> 
> Yes
> No
> 
> \stopbuffer
>  \starttext
>  \xmlprocessbuffer{test}{test}{}
>  \stoptext


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

[NTG-context] xmldoif: checking for contents of attribute

2023-08-24 Thread denis.maier
Hi,

I'm trying to check whether an attribute contains (or, actually starts with) a 
given string.
I've tried a whole bunch of different combinations, but I've had no luck so 
far. Minimal example below. Anyone has a hint?

Best,
Denis


%
\startxmlsetups xml:test
\xmlsetsetup{#1}{*}{-}
\xmlsetsetup{#1}{doc|element}{xml:*}
\stopxmlsetups

\xmlregisterdocumentsetup{test}{xml:test}


\startxmlsetups xml:doc
\xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:element
\xmlfilter{#1}{./find(attribute('class'), 'abc')/command(xml:whatever)}

\xmldoifelse{#1}{./attribute('class')/contains('abc')} {Yes}{No}
\stopxmlsetups

\startxmlsetups xml:whatever
Yes
\stopxmlsetups

\startbuffer[test]


Yes
No

\stopbuffer

\starttext

\xmlprocessbuffer{test}{test}{}

\stoptext
___
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
___

[NTG-context] Re: Question about building an array of values with Lua

2023-08-24 Thread Otared Kavian

> On 24 Aug 2023, at 06:03, Wolfgang Schuster 
>  wrote:
>> […]
> 
> I would drop the column check in this case.
> 
> for i = 0,9 do
> context.startxrow()
> context.startxcell()
> context(i)
> context.stopxcell()
> context.startxcell()
> context(math.mod(i*i,10))
> context.stopxcell()
> context.startxcell()
> context(i)
> context.stopxcell()
> context.startxcell()
> context(math.mod(2*i*i,10))
> context.stopxcell()
> context.stopxrow()
> end
> 
> Wolfgang


Indeed this is much more elegant… It feels so good to be on this list and learn 
from such insights :-)

Best regards: Otared___
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
___

[NTG-context] Re: An strange error with section and page

2023-08-24 Thread Xavier B.
Oh Awesome.

I'm looking forward to the solution.

Thanks a lot,
Xavier


On Wed, 23 Aug 2023 22:04:36 +0200
Wolfgang Schuster  ha escrit:

> Xavier B. schrieb am 23.08.2023 um 15:02:
> > Wolfgang,
> >
> > I detect something extrange: when I use \startexercici \stopexercici (see 
> > [https://repo.or.cz/apunts-espa-matematiques.git/blob/HEAD:/ng-entorn-minimal.conTeXt])
> >  in some cases there is an *undesired* indent (see attachment image). I saw 
> > the source 
> > [https://repo.or.cz/apunts-espa-matematiques.git/blob/HEAD:/ng-aritmetica-problemes-nombres-fraccions.conTeXt]
> >  which is the first time it happens.
> >
> > I don't see anything weird.
> >
> > Can you please help me?
> 
> I found the problem but I have to discuss it with Hans.
> 
> Wolfgang
___
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
___


[NTG-context] Re: Question about building an array of values with Lua

2023-08-24 Thread Fabrice Couvreur
Hi Otared and Wolgang,
Thanks for the answers. In fact, being familiar with Python and not at all
with Lua, I didn't have the reflex to think of using a mathematical
function which gives the remainder in the Euclidean division by 10, it's
strange !!
Fabrice

Le jeu. 24 août 2023 à 04:06, Wolfgang Schuster <
wolfgang.schuster.li...@gmail.com> a écrit :

> Otared Kavian schrieb am 24.08.2023 um 01:04:
>
> Hi Fabrice,
>
> As Wolfgang points out, it is indeed possible to fill-in your table with
> Lua: maybe you were wondering how to fill the columns 2, 3 and 4. In this
> case you need to use the Lua function math.mod as in the following, which
> is a completed version of what Wolfgang sent:
>
>
> I guess I completely missed the units digit part :)
>
> %% begin filling-with-lua.tex
> \starttext
>
> \startluacode
> context.startxtable{ align = "middle,lohi", bodyfont = "9pt", framecolor =
> "black" }
> context.startxrow{ background = "color", backgroundcolor = "lightgray"
> }
> context.startxcell{ nx = 4 }
> context("Units digit of")
> context.stopxcell()
> context.stopxrow()
> context.startxrow()
> context.startxcell{ width = "1cm" }
> context.im("a")
> context.stopxcell()
> context.startxcell{ width = "1cm" }
> context.im("a^2")
> context.stopxcell()
> context.startxcell{ width = "1cm" }
> context.im("b")
> context.stopxcell()
> context.startxcell{ width = "1cm" }
> context.im("2b^2")
> context.stopxcell()
> context.stopxrow()
> for i = 0,9 do
> context.startxrow()
> for j = 1,4 do
> context.startxcell()
> if j == 1 then
> context(i)
> elseif j == 2 then
> context(math.mod(i*i,10))
>  elseif j == 3 then
>   context(i)
>  else
>   context(math.mod(2*i*i,10))
> end
> context.stopxcell()
> end
> context.stopxrow()
> end
>
>
> I would drop the column check in this case.
>
> for i = 0,9 do
> context.startxrow()
> context.startxcell()
> context(i)
> context.stopxcell()
> context.startxcell()
> context(math.mod(i*i,10))
> context.stopxcell()
> context.startxcell()
> context(i)
> context.stopxcell()
> context.startxcell()
> context(math.mod(2*i*i,10))
> context.stopxcell()
> context.stopxrow()
> end
>
> Wolfgang
>
>
> ___
> 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
>
> ___
___
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
___