\documentclass[landscape]{article}
\usepackage{amsmath,amssymb}
\usepackage{booktabs}
\usepackage{mathtools}
\usepackage{savetrees}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\parindent=0pt
\parskip=0pt
\usepackage{expl3}
\pagestyle{myheadings}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand\Done[1][\ell]{$D^{(1)}_{#1}$}
\renewcommand\c{\mathsf{c}}
\renewcommand\r{\mathsf{r}}
\newcommand\x{\mathsf{x}}
\newcommand\R{\mathbb{R}}
\newcommand\Z{\mathbb{Z}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\Vline{\space\vrule width 1.5pt\space}
\newcommand\Hline{\noalign{\hrule height 1.5pt}}

\newif\ifghost

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ExplSyntaxOn
\fp_const:Nn \l_eps_fp {0.05}   % (r+c)*eps
\fp_const:Nn \l_eeps_fp {0.05} %  res * eeps
\newcommand\Eps{\fp_use:N \l_eps_fp}
\newcommand\Eeps{\fp_use:N \l_eeps_fp}

\fp_new:N \l_coord_fp
\fp_new:N \l_ghost_fp
\int_new:N \g_content_int
\int_new:N \l_kp_int
\int_new:N \g_position_int
\int_new:N \l_kpp_int
\int_new:N \l_k_int
\int_new:N \l_l_int
\int_new:N \l_res_int
\int_new:N \l_mod_int

% \__set_content:nnnn {n}{e}{m}{r}{c}
% returns:
%     k'+1    - \eps(r+c)  if 0\le k'\le e
%     2e+1-k' + \eps(r+c)  if l< k' 2l
% where k=c-r and k' = k mod (2e+1)
\cs_new:Npn \__set_content:nnnnn #1 #2 #3 #4 #5
{
  \int_set:Nn \l_l_int {#2}
  \int_set:Nn \l_k_int {#5-1}
  \int_set:Nn \l_kp_int { \int_mod:nn {\l_k_int} {2*\l_l_int+2} } % integer mod
  \int_compare:nT { \l_kp_int < 0} { \int_add:Nn \l_kp_int {2*\l_l_int+2} }
  % compute the residue
  \int_compare:nTF { \l_kp_int <= \l_l_int}{
    \int_set:Nn \l_res_int {\l_kp_int}
  }{
    \int_set:Nn \l_res_int {2*\l_l_int+1-\l_kp_int}
  }
  \int_compare:nT { \l_res_int < 0} {
    \int_set:Nn \l_res_int {\l_res_int+\l_l_int}
  }
  % compute the content
  \global\ghosttrue
  \int_gincr:N \g_position_int
  \int_gset:Nn \g_content_int {\l_res_int-2}
  \int_case:nnF {\l_res_int}
  {
    {0}          {\global\ghostfalse \int_gadd:Nn \g_content_int {2} }
    {1}          {\global\ghosttrue}
    {\l_l_int}   {\global\ghostfalse}
  }{ \global\ghosttrue}

  % increment the position function
  \fp_set:Nn \l_coord_fp { \g_content_int - \l_eps_fp * \g_position_int } % - \l_eeps_fp*(#4+#5) }
  \fp_set:Nn \l_ghost_fp { \l_coord_fp + 1 }
}

\int_new:N \g_N_int
\tl_new:N \g_mu_coord_tl
\tl_new:N \g_mu_ghost_tl
\tl_new:N \g_mu_head_tl
\tl_new:N \g_mu_res_tl
\clist_new:N \g_mu_sorted_clist
\newcommand\ResetCoordinates{
  \int_gzero:N \g_N_int
  \tl_gclear:N \g_mu_head_tl
  \tl_gclear:N \g_mu_coord_tl
  \tl_gclear:N \g_mu_ghost_tl
  \tl_gclear:N \g_mu_res_tl
  \int_gzero:N \g_position_int
  \clist_gclear:N \g_mu_sorted_clist
}

% \SetCoordinates{n}{e}{r}{c}
\newcommand\SetCoordinates[4]{
  \int_gincr:N \g_N_int
  \__set_content:nnnnn {#1}{#2}{\int_use:N\g_N_int}{#3}{#4}
  \xdef\coord{\fp_use:N \l_coord_fp}
  \xdef\gcoord{\fp_use:N \l_ghost_fp}
  \xdef\res{\int_use:N \l_res_int}
  \tl_gput_right:Nx \g_mu_head_tl { \int_use:N \g_N_int &}
  \tl_gput_right:Nx \g_mu_res_tl { \res &}
  \tl_gput_right:Nx \g_mu_coord_tl { \fp_to_decimal:n {\fp_eval:n {\fp_to_int:n{100*\l_coord_fp}/100}} &}
  \tl_gput_right:Nx \g_mu_ghost_tl { \ifghost\fp_to_decimal:n {\fp_eval:n {\fp_to_int:n{100*\l_ghost_fp}/100}}\else*\fi &}
  \clist_gput_right:Nx \g_mu_sorted_clist {\fp_to_decimal:n {\fp_eval:n {\fp_to_int:n{100*\l_coord_fp}/100}}}
}
\newcommand\PrintCoordinates{
   \int_gincr:N \g_N_int
   \int_gincr:N \g_N_int
    \clist_gsort:Nn \g_mu_sorted_clist
   {
    \fp_compare:nNnTF { ##1 } > { ##2 }
        { \sort_return_swapped: }
        { \sort_return_same: }
   }
   \[
   \begin{array}{l@{:\quad}*{\int_use:N \g_N_int}{r}}\toprule
         k     & \tl_use:N \g_mu_head_tl \\ \midrule
         \r(k) & \tl_use:N \g_mu_res_tl \\
         \c(k) & \tl_use:N \g_mu_coord_tl\\
         \mathsf{g}(k) & \tl_use:N \g_mu_ghost_tl\\
         \vartriangleright\c_math_subscript_token\x & \clist_use:Nn \g_mu_sorted_clist {&} \\
         \bottomrule
     \end{array}
   \]
}

% print table of residue, content and coordinate functions
\tl_new:N \l_k_row_tl
\tl_new:N \l_r_row_tl
\tl_new:N \l_c_row_tl
\tl_new:N \l_x_row_tl
\int_new:N \l_m_int
\newcommand\ResidueContentTable[1]{
  \tl_clear:N \l_k_row_tl
  \tl_clear:N \l_r_row_tl
  \tl_clear:N \l_c_row_tl
  \tl_clear:N \l_x_row_tl
  \int_set:Nn \l_m_int {-3}
  \int_while_do:nNnn {\l_m_int}<{17} {
  \__set_content:nnnnn{10} {#1}{\l_m_int}{0}{\int_use:N\l_m_int}
     \tl_put_right:Nx \l_k_row_tl {\int_use:N\l_m_int&}
     \tl_put_right:Nx \l_r_row_tl {\int_use:N\l_res_int&}
  %  \tl_put_right:Nx \l_c_row_tl {\int_use:N\g_content_int&}
     \tl_put_right:Nx \l_x_row_tl {\fp_use:N\l_coord_fp&}

     \int_incr:N \l_m_int
  }
  \[
    \begin{array}{l@{\Vline}*{22}r}
      k     & \l_k_row_tl \\\Hline
      \r(k) & \l_r_row_tl \\
      \c(k) & \l_c_row_tl \\
      \x(k) & \l_x_row_tl
    \end{array}
  \]
}

\ExplSyntaxOff

\usetikzlibrary{arrows.meta,decorations.markings}
\tikzset{
  solid/.style = {thick, MidnightBlue},
  ghost/.style = {thin, gray},
  red/.style   = {very thick, draw=red},
  ->-/.style={decoration={markings, mark=at position 0.6 with
        {\arrow{Latex}}}, postaction={decorate}},
}

% \IdempotentDiagram{n}{e}{mu}
\newcommand\IdempotentDiagram[3]{
  $\mathbf{1}_{#3}=$
  \begin{tikzpicture}[
    yscale=0.9,
    xscale=2.8,
    baseline={([yshift=-1ex]current bounding box.center)}
  ]
    \ResetCoordinates
    \draw[red](0,0) -- ++(0,1);
    \foreach \mur [count=\rr] in {#3} {
      \foreach \cc in {1,...,\mur} {
        \SetCoordinates{#1}{#2}{\rr}{\cc}
        \draw[solid](\coord,0)node[below]{$\res$} -- ++(0,1);
        \ifghost
          \ifnum\res=1
          \draw[double,ghost](\gcoord,0) -- ++(0,1)node[above]{$\res$};
          \else
          \draw[ghost](\gcoord,0) -- ++(0,1)node[above]{$\res$};
          \fi
        \fi
      }
    }
  \end{tikzpicture}
  \PrintCoordinates
  \par
}

\newcommand\TypeAQuiverver[1]{%
  \Done[#1] \qquad
  \begin{tikzpicture}[
        xscale=2, thick,
        baseline=(current bounding box.center)
    ]
     \foreach \c [remember=\c as \cl] in {0,...,#1} {
        \node[circle,draw, inner sep=1pt](\c) at (\c,0){\c};
        \ifnum\c=1
          \draw[->-, double](\cl)--(\c);
        \else
          \ifnum\c=#1
            \draw[->-, double](\cl)--(\c);
          \else
            \draw(\cl)--(\c);
          \fi
        \fi
     }
  \end{tikzpicture}
}

\begin{document}

\section{Residues and contents for \Done}
Let $I=\{0,1,\dots,\ell\}$ be the vertex set of the quiver of
type~\Done. Given an integer $k\in\Z$ write $k=2\ell k'+k''$,
where $k',k'\in\Z$ are the unique integers such that $0\le k''<2\ell$.

\subsection{Residues}

Define a \textbf{residue function} $\r\colon\Z\longrightarrow I$ by
\[
\r(k) = \begin{cases*}
    k'',& if $0\le k''<\ell$,\\
    2\ell-k'',& if $\ell\le k''<2\ell$.
  \end{cases*}
\]

\subsection{Coordinates}

Pick sufficiently small numbers $\varepsilon,\varepsilon'>0$ and
define the \textbf{content function} $\c\colon I I$ by
\[
      \c(r) = \begin{cases*}
         r, & if $0\le r<\ell$,\\
         \ell-2, & if $r=\ell$,
      \end{cases*}
\]
and define the coordinate of the $k$ string to be:
\[
    \x(k) = \c(\r(k)) - \varepsilon k.
\]

In the diagrams below, $\varepsilon = \Eps$ and $\varepsilon'=\Eeps$.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\foreach \ll in {2,3,4} {

  \newpage
  \section{Idempotent diagrams for \Done[\ll]}
  \markright{Idempotent diagrams for \Done[\ll]}
  \TypeAQuiverver{\ll}

  \ResidueContentTable{\ll}

  \IdempotentDiagram1{\ll}{1}
  \IdempotentDiagram2{\ll}{2}

  \IdempotentDiagram3{\ll}{2,1}
  \IdempotentDiagram3{\ll}{3}

  \IdempotentDiagram4{\ll}{3,1}
  \IdempotentDiagram4{\ll}{4}

  \IdempotentDiagram5{\ll}{3,2}
  \IdempotentDiagram5{\ll}{4,1}
  \IdempotentDiagram5{\ll}{5}

  \IdempotentDiagram6{\ll}{3,2,1}
  \IdempotentDiagram6{\ll}{4,2}
  \IdempotentDiagram6{\ll}{5,1}
  \IdempotentDiagram6{\ll}{6}

  \IdempotentDiagram7{\ll}{4,2,1}
  \IdempotentDiagram7{\ll}{5,2}
  \IdempotentDiagram7{\ll}{6,1}
  \IdempotentDiagram7{\ll}{7}

  \IdempotentDiagram8{\ll}{4,3,1}
  \IdempotentDiagram8{\ll}{5,2,1}
  \IdempotentDiagram8{\ll}{5,3}
  \IdempotentDiagram8{\ll}{6,2}
  \IdempotentDiagram8{\ll}{7,1}
  \IdempotentDiagram8{\ll}{8}


% \IdempotentDiagram5{\ll}{5}
%  \IdempotentDiagram6{\ll}{6}
%  \IdempotentDiagram7{\ll}{7}
%  \IdempotentDiagram8{\ll}{8}
%  \IdempotentDiagram9{\ll}{9}
%  \IdempotentDiagram{10}{\ll}{10}
%  \IdempotentDiagram{11}{\ll}{11}
%  \IdempotentDiagram{12}{\ll}{12}
%  \IdempotentDiagram{13}{\ll}{13}
% \IdempotentDiagram{14}{\ll}{14}
%  \IdempotentDiagram{3}{\ll}{3}
%  \IdempotentDiagram{4}{\ll}{3,1}
%  \IdempotentDiagram{5}{\ll}{3,2}
%  \IdempotentDiagram{6}{\ll}{3,3}
%  \IdempotentDiagram{7}{\ll}{3,3,1}
%  \IdempotentDiagram{8}{\ll}{3,3,2}
%  \IdempotentDiagram{9}{\ll}{3,3,3}
%  \IdempotentDiagram{16}{\ll}{4,4,4,4}
%  \IdempotentDiagram{20}{\ll}{5,5,5,5}
%  \IdempotentDiagram{25}{\ll}{5,5,5,5,5}

%  \IdempotentDiagram{6}{\ll}{1,1,1,1,1,1}
%  \IdempotentDiagram{18}{\ll}{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
%  \IdempotentDiagram{36}{\ll}{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
%
%  \IdempotentDiagram{36}{\ll}{6,6,6,6,6,6}
%  \IdempotentDiagram{49}{\ll}{7,7,7,7,7,7,7}
%  \IdempotentDiagram{48}{\ll}{8,8,8,8,8,8}

%  \IdempotentDiagram3{\ll}{2,1}
%  \IdempotentDiagram8{\ll}{4,4}
%  \IdempotentDiagram4{\ll}{4}
%  \IdempotentDiagram4{\ll}{3,1}
%  \IdempotentDiagram4{\ll}{2,2}
%  \IdempotentDiagram4{\ll}{2,1,1}
%  \IdempotentDiagram4{\ll}{1,1,1,1}
%  \IdempotentDiagram6{\ll}{6}
%  \IdempotentDiagram6{\ll}{5,1}
%  \IdempotentDiagram6{\ll}{4,2}
%  \IdempotentDiagram6{\ll}{4,1,1}
%  \IdempotentDiagram6{\ll}{3,3}
%  \IdempotentDiagram6{\ll}{3,2,1}
%  \IdempotentDiagram6{\ll}{3,1,1,1}
%  \IdempotentDiagram6{\ll}{2,2,2}
%  \IdempotentDiagram6{\ll}{2,2,1,1}
%  \IdempotentDiagram6{\ll}{2,1,1,1,1}
%  \IdempotentDiagram6{\ll}{1,1,1,1,1,1}
%  \IdempotentDiagram7{\ll}{1,1,1,1,1,1,1}
%  \IdempotentDiagram8{\ll}{8}
%  \IdempotentDiagram9{\ll}{9}
%  \IdempotentDiagram9{\ll}{1,1,1,1,1,1,1,1,1}
%  \IdempotentDiagram9{\ll}{3,3,3}
%  \IdempotentDiagram{16}{\ll}{4,4,4,4}
%  \IdempotentDiagram{16}{\ll}{16}
%  \IdempotentDiagram{18}{\ll}{18}
%  \IdempotentDiagram{19}{\ll}{19}
%  \IdempotentDiagram{21}{\ll}{21}
%  \IdempotentDiagram{8}{\ll}{4,4}
%  \IdempotentDiagram{8}{\ll}{4,3,1}
%  \IdempotentDiagram{8}{\ll}{2,1,1,1,1,1,1}
}

\end{document}



