summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/decision-table/decision-table.dtx
blob: b45704637742109dee93cb31a38802d8a41099d3 (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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
% \iffalse meta-comment
%
% Copyright (C) 2020-2021 by S. Vandevelde, F. Pantigny
% ------------------------------------------------
%
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in:
%
% http://www.latex-project.org/lppl.txt
%
% and version 1.3c or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% \fi
% \iffalse
%
\def\dmnfileversion{0.0.4}
\def\dmnfiledate{2021/10/01}
%
%<*batchfile>
\begingroup
\input l3docstrip.tex
\keepsilent
\usedir{tex/latex/cascade}
\preamble

Copyright (C) 2020-2021 by S.Vandevelde, F. Pantigny
-----------------------------------

This file may be distributed and/or modified under the
conditions of the LaTeX Project Public License, either version 1.3
of this license or (at your option) any later version.
The latest version of this license is in:

http://www.latex-project.org/lppl.txt

and version 1.3c or later is part of all distributions of LaTeX
version 2005/12/01 or later.

\endpreamble
\askforoverwritefalse
\endgroup
%</batchfile>
%
%<@@=cascade>
%<*driver>
\documentclass[dvipsnames]{l3doc}% option dvipsnames is for xcolor (loaded by tikz)
\usepackage{xltxtra}
\usepackage{geometry}
\geometry{left=2.8cm,right=2.8cm,top=2.5cm,bottom=2.5cm,papersize={21cm,29.7cm}}
\setlength{\fboxsep}{0pt}
\usepackage{tikz}
\usepackage{hyperref}
\usepackage{listings}
\usepackage{float}
\usetikzlibrary{calc}
\usepackage{decision-table}
\hfuzz=5cm
\def\interitem{\vskip 7mm plus 2 mm minus 3mm}          
\def\emphase{\bgroup\color{RoyalPurple}\let\next=}
\fvset{commandchars=\~\#\@,formatcom={\color{gray}}}
\parindent 0pt
\skip\footins = 2\bigskipamount



\begin{document}
\DocInput{decision-table.dtx}
\end{document}
%</driver>
% \fi
% \title{The package \pkg{decision-table}\thanks{This document corresponds to the
% version~\dmnfileversion\space of \pkg{decision-table}, at the date of~\dmnfiledate.}} 
% \author{S. Vandevelde, F. Pantigny \\ \texttt{s.vandevelde@kuleuven.be} \\ \texttt{fpantigny@wanadoo.fr}}
%
% \maketitle
%
% \begin{abstract}
% The LaTeX package \pkg{decision-table} provides a command |\dmntable|, which allows for an easy way to generate decision tables in the Decision Model and Notation (DMN) format. (See Fig.~\ref{ex1})
% This package ensures consistency in the tables (i.e. fontsize), and is thus a better alternative to inserting tables via images.
% Besides pure DMN tables, it also supports the tables used in the cDMN and pDMN extensions, namely glossary and probability tables.
% \end{abstract}
% 
%
%
% \vspace{1cm}
% \section{Description}
% 
% The \texttt{decision-table} package allows for easy and straightforward generation of decision tables (with or without input columns) in the Decision Model and Notation (DMN) format, as demonstrated in Fig.~\ref{ex1}.
% Additionally, it also supports glossary and goal tables as defined by cDMN\footnote{https://cdmn.be}, and probability tables as defined by pDMN\footnote{Vandevelde S., et al., ``A Table-Based Representation for Probabilistic Logic: Preliminary Result''.}.
% Usage of this package ensures consistency in tables (i.e. font type, font size, color, $\ldots$), and is thus a better alternative to inserting tables via images.
% 
% \begin{figure}[H]
%     \centering
%     \dmntable{BMI Level}{U}{BMI}{BMILevel}
%              {$< 18.5$, Underweight,
%               $[18.5..25]$, Normal,
%               $(25..30]$, Overweight,
%               $> 30$, Obese}
%     \caption{Example of a DMN table}
%     \label{ex1}
% \end{figure}
% \section{Usage}
%
% In total, the \texttt{decision-table} package adds 5 new commands.
% \begin{itemize}
%     \item \texttt{dmntable}: basic DMN table.
%     \item \texttt{dmnoutputtable}: basic DMN table, but without input columns.
%     \item \texttt{dmnglossarytable}: glossary table, as defined by cDMN.
%     \item \texttt{goaltable}: goal table, as defined by cDMN.
%     \item \texttt{pdmntable}: probability table, as defined by pDMN.
%     \item \texttt{pdmnoutputtable}: probability table, but without input columns.
% \end{itemize}

% \subsection{dmntable}
% The \texttt{dmntable} command generates standard DMN decision tables.
% This command expands into a \texttt{tabular}, so it can be used within a \texttt{table} or \texttt{figure} environment.
% Furthermore, this allows labels and captions to be added seamlessly, and allows placing multiple DMN tables in the same environment.
% These tables will automatically arrange themselves based on size.
% 
% The \texttt{dmntable} command has the following inputs:
% \begin{itemize}
%     \item title
%     \item hit policy
%     \item input column headers
%     \item output column headers
%     \item the table values
% \end{itemize}
% The command is used as follows:
% \iffalse
%<*example>
% \fi
\begin{lstlisting}[language=tex, frame=single]
\dmntable{title}{hitpolicy}{input}{output}{values}
\end{lstlisting}
% \iffalse
%</example>
% \fi
% 
% The input, output and cell values are split by a comma.
% It is not necessary to include the row numbers for the cell values.
% For example, Fig.~\ref{ex1} is generated by the following code:

% \iffalse
%<*example>
% \fi
\begin{lstlisting}[language=tex, frame=single, basicstyle=\small]
\begin{figure}[H]
    \centering
    \dmntable{BMI Level}{U}{BMI}{BMILevel}
             {$< 18.5$, Underweight,
              $[18.5..25]$, Normal,
              $(25..30]$, Overweight,
              $> 30$, Obese}
    \caption{Example of a DMN table}
    \label{ex1}
\end{figure}
\end{lstlisting}
% \iffalse
%</example>
% \fi
% 
% If a cell value contains multiple values (e.g. multiple string values), then accolades should be written around them.
% See the example shown in Fig.~\ref{ex2}.

% It is also possible to have cells be multiline using the \texttt{makecell} package. This is useful in cases where large text causes page overflow.
% \iffalse
%<*example>
% \fi
\begin{lstlisting}[language=tex, frame=single, basicstyle=\small]
\include{makecell} % This should be somewhere at the top of document
\begin{figure}[H]
    \centering
    \dmntable{BMI Level}{U}{BMI}{\makecell{BMI \\ Level}}
             {$< 18.5$, Underweight,
              $[18.5..25]$, Normal,
              $(25..30]$, Overweight,
              $> 30$, Obese}
    \caption{Example of a DMN table with multiline cell}
    \label{ex1}
\end{figure}
\end{lstlisting}
% \iffalse
%</example>
% \fi
% 
% \subsection{dmnoutputtable}
% Decision tables that have no input columns can be created using the \texttt{dmnoutputtable} command.
% Its usage is the same as the standard decision table, except that no input columns should be given.
% For example, the following code generates the table shown in Fig.~\ref{outputtable}.
% \iffalse
%<*example>
% \fi
\begin{lstlisting}[language=tex, frame=single, basicstyle=\small]
\begin{figure}[H]
    \centering
    \dmnoutputtable{BMI Level}{U}{BMI}{5}
    \caption{Example of a DMN output table}
    \label{ex1}
\end{figure}
\end{lstlisting}
% \iffalse
%</example>
% \fi
% \begin{figure}[H]
%     \centering
%     \dmnoutputtable{BMI Level}{U}{BMI}{5}
%     \caption{Example of a DMN output table}
%     \label{outputtable}
% \end{figure}
% 
% \subsection{dmnglossarytable}
% Glossary tables are added by using the \texttt{glossarytable} command.
% This command accepts three inputs: the title, the sub-titles of the columns, and the actual elements.
% See Fig. \ref{glos1} for an example.
% \iffalse
%<*example>
% \fi
\begin{lstlisting}[language=tex, frame=single, basicstyle=\small]
\begin{figure}[H]
   \centering
   \glossarytable{Type}{Name, DataType, Possible Values}
                       {Country, String, {Belgium, France, Germany}}
   \glossarytable{Function}{Name, DataType}{color of Country, Color}
   \glossarytable{Relation}{Name}{Country borders Country}
   \caption{Example glossary}
   \label{glos1}
\end{figure}
\end{lstlisting}
% \iffalse
%</example>
% \fi
%
%
% \begin{figure}[H]
%    \centering
%    \glossarytable{Type}{Name, DataType, Possible Values}
%                        {Country, String, {Belgium, France, Germany}}
%    \glossarytable{Function}{Name, DataType}{color of Country, Color}
%    \glossarytable{Relation}{Name}{Country borders Country}
%    \caption{Example glossary}
%    \label{glos1}
% \end{figure}

% \subsection{goaltable}

% Generating a \texttt{Goal} table is straightforward:

% \iffalse
%<*example>
% \fi
\begin{lstlisting}[language=tex, frame=single]
\goaltable{tablename}{values}
\end{lstlisting}
% \iffalse
%</example>
% \fi

% \begin{figure}[H]
%     \centering
%     \goaltable{tablename}{value1, value2}
% \end{figure}

% \subsection{pdmntable}

% pDMN probability tables are similar to standard DMN tables, but with a few changes.
% The biggest change is the addition of probabilities. The syntax of \texttt{pdmntable} is as follows:

% \iffalse
%<*example>
% \fi
\begin{lstlisting}[language=tex, frame=single]
\pdmntable{title}{hitpolicy}{inputs}{outputs}{output values}{cell values}
\end{lstlisting}
% \iffalse
%</example>
% \fi

%For example, a table expressing the probabilities of an unbiased and biased dice throw can be expressed as follows:

% \iffalse
%<*example>
% \fi
\begin{lstlisting}[language=tex, frame=single]
\pdmntable{Throwing Dice}{Ch}{biased}{die value}
          {one, two, three, four, five, six}
          {No, $1/6$, $1/6$, $1/6$, $1/6$, $1/6$, $1/6$,
           Yes, $0.1$, $0.1$, $0.1$, $0.1$, $0.1$, $0.5$}
\end{lstlisting}
% \iffalse
%</example>
% \fi

% \begin{figure}[H]
%     \centering
% \pdmntable{Throwing Dice}{Ch}{biased}{die value}
%           {one, two, three, four, five, six}
%           {No, $1/6$, $1/6$, $1/6$, $1/6$, $1/6$, $1/6$,
%            Yes, $0.1$, $0.1$, $0.1$, $0.1$, $0.1$, $0.5$}
% \end{figure}


% \subsection{pdmnoutputtable}
% The final type of table, \texttt{pdmnoutputtable}, is the same as the one shown in the previous subsection but without any input columns.

% \iffalse
%<*example>
% \fi
\begin{lstlisting}[language=tex, frame=single]
\pdmnoutputtable{tablename}{hitpolicy}{output}{outputvalue}{probabilities}
\end{lstlisting}
% \iffalse
%</example>
% \fi

% \begin{figure}[H]
%     \centering
%     \pdmnoutputtable{h1}{U}{heads1}{Yes}{0.5}
% \end{figure}

% \section{Contributing}
% 
% Contributions are always welcome.
% The project is hosted at \url{https://gitlab.com/Vadevesi/dmn-tex}

%
% \newgeometry{left=4cm}
%
% \section{Implementation}
%
%<@@=dmn>
% 
% \bigskip
%
% 
% We give the traditional declaration of a package written with |expl3|:
%    \begin{macrocode}
\RequirePackage{l3keys2e}
\ProvidesExplPackage
  {decision-table}
  {\dmnfiledate}
  {\dmnfileversion}
  {Table of decision}
%    \end{macrocode}
%
%    \begin{macrocode}
\RequirePackage { nicematrix }
%    \end{macrocode}
%
% \bigskip
% We define the command |\dmntable| with the tools of \pkg{xparse}.
%    \begin{macrocode}
\NewDocumentCommand \dmntable { m m m m m }
  {
%    \end{macrocode}
% The clist (\emph{comma separated list}) |\l_@@_input_clist| is for the list
% of the names of the input fields. 
%    \begin{macrocode}
    \clist_clear_new:N \l_@@_input_clist
    \clist_set:Nn \l_@@_input_clist { #3 }
%    \end{macrocode}
%
% \bigskip
% The clist |\l_@@_output_clist| is for the list of the names of the output fields.
%    \begin{macrocode}
    \clist_clear_new:N \l_@@_output_clist
    \clist_set:Nn \l_@@_output_clist { #4 }
%    \end{macrocode}
%
% \bigskip
% The integer |\l_@@_input_int| is the number of the input fields.
%    \begin{macrocode}
    \int_zero_new:N \l_@@_input_int
    \int_set:Nn \l_@@_input_int { \clist_count:N \l_@@_input_clist }
%    \end{macrocode}
%
% \bigskip
% The integer |\l_@@_output_int| is the number of the output fields.
%    \begin{macrocode}
    \int_zero_new:N \l_@@_output_int
    \int_set:Nn \l_@@_output_int { \clist_count:N \l_@@_output_clist }
%    \end{macrocode}
% 
%
% \bigskip
% The sequence |\l_@@_cells_seq| is the sequence of all the cells of the
% ``body'' of the tabular. 
%    \begin{macrocode}
    \seq_clear_new:N \l_@@_cells_seq
    \seq_set_split:Nnn \l_@@_cells_seq { , } { #5 }
%    \end{macrocode}
% 
% 
% \vspace{1cm}
% Now, we will begin the construction of the tabular (a |{NiceTabular}| of
% \pkg{nicematrix}). 
% 
% \bigskip
% The command |\use:x| will expand its argument. Indeed, the preamble of the
% |{NiceTabular}| (which has the same format as a preamble of |{tabular}| must
% be computed before the execution of the |\begin{NiceTabular}|.
%    \begin{macrocode}
    \use:x
      {
        \exp_not:N \begin { NiceTabular } 
%    \end{macrocode}
% Here is the preamble of the tabular. The command |\prg_replicate:nn| is
% expandable and hence will be expanded by the |use:x|.
%    \begin{macrocode}
        { r \prg_replicate:nn { \l_@@_input_int + \l_@@_output_int } l }
%    \end{macrocode}
% Here is the list of options of the |{NiceTabular}| (a standard tabular of
% |{array}| don't have such list of options. Once again, we have to compute some
% quantities in this list of options before the execution of |\begin{NiceTabular}|.
%    \begin{macrocode}
        [ 
%    \end{macrocode}
% The key |hvlines-except-corners| will draw all the rules of the tabular,
% excepted in the (upper right) corner.
%    \begin{macrocode}
          hvlines-except-corners ,
%    \end{macrocode}
% The key |code-before| of |{NiceTabular}| contains instructions to color the
% cells \emph{before} the rules (doing so, the resulting \textsc{pdf} gives
% better results in the \textsc{pdf} viewers).
%    \begin{macrocode}
          code-before = 
%    \end{macrocode}
% First, a |\rectanglecolor| for the labels of the ``input'' fields. The command
% |\int_eval:n| is expandable and, hence, will be expanded by the |\use:x|. On
% the other side, we have to prevent the expansion of |\rectanglecolor| which,
% in fact, at that point is not defined (it will be defined by \pkg{nicematrix}
% after the construction of the array).
%    \begin{macrocode}
           \exp_not:N \rectanglecolor 
             { blue!10!green!60!black!30 }
             { 2 - 2 }
             { 2 - \int_eval:n { \l_@@_input_int + 1 } }
%    \end{macrocode}
% A |\rectanglecolor| for the labels of the ``output'' fields.
%    \begin{macrocode}
           \exp_not:N \rectanglecolor 
             { green!30!blue!15 }
             { 2 - \int_eval:n { \l_@@_input_int + 2 } }
             { 2 - \int_eval:n { \l_@@_input_int + \l_@@_output_int + 1 } }
        ]
      }
%    \end{macrocode}
% Now, we begin the body of the tabular (the environment |{NiceTabular}|).
% 
% \medskip
% The body begins by a |\multicolumn| for the title. However, we have to compute
% the number of cells of that |\multicolumn|. That's why we have to expand the
% first argument of the |\multicolumn| before executing the |\multicolumn|.
% However, we have to do that in an expandable way in order to prevent the
% functionnality of the |\multicolumn| (which internally give a |\omit| of TeX).
% That's why we have to use |\exp_args:Ne| (|\exp_args:Nx| would not do the job).
%    \begin{macrocode}
    \exp_args:Ne \multicolumn 
      { \int_eval:n { \l_@@_input_int + 1 } } 
      { l } 
      { #1 } \\
%    \end{macrocode}
% |#2| is the \emph{hit policy}.
%    \begin{macrocode}
    #2 & 
%    \end{macrocode}
% Now, the fields (``input fields'' and ``output fields''). By using
% |\clist_use:Nn|, we replace the commas by ampersands (|&|).
%    \begin{macrocode}
    \clist_use:Nn \l_@@_input_clist { & } & 
    \clist_use:Nn \l_@@_output_clist { & } \\
%    \end{macrocode}
% Now, all the rows corresponding to the rules. We begin a loop over all the
% cells with |\seq_map_inline:Nn|. 
%    \begin{macrocode}
    1 & 
    \seq_map_inline:Nn \l_@@_cells_seq
      {
%    \end{macrocode}
% |\c@jCol| and |\c@iRow| are counters provided by |{NiceTabular}| for the
% current column and the current row. If you are in the first column, we insert
% the number of rule.
%    \begin{macrocode}
        \int_compare:nT { \c@jCol = 0 } { \int_eval:n { \c@iRow - 1 } & } 
%    \end{macrocode}
% Now, we add one composante of |\l_@@_cells_seq|.
%    \begin{macrocode}
        ##1
%    \end{macrocode}
% Before the following cell, we have, of course, to add |\\| (if we are at the
% end of the row) or |&| (elsewhere).
%    \begin{macrocode}
        \int_compare:nTF { \c@jCol = \l_@@_input_int + \l_@@_output_int + 1 } 
          { \\ } 
          { & }
      }
    \end { NiceTabular }
  }
%    \end{macrocode}
% The other two commands are simply more of the same.
%    \begin{macrocode}
\NewDocumentCommand \dmnoutputtable { m m m m }
  {
    \clist_clear_new:N \l__dmn_output_clist
    \clist_set:Nn \l__dmn_output_clist { #3 }
    \int_zero_new:N \l__dmn_output_int
    \int_set:Nn \l__dmn_output_int { \clist_count:N \l__dmn_output_clist }
    \seq_clear_new:N \l__dmn_cells_seq
    \seq_set_split:Nnn \l__dmn_cells_seq { , } { #4 }
    \use:x
      {
        \exp_not:N \begin { NiceTabular }
        { r \prg_replicate:nn { \l__dmn_output_int } l }
        [
          hvlines-except-corners ,
          code-before =
           \exp_not:N \rectanglecolor
             { blue!10!green!60!black!30 }
             { 2 - 2 }
             { 2 - \int_eval:n { 1 } }
           \exp_not:N \rectanglecolor
             { green!30!blue!15 }
             { 2 - \int_eval:n { 2 } }
             { 2 - \int_eval:n { \l__dmn_output_int + 1 } }
        ]
      }
    \exp_args:Ne \multicolumn
      { \int_eval:n { 1 } }
      { l }
      { #1 } \\
    #2 &
    \clist_use:Nn \l__dmn_output_clist { & } \\
    1 &
    \seq_map_inline:Nn \l__dmn_cells_seq
      {
        \int_compare:nT { \c@jCol = 0 } { \int_eval:n { \c@iRow - 1 } & }
        ##1
        \int_compare:nTF { \c@jCol = \l__dmn_output_int + 1 }
          { \\ }
          { & }
      }
    \end { NiceTabular }
  }

\NewDocumentCommand \glossarytable { m m m }
  {
    \clist_clear_new:N \l__clist
    \clist_set:Nn \l__clist { #2 }
    \int_zero_new:N \l__cint
    \int_set:Nn \l__cint { \clist_count:N \l__clist }
    \seq_clear_new:N \l__dmn_cells_seq
    \seq_set_split:Nnn \l__dmn_cells_seq { , } { #3 }
    \use:x
      {
        \exp_not:N \begin { NiceTabular }
        { c \prg_replicate:nn { \l__cint -1 } c }
        [
          hvlines-except-corners ,
          code-before =
           \exp_not:N \rectanglecolor
             { blue!30!green!10!red!40 }
             { 1 - \int_eval:n { 1 } }
             { 1 - \int_eval:n { \l__cint} }
        ]
      }
    \exp_args:Ne \multicolumn
      { \int_eval:n { \l__cint } }
      { c }
      { \textbf{#1} } \\
    \bf \clist_use:Nn \l__clist { & \bf } \\
    \seq_map_inline:Nn \l__dmn_cells_seq
      {
        \int_compare:nT { \c@jCol = 0 } { }
        ##1
        \int_compare:nTF { \c@jCol = \l__cint }
          { \\ }
          { & }
      }
    \end { NiceTabular }
  }
\NewDocumentCommand \pdmntable { m m m m m m}
  {
    \clist_clear_new:N \l__dmn_input_clist
    \clist_set:Nn \l__dmn_input_clist { #3 }
    \clist_clear_new:N \l__dmn_output_clist
    \clist_set:Nn \l__dmn_output_clist { #4 }
    \clist_clear_new:N \l__suboutput_clist
    \clist_set:Nn \l__dmn_suboutput_clist { #5 }
    \int_zero_new:N \l__dmn_input_int
    \int_set:Nn \l__dmn_input_int { \clist_count:N \l__dmn_input_clist }
    \int_zero_new:N \l__dmn_output_int
    \int_set:Nn \l__dmn_output_int { \clist_count:N \l__dmn_output_clist }
    \int_zero_new:N \l__dmn_suboutput_int
    \int_set:Nn \l__dmn_suboutput_int { \clist_count:N \l__dmn_suboutput_clist }
    \seq_clear_new:N \l__dmn_cells_seq
    \seq_set_split:Nnn \l__dmn_cells_seq { , } { #6 }
    \seq_clear_new:N \l__dmn_inputcells_seq
    \seq_set_split:Nnn \l__dmn_inputcells_seq { , } { #3 }
    \use:x
      {
        \exp_not:N \begin { NiceTabular }
        { r \prg_replicate:nn { \l__dmn_input_int + \l__dmn_suboutput_int  + 1} l }
        [
          hvlines-except-corners ,
          code-before =
           \exp_not:N \rectanglecolor
             { blue!10!green!60!black!30 }
             { 2 - 2 }
             { 2 - \int_eval:n { \l__dmn_input_int + 1 } }
           \exp_not:N \rectanglecolor
             { green!30!blue!15 }
             { 2 - \int_eval:n { \l__dmn_input_int + 2 } }
             { 2 - \int_eval:n { \l__dmn_input_int + \l__dmn_suboutput_int + 1 } }
          \exp_not:N \rectanglecolor
             { red!60!green!60!blue!15}
             { 3 - \int_eval:n { 1 } }
             { 3 - \int_eval:n { \l__dmn_input_int + \l__dmn_suboutput_int + 1 } }
        ]
      }
    \exp_args:Ne \multicolumn
      { \int_eval:n { \l__dmn_input_int + 1 } }
      { l }
      { #1 } \\
    #2 &
    \clist_use:Nn \l__dmn_input_clist { & } &
    \exp_args:Ne \multicolumn
      { \int_eval:n {\l__dmn_suboutput_int}} 
      { c }
      { #4 } \\
    \seq_map_inline:Nn \l__dmn_inputcells_seq 
      { & }
    & \clist_use:Nn \l__dmn_suboutput_clist { & } & \\
    %\clist_use:Nn \l__dmn_output_clist { & } \\
    1 &
    \seq_map_inline:Nn \l__dmn_cells_seq
      {
        \int_compare:nT { \c@jCol = 0 } { \int_eval:n { \c@iRow - 2 } & }
        ##1
        \int_compare:nTF { \c@jCol = \l__dmn_input_int + \l__dmn_suboutput_int + 1 }
          { \\ }
          { & }
      }
    \end { NiceTabular }
  }
\NewDocumentCommand \pdmnoutputtable { m m m m m }
  {
    \clist_clear_new:N \l__dmn_output_clist
    \clist_set:Nn \l__dmn_output_clist { #3 }
    \clist_clear_new:N \l__suboutput_clist
    \clist_set:Nn \l__dmn_suboutput_clist { #4 }
    \int_zero_new:N \l__dmn_output_int
    \int_set:Nn \l__dmn_output_int { \clist_count:N \l__dmn_output_clist }
    \int_zero_new:N \l__dmn_suboutput_int
    \int_set:Nn \l__dmn_suboutput_int { \clist_count:N \l__dmn_suboutput_clist }
    \seq_clear_new:N \l__dmn_cells_seq
    \seq_set_split:Nnn \l__dmn_cells_seq { , } { #5 }
    \use:x
      {
        \exp_not:N \begin { NiceTabular }
        { r \prg_replicate:nn { \l__dmn_suboutput_int } l }
        [
          hvlines-except-corners ,
          code-before =
           \exp_not:N \rectanglecolor
             { blue!10!green!60!black!30 }
             { 2 - 2 }
             { 2 - \int_eval:n { 1 } }
           \exp_not:N \rectanglecolor
             { green!30!blue!15 }
             { 2 - \int_eval:n { 2 } }
             { 2 - \int_eval:n { \l__dmn_suboutput_int + 1 } }
          \exp_not:N \rectanglecolor
             { red!60!green!60!blue!15}
             { 3 - \int_eval:n { 1 } }
             { 3 - \int_eval:n { \l__dmn_suboutput_int + 1 } }
        ]
      }
    \exp_args:Ne \multicolumn
      { \int_eval:n { 1 } }
      { l }
      { #1 } \\
    #2 &
    \exp_args:Ne \multicolumn
      { \int_eval:n {\l__dmn_suboutput_int}} 
      { c }
      { #3 } \\
    & \clist_use:Nn \l__dmn_suboutput_clist { & } \\
    1 &
    \seq_map_inline:Nn \l__dmn_cells_seq
      {
        \int_compare:nT { \c@jCol = 0 } { \int_eval:n { \c@iRow - 1 } & }
        ##1
        \int_compare:nTF { \c@jCol = \l__dmn_suboutput_int + 1 }
          { \\ }
          { & }
      }
    \end { NiceTabular }
  }

\NewDocumentCommand \goaltable { m m }
  {
    \seq_clear_new:N \l__dmn_cells_seq
    \seq_set_split:Nnn \l__dmn_cells_seq { , } { #2 }
    \use:x
      {
        \exp_not:N \begin { NiceTabular }
        { \prg_replicate:nn { 1 } c }
        [
          hvlines-except-corners ,
          code-before =
           \exp_not:N \rectanglecolor
             { blue!30!green!10!red!20 }
             { 1 - \int_eval:n { 1 } }
             { 1 - \int_eval:n { 1} }
        ]
      }
    \textbf{#1} \\
    %\exp_args:Ne \multicolumn
    %  { \int_eval:n { 1 } }
    %  { c }
    %  { \textbf{#1} } \\
    \seq_map_inline:Nn \l__dmn_cells_seq
      {
        \int_compare:nT { \c@jCol = 0 } { }
        ##1
        \int_compare:nTF { \c@jCol = 1 }
          { \\ }
          { & }
      }
    \end { NiceTabular }
  }

\endinput
%%
%% End of file `decision-table.sty'.

%    \end{macrocode}
% 
%
%
% \tableofcontents
%
% \end{document}
% 
% Local Variables:
% TeX-fold-mode: t
% TeX-fold-preserve-comments: nil
% flyspell-mode: nil
% fill-column: 80
% End: