%!TEX pdflatex

\documentclass[a4paper,french,11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[margin=1.5cm]{geometry}
\usepackage{babel}
\usepackage[table,svgnames]{xcolor}
\usepackage{simplekv}
\usepackage{codehigh}
\usepackage{tabularray}
\setlength\parindent{0mm}

\begin{document}

\newcommand\ColC{\SetCell{bg=\PLSMcouleur}}

\ExplSyntaxOn
\NewChildSelector{PLcycle}[1]{%child cycle tblr pour tracer des traits sépciaux de #1 en #1
	\int_step_inline:nnnn {1} {#1} {\l_tblr_childs_total_tl}
	{\clist_put_right:Nn \l_tblr_childs_clist {##1}}
}
\ExplSyntaxOff

\defKV[PLTBLRSUDOM]{%
	couleurtexte=\def\PLSMcoulcase{#1},%
	epaisseur=\def\PLSMep{#1},%
	epaisseurg=\def\PLSMepg{#1},%
	unite=\def\PLSMunite{#1},%
	couleurcase=\def\PLSMcouleur{#1},%
	nbcol=\def\PLSMnbcol{#1},%
	nbsubcol=\def\PLSMnbsubcol{#1},%
	nblig=\def\PLSMnblig{#1},%
	nbsublig=\def\PLSMnbsublig{#1},%
	police=\def\PLSMfonte{#1}
}

\setKVdefault[PLTBLRSUDOM]{%
	epaisseurg=1.75pt,%
	epaisseur=0.875pt,%
	unite=1cm,%
	couleurcase=LightBlue!50,%
	couleurtexte=blue,%
	nbcol=9,%
	nbsubcol=3,%
	nblig=9,%
	nbsublig=3,%
	police=\normalfont\normalsize
}

\NewDocumentEnvironment{PLsudomaths}{ O{} }
{
	\useKVdefault[PLTBLRSUDOM]
	\setKV[PLTBLRSUDOM]{#1}% on paramètres les nouvelles clés et on les simplifie
	\def\larcolinter{\inteval{\PLSMnbcol/\PLSMnbsubcol}}
	\def\larliginter{\inteval{\PLSMnblig/\PLSMnbsublig}}
	\begin{tblr}[expand=\ColC]{%
			rowsep=0pt,colsep=0pt,%
			hlines={\PLSMep},vlines={\PLSMep},%
			colspec={*{\PLSMnbcol}{Q[c,m,\PLSMunite]}},%
			rows={\PLSMunite},%
			vline{PLcycle{\larcolinter}}={\PLSMepg},%
			hline{PLcycle{\larliginter}}={\PLSMepg},%
			cells={fg=\PLSMcoulcase,font=\PLSMfonte}
	}
}%
{
	\end{tblr}
}

\part*{SudoMaths 6$\times$6}

{\small \begin{codehigh}[language=latex/latex3]
\begin{PLsudomaths}[nbcol=6,nbsubcol=2,nblig=6,nbsublig=3,police=\bfseries\sffamily]
    \ColC(a) & \ColC(b) &          &          & \ColC(c) & \ColC(d) \\
    \ColC(e) &          &          & \ColC(f) & \ColC(g) & \ColC(h) \\
             &          & \ColC(i) &          &          & \ColC(j) \\
             &          & \ColC(k) &          & \ColC(l) & \ColC(m) \\
    \ColC(n) &          & \ColC(o) &          &          & \ColC(p) \\
             &          &          & \ColC(q) &          &          \\
\end{PLsudomaths}
\end{codehigh}}

\begin{PLsudomaths}[nbcol=6,nbsubcol=2,nblig=6,nbsublig=3,police=\bfseries\sffamily]
\ColC(a) & \ColC(b) &          &          & \ColC(c) & \ColC(d) \\
\ColC(e) &          &          & \ColC(f) & \ColC(g) & \ColC(h) \\
&          & \ColC(i) &          &          & \ColC(j) \\
&          & \ColC(k) &          & \ColC(l) & \ColC(m) \\
\ColC(n) &          & \ColC(o) &          &          & \ColC(p) \\
&          &          & \ColC(q) &          &        \\
\end{PLsudomaths}

\part*{SudoMaths 9$\times$9 vide}

{\small \begin{codehigh}[language=latex/latex3]
\begin{PLsudomaths}[unite=0.5cm]
    &&&&&&&&\\
    &&&&&&&&\\
    &&&&&&&&\\
    &&&&&&&&\\
    &&&&&&&&\\
    &&&&&&&&\\
    &&&&&&&&\\
    &&&&&&&&\\
    &&&&&&&&\\
\end{PLsudomaths}
\end{codehigh}}

\begin{PLsudomaths}[unite=0.5cm]
&&&&&&&&\\
&&&&&&&&\\
&&&&&&&&\\
&&&&&&&&\\
&&&&&&&&\\
&&&&&&&&\\
&&&&&&&&\\
&&&&&&&&\\
&&&&&&&&\\
\end{PLsudomaths}

\part*{SudoMaths imaginaire 4$\times$8}

{\small \begin{codehigh}[language=latex/latex3]
\begin{PLsudomaths}[%
    nbcol=8,nbsubcol=4,nblig=4,nbsublig=4,unite=0.5cm,%
    police=\large\sffamily,couleurtexte=red,couleurcase=yellow!50]
\ColC1 & 2      & 3      & 4      & \ColC5 & 6      & 7      & 8      \\
8      & \ColC1 & 2      & 3      & 4      & \ColC5 & 6      & 7      \\
7      & 8      & \ColC1 & 2      & 3      & 4      & \ColC5 & 6      \\
6      & 7      & 8      & \ColC1 & 2      & 3      & 4      & \ColC5 \\
\end{PLsudomaths}
\end{codehigh}}

\begin{PLsudomaths}[%
    nbcol=8,nbsubcol=4,nblig=4,nbsublig=4,unite=0.8cm,%
    police=\large\sffamily,couleurtexte=red,couleurcase=yellow!50]
\ColC1&2&3&4&\ColC5&6&7&8\\
8&\ColC1&2&3&4&\ColC5&6&7\\
7&8&\ColC1&2&3&4&\ColC5&6\\
6&7&8&\ColC1&2&3&4&\ColC5\\
\end{PLsudomaths}

\end{document}