From: Jaroslav Hajtmar <hajtmar@gyza.cz>
To: ntg-context@ntg.nl
Subject: Re: sorted phone directory
Date: Wed, 03 Aug 2011 04:41:21 +0200 [thread overview]
Message-ID: <4E38B551.6030501@gyza.cz> (raw)
In-Reply-To: <4E38586F.8090705@uni-bonn.de>
Hello Johan,
Certainly it is possible to combine solution of Wolfgang with retrieving
data from an external file without having to sort the data by another
application. Enough to define a simple ConTeXt macro that contains a
piece of Lua code. Here my modification of Wolfgang last solution for
your inspiration:
\def\processexternalfile#1{
\startluacode
myextfile=io.open('#1',"r")
repeat
line=myextfile:read()
if line ~= nil then
splitline=string.split(line, ",")
context('\\Telefon['..splitline[1]..']{'..splitline[2]..'}')
end
until (line == nil)
myextfile:close()
\stopluacode
}
\mainlanguage[swedish]
\definedescription
[TelefonEntry]
[width=2em]
\unexpanded\def\TelefonCommand#1#2#3%
{\hbox to \hsize{#2\hfil#3}\par}
\definesorting[Telefon][Telefone]
\starttext
Wolfgang's solution:
\Telefon[Eldallah Awdawebi]{78423}
\Telefon[Nada Pipidepaulou]{78264}
\Telefon[Aölaksd aölksd]{044578264}
\Telefon[Ö]{320399}
\Telefon[å]{23402394}
\Telefon[åå]{23042}
\Telefon[ååå]{098234}
\startcolumns[n=3]
\placelistofsorts[Telefon][criterium=all,command=\TelefonCommand]
\stopcolumns
\blank[big]
% Create external CSV file "extfile.csv".
% Structure of this file is:
% Eldallah Awdawebi,78423
% Nada Pipidepaulou,78264
% Aölaksd aölksd,044578264
% Ö,320399
% å,23402394
% åå,23042
% ååå,098234
My solution - processing an external file \quotation{extfile.csv}:
\processexternalfile{extfile.csv}
\startcolumns[n=3]
\placelistofsorts[Telefon][criterium=all,command=\TelefonCommand]
\stopcolumns
\stoptext
Best regards
Jaroslav
Dne 2.8.2011 22:05, Thomas A. Schmitz napsal(a):
> On 08/02/2011 04:08 PM, Johan Sandblom wrote:
>> Thank you for your suggestions!
>>
>> Jaroslav, having the numbers in a separate file and sorting there,
>> while possible, would increase overhead in managing the document and
>> make it impossible to enter phone numbers at other places in the text.
>>
> Ultimately, it is of course your decision what you want to do, but I
> think you were a bit quick to reject Jaroslav's suggestion. TeX isn't
> meant to store databases. Having the information in some external file
> will actually make things much easier in the middle and long run. It's
> easier to manage, it scales better, and it will allow you to reuse
> this information in other ways. And ConTeXt is excellent in that it
> can handle many different input formats. I wrote something about using
> databases in xml or sql format in the latest MAPS issue; csv is easy
> to produce (libreoffice calc can produce csv). You could even store
> the information in a raw lua table and then retrieve it via some
> macros. I think the sorting itself should be done in ConTeXt because
> language support for the other solutions is probably not as
> straightforward (if it exists at all), but I would definitely store
> the information in some other format. Again, it is your decision, and
> of course we don't know what special requirements you have, but using
> some sort of well-known format would make your solution much more
> future-proof.
>
> Good luck
>
> Thomas
> ___________________________________________________________________________________
>
> 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://tex.aanhet.net
> archive : http://foundry.supelec.fr/projects/contextrev/
> wiki : http://contextgarden.net
> ___________________________________________________________________________________
>
>
___________________________________________________________________________________
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://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2011-08-03 2:41 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-02 9:08 Johan Sandblom
2011-08-02 10:44 ` Jaroslav Hajtmar
2011-08-02 11:15 ` Pontus Lurcock
2011-08-02 11:33 ` Wolfgang Schuster
2011-08-02 14:08 ` Johan Sandblom
2011-08-02 14:23 ` Wolfgang Schuster
2011-08-02 14:50 ` Johan Sandblom
2011-08-02 15:01 ` Wolfgang Schuster
2011-08-02 15:10 ` Johan Sandblom
2011-08-02 15:15 ` Johan Sandblom
2011-08-02 15:19 ` Wolfgang Schuster
2011-08-02 20:05 ` Johan Sandblom
2011-08-02 20:05 ` Thomas A. Schmitz
2011-08-03 2:41 ` Jaroslav Hajtmar [this message]
2011-08-03 5:29 ` Johan Sandblom
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4E38B551.6030501@gyza.cz \
--to=hajtmar@gyza.cz \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).