Changes

Jump to navigation Jump to search
2,759 bytes added ,  03:25, 13 November 2005
tables from CSV (by Christopher Creutzig)
and <cmd>setupTABLE</cmd><tt>[split=yes]</tt> or <tt>[split=repeat]</tt>
see also [[source:core-ntb.tex|core-ntb.tex]] == Creating tables from CSV data (Comma Separated Values) == <!-- Maybe some other place or a separate page is more appropriate for this section --> An interesting example of creating a table using comma separated values was posted to the [http://sourcearchive.contextgarden.net/core-ntbmessage/20050923.193302.f2110c93.en.html mailing list] by [[User:ChristopherCreutzig|Christopher Creutzig]] The following macros take care of processing CSV data:<texcode>% Iterate over all the lines of text captured with \obeylines active% command to call is first argument, is not called for empty lines\bgroup\obeylines\gdef\ProcessLines#1#2{\doProcessLines{#1}#2^^M\doProcessLines}%\gdef\doProcessLines#1#2^^M#3\doProcessLines{% \doifnotempty{#2}{#1{#2}}% \doifnotempty{#3}{\doProcessLines{#1}#3\doProcessLines}%}%\egroup \def\startCSV{\bgroup\obeylines\dostartCSV}</texcode> The next lines are an example of transforming the data into a natural table, but can be easily adapted to any type of the table or perhaps (mis)used in even more strange ways: <texcode>\def\TBLentry#1{\bTD#1\eTD}\def\TBLline#1{\bTR\processcommalist[#1]\TBLentry} \def\dostartCSV#1\stopCSV{% \bTABLE \ProcessLines\TBLline{#1}% \eTABLE \egroup}</texcode> The following lines will then finally result in a desired table: <texcode>% some additional settings for the table may be made as well\setupTABLE[c][2][style=\tt]\setupTABLE[c][3][align=middle]\setupTABLE[r][1][style=bold] % how to override the \tt in the second column? \startCSVName,Email,Accepted\CONTEXT,worth@trying.to,YesHans,main@developer.tex core-ntbof,YesBug,get@rid.texof,No\stopCSV</texcode> <context>% Iterate over all the lines of text captured with \obeylines active% command to call is first argument, is not called for empty lines\bgroup\obeylines\gdef\ProcessLines#1#2{\doProcessLines{#1}#2^^M\doProcessLines}%\gdef\doProcessLines#1#2^^M#3\doProcessLines{% \doifnotempty{#2}{#1{#2}}% \doifnotempty{#3}{\doProcessLines{#1}#3\doProcessLines}%}%\egroup \def\startCSV{\bgroup\obeylines\dostartCSV} \def\TBLentry#1{\bTD#1\eTD}\def\TBLline#1{\bTR\processcommalist[#1]\TBLentry} \def\dostartCSV#1\stopCSV{% \bTABLE \ProcessLines\TBLline{#1}% \eTABLE \egroup} \setupTABLE[c][2][style=\tt]\setupTABLE[c][3][align=middle]\setupTABLE[r][1][style={\rm\bf}]\startCSVName,Email,Accepted\CONTEXT,worth@trying.to,YesHans,main@developer.of,YesBug,get@rid.of,No\stopCSV</context> Some remarks: the (tentative) code ignores the fact that* csv data may optionally be enclosed in "" quotes that have to be removed (to be done in \TBLentry) * quoted strings may contain commas themselves (which means writing a custom version of \processcommalist instead). {{howto}} What about separating the values using tabs? 
== Designing complex TABLEs ==

Navigation menu