summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/profcollege/latex/PfCRepresenterTableur.tex
blob: 35eed814310ddb8d59f2b8a4fd245dd706510d2f (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
%%%
% Tableur
%%%
\setKVdefault[Tableur]{Colonnes=4,Largeur=30pt,LargeurUn=30pt,Bandeau=true,Formule={},Cellule=A1,Ligne=0,Colonne=0,PasL=1,PasC=1,Selection=false,DebutColonnes=0,DebutLignes=0}%
%Idee de P. Nuns
\defKV[Tableur]{Couleur=\setKV[Tableur]{Selection}}%
%

%Bas\'e sur un code de Christian T\'ell\'ech\'ea.
\newcount\cntlin%
\newcount\cntcol%
\newcount\Affichecntcol%
\newcount\Affichecntlin%
\makeatletter%
% Pour la version nicematrix
\newtoks\t@b%
\long\def\ifremain@lines#1\\#2\@nil{%
  \csname @\ifx\@empty#2\@empty second\else first\fi oftwo\endcsname}%
\long\def\subst@eol#1\\#2\@nil{\addtot@b{#1\\}%
  \ifremain@lines#2\\\@nil{\addtot@b&\subst@eol#2\@nil}{\addtot@b{#2\CodeAfter\xintifboolexpr{\useKV[Tableur]{Ligne}==0 || \useKV[Tableur]{Colonne}==0}{}{%
        \tikz\node at (row-\fpeval{\useKV[Tableur]{Ligne}+1+\useKV[Tableur]{PasL}}-|col-\fpeval{\useKV[Tableur]{Colonne}+1+\useKV[Tableur]{PasC}}) {\tiny$\blacksquare$};%
      }%
    \end{NiceTabular}}}}%
\long\def\collectcp@body#1\end{\subst@eol#1\@nil\end}%

\newcommand\addtot@b[1]{\t@b\expandafter{\the\t@b#1}}%
\newcommand\edftot@b[1]{\edef\temp@{#1}\expandafter\addtot@b\expandafter{\temp@}}%
%%%%%%%%%%
% Pour la version tabular
\newtoks\t@bs%
\long\def\ifremain@liness#1\\#2\@nil{%
  \csname @\ifx\@empty#2\@empty second\else first\fi oftwo\endcsname}%
\long\def\subst@eols#1\\#2\@nil{\addtot@bs{#1\\\hline}%
  \ifremain@lines#2\\\@nil{\addtot@bs&\subst@eols#2\@nil}{\addtot@bs{#2\end{tabular}}}}%
\long\def\collectcp@bodys#1\end{\subst@eols#1\@nil\end}%

\newcommand\addtot@bs[1]{\t@bs\expandafter{\the\t@bs#1}}%
\newcommand\edftot@bs[1]{\edef\temp@{#1}\expandafter\addtot@bs\expandafter{\temp@}}%
%%%%%%%%%%%%%%%

\newlength\PfCLongInter%
\newlength\PfCTableurLargeurUn%
\newlength\PfCTableurLargeur%

\NewDocumentEnvironment{Tableur}{so}{%
  \useKVdefault[Tableur]%
  \setKV[Tableur]{#2}%
  \setlength{\PfCTableurLargeurUn}{\fpeval{\useKV[Tableur]{LargeurUn}}pt}%
  \setlength{\PfCTableurLargeur}{\fpeval{\useKV[Tableur]{Largeur}}pt}%
  \ifnum\useKV[Tableur]{DebutColonnes}=0\relax
    \Affichecntcol\z@%
  \else
    \Affichecntcol=\number\numexpr\useKV[Tableur]{DebutColonnes}-1%
  \fi
  \ifnum\useKV[Tableur]{DebutLignes}=0\relax
    \Affichecntlin\z@%
  \else
    \Affichecntlin=\number\numexpr\useKV[Tableur]{DebutLignes}-1%
  \fi
  \ttfamily%
  \newcolumntype{A}{>{\centering\arraybackslash}m{\PfCTableurLargeurUn}}%
  \newcolumntype{B}{>{\centering\arraybackslash}m{\PfCTableurLargeur}}%
  \IfBooleanTF{#1}{%
    \setlength{\PfCLongInter}{-40pt+\fpeval{\useKV[Tableur]{LargeurUn}}pt+\fpeval{(\useKV[Tableur]{Colonnes}-2)*\useKV[Tableur]{Largeur}}pt+\fpeval{2*\useKV[Tableur]{Colonnes}-6}\tabcolsep+\fpeval{\useKV[Tableur]{Colonnes}-3}\arrayrulewidth}%
  \ifboolKV[Tableur]{Bandeau}{%
    \begin{tabular}{|p{\PfCTableurLargeur}|p{10pt}|p{50pt}|p{\PfCLongInter}|}%
      \hhline{--~-}%
      \useKV[Tableur]{Cellule}&\scriptsize$\blacktriangledown$&$f_x$\hfill$\sum$~\scriptsize$\blacktriangledown$\hfill$=$&\useKV[Tableur]{Formule}\hfill\scriptsize$\blacktriangledown$\\%
      \hhline{--~-}%
    \end{tabular}%
    \nopagebreak%
    \\%
  }{}%
  \cntlin\z@%
  \t@bs{%
    \begin{tabular}{%
      |>{%
      \cellcolor{gray!15}%
          \global\cntcol\z@
          \global\advance\cntlin\@ne%
          \centering\arraybackslash%
          \ifnum\cntlin>\@ne%
          \fpeval{\cntlin+\Affichecntlin-1}\fi}%
      wc{20pt}|A|*{\fpeval{\useKV[Tableur]{Colonnes}-1}}{B|}}%
      \hline%
      \rowcolor{gray!15}%
      }%
  \loop%
  \ifnum\cntcol<\useKV[Tableur]{Colonnes}%
    \advance\cntcol\@ne%
    \advance\Affichecntcol\@ne%
    \addtot@bs{&}%
    % \edftot@bs{\@Alph{\the\cntcol}}%
    \edftot@bs{\@Alph{\the\Affichecntcol}}%
  \repeat%
  \addtot@bs{\\\hline&}%
  \collectcp@bodys
  }{%
  \setlength{\PfCLongInter}{-40pt+\fpeval{\useKV[Tableur]{LargeurUn}}pt+\fpeval{(\useKV[Tableur]{Colonnes}-2)*\useKV[Tableur]{Largeur}}pt+\fpeval{2*\useKV[Tableur]{Colonnes}-6}\tabcolsep+\fpeval{\useKV[Tableur]{Colonnes}+2}\arrayrulewidth}%  
  \ifboolKV[Tableur]{Bandeau}{%
    \begin{NiceTabular}{p{\PfCTableurLargeur}p{10pt}p{50pt}p{\PfCLongInter}}%
      \Block[draw,l]{}{\useKV[Tableur]{Cellule}}&\Block[draw]{}{\scriptsize$\blacktriangledown$}&\Block{}{$f_x$\hfill$\sum$~\scriptsize$\blacktriangledown$\hfill$=$}&\Block[draw]{}{\useKV[Tableur]{Formule}\hfill\scriptsize$\blacktriangledown$}\\
    \end{NiceTabular}%
    \nopagebreak%
    \\%
  }{}%
  \cntlin\z@%
  \t@b{%
    \begin{NiceTabular}{%
        >{%
          \global\cntcol\z@
          \global\advance\cntlin\@ne%
          \centering\arraybackslash%
          \ifnum\cntlin>\@ne%
          \ifboolKV[Tableur]{Selection}{%
            \xintifboolexpr{\cntlin>\useKV[Tableur]{Ligne} && \cntlin<\fpeval{\useKV[Tableur]{Ligne}+\useKV[Tableur]{PasL}+1}}{\textcolor{white}{\fpeval{\cntlin+\Affichecntlin-1}}}{\fpeval{\cntlin+\Affichecntlin-1}}%
          }{\fpeval{\cntlin+\Affichecntlin-1}}\fi}%
        wc{20pt}A*{\fpeval{\useKV[Tableur]{Colonnes}-1}}{B}}[hvlines,color-inside]%
      \CodeBefore
      % on colorie en gris toute la première ligne
      \tikz\fill[gray!15](row-1-|col-1) rectangle (row-2-|last);%
      % on colorie en gris toute la première colonne
      \tikz\fill[gray!15](row-1-|col-1) rectangle (last-|col-2);%
      %
      \xintifboolexpr{\useKV[Tableur]{Ligne}==0 || \useKV[Tableur]{Colonne}==0}{}{%
        \ifboolKV[Tableur]{Selection}{%
          \xdef\PfCTabCouleur{\useKV[Tableur]{Couleur}}%
          % on colorie les cellules sans les tracer
          \tikz\fill[\PfCTabCouleur!50](row-\fpeval{\useKV[Tableur]{Ligne}+1}-|col-\fpeval{\useKV[Tableur]{Colonne}+1}) rectangle (row-\fpeval{\useKV[Tableur]{Ligne}+1+\useKV[Tableur]{PasL}}-|col-\fpeval{\useKV[Tableur]{Colonne}+1+\useKV[Tableur]{PasC}});%
          % on trace la première cellule qui a servi à sélectionner
          \tikz\draw[line width=1.25pt,fill=\PfCTabCouleur!50](row-\fpeval{\useKV[Tableur]{Ligne}+1}-|col-\fpeval{\useKV[Tableur]{Colonne}+1}) rectangle (row-\fpeval{\useKV[Tableur]{Ligne}+1+1}-|col-\fpeval{\useKV[Tableur]{Colonne}+1+1});%
          % on colorie la zone nécessaire sur la première ligne
          \tikz\fill[\PfCTabCouleur](row-1-|col-\fpeval{\useKV[Tableur]{Colonne}+1}) rectangle (row-2-|col-\fpeval{\useKV[Tableur]{Colonne}+1+\useKV[Tableur]{PasC}});%
          % on colorie la zone nécessaire sur la première colonne
          \tikz\fill[\PfCTabCouleur](row-\fpeval{\useKV[Tableur]{Ligne}+1}-|col-1) rectangle (row-\fpeval{\useKV[Tableur]{Ligne}+1+\useKV[Tableur]{PasL}}-|col-2);%
        }{%
          \tikz\draw[line width=1.25pt](row-\fpeval{\useKV[Tableur]{Ligne}+1}-|col-\fpeval{\useKV[Tableur]{Colonne}+1}) rectangle (row-\fpeval{\useKV[Tableur]{Ligne}+1+\useKV[Tableur]{PasL}}-|col-\fpeval{\useKV[Tableur]{Colonne}+1+\useKV[Tableur]{PasC}});%
        }%
      }%
      \Body
    %
    }%
  \loop%
  \ifnum\cntcol<\useKV[Tableur]{Colonnes}%
    \advance\cntcol\@ne%
    \advance\Affichecntcol\@ne%
  \addtot@b{&}%
  % modif by Pascal Nuns
  \ifboolKV[Tableur]{Selection}{%
    \ifnum\cntcol>\fpeval{\useKV[Tableur]{Colonne}-1}%
    \ifnum\cntcol<\fpeval{\useKV[Tableur]{Colonne}+\useKV[Tableur]{PasC}}%
    \edftot@b{{\noexpand\textcolor{white}{\noexpand\bfseries\@Alph{\the\Affichecntcol}}}}%
    \else%
    \edftot@b{\@Alph{\the\Affichecntcol}}%
    \fi%
    \else%
    \edftot@b{\@Alph{\the\Affichecntcol}}%
    \fi%
  }{\edftot@b{\@Alph{\the\Affichecntcol}}}%
  % fin de modif
  \repeat%
  \addtot@b{\\&}%
  \collectcp@body}}{\IfBooleanTF{#1}{\the\t@bs}{\the\t@b}}%
\makeatother