summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/profcollege/latex/PfCRepresenterTableur.tex
blob: 4ac96a74e6653ec8a98947bd09a8a191f27b5075 (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
%%%
% 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%
\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@}}%

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

\newenvironment{Tableur}[1][]{%
  \useKVdefault[Tableur]%
  \setKV[Tableur]{#1}%
  \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}}%
  \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}{\the\t@b}%
\makeatother