summaryrefslogtreecommitdiff
path: root/tex/context/base/mkii/supp-ali.mkii
blob: c4a1aadc5260465da4438a485c29fda61c1f8e5d (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
%D \module
%D   [       file=supp-ali,
%D        version=2000.04.17,
%D          title=\CONTEXT\ Support Macros,
%D       subtitle=Alignment,
%D         author=Hans Hagen,
%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.

%D Yet undocumented.

% 0 = centered
% 1 = left  in before
% 2 = right in before
% 3 = left  in after
% 4 = right in after

\unprotect

% \starttabulate[|cg{.}|cg{,}|cg{,}|]
% \NC period     \NC comma      \NC comma   \NC\NR
% \NG 100.000,00 \NG 100.000,00 \NG 100,00  \NC\NR
% \NG 10.000,00  \NG 10.000,00  \NG 1000,00 \NC\NR
% \NG 100,00     \NG 100,00     \NG 10,00   \NC\NR
% \NG 100,00     \NG 100,00     \NG 10,00   \NC\NR
% \NG 10\\       \NG 10\\       \NG 0,00    \NC\NR
% \NG 10         \NG 10         \NG 0,00    \NC\NR
% \NG 10         \NG 10         \NG 0,00    \NC\NR
% \stoptabulate

\chardef\characteralignmentmode=4
\chardef\characteralignmentslot=1

\newtoks\@@characteralignlst

\let\afterassignwidth \!!zeropoint
\let\beforeassignwidth\!!zeropoint

\def\alignmentcharacter{.}

\let\alignmentclass\s!default % can be used to handle multiple mixed ones

\def\setfirstpasscharacteralign
  {\popcharacteralign
   \expanded{\dosetfirstpasscharacteralign{\alignmentcharacter}}}

\def\dosetfirstpasscharacteralign#1%
  {\def\checkalignment##1%
     {\popcharacteralign
      \let\\\empty
      \setbox\scratchbox\hbox{#1}%
      \edef\characterassignwidth{\the\wd\scratchbox}%
      \setbox\scratchbox\null
      \docheckalignment##1#1\relax\relax
      \scratchdimen-\wd\scratchbox
      \setbox\scratchbox\hbox{\ignorespaces##1\unskip}%
      \advance\scratchdimen \wd\scratchbox
      \ifdim\scratchdimen>\beforeassignwidth\relax
        \edef\beforeassignwidth{\the\scratchdimen}%
      \fi
      \ifdim\scratchdimen=\zeropoint
        \setbox\scratchbox\hbox{\ignorespaces##1\unskip}%
        \scratchdimen\wd\scratchbox
        \ifcase\characteralignmentmode
          % do nothing
        \else\ifnum\characteralignmentmode<\plusthree
          \advance\scratchdimen \characterassignwidth
          \ifdim\scratchdimen>\beforeassignwidth\relax
            \edef\beforeassignwidth{\the\scratchdimen}%
          \fi
        \else
          \ifdim\scratchdimen>\afterassignwidth\relax
            \edef\afterassignwidth{\the\scratchdimen}%
          \fi
        \fi\fi
      \fi
      \pushcharacteralign}%
   \def\docheckalignment##1#1##2##3\relax
     {\ifx##2\relax
        \setbox\scratchbox\hbox{\ignorespaces##1\unskip}%
        \ifdim\wd\scratchbox>\afterassignwidth
          \edef\afterassignwidth{\the\wd\scratchbox}%
        \fi
      \else
        \docheckalignment##2##3\relax\relax
      \fi}}

\def\setsecondpasscharacteralign
  {\popcharacteralign
   \expanded{\dosetsecondpasscharacteralign{\alignmentcharacter}}}

\def\dosetsecondpasscharacteralign#1%
  {\def\checkalignment##1%
     {\popcharacteralign
      \let\\\empty % beware, no grouping
      \setbox\scratchbox\hbox{#1}%
      \edef\characterassignwidth{\the\wd\scratchbox}%
      \setbox\scratchbox\null
      % new 12,34 vs 10\\ where 10 aligns on 12 if #1 = ,
      \ifcase\characteralignmentslot
        \docheckalignment##1#1\relax\relax
        \scratchdimen\wd\scratchbox
        \setbox\scratchbox\hbox{\ignorespaces##1\unskip}%
      \else
        \def\\{#1}%
        \expanded{\docheckalignment##1#1\relax\relax}%
        \scratchdimen\wd\scratchbox
        \setbox\scratchbox\hbox{\def\\{\hphantom{#1}}\ignorespaces##1\unskip}%
      \fi
      \noindent
      \ifdim\scratchdimen=\wd\scratchbox
        \ifcase\characteralignmentmode
          \box\scratchbox
        \else
          \hbox
            {\dontcomplain
             \hbox to \beforeassignwidth
               {\ifcase\characteralignmentmode\or
                  \box\scratchbox\hss
                \or
                  \hss\box\scratchbox\hskip\characterassignwidth
                \or
                  \hss\rlap{\box\scratchbox}%
                \or
                  \hss\rlap{\hbox to \afterassignwidth{\hss\box\scratchbox}}%
                \fi}%
             \hskip\afterassignwidth}%
        \fi
      \else
        \hbox
          {\hbox to \beforeassignwidth
             {\hss\box\scratchbox\hskip-\scratchdimen}%
           \hskip\afterassignwidth}%
      \fi}%
   \def\docheckalignment##1#1##2##3\relax
     {\ifx##2\relax
        \setbox\scratchbox\hbox{\ignorespaces##1\unskip}%
      \else
        \docheckalignment##2##3\relax\relax
      \fi}}

% provide a means to use multiple alignments mixed

\def\pushcharacteralign
  {\ifundefined{@cac@\alignmentclass}%
     \doglobal\appendetoks\noexpand\do{\alignmentclass}\to\@@characteralignlst
   \fi
   \setxvalue{@cac@\alignmentclass}{\noexpand\do
     {\afterassignwidth}{\beforeassignwidth}{\alignmentcharacter}}}

\def\popcharacteralign
  {\def\do##1##2##3%
     {\def\afterassignwidth  {##1}%
      \def\beforeassignwidth {##2}%
      \def\alignmentcharacter{##3}}%
   \executeifdefined{@cac@\alignmentclass}\donothing}

\def\resetcharacteralign % does not work well nested
  {\def\do##1{\global\letbeundefined{@cac@##1}}% global !
   \the\@@characteralignlst
   \global\@@characteralignlst\emptytoks}

\long\def\startcharacteralign#1\stopcharacteralign
  {\bgroup
   \setfirstpasscharacteralign #1%
   \setsecondpasscharacteralign#1%
   \egroup}

\protect \endinput