I agree there may be advantages with a solution involving an external
file. The phone directory is slowly growing, but it has taken it years
to reach one page, so I am not sure the size of the database will ever
be a problem. The current solution works for now, but it is good to be
able to handle external files this way if the need arises.
Thank you for your opinions.
Johan
2011/8/3 Jaroslav Hajtmar
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 ___________________________________________________________________________________
-- Johan Sandblom, MD PhD m +46735521477 Sweden "What is wanted is not the will to believe, but the will to find out, which is the exact opposite" - Bertrand Russell