* [NTG-context] Question about building an array of values with Lua @ 2023-08-23 17:28 Fabrice Couvreur 2023-08-23 15:48 ` [NTG-context] " Wolfgang Schuster 0 siblings, 1 reply; 8+ messages in thread From: Fabrice Couvreur @ 2023-08-23 17:28 UTC (permalink / raw) To: mailing list for ConTeXt users [-- Attachment #1.1: Type: text/plain, Size: 1289 bytes --] Hi, I'm trying to fill an array using lua. So far it works but then I don't know if it's possible. Thanks Fabrice \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²}") context.stopxcell() context.startxcell({"width=1cm"}) context("\\im{b}") context.stopxcell() context.startxcell({"width=1cm"}) context("\\im{2b²}") context.stopxcell() context.stopxrow() for i = 0, 9 do context.startxrow() context.startxcell() context(i) context.stopxcell() context.stopxrow() end context.stopxtable() \stopluacode [-- Attachment #1.2: Type: text/html, Size: 2086 bytes --] [-- Attachment #2: Type: text/plain, Size: 495 bytes --] ___________________________________________________________________________________ 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 8+ messages in thread
* [NTG-context] Re: Question about building an array of values with Lua 2023-08-23 17:28 [NTG-context] Question about building an array of values with Lua Fabrice Couvreur @ 2023-08-23 15:48 ` Wolfgang Schuster 2023-08-23 23:04 ` Otared Kavian 0 siblings, 1 reply; 8+ messages in thread From: Wolfgang Schuster @ 2023-08-23 15:48 UTC (permalink / raw) To: mailing list for ConTeXt users, Fabrice Couvreur [-- Attachment #1.1: Type: text/plain, Size: 1635 bytes --] Fabrice Couvreur schrieb am 23.08.2023 um 19:28: > Hi, > I'm trying to fill an array using lua. So far it works but then I > don't know if it's possible. Where do you have problems (look into cld-mkiv.pdf for hins)? \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) end context.stopxcell() end context.stopxrow() end context.stopxtable() \stopluacode \stoptext Wolfgang [-- Attachment #1.2: Type: text/html, Size: 2246 bytes --] [-- Attachment #2: Type: text/plain, Size: 495 bytes --] ___________________________________________________________________________________ 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 8+ messages in thread
* [NTG-context] Re: Question about building an array of values with Lua 2023-08-23 15:48 ` [NTG-context] " Wolfgang Schuster @ 2023-08-23 23:04 ` Otared Kavian 2023-08-24 4:03 ` Wolfgang Schuster 0 siblings, 1 reply; 8+ messages in thread From: Otared Kavian @ 2023-08-23 23:04 UTC (permalink / raw) To: mailing list for ConTeXt users [-- Attachment #1.1: Type: text/plain, Size: 3849 bytes --] 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: %% 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 context.stopxtable() \stopluacode \stoptext %% end filling-with-lua.tex Best regards: Otared > On 23 Aug 2023, at 17:48, Wolfgang Schuster <wolfgang.schuster.lists@gmail.com> wrote: > > Fabrice Couvreur schrieb am 23.08.2023 um 19:28: >> Hi, >> I'm trying to fill an array using lua. So far it works but then I don't know if it's possible. > > Where do you have problems (look into cld-mkiv.pdf for hins)? > > \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) > end > context.stopxcell() > end > context.stopxrow() > end > context.stopxtable() > \stopluacode > > \stoptext > > 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 > ___________________________________________________________________________________ Otared Kavian e-mail: otared@gmail.com Phone: +33 6 88 26 70 95 [-- Attachment #1.2: Type: text/html, Size: 9875 bytes --] [-- Attachment #2: Type: text/plain, Size: 495 bytes --] ___________________________________________________________________________________ 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 8+ messages in thread
* [NTG-context] Re: Question about building an array of values with Lua 2023-08-23 23:04 ` Otared Kavian @ 2023-08-24 4:03 ` Wolfgang Schuster 2023-08-24 10:50 ` Otared Kavian 2023-08-24 11:15 ` Fabrice Couvreur 0 siblings, 2 replies; 8+ messages in thread From: Wolfgang Schuster @ 2023-08-24 4:03 UTC (permalink / raw) To: mailing list for ConTeXt users, Otared Kavian [-- Attachment #1.1: Type: text/plain, Size: 2172 bytes --] 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 [-- Attachment #1.2: Type: text/html, Size: 4226 bytes --] [-- Attachment #2: Type: text/plain, Size: 495 bytes --] ___________________________________________________________________________________ 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 8+ messages in thread
* [NTG-context] Re: Question about building an array of values with Lua 2023-08-24 4:03 ` Wolfgang Schuster @ 2023-08-24 10:50 ` Otared Kavian 2023-08-24 19:43 ` Wolfgang Schuster 2023-08-24 11:15 ` Fabrice Couvreur 1 sibling, 1 reply; 8+ messages in thread From: Otared Kavian @ 2023-08-24 10:50 UTC (permalink / raw) To: Wolfgang Schuster, mailing list for ConTeXt users [-- Attachment #1.1: Type: text/plain, Size: 835 bytes --] > On 24 Aug 2023, at 06:03, Wolfgang Schuster <wolfgang.schuster.lists@gmail.com> 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 [-- Attachment #1.2: Type: text/html, Size: 2688 bytes --] [-- Attachment #2: Type: text/plain, Size: 495 bytes --] ___________________________________________________________________________________ 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 8+ messages in thread
* [NTG-context] Re: Question about building an array of values with Lua 2023-08-24 10:50 ` Otared Kavian @ 2023-08-24 19:43 ` Wolfgang Schuster 2023-08-25 12:47 ` Fabrice Couvreur 0 siblings, 1 reply; 8+ messages in thread From: Wolfgang Schuster @ 2023-08-24 19:43 UTC (permalink / raw) To: Otared Kavian; +Cc: mailing list for ConTeXt users [-- Attachment #1.1: Type: text/plain, Size: 1891 bytes --] Otared Kavian schrieb am 24.08.2023 um 12:50: > >> On 24 Aug 2023, at 06:03, Wolfgang Schuster >> <wolfgang.schuster.lists@gmail.com >> <mailto:wolfgang.schuster.lists@gmail.com>> 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 [-- Attachment #1.2: Type: text/html, Size: 3119 bytes --] [-- Attachment #2: Type: text/plain, Size: 495 bytes --] ___________________________________________________________________________________ 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 8+ messages in thread
* [NTG-context] Re: Question about building an array of values with Lua 2023-08-24 19:43 ` Wolfgang Schuster @ 2023-08-25 12:47 ` Fabrice Couvreur 0 siblings, 0 replies; 8+ messages in thread From: Fabrice Couvreur @ 2023-08-25 12:47 UTC (permalink / raw) To: mailing list for ConTeXt users [-- Attachment #1.1: Type: text/plain, Size: 2256 bytes --] Hi Wolfgang, Thank you so much Fabrice Le jeu. 24 août 2023 à 19:46, Wolfgang Schuster < wolfgang.schuster.lists@gmail.com> a écrit : > Otared Kavian schrieb am 24.08.2023 um 12:50: > > > On 24 Aug 2023, at 06:03, Wolfgang Schuster < > wolfgang.schuster.lists@gmail.com> 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 > > ___________________________________________________________________________________ [-- Attachment #1.2: Type: text/html, Size: 4048 bytes --] [-- Attachment #2: Type: text/plain, Size: 495 bytes --] ___________________________________________________________________________________ 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 8+ messages in thread
* [NTG-context] Re: Question about building an array of values with Lua 2023-08-24 4:03 ` Wolfgang Schuster 2023-08-24 10:50 ` Otared Kavian @ 2023-08-24 11:15 ` Fabrice Couvreur 1 sibling, 0 replies; 8+ messages in thread From: Fabrice Couvreur @ 2023-08-24 11:15 UTC (permalink / raw) To: mailing list for ConTeXt users [-- Attachment #1.1: Type: text/plain, Size: 3286 bytes --] 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.lists@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 > > ___________________________________________________________________________________ [-- Attachment #1.2: Type: text/html, Size: 5770 bytes --] [-- Attachment #2: Type: text/plain, Size: 495 bytes --] ___________________________________________________________________________________ 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-08-25 10:49 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-08-23 17:28 [NTG-context] Question about building an array of values with Lua Fabrice Couvreur 2023-08-23 15:48 ` [NTG-context] " Wolfgang Schuster 2023-08-23 23:04 ` Otared Kavian 2023-08-24 4:03 ` Wolfgang Schuster 2023-08-24 10:50 ` Otared Kavian 2023-08-24 19:43 ` Wolfgang Schuster 2023-08-25 12:47 ` Fabrice Couvreur 2023-08-24 11:15 ` Fabrice Couvreur
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).