summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/profcollege/latex/PfCMotsEmpiles.tex
blob: 634baa969e70279efac61bcc108aeb79a6c77217 (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
%%%
% Mots empilés
%%%
\setKVdefault[ClesMotEmpile]{Colonne=4,Solution=false,Couleur=black}

\newcounter{CompteurMotEmpile}

\newcommand\MotsEmpiles[2][]{%
  \useKVdefault[ClesMotEmpile]%
  \setKV[ClesMotEmpile]{#1}%
  \setcounter{CompteurMotEmpile}{0}%
  \setsepchar[*]{,*/}%
  \readlist*\ListeMotsEmpiles{#2}%
  \xdef\ListeMotsEmpilesMax{0}%
  \colorlet{MotEmpileCouleur}{\useKV[ClesMotEmpile]{Couleur}}%
  \foreachitem\compteur\in\ListeMotsEmpiles{%
    \StrLen{\ListeMotsEmpiles[\compteurcnt,2]}[\LongueurMot]%
    \xintifboolexpr{\ListeMotsEmpilesMax<\fpeval{\ListeMotsEmpiles[\compteurcnt,1]+\LongueurMot}}{\xdef\ListeMotsEmpilesMax{\fpeval{\ListeMotsEmpiles[\compteurcnt,1]+\LongueurMot}}}{}%
  }%
  \begin{NiceTabular}{c|*{\fpeval{\ListeMotsEmpilesMax}}{m{10pt}}}%
    \Block{1-\fpeval{\useKV[ClesMotEmpile]{Colonne}+2}}{}\xintFor* ##1 in {\xintSeq {1}{\fpeval{\useKV[ClesMotEmpile]{Colonne}}}}\do{&}&$\downarrow$\xintFor* ##1 in {\xintSeq {1}{\fpeval{\ListeMotsEmpilesMax-\useKV[ClesMotEmpile]{Colonne}-1}}}\do{&}\\
    \xintFor* ##1 in {\xintSeq {1}{\fpeval{\ListeMotsEmpileslen}}}\do{%
      \rule[-1.2ex]{0pt}{3.8ex}\stepcounter{CompteurMotEmpile}\Alph{CompteurMotEmpile}&\Block{1-\fpeval{\ListeMotsEmpiles[##1,1]}}{}\xintFor* ##2 in {\xintSeq {1}{\fpeval{\ListeMotsEmpiles[##1,1]}}}\do{%
        &
      }%
      \StrLen{\ListeMotsEmpiles[##1,2]}[\LongueurMot]%
      \xintFor* ##3 in {\xintSeq {1}{\fpeval{\LongueurMot}}}\do{%
        \xintifForFirst{}{&}\Block[draw=black]{1-1}{\ifboolKV[ClesMotEmpile]{Solution}{\centering\arraybackslash\StrMid{\ListeMotsEmpiles[##1,2]}{##3}{##3}}{}}%%
      }%
      \\
    }%
    \CodeAfter\tikz\draw[line width=1.5pt,MotEmpileCouleur](row-2-|col-\fpeval{\useKV[ClesMotEmpile]{Colonne}+2}) rectangle (row-\fpeval{\ListeMotsEmpileslen+2}-|col-\fpeval{\useKV[ClesMotEmpile]{Colonne}+3});
  \end{NiceTabular}%
}%