Re: [NTG-context] To \getbuffer or to \input: which one is it better?

2018-02-13 Thread Otared Kavian


> On 11 Feb 2018, at 14:17, Aditya Mahajan  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
___

Re: [NTG-context] To \getbuffer or to \input: which one is it better?

2018-02-11 Thread Hans Hagen

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
___

Re: [NTG-context] To \getbuffer or to \input: which one is it better?

2018-02-11 Thread Aditya Mahajan

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

Re: [NTG-context] To \getbuffer or to \input: which one is it better?

2018-02-11 Thread Hans Hagen

On 2/11/2018 8:49 AM, Otared Kavian wrote:

On 10 Feb 2018, at 17:56, Hans Hagen  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()
  

[NTG-context] To \getbuffer or to \input: which one is it better?

2018-02-10 Thread Otared Kavian
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
___