Hi Hans, natural tables are perfect to create tables with a fixed size for the cells but the syntax requires sometimes a lot of typing for small content and takes to many lines of code in the document. I wrote a while ago a simple wrapper to use a table/tabulate like syntax for the input, what I don't like is to load a extra module for just a few lines of code and I think they can be integrated in the core-ntb code. Wolfgang %D \module %D [ file=wolf-tab, %D version=2007.01.26, %D title=\CONTEXT\ User Module, %D subtitle=New Tables, %D author=Wolfgang Schuster, %D date=\currentdate, %D copyright=Wolfgang Schuster] \writestatus{loading}{Context User Module / New Tables} \unprotect %D This module provides an easy way to use natural in a similiar %D way as the older table module (based on the \TABLE\ macros) and %D the newer tabulate module. %D %D You can see the advantage in the following table, once created %D with the new macros and once with the normal macros provided %D with the natural table module. %D %D Let us start with the original macros: %D %D \starttyping %D \bTABLE %D \bTR %D \bTD Text 1 \eTD %D \bTD Text 2 \eTD %D \eTR %D \bTR %D \bTD Text 3 \eTD %D \bTD Text 4 \eTD %D \eTR %D \eTABLE %D \stoptyping %D %D and now with my new macros: %D %D \starttyping %D \startTABLE %D \NC Text 1 \NC Text 2 \NC\NR %D \NC Text 3 \NC Text 4 \NC\NR %D \stopTABLE %D \stoptyping \def\startTABLE {\dosingleempty\dostartTABLE} \def\dostartTABLE[#1]% {\bgroup \def\NC{\parseNC} \bTABLE[#1]} \def\stopTABLE {\eTABLE \egroup} \def\parseNC#1\NR {\bTR \processNC#1\stopNC\NC} \def\stopNC{\stopNC} \def\processNC#1\NC% {\def\temp{#1}% \ifx\temp\stopNC \eTR \else \bTD#1\eTD% \expandafter\processNC \fi} % shorter but did not work when external files are loaded in the table, % e.g. \bTD \input knuth \eTD. % %\def\parseNC#1\NC\NR % {\bTR % \processseparatedlist[#1][\NC]\processNC % \eTR} % %\def\processNC#1% % {\bTD#1\eTD} %D I used the same mechanism as in \type{core-ntb.tex} to allow different %D headers on the first and the following pages. The only changes ist that %D I renamed the commands from \tex{bTABLE...} to \tex{startTABLE...} and %D from \tex{eTABLE...} to \tex{stopTABLE...} to match the start and stop %D pair at begin and end of the table. \long\def\startTABLEhead{\dosingleempty\dostartTABLEhead} \long\def\startTABLEnext{\dosingleempty\dostartTABLEnext} \long\def\startTABLEbody{\dosingleempty\dostartTABLEbody} \long\def\startTABLEfoot{\dosingleempty\dostartTABLEfoot} \long\def\dostartTABLEhead[#1]#2\stopTABLEhead{\appendtoks \doTABLEsection[#1]{#2}\to\TBLhead} \long\def\dostartTABLEnext[#1]#2\stopTABLEnext{\appendtoks \doTABLEsection[#1]{#2}\to\TBLnext} \long\def\dostartTABLEbody[#1]#2\stopTABLEbody{\appendtoks \doTABLEsection[#1]{#2}\to\TBLbody} \long\def\dostartTABLEfoot[#1]#2\stopTABLEfoot{\appendtoks \doTABLEsection[#1]{#2}\to\TBLfoot} %D \startbuffer %D \startTABLE %D \NC Text 1 \NC Text 2 \NC\NR %D \NC Text 3 \NC Text 4 \NC\NR %D \stopTABLE %D \stopbuffer %D %D My example from the begin of this module %D %D \typebuffer %D %D looks like this: %D %D \startlinecorrection %D \getbuffer %D \stoplinecorrection \protect \endinput
On Sun, 8 Mar 2009, Wolfgang Schuster wrote:
Hi Hans,
natural tables are perfect to create tables with a fixed size for the cells but the syntax requires sometimes a lot of typing for small content and takes to many lines of code in the document.
I wrote a while ago a simple wrapper to use a table/tabulate like syntax for the input, what I don't like is to load a extra module for just a few lines of code and I think they can be integrated in the core-ntb code.
Only yesterday I went over my old mails to search for this and hoped that it would be available as a module :) Just a few comments.
%D \module %D [ file=wolf-tab, %D version=2007.01.26, %D title=\CONTEXT\ User Module, %D subtitle=New Tables, %D author=Wolfgang Schuster, %D date=\currentdate, %D copyright=Wolfgang Schuster]
\writestatus{loading}{Context User Module / New Tables}
\unprotect
%D This module provides an easy way to use natural in a similiar %D way as the older table module (based on the \TABLE\ macros) and %D the newer tabulate module. %D %D You can see the advantage in the following table, once created %D with the new macros and once with the normal macros provided %D with the natural table module. %D %D Let us start with the original macros: %D %D \starttyping %D \bTABLE %D \bTR %D \bTD Text 1 \eTD %D \bTD Text 2 \eTD %D \eTR %D \bTR %D \bTD Text 3 \eTD %D \bTD Text 4 \eTD %D \eTR %D \eTABLE %D \stoptyping %D %D and now with my new macros: %D %D \starttyping %D \startTABLE %D \NC Text 1 \NC Text 2 \NC\NR %D \NC Text 3 \NC Text 4 \NC\NR %D \stopTABLE %D \stoptyping
\def\startTABLE {\dosingleempty\dostartTABLE}
\def\dostartTABLE[#1]% {\bgroup \def\NC{\parseNC} \bTABLE[#1]}
\def\stopTABLE {\eTABLE \egroup}
\def\parseNC#1\NR {\bTR \processNC#1\stopNC\NC}
To avoid potential conflicts, can you name \parseNC as \paseTABLENC, \processNC as \processTABLENC, and \stopNC as \stopTABLENC.
\def\stopNC{\stopNC}
\def\processNC#1\NC% {\def\temp{#1}%
How about \currentTABLEcell instead of \temp?
\ifx\temp\stopNC \eTR \else \bTD#1\eTD% \expandafter\processNC \fi}
% shorter but did not work when external files are loaded in the table, % e.g. \bTD \input knuth \eTD. % %\def\parseNC#1\NC\NR % {\bTR % \processseparatedlist[#1][\NC]\processNC % \eTR} % %\def\processNC#1% % {\bTD#1\eTD}
%D I used the same mechanism as in \type{core-ntb.tex} to allow different %D headers on the first and the following pages. The only changes ist that %D I renamed the commands from \tex{bTABLE...} to \tex{startTABLE...} and %D from \tex{eTABLE...} to \tex{stopTABLE...} to match the start and stop %D pair at begin and end of the table.
\long\def\startTABLEhead{\dosingleempty\dostartTABLEhead} \long\def\startTABLEnext{\dosingleempty\dostartTABLEnext} \long\def\startTABLEbody{\dosingleempty\dostartTABLEbody} \long\def\startTABLEfoot{\dosingleempty\dostartTABLEfoot}
\long\def\dostartTABLEhead[#1]#2\stopTABLEhead{\appendtoks\doTABLEsection[#1]{#2}\to\TBLhead} \long\def\dostartTABLEnext[#1]#2\stopTABLEnext{\appendtoks\doTABLEsection[#1]{#2}\to\TBLnext} \long\def\dostartTABLEbody[#1]#2\stopTABLEbody{\appendtoks\doTABLEsection[#1]{#2}\to\TBLbody} \long\def\dostartTABLEfoot[#1]#2\stopTABLEfoot{\appendtoks\doTABLEsection[#1]{#2}\to\TBLfoot}
%D \startbuffer %D \startTABLE %D \NC Text 1 \NC Text 2 \NC\NR %D \NC Text 3 \NC Text 4 \NC\NR %D \stopTABLE %D \stopbuffer %D %D My example from the begin of this module %D %D \typebuffer %D %D looks like this: %D %D \startlinecorrection %D \getbuffer %D \stoplinecorrection
\protect \endinput
Thanks, Aditya
Aditya Mahajan wrote:
On Sun, 8 Mar 2009, Wolfgang Schuster wrote:
Hi Hans,
natural tables are perfect to create tables with a fixed size for the cells but the syntax requires sometimes a lot of typing for small content and takes to many lines of code in the document.
less code and more efficient too ... can you test this? \def\startTABLE {\dosingleempty\dostartTABLE} \def\dostartTABLE[#1]% {\bgroup \bTABLE[#1]% \let\NC\doTABLENC \let\NR\doTABLENR \let\bTR\relax \let\bTD\relax \let\bTH\relax \let\bTN\relax} \def\stopTABLE {\eTABLE \egroup} \newconditional\inTABLEnc \unexpanded\def\doTABLENR {\eTR \setfalse\inTABLEnc} \unexpanded\def\doTABLENC {\futurelet\next\dodoTABLENC} \def\dodoTABLENC {\ifx\next\doTABLENR \else \expandafter\dododoTABLENC \fi} \long\def\dododoTABLENC#1\NC {\ifconditional\inTABLEnc\else\settrue\inTABLEnc\parseTR[][]\fi \parseTD[][]#1\eTD\NC} watch the relaxing of the b commands, so that we catch mixed usage Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Hans Hagen
John Devereux wrote:
Hans Hagen
writes: [...]
Hi Hans,
Is there any possible way to use the wiki-style tables like:
^ Heading 1 ^ Heading 2 ^ | Item 1 | Item 2 | | Item 3 | Item 4 |
(Probably with some wrapper)
Perhaps this boils down to asking if it is possible to (re)define "special" characters, within a region of text.
doing that in the running text is asking for troubles (catcode mess) if there is real interest in that kind of stuff we can make a module that does something \starttext \startluacode function commands.wiki_to_table(str) -- wrong namespace str = string.gsub(str,"%^ *[\n\r]","\\NC\\NR\n") str = string.gsub(str,"%^","\\NC ") str = string.gsub(str,"| *[\n\r]","\\NC\\NR\n") str = string.gsub(str,"|","\\NC ") tex.sprint(tex.ctxcatcodes,"\\startTABLE") tex.sprint(tex.ctxcatcodes,str) tex.sprint(tex.ctxcatcodes,"\\stopTABLE") end \stopluacode \def\startwikitable {\bgroup \obeylines \dostartwikitable} \long\def\dostartwikitable#1\stopwikitable {\ctxlua{commands.wiki_to_table([[\detokenize{#1}]])}% \egroup} \startwikitable ^ Heading 1 ^ Heading 2 ^ | Item 1 | Item 2 | | Item 3 | Item 4 | \stopwikitable \startTABLE \NC Text 1 \NC Text 2 \NC \NR \NC Text 3 \NC Text 4 \NC \NR \stopTABLE \stoptext ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Hans Hagen
John Devereux wrote:
Hans Hagen
writes: [...]
Hi Hans,
Is there any possible way to use the wiki-style tables like:
^ Heading 1 ^ Heading 2 ^ | Item 1 | Item 2 | | Item 3 | Item 4 |
(Probably with some wrapper)
Perhaps this boils down to asking if it is possible to (re)define "special" characters, within a region of text.
doing that in the running text is asking for troubles (catcode mess)
if there is real interest in that kind of stuff we can make a module that does something
\starttext
\startluacode function commands.wiki_to_table(str) -- wrong namespace str = string.gsub(str,"%^ *[\n\r]","\\NC\\NR\n") str = string.gsub(str,"%^","\\NC ") str = string.gsub(str,"| *[\n\r]","\\NC\\NR\n") str = string.gsub(str,"|","\\NC ") tex.sprint(tex.ctxcatcodes,"\\startTABLE") tex.sprint(tex.ctxcatcodes,str) tex.sprint(tex.ctxcatcodes,"\\stopTABLE") end \stopluacode
\def\startwikitable {\bgroup \obeylines \dostartwikitable}
\long\def\dostartwikitable#1\stopwikitable {\ctxlua{commands.wiki_to_table([[\detokenize{#1}]])}% \egroup}
\startwikitable ^ Heading 1 ^ Heading 2 ^ | Item 1 | Item 2 | | Item 3 | Item 4 | \stopwikitable
\startTABLE \NC Text 1 \NC Text 2 \NC \NR \NC Text 3 \NC Text 4 \NC \NR \stopTABLE
\stoptext
That appears to be exactly what I was after! (Sorry I don't have MKIV set up right now but will try it when I can). I don't know if it is of general interest. I find that writing documents for context - once you get used to it - is much nicer than using a wordprocessor. But the process of entering tables remains tedious and error prone, compared to e.g. the Word equivalent that many will be used to. -- John Devereux
On Sun, Mar 8, 2009 at 4:10 PM, John Devereux
[...] I find that writing documents for context - once you get used to it - is much nicer than using a wordprocessor.
But the process of entering tables remains tedious and error prone, compared to e.g. the Word equivalent that many will be used to.
Many of my tables are results from some numerical computation, I usually
write a short program to print the data in the required ConTeXt/LaTeX
format. The others I try to find some similar existing table and update
the text.
--
George N. White III
Thank you for the two new table syntaxes! I wikified them: http://wiki.contextgarden.net/wikitable http://wiki.contextgarden.net/TABLE#TABLEs_with_old_table_syntax Greetlings from Lake Constance! Hraban --- http://www.fiee.net/texnique/ http://wiki.contextgarden.net https://www.cacert.org (I'm an assurer)
On Sun, Mar 8, 2009 at 19:03, John Devereux wrote:
Hans Hagen
writes: [...]
Hi Hans,
Is there any possible way to use the wiki-style tables like:
^ Heading 1 ^ Heading 2 ^ | Item 1 | Item 2 | | Item 3 | Item 4 |
(Probably with some wrapper)
Perhaps this boils down to asking if it is possible to (re)define "special" characters, within a region of text.
Hans already answered your question for mkiv. To a certain degree that's already implemented in the database module that also works with mkii (http://wiki.contextgarden.net/m-database) and sometimes a bit buggy, but it works. You may take a look at that one. Mojca
On Sun, Mar 8, 2009 at 5:58 PM, Hans Hagen
Aditya Mahajan wrote:
On Sun, 8 Mar 2009, Wolfgang Schuster wrote:
Hi Hans,
natural tables are perfect to create tables with a fixed size for the cells but the syntax requires sometimes a lot of typing for small content and takes to many lines of code in the document.
less code and more efficient too ... can you test this?
\def\startTABLE {\dosingleempty\dostartTABLE}
\def\dostartTABLE[#1]% {\bgroup \bTABLE[#1]% \let\NC\doTABLENC \let\NR\doTABLENR \let\bTR\relax \let\bTD\relax \let\bTH\relax \let\bTN\relax}
\def\stopTABLE {\eTABLE \egroup}
\newconditional\inTABLEnc
\unexpanded\def\doTABLENR {\eTR \setfalse\inTABLEnc}
\unexpanded\def\doTABLENC {\futurelet\next\dodoTABLENC}
\def\dodoTABLENC {\ifx\next\doTABLENR \else \expandafter\dododoTABLENC \fi}
\long\def\dododoTABLENC#1\NC {\ifconditional\inTABLEnc\else\settrue\inTABLEnc\parseTR[][]\fi \parseTD[][]#1\eTD\NC}
Can you change this to \long\def\dododoTABLENC#1\NC {\ifconditional\inTABLEnc\else\settrue\inTABLEnc\parseTR[][]\fi \dodoubleempty\parseTD#1\eTD\NC} I want to be able to give argument with \NC too, it's important for me to be able to use spanned columns/rows in the simple form. Wolfgang
Wolfgang Schuster wrote:
\long\def\dododoTABLENC#1\NC {\ifconditional\inTABLEnc\else\settrue\inTABLEnc\parseTR[][]\fi \dodoubleempty\parseTD#1\eTD\NC}
I want to be able to give argument with \NC too, it's important for me to be able to use spanned columns/rows in the simple form.
i had that but then considered it kind of contraditing the simple setup anyhow, i changed it ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
participants (7)
-
Aditya Mahajan
-
George N. White III
-
Hans Hagen
-
Henning Hraban Ramm
-
John Devereux
-
Mojca Miklavec
-
Wolfgang Schuster