\usepackage{tcolorbox}
\tcbuselibrary{listings,breakable}
%\tcbuselibrary{documentation}
\usepackage{enumitem}
\usepackage[tikz]{bclogo}
\usepackage{mflogo}
\usepackage{hologo}
\usepackage{luamplib}
\mplibtextextlabel{enable}
\usepackage{biblatex}
\addbibresource{ctan.bib}
\usepackage{wrapfig}
\usepackage{accsupp}
\usepackage{siunitx}
\usepackage{imakeidx}
%\usepackage{csquotes}
\usepackage{fancyvrb,xparse,xargs}
\usepackage[sfdefault]{FiraSans}
\usepackage[mathrm=sym]{firamath-otf}
\setmonofont{Fira Mono}
%\setmonofont{FiraCode-Regular.ttf}[BoldFont= FiraCode-Bold.ttf,ItalicFont= FiraCode-RegularItalic.otf,BoldItalicFont= FiraCode-BoldItalic.otf,Ligatures={NoCommon, NoDiscretionary, NoHistoric, NoRequired, NoContextual}]

\usepackage{xspace}
\usepackage{animate}
\newcommand{\ctan}{\textsc{ctan}}
\NewDocumentCommand{\package}{ m }{%
  \href{https://ctan.org/pkg/#1}{#1}\xspace
}

\definecolor{darkred}{rgb}{0.6,0.1,0.1}
\definecolor{vert}{rgb}{0.1,0.4,0.1}
\definecolor{bleu}{rgb}{0.2,0.2,0.6}
\definecolor{orange}{rgb}{0.6,0.4,0.}
\colorlet{code}{blue!80!black}

\usepackage[colorlinks=true,urlcolor=orange,linkcolor=orange,menucolor=black,citecolor=orange]{hyperref}

\newcommand \file       {\nolinkurl}
\renewcommand \cmd        {\texttt}
\renewcommand \code   [1] {\texorpdfstring {\texttt{\color{code}#1}} {#1}}
\renewcommand*\cs     [1] {\code{\textbackslash #1}}



\newcommand*\commande{\par\bigskip\noindent\hspace{-30pt}%
  \SaveVerb[aftersave={%
   \UseVerb{Vitem}%
  }%
  ]{Vitem}%
  }
  \newcommand\vitem[1][]{\SaveVerb[%
  aftersave={\item[\textnormal{\UseVerb[#1]{vsave}}]}]{vsave}}
\newcommand*\textme[1]{\textcolor{black}{\rmfamily\textit{#1}}}
%\renewcommand*\meta[1]{% % meta
%  \textme{\ensuremath{\langle}#1\ensuremath{\rangle}}}
\newcommand*\optstar{% % optional star
  \meta{\ensuremath{*}}\xspace}
\DefineShortVerb{\|}
\newcommand\R{\mathbf{R}}
\setlength{\fboxsep}{2pt}
\fvset{%
  codes={\catcode`\«\active \catcode`\×\active },
  defineactive={\makefancyog\makefancytimes},
  formatcom=\color{darkred},
  frame=single
}
% rendre «...» équivalent à \meta{...}
{\catcode`\«\active
  \newcommandx\makefancyog[0][addprefix=\global]{%
    \def«##1»{\meta{##1}}}}
% rendre × équivalent à \optstar
{\catcode`\×\active
  \newcommandx\makefancytimes[0][addprefix=\global]{%
    \def×{\optstar{}}}}


\newcommand\mpchess{\textbf{\textlogo{MP}}\textit{chess}\xspace}



%\addbibresource{biblio.bib}


\lstset{
  numberstyle=\footnotesize\color{vert},
  keywordstyle=\ttfamily\bfseries\color{bleu},
  basicstyle=\ttfamily,
  commentstyle=\itshape\color{vert},
  stringstyle=\ttfamily\color{orange},
  showstringspaces=false,
  language=MetaPost,
  breaklines=true,
  breakindent=30pt,
  defaultdialect=MetaPost,
  classoffset=1,% frame=tb
  morekeywords={init_backboard,set_backboard_width,set_backboard_size,set_color_theme,get_backboard_width,get_backboard_size,set_backboard_width,get_square_dim,set_white_color,set_black_color,set_coords_inside,set_coords_outside,set_coords_font,set_coords,
  set_no_coords,set_white_view,set_black_view,
  set_white_player,set_black_player,set_pieces_theme,set_players_side,init_chessboard,set_empty_chessboard,add_white_pieces,add_black_pieces,clear_areas,clear_files,clear_ranks,clear_squares,build_chessboard_from_fen,build_chessboards_from_pgn,clear_chessboard,
  color_square,draw_arrows,draw_circles,draw_comment,draw_crosses,get_halfmove_number,get_totalmove_number,
  reset_mpchess,set_black_to_move,set_last_move_color,set_comment_color,set_white_to_move,set_whos_to_move,show_last_move,unset_whos_to_move,set_arrow_width,clip_chessboard,build_chessboard_from_fen_file,build_chessboard_from_pgn_file,draw_black_main_lines,draw_black_main_lines_step,draw_white_main_lines,draw_white_main_lines_step,set_main_lines_color,set_possible_moves_color,show_possible_moves,show_possible_moves_step,hide_coordinates,hide_whos_to_move,set_black_squares_color,set_coordinates_font,set_coordinates_position,set_white_squares_color,show_coordinates,show_whos_to_move,set_board_type},
  keywordstyle=\color{darkred},
  classoffset=2,% frame=tb
  morekeywords={backboard,chessboard,chessboard_step},
  keywordstyle=\color{vert},
  classoffset=0,% frame=tb
  morekeywords={draw},
  keywordstyle=\color{bleu}
}

\makeatletter
\tcbset{%
    listing metapost/.code={%
        \def\tcbuselistingtext@input{\begin{mplibcode} input \jobname.listing; \end{mplibcode}}%
    }
}
\makeatother
\newtcblisting[auto counter,]{ExempleMP}[1][]{%
  arc=0pt,outer arc=0pt,
  colback=darkred!3,
  colframe=darkred,
  breakable,fontupper=\small,
  boxsep=0pt,left=5pt,right=5pt,top=5pt,bottom=5pt, bottomtitle =
  3pt, toptitle=3pt,
  boxrule=0pt,bottomrule=0.5pt,toprule=0.5pt, toprule at break =
  0pt, bottomrule at break = 0pt,
  listing side text,
  listing metapost,
  title=Exemple~\thetcbcounter,
  listing options={breaklines},#1
}

\newtcblisting{commandshell}{colback=black,colupper=white,colframe=black,
  arc=0pt,
  listing only,boxsep=0pt,listing
  options={style=tcblatex,language=sh},
  every listing line={\BeginAccSupp{ActualText={}}\textcolor{red}{\small\ttfamily\bfseries user \$> }}\EndAccSupp{}}


  \newtcblisting{mpcode}{
  arc=0pt,outer arc=0pt,
  colback=darkred!3,
  colframe=darkred,
  breakable,
  boxsep=0pt,left=5pt,right=5pt,top=5pt,bottom=5pt, bottomtitle =
  3pt, toptitle=3pt,
  boxrule=0pt,bottomrule=0.5pt,toprule=0.5pt, toprule at break =
  0pt, bottomrule at break = 0pt,
  listing only,boxsep=0pt,listing
  options={breaklines}
}

\newtcblisting{latexcode}{
  arc=0pt,outer arc=0pt,
  colback=darkred!3,
  colframe=darkred,
  breakable,
  boxsep=0pt,left=5pt,right=5pt,top=5pt,bottom=5pt, bottomtitle =
  3pt, toptitle=3pt,
  boxrule=0pt,bottomrule=0.5pt,toprule=0.5pt, toprule at break =
  0pt, bottomrule at break = 0pt,
  listing only,boxsep=0pt,listing
  options={breaklines,language={[LaTeX]TeX}}
}


\newcommand\pdf{\textsc{pdf}}


\newfontfamily{\chessfont}{mpchess font}
\newcommand\bP{{\chessfont \char"265F}} % black Pawn
\newcommand\bN{{\chessfont \char"265E}} % black Knight
\newcommand\bB{{\chessfont \char"265D}} % black Bishop
\newcommand\bR{{\chessfont \char"265C}} % black Rook
\newcommand\bQ{{\chessfont \char"265B}} % black Queen
\newcommand\bK{{\chessfont \char"265A}} % black King
\newcommand\wP{{\chessfont \char"2659}} % white Pawn
\newcommand\wN{{\chessfont \char"2658}} % white Knight
\newcommand\wB{{\chessfont \char"2657}} % white Bishop
\newcommand\wR{{\chessfont \char"2656}} % white Rook
\newcommand\wQ{{\chessfont \char"2655}} % white Queen
\newcommand\wK{{\chessfont \char"2654}} % white King