summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/tabl-nte.mkiv
blob: af74a2abe9b1a5061d04c2a05151e5cd6937b533 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
%D \module
%D   [       file=core-nte,
%D        version=2009.03.08,
%D          title=\CONTEXT\ Table Macros,
%D       subtitle=Natural Tables Extensions,
%D         author=Hans Hagen \& Wolfgang Schuster,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Table Module / Natural Tables Extensions}

\unprotect

%D This module is suggested by Wolfgang Schuster who also prototyped
%D it and came up with the rationale:
%D
%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 \startbuffer
%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 \stopbuffer
%D
%D \typebuffer \getbuffer
%D
%D Watch how the new macros use less code:
%D
%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 \typebuffer \getbuffer
%D
%D The actual code differs from the prototype that it does not need
%D to collect whole rows and parse them but looks ahead instead.

\newconditional\c_tabl_nte_in_nc

\unexpanded\def\startTABLE
  {\dosingleempty\tabl_nte_start}

\def\tabl_nte_start[#1]%
  {\bgroup
   \bTABLE[#1]%
   \let\NC\tabl_nte_start_nc
   \let\NR\tabl_nte_start_nr
   \let\bTR\relax
   \let\bTD\relax
   \let\bTH\relax
   \let\bTN\relax}

\unexpanded\def\stopTABLE
  {\eTABLE
   \egroup}

\unexpanded\def\tabl_nte_start_nr
  {\eTR
   \setfalse\c_tabl_nte_in_nc}

\unexpanded\def\tabl_nte_start_nc
  {\futurelet\next\tabl_nte_start_nc_indeed}

\def\tabl_nte_start_nc_indeed
  {\ifx\next\tabl_nte_start_nr \else
     \expandafter\tabl_nte_start_nc_finish
   \fi}

\def\tabl_nte_start_nc_finish#1\NC
  {\ifconditional\c_tabl_nte_in_nc \else
     \settrue\c_tabl_nte_in_nc
     \dobTR[]%
   \fi
   \dobTD#1\eTD\NC}

%D The related structure commands are also available:

\unexpanded\def\startTABLEhead{\dosingleempty\tabl_nte_start_head} \let\stopTABLEhead\relax
\unexpanded\def\startTABLEnext{\dosingleempty\tabl_nte_start_next} \let\stopTABLEnext\relax
\unexpanded\def\startTABLEbody{\dosingleempty\tabl_nte_start_body} \let\stopTABLEbody\relax
\unexpanded\def\startTABLEfoot{\dosingleempty\tabl_nte_start_foot} \let\stopTABLEfoot\relax

\def\tabl_nte_start_head[#1]#2\stopTABLEhead{\appendtoks\tabl_ntb_section[#1]{#2}\to\t_tabl_ntb_head}
\def\tabl_nte_start_next[#1]#2\stopTABLEnext{\appendtoks\tabl_ntb_section[#1]{#2}\to\t_tabl_ntb_next}
\def\tabl_nte_start_body[#1]#2\stopTABLEbody{\appendtoks\tabl_ntb_section[#1]{#2}\to\t_tabl_ntb_body}
\def\tabl_nte_start_foot[#1]#2\stopTABLEfoot{\appendtoks\tabl_ntb_section[#1]{#2}\to\t_tabl_ntb_foot}

\protect \endinput