ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* To \getbuffer or to \input: which one is it better?
@ 2018-02-10 15:10 Otared Kavian
       [not found] ` <9d5cc80b-f851-6b00-53d7-300963e1e55a@wxs.nl>
  0 siblings, 1 reply; 5+ messages in thread
From: Otared Kavian @ 2018-02-10 15:10 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi all,

In a project using the \setvariables command of ConTeXt, a file containing more than 200 instances of a structure resembling (but with much more fields…)

	\setvariables[talk]
		[speaker={Dr Some Speaker},
		title={Some title},
		room={Some Room},
		]

is input several times, in order to extract from these variables one or more informations to be typeset, for different types of documents. However I don’t know whether this is a wise solution, or is it better to define once and for all a buffer and then use the \getbuffer command for each of the different uses in my global document.

For now, unfortunately, I cannot come up with a minimal example because the question I am asking is about a real situation where nothing is minimal. That is why I am asking a general abstract question to understand the general philosophy underlining the buffer commands versus the \input command.

Thanks in advance for any hint: OK


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

* Re: To \getbuffer or to \input: which one is it better?
       [not found]   ` <A462E411-1306-4E12-88B7-54A1AABC27F7@gmail.com>
@ 2018-02-11 11:51     ` Hans Hagen
  2018-02-11 13:17       ` Aditya Mahajan
  0 siblings, 1 reply; 5+ messages in thread
From: Hans Hagen @ 2018-02-11 11:51 UTC (permalink / raw)
  To: Otared Kavian, mailing list for ConTeXt users

On 2/11/2018 8:49 AM, Otared Kavian wrote:
> On 10 Feb 2018, at 17:56, Hans Hagen <pragma@wxs.nl> wrote:
>>
>> On 2/10/2018 4:10 PM, Otared Kavian wrote:
>>> […]
>> buffers are quite efficient as they never see the file system while input reads the file each time .. both are fresh reads so they obey catcode changes (different interpretations of characters)
>>
>> there might be more efficient ways for your case but without an example that's guessing
> 
> Hi Hans,
> 
> Thank you very much for your attention and your explanations about buffers.
> 
> I send below a working example showing what I wish to do: to extract from a data buffer some informations to be typeset separately according to some criteria. Maybe I am using the buffer where the data is stored inappropriately, but I can obtain what I want.
> 
> However if a sorting were necessary, then my approach would not work…. Is it possible to sort the buffer containing the data according to some key?

Think different ... see end.

> Best regards: OK
> 
> %% begin setvariable-getbuffer.tex
> \startbuffer[talkdata]
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> \setvariables[talk]%
> 	[speakername={Gauss},
> 	title={Remarks on Number Theory},
> 	time={8am},
> 	room={B},
> 	day={Monday},
> 	]
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> 
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> \setvariables[talk]%
> 	[speakername={Ampère},
> 	title={What is Magnetism},
> 	time={10am},
> 	room={A},
> 	day={Monday},
> 	]
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> 
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> \setvariables[talk]%
> 	[speakername={Dirac},
> 	title={Quaternions and the wave equation},
> 	time={11am},
> 	room={B},
> 	day={Tuesday},
> 	]
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> \stopbuffer
> 
> % we define what is to be typeset for each day
> \define[1]\talksofday{%
> 	\expdoif{\getvariable{talk}{day}}{#1}{%
> 		\starttabulate[|f{\bi}l|p|][before=]%
> 			\NC Speaker \EQ \getvariable{talk}{speakername} \NC\NR
> 			\NC Title   \EQ \getvariable{talk}{title} \NC\NR
> 			\NC Location and Time    \EQ Room \getvariable{talk}{room},
> 				at \getvariable{talk}{time} \NC\NR
> 		\HL
> 		\stoptabulate
> 	}
> 	}
> 
> % we define what is to be typeset for each room
> \define[1]\talksofroom{%
> 	\expdoif{\getvariable{talk}{room}}{#1}{
> 		\starttabulate[|f{\bi}l|p|][before=]%
> 		\NC Speaker \EQ \getvariable{talk}{speakername} \NC\NR
> 		\NC Title   \EQ \getvariable{talk}{title} \NC\NR
> 		\NC Day and Time    \EQ \getvariable{talk}{day}, at \getvariable{talk}{time} \NC\NR
> 		\HL
> 		\stoptabulate
> 	}
> 	}
> 
> \starttext
> 
> \starttitle[title={Monday talks}]
> \setvariable{talk}{set}{\talksofday{Monday}}
> \getbuffer[talkdata]
> \stoptitle
> \page
> 
> \starttitle[title={Tuesday talks}]
> \setvariable{talk}{set}{\talksofday{Tuesday}}
> \getbuffer[talkdata]
> \stoptitle
> \page
> 
> \starttitle[title={Talks in room B}]
> \setvariable{talk}{set}{\talksofroom{B}}
> \getbuffer[talkdata]
> \stoptitle
> 
> \stoptext
> %% end setvariable-getbuffer.tex
\startluacode

      -- document.speakerdata = table.load("somefile.lua")
      --
      -- with somefile.lue: return { ... }

     document.speakerdata = {
         {
             speakername = "Gauss",
             title       = "Remarks on Number Theory",
             time        = "8am",
             room        = "B",
             day         = "Monday",
         },
         {
             speakername = "Ampère",
             title       = "What is Magnetism",
             time        = "10am",
             room        = "A",
             day         = "Monday",
         },
         {
             speakername = "Dirac",
             title       = "Quaternions and the wave equation",
             time        = "11am",
             room        = "B",
             day         = "Tuesday",
         },
     }

\stopluacode

\startluacode
     document.talksofday = function(how)
         local data = document.speakerdata
         if how == "speakername" then
             local sort = { } for i=1,#data do sort[i] = data[i] end
             table.sort(sort,function(a,b) return a.speakername < 
b.speakername end)
             data = sort
         end
         context.starttabulate { "|f{\\bi}l|p|" }
         context.HL()
         for i=1,#data do
             local d = data[i]
			context.NC()
                 context("Speaker")
                 context.EQ()
                 context(d.speakername)
                 context.NC()
                 context.NR()
			context.NC()
                 context("Title")
                 context.EQ()
                 context(d.title)
                 context.NC()
                 context.NR()
			context.NC()
                 context("Location and Time")
                 context.EQ()
                 context("Room %s at %s",d.room,d.time)
                 context.NC()
                 context.NR()
             context.HL()
         end
         context.stoptabulate()
     end

\stopluacode

\starttext

\starttitle[title={Monday talks}]
     \ctxlua{document.talksofday()}
\stoptitle

\starttitle[title={Monday talks}]
     \ctxlua{document.talksofday("speakername")}
\stoptitle

\starttitle[title={Monday talks}]
     \ctxlua{document.talksofday()}
\stoptitle

\stoptext




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

* Re: To \getbuffer or to \input: which one is it better?
  2018-02-11 11:51     ` Hans Hagen
@ 2018-02-11 13:17       ` Aditya Mahajan
  2018-02-11 16:52         ` Hans Hagen
  2018-02-13  8:09         ` Otared Kavian
  0 siblings, 2 replies; 5+ messages in thread
From: Aditya Mahajan @ 2018-02-11 13:17 UTC (permalink / raw)
  To: mailing list for ConTeXt users

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1030 bytes --]

On Sun, 11 Feb 2018, Hans Hagen wrote:

> Think different ... see end.
>
> \startluacode
>
>     document.speakerdata = {
>         {
>             speakername = "Gauss",
>             title       = "Remarks on Number Theory",
>             time        = "8am",
>             room        = "B",
>             day         = "Monday",
>         },
>         {
>             speakername = "Ampère",
>             title       = "What is Magnetism",
>             time        = "10am",
>             room        = "A",
>             day         = "Monday",
>         },
>         {
>             speakername = "Dirac",
>             title       = "Quaternions and the wave equation",
>             time        = "11am",
>             room        = "B",
>             day         = "Tuesday",
>         },
>     }
>
> \stopluacode

I prefer starting with XML and converting it to a lua table using helper 
functions. The advantage of XML is that you can verify the data using an 
RNC schema.

Aditya

[-- Attachment #2: Type: text/plain, Size: 492 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] 5+ messages in thread

* Re: To \getbuffer or to \input: which one is it better?
  2018-02-11 13:17       ` Aditya Mahajan
@ 2018-02-11 16:52         ` Hans Hagen
  2018-02-13  8:09         ` Otared Kavian
  1 sibling, 0 replies; 5+ messages in thread
From: Hans Hagen @ 2018-02-11 16:52 UTC (permalink / raw)
  To: ntg-context

On 2/11/2018 2:17 PM, Aditya Mahajan wrote:
> On Sun, 11 Feb 2018, Hans Hagen wrote:
> 
>> Think different ... see end.
>>
>> \startluacode
>>
>>     document.speakerdata = {
>>         {
>>             speakername = "Gauss",
>>             title       = "Remarks on Number Theory",
>>             time        = "8am",
>>             room        = "B",
>>             day         = "Monday",
>>         },
>>         {
>>             speakername = "Ampère",
>>             title       = "What is Magnetism",
>>             time        = "10am",
>>             room        = "A",
>>             day         = "Monday",
>>         },
>>         {
>>             speakername = "Dirac",
>>             title       = "Quaternions and the wave equation",
>>             time        = "11am",
>>             room        = "B",
>>             day         = "Tuesday",
>>         },
>>     }
>>
>> \stopluacode
> 
> I prefer starting with XML and converting it to a lua table using helper 
> functions. The advantage of XML is that you can verify the data using an 
> RNC schema.
i must admit that i never validate xml .. probably also because most xml 
we get is invalid or has element abuse anyway so one has to look into 
what one gets and act upon interferences

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

* Re: To \getbuffer or to \input: which one is it better?
  2018-02-11 13:17       ` Aditya Mahajan
  2018-02-11 16:52         ` Hans Hagen
@ 2018-02-13  8:09         ` Otared Kavian
  1 sibling, 0 replies; 5+ messages in thread
From: Otared Kavian @ 2018-02-13  8:09 UTC (permalink / raw)
  To: mailing list for ConTeXt users



> On 11 Feb 2018, at 14:17, Aditya Mahajan <adityam@umich.edu> wrote:
> 
> On Sun, 11 Feb 2018, Hans Hagen wrote:
> […]
> 
> I prefer starting with XML and converting it to a lua table using helper functions. The advantage of XML is that you can verify the data using an RNC schema.

Hi Aditya,

Thanks for your input. 
Since, to say the least, I am more than very limited in programming, I am not yet able to explore the XML approach your are suggesting. But once I have done some progress in using Lua + ConTeXt as Hans has shown me, I’ll try to explore also the XML approach, since it might be interesting to have a version  for webpages of the document I am preparing.

Best regards: OK
___________________________________________________________________________________
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] 5+ messages in thread

end of thread, other threads:[~2018-02-13  8:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-10 15:10 To \getbuffer or to \input: which one is it better? Otared Kavian
     [not found] ` <9d5cc80b-f851-6b00-53d7-300963e1e55a@wxs.nl>
     [not found]   ` <A462E411-1306-4E12-88B7-54A1AABC27F7@gmail.com>
2018-02-11 11:51     ` Hans Hagen
2018-02-11 13:17       ` Aditya Mahajan
2018-02-11 16:52         ` Hans Hagen
2018-02-13  8:09         ` Otared Kavian

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