Changes

Jump to navigation Jump to search
307 bytes added ,  21:05, 9 March 2023
add \bTABLEsection; move old CSV section to the bottom; small fixes
Try to divide your table into...
* {{cmd|bTABLEhead}} (table header, can repeat after page breaks)* {{cmd|bTABLEnext}} (alternate table header on following pages)* {{cmd|bTABLEsection}} (subtitle that also can repeat after page breaks)* {{cmd|bTABLEbody}} (table body)* {{cmd|bTABLEfoot}} (table footer)
and {{cmd|setupTABLE}}<tt>[split=yes]</tt> or <tt>[split=repeat]</tt>
is printed only once at the beginning of the table. But if you use <tt>[split=repeat]</tt>,
it is printed on top of every new page, that contains parts of
your multipage table. Please take account of the fact, that thehead cells are enclosed by {{cmd|bTH}} and {{cmd|eTH}} (and not \[be]TCTD).
If you want to use an alternative table header for all following pages,
'''Beware:''' Split tables often begin not on the page (or in the column, if you use them) where they ''could'' start, but on/in the next one.
This is a known limitation due to the complicated calculation of remaining space on the page.
 That won't won’t become better before this calculations are newly written in Lua. (Said Hans on 2010-09-24.)And it became better for LMTX, in 2021/2022.
The following standalone example deals with all the mentioned aspects of natural tables.
== Headers with TABLEs ==
When one has you have a multi-page TABLE in the document (using either the <tt>split=repeat</tt> or <tt>split=yes</tt> options), and the (page) header text is also organized as styled with a TABLE, the table header ends up getting crammed into the document header resulting in incorrect output. To alleviate this , {{cmd|bTABLEnested}} and {{cmd|eTABLEnested}} may be used as in the example below to ensure that table headers don't don’t get mixed up with the document header.
<texcode>
= Tables in multiple columns =
... should just work (at least in luaTeX and your installation but not here...). See the following example.
<texcode>
\starttext
\startcolumns[n=3]
\bTABLE
\eTABLE
\stopcolumns
\stoptext
</texcode>
= Creating tables from CSV data (Comma Separated Values) =
 
See also [[M-database|the database module]]!
 
and [http://dl.contextgarden.net/myway/csv.pdf Creating Tables using CSV (Comma-separated values)] by Mojca Miklavec
 
 
<!-- 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://archive.contextgarden.net/message/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?
 
\startCSV
Name,Email,Accepted
\CONTEXT,worth@trying.to,Yes
Hans,main@developer.of,Yes
Bug,get@rid.of,No
\stopCSV
</texcode>
 
<context>
\setuppapersize[A5]
 
% 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}]
\startCSV
Name,Email,Accepted
\CONTEXT,worth@trying.to,Yes
Hans,main@developer.of,Yes
Bug,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).
 
See also {{cmd|processseparatedlist}}.
= Designing complex TABLEs =
\stop
</texcode>
 
= Creating tables from CSV data (Comma Separated Values) =
 
'''Beware, this is very old code'''; while it might still work (untested), it makes more sense to do data processing with Lua.
 
See also [[M-database|the database module]]!
 
and [http://dl.contextgarden.net/myway/csv.pdf Creating Tables using CSV (Comma-separated values)] by Mojca Miklavec
 
 
<!-- 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://archive.contextgarden.net/message/20050923.193302.f2110c93.en.html mailing list] in 2005 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?
 
\startCSV
Name,Email,Accepted
\CONTEXT,worth@trying.to,Yes
Hans,main@developer.of,Yes
Bug,get@rid.of,No
\stopCSV
</texcode>
 
<context>
\setuppapersize[A5]
 
% 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}]
\startCSV
Name,Email,Accepted
\CONTEXT,worth@trying.to,Yes
Hans,main@developer.of,Yes
Bug,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).
 
See also {{cmd|processseparatedlist}}.

Navigation menu