%%%
%Autonomie
%%%
\def\filedateAutonomie{2024/08/04}%
\def\fileversionAutonomie{0.1}%
\message{-- \filedateAutonomie\space v\fileversionAutonomie}%
%
\setKVdefault[Autonomie]{AfficheMarge=false,TitreEnigme=Enigme,TitreAtoi=\`A toi,Enigme=false,TexteCorrection=\bfseries Correction,ARemplir=false,Deux=false,Landscape=false}%

\newcommand\Autonomie[3][]{%
  \useKVdefault[Autonomie]%
  \setKV[Autonomie]{#1}%
  \setsepchar[*]{§*/}\reademptyitems%
  \readlist*\ListeAutoQ{#2}%
  % \setsepchar{§}
  % \readlist*\ListeAutoR{#3}%
  \setsepchar[*]{§*/}%
  \readlist*\ListeAutoEn{#3}%
  \clearpage
  \begin{tikzpicture}[remember picture,overlay]%
    \ifboolKV[Autonomie]{AfficheMarge}{%
      \node[xshift=5mm,yshift=-5mm,circle] (PfCA) at (current page.north west) {};%
      \node[xshift=-5mm,yshift=5mm] (PfCB) at (current page.south east) {};%
      \draw[blue,dashed] (PfCA) rectangle (PfCB);%
    }{}%
    \foreach \i in {1,...,3}{%
      \coordinate[xshift=\i*0.25*\paperwidth] (A\i) at (current page.north west);%
      \coordinate[xshift=\i*0.25*\paperwidth] (B\i) at (current page.south west);%
    }%
    \foreach \i in{1,...,4}{%
      \coordinate[yshift=-\i*0.25*\paperheight] (C\i) at (current page.north west);%
      \coordinate[yshift=-\i*0.25*\paperheight] (F\i) at (current page.north east);%
      \coordinate[yshift=-\i*0.25*\paperheight] (D\i) at (A1);%
      \coordinate[yshift=-\i*0.25*\paperheight] (E\i) at (A3);%
    }%
    \ifboolKV[Autonomie]{Deux}{%
      \draw (C2) to (D2);%
      \draw (E2) to (F2);%
    }{%
      \foreach\i in{1,...,4}{%
        \draw (C\i) to (D\i);%
        \draw (E\i) to (F\i);%
      }%
    }%
    \coordinate (O1) at ($(D1)!0.5!(D2)$);
    \coordinate (O2) at ($(D3)!0.5!(D4)$);
    \coordinate (O3) at ($(E1)!0.5!(E2)$);
    \coordinate (O4) at ($(E3)!0.5!(E4)$);
    \coordinate (Q1) at ($(F1)!0.5!(A3)$);%
    \coordinate (Q2) at ($(F2)!0.5!(E1)$);%
    \coordinate (Q3) at ($(F3)!0.5!(E2)$);%
    \coordinate (Q4) at ($(F4)!0.5!(E3)$);%
    \coordinate (Q5) at ($(C1)!0.5!(A1)$);%
    \coordinate (Q6) at ($(C2)!0.5!(D1)$);%
    \coordinate (Q7) at ($(C3)!0.5!(D2)$);%
    \coordinate (Q8) at ($(C4)!0.5!(D3)$);%
    \ifboolKV[Autonomie]{Landscape}{%
      \draw[dashed] (C1) to (F1);
      \draw[dashed] (C3) to (F3);
      \draw (A2) to (B2);%
    }{%
      \ifboolKV[Autonomie]{Deux}{%
        \draw (C2) to (D2);
        \draw (E2) to (F2);
      }{%
        \foreach\i in{1,...,4}{%
          \draw (C\i) to (D\i);
          \draw (E\i) to (F\i);
        }%
      }%
      \draw[dashed] (A1) to (B1);%
      \draw[dashed] (A3) to (B3);%
    }%
    %\draw[dashed] (A1) to (B1);%
    %\draw[dashed] (A3) to (B3);%
    \ifboolKV[Autonomie]{ARemplir}{%
      \ifboolKV[Autonomie]{Landscape}{%
        \node[align=justify,anchor=center,text width=0.9*0.5\textwidth] at (O1) {\ListeAutoQ[1,1]};
        \node[align=justify,anchor=center,text width=0.9*0.5\textwidth] at (O2) {\ListeAutoQ[2,1]};
        \node[align=justify,anchor=center,text width=0.9*0.5\textwidth] at (O3) {\ListeAutoQ[3,1]};
        \node[align=justify,anchor=center,text width=0.9*0.5\textwidth] at (O4) {\ListeAutoQ[4,1]};
      }{%
        \ifboolKV[Autonomie]{Deux}{%
          \node[align=justify,anchor=center,text width=0.9*0.25\textwidth] (Test1) at ($(Q1)!0.5!(Q2)$) {\ListeAutoQ[1,1]};%
          \node[align=justify,anchor=center,text width=0.9*0.25\textwidth] (Test2) at ($(Q3)!0.5!(Q4)$) {\ListeAutoQ[2,1]};%
          \node[align=justify,anchor=center,text width=0.9*0.25\textwidth] (Test3) at ($(Q5)!0.5!(Q6)$) {\ListeAutoQ[3,1]};%
          \node[align=justify,anchor=center,text width=0.9*0.25\textwidth] (Test4) at ($(Q7)!0.5!(Q8)$) {\ListeAutoQ[4,1]};%
        }{%
          \foreach \i in {1,...,4}{%
            \node[align=justify,anchor=center,text width=0.9*0.25\textwidth] (Test\i) at (Q\i) {\ListeAutoQ[\i,1]};%
          }%
          \foreach \i in {5,...,8}{%
            \node[align=justify,anchor=center,text width=0.9*0.25\textwidth] (Test\i) at (Q\i) {\ListeAutoQ[\i,1]};%
          }%
        }%
      }%
    }{%
      \foreach \i in {1,...,4}{%
        \node[xshift=-5mm,align=justify,anchor=center,text width=0.8*0.25\textwidth] (Test\i) at (Q\i) {\ding{\fpeval{171+\i}}~\ListeAutoQ[\i,1]};%
      }%
      \foreach \i in {5,...,8}{%
        \node[align=justify,anchor=center,text width=0.8*0.25\textwidth] (Test\i) at (Q\i) {\ding{\fpeval{171+\i}}~\ListeAutoQ[\i,1]};%
      }%
    }%
  \end{tikzpicture}%
  \clearpage%
  \begin{tikzpicture}[remember picture,overlay]%
    \ifboolKV[Autonomie]{AfficheMarge}{%
      \node[xshift=5mm,yshift=-5mm,circle] (PfCA) at (current page.north west) {};%
      \node[xshift=-5mm,yshift=5mm] (PfCB) at (current page.south east) {};%
      \draw[blue,dashed] (PfCA) rectangle (PfCB);%
    }{}%
    \foreach \i in {1,...,3}{%
      \coordinate[xshift=\i*0.25*\paperwidth] (A\i) at (current page.north west);%
      \coordinate[xshift=\i*0.25*\paperwidth] (B\i) at (current page.south west);%
    }%
    \foreach \i in{1,...,4}{%
      \coordinate[yshift=-\i*0.25*\paperheight] (C\i) at (current page.north west);%
      \coordinate[yshift=-\i*0.25*\paperheight] (F\i) at (current page.north east);%
      \coordinate[yshift=-\i*0.25*\paperheight] (D\i) at (A1);%
      \coordinate[yshift=-\i*0.25*\paperheight] (G\i) at (A2);%
      \coordinate[yshift=-\i*0.25*\paperheight] (E\i) at (A3);%
    }%
    \ifboolKV[Autonomie]{Deux}{%
      \draw (C2) to (F2);%
    }{%
      \foreach \i in{1,...,4}{%
        \draw (C\i) to (F\i);%
      }%
    }%
    \coordinate (T1) at ($(current page.north west)!0.5!(A1)$);%
    \coordinate (T2) at ($(C1)!0.5!(D1)$);%
    \coordinate (T3) at ($(C2)!0.5!(D2)$);%
    \coordinate (T4) at ($(C3)!0.5!(D3)$);%
    \coordinate (T5) at ($(current page.north east)!0.5!(A3)$);%
    \coordinate (T6) at ($(E1)!0.5!(F1)$);%
    \coordinate (T7) at ($(E2)!0.5!(F2)$);%
    \coordinate (T8) at ($(E3)!0.5!(F3)$);%
    \coordinate (U1) at ($(C1)!0.5!(D1)$);%
    \coordinate (U2) at ($(C2)!0.5!(D2)$);%
    \coordinate (U3) at ($(C3)!0.5!(D3)$);%
    \coordinate (U4) at ($(current page.south west)!0.5!(B1)$);%
    \coordinate (U5) at ($(E1)!0.5!(F1)$);%
    \coordinate (U6) at ($(E2)!0.5!(F2)$);%
    \coordinate (U7) at ($(E3)!0.5!(F3)$);%
    \coordinate (U8) at ($(B3)!0.5!(current page.south east)$);%
    \coordinate (R1) at ($(D1)!0.5!(A2)$);%
    \coordinate (R2) at ($(D2)!0.5!(G1)$);%
    \coordinate (R3) at ($(D3)!0.5!(G2)$);%
    \coordinate (R4) at ($(D4)!0.5!(G3)$);%
    \coordinate (R5) at ($(E1)!0.5!(A2)$);%
    \coordinate (R6) at ($(E2)!0.5!(G1)$);%
    \coordinate (R7) at ($(E3)!0.5!(G2)$);%
    \coordinate (R8) at ($(E4)!0.5!(G3)$);%
    \coordinate (S1) at ($(A1)!0.5!(D1)$);%
    \coordinate (S2) at ($(D1)!0.5!(D2)$);%
    \coordinate (S3) at ($(D2)!0.5!(D3)$);%
    \coordinate (S4) at ($(D3)!0.5!(B1)$);%
    \coordinate (S5) at ($(R1)!0.5!(R5)$);%
    \coordinate (S6) at ($(R2)!0.5!(R6)$);%
    \coordinate (S7) at ($(R3)!0.5!(R7)$);%
    \coordinate (S8) at ($(R4)!0.5!(R8)$);%
    \coordinate (V1) at ($(T1)!0.5!(U1)$);%
    \coordinate (V2) at ($(T2)!0.5!(U2)$);%
    \coordinate (V3) at ($(T3)!0.5!(U3)$);%
    \coordinate (V4) at ($(T4)!0.5!(U4)$);%
    \coordinate (V5) at ($(T5)!0.5!(U5)$);%
    \coordinate (V6) at ($(T6)!0.5!(U6)$);%
    \coordinate (V7) at ($(T7)!0.5!(U7)$);%
    \coordinate (V8) at ($(T8)!0.5!(U8)$);%
    \coordinate (W1) at ($(A3)!0.5!(E1)$);
    \coordinate (W2) at ($(E1)!0.5!(E2)$);
    \coordinate (W3) at ($(E2)!0.5!(E3)$);
    \coordinate (W4) at ($(E3)!0.5!(E4)$);
    \coordinate (W5) at ($(A1)!0.5!(D1)$);
    \coordinate (W6) at ($(D1)!0.5!(D2)$);
    \coordinate (W7) at ($(D2)!0.5!(D3)$);
    \coordinate (W8) at ($(D3)!0.5!(D4)$);
    \ifboolKV[Autonomie]{Landscape}{%
      \draw[dashed] (C1) to (F1);%
      \draw[dashed] (C3) to (F3);
      \draw (A2) to (B2);%
    }{%
      \draw[dashed] (A1) to (B1);%
      \draw[dashed] (A2) to (B2);
      \draw[dashed] (A3) to (B3);%
    }%
    %\draw[dashed] (A1) to (B1);%
    %\draw[dashed] (A2) to (B2);%
    %\draw[dashed] (A3) to (B3);%
    \ifboolKV[Autonomie]{ARemplir}{%
      \ifboolKV[Autonomie]{Landscape}{%
        \node[align=justify,anchor=center,text width=0.9*0.5\textwidth] at (W2) {\ListeAutoEn[4,1]};
        \node[align=justify,anchor=center,text width=0.9*0.5\textwidth] at (W4) {\ListeAutoEn[3,1]};
        \node[align=justify,anchor=center,text width=0.9*0.5\textwidth] at (W6) {\ListeAutoEn[2,1]};
        \node[align=justify,anchor=center,text width=0.9*0.5\textwidth] at (W8) {\ListeAutoEn[1,1]};
        \node[align=justify,anchor=center,text width=0.9*0.5\textwidth] at (W1) {\ListeAutoQ[4,2]};
        \node[align=justify,anchor=center,text width=0.9*0.5\textwidth] at (W3) {\ListeAutoQ[3,2]};
        \node[align=justify,anchor=center,text width=0.9*0.5\textwidth] at (W5) {\ListeAutoQ[2,2]};
        \node[align=justify,anchor=center,text width=0.9*0.5\textwidth] at (W7) {\ListeAutoQ[1,2]};
      }{%
        \ifboolKV[Autonomie]{Deux}{%
          \node[align=justify,anchor=center,text width=0.9*0.25\textwidth] at ($(V1)!0.5!(V2)$) {\ListeAutoEn[1,1]};%
          \node[align=justify,anchor=center,text width=0.9*0.25\textwidth] at ($(V3)!0.5!(V4)$) {\ListeAutoEn[2,1]};%
          \node[align=justify,anchor=center,text width=0.9*0.25\textwidth] at ($(V5)!0.5!(V6)$) {\ListeAutoEn[3,1]};%
          \node[align=justify,anchor=center,text width=0.9*0.25\textwidth] at ($(V7)!0.5!(V8)$) {\ListeAutoEn[4,1]};%
          \node[align=justify,anchor=center,text width=0.9*0.25\textwidth] at ($(R1)!0.5!(R2)$) {\ListeAutoQ[1,2]};%%
          \node[align=justify,anchor=center,text width=0.9*0.25\textwidth] at ($(R3)!0.5!(R4)$) {\ListeAutoQ[2,2]};%%
          \node[align=justify,anchor=center,text width=0.9*0.25\textwidth] at ($(R5)!0.5!(R6)$) {\ListeAutoQ[3,2]};%%
          \node[align=justify,anchor=center,text width=0.9*0.25\textwidth] at ($(R7)!0.5!(R8)$) {\ListeAutoQ[4,2]};%%
        }{%
          \foreach \i in {1,...,8}{%
            \node[text width=0.9*0.25\paperwidth] at (V\i) {\ListeAutoQ[\i,2]};%
            \node[text width=0.9*0.25\paperwidth] at (R\i) {\ListeAutoEn[\i,1]};%
          }%
        }%
      }%
    }{%
      \foreach \i in {1,...,8}{%
        \node[rotate=90,anchor=north] (Cor\i) at (S\i) {\useKV[Autonomie]{TexteCorrection}};%
        \node[anchor=west,xshift=2em,text width=0.8*0.25\paperwidth] (Test\i)
        at (S\i) {\ListeAutoQ[\i,2]};%
        \node[anchor=north,yshift=-1em,text width=0.85*0.25\paperwidth] (TestEn\i)
        at (T\i) {\textbf{\useKV[Autonomie]{TitreAtoi}} \ListeAutoEn[\i,1]};%
        \ifboolKV[Autonomie]{Enigme}{%
          \node[anchor=south,yshift=1em,text width=0.85*0.25\paperwidth] (TestREn\i)
          at (U\i) {%
            \ListeAutoEn[\i,2] : \pointilles\\%
            Lettre \ding{\fpeval{171+\i}} : \pointilles%
          };%
        }{%
          \node[anchor=south,yshift=1em,text width=0.85*0.25\paperwidth] (TestREn\i)
          at (U\i) {%
            \ListeAutoEn[\i,2]%
          };%
        }%
      }%
    }%
  \end{tikzpicture}%
}%