%%%
%%%
%%% Extensions : commun.sty
%%% Version : 1.0
%%% Date : 03/05/15
%%%
%%% Version : 2.0
%%% Date : 11/08/16
%%% Mods : Change some packages call to be compatible with LuaLaTeX
%%%
%%% Auteur : Jeff LANCE
%%%
%%%

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{commun}[2015/05/03 Ensembles d'environnements et de fonctions
                                    utilisables partout, v2.0]


%
%
% PACKAGES
%
%

% development
\RequirePackage{xifthen}
\RequirePackage{ifmtarg}
\RequirePackage{ifpdf}
\RequirePackage{xstring}
\RequirePackage{multido}
\RequirePackage{xparse}
\RequirePackage{etoolbox}
\RequirePackage{ifluatex}
\RequirePackage{import}

% language
\ifluatex
	\RequirePackage{polyglossia}		% => babel
	\setdefaultlanguage{french}		% => inputenc
	\RequirePackage{luatextra}		% charge fontspec => fontenc
	% \defaultfontfeatures{Ligatures=TeX}
\else
	\RequirePackage[francais]{babel}	% => polyglossia
	\RequirePackage[utf8]{inputenc}		% => fontspec
	\RequirePackage[T1]{fontenc}		% => fontspec
\fi

% fonts
\RequirePackage{libertine}
\RequirePackage{pifont}
\RequirePackage{fontawesome}
\RequirePackage{eurosym}
\RequirePackage{frcursive}

% color and graphics
\ifluatex
	\RequirePackage{luacolor}
\fi
%\RequirePackage[table,xcdraw]{xcolor} % there's a bug when used with some mdframed content
\RequirePackage[]{xcolor}
\RequirePackage[framemethod=tikz]{mdframed}
\RequirePackage{graphicx}
\RequirePackage{transparent}
\RequirePackage{fancybox}
\RequirePackage[tikz]{bclogo}

% maths
\RequirePackage{amsmath, amsthm}
\RequirePackage{amssymb}
\RequirePackage{tkz-euclide}
\usetikzlibrary{shadows}
\RequirePackage{calc}
% \RequirePackage{pgffor,pgfmath} % loaded by tikz
\RequirePackage{pgfplots}
\pgfplotsset{compat=1.16}
\RequirePackage[output-decimal-marker={,}]{siunitx}
\RequirePackage{asymptote}
\RequirePackage{mathrsfs}
\RequirePackage{xlop}

% tableaux de signe
%\RequirePackage{tabvar}    % replaced by pdftabvar from pdfadd
\RequirePackage{fp}
\RequirePackage[luatex]{pict2e}
\RequirePackage{picture}
\RequirePackage{color}
\input pdftabvar
%

% tables
\RequirePackage{array}
\RequirePackage{tabularx}
\RequirePackage{multicol}
\RequirePackage{boldline}

% layout
\RequirePackage{varwidth}
\RequirePackage{adjustbox}
\RequirePackage{lscape}

% text
\RequirePackage[dash]{dashundergaps}
\RequirePackage{comment}
\RequirePackage{caption}



\makeatletter



%
%
% SETTINGS
%
%

% \providetoggle{display}
% \toggletrue{display}


%
%
% MACROS
%
%

% Tableau
% Alignment commands of the content in the column with a defined width.

\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{M}[1]{>{\centering}m{#1}}
%% lh{largeur} : gauche - haut
%\newcolumntype{lh}[1]{>{\raggedright}p{#1}}
%% ch{largeur} : centre - haut
%\newcolumntype{ch}[1]{>{\centering\arraybackslash}p{#1}}
%% rh{largeur} : droite - haut
%\newcolumntype{rh}[1]{>{\raggedleft}p{#1}}
%% lc{largeur} : gauche - centre
%\newcolumntype{lc}[1]{>{\raggedright}m{#1}}
%% cc{largeur} : centre - centre
% \newcolumntype{M}[1]{ >{\centering\arraybackslash} m{#1} }
%% rc{largeur} : droite - centre
%\newcolumntype{rc}[1]{>{\raggedleft}m{#1}}
%% lb{largeur} : gauche - bas
%\newcolumntype{lb}[1]{>{\raggedright}b{#1}}
%% cb{largeur} : centre - bas
%\newcolumntype{cb}[1]{>{\centering}b{#1}}
%% rb{largeur} : droite - bas
%\newcolumntype{rb}[1]{>{\raggedleft}b{#1}}

% Item in a tab.
\newcommand{\tabitem}{~~\llap{\textbullet}~~}



%
%
% Texte
%
%

% \hcancel[color][size]{text}
% Strike text with a color and a defined thickness.
\newcommand\hcancel[2][black]{
	\setbox0=\hbox{$#2$}%
	\rlap{\raisebox{.45\ht0}{\textcolor{#1}{\rule{\wd0}{1pt}}}}#2
}

% \circled{text}
% Circled text.
\newcommand*\circled[1]{
  \tikz[baseline=(char.base)]{
    \node[shape=circle,draw,inner sep=2pt] (char) {#1};
  }
}

% \keystroke{text}
% Boxed text as a keyboard key.
% Why: menukeys and tipfr packages don't really run correctly with beamer.
\newcommand*\keystroke[1]{%
    \tikz[baseline=(key.base)]
    \node[%
    draw,
    fill=white,
    drop shadow={shadow xshift=0.25ex,shadow yshift=-0.25ex,fill=black,opacity=0.75},
    rectangle,
    rounded corners=2pt,
    inner sep=1pt,
    line width=0.5pt,
    font=\scriptsize\sffamily
    ](key) {#1\strut}
    ;
}

\NewDocumentCommand \getrandomletter { s G{1} G{26} }{%
  \IfBooleanTF { #1 }{
    \pgfmathrandominteger{\zzz}{#2}{#3}\csname pgffor@Alpha\endcsname{\zzz}
  }{
    \pgfmathrandominteger{\zzz}{#2}{#3}\csname pgffor@alpha\endcsname{\zzz}
  }
}

\NewDocumentCommand \@getletter{ G{1} G{26} }{
	\pgfmathsetmacro{\random}{rnd}
	\pgfmathparse{\random >= 0.5 ? "\noexpand\getrandomletter{#1}{#2}" : "\noexpand\getrandomletter*{#1}{#2}"}
	\pgfmathresult
}



%
%
% BCLOGO
%
%

\renewcommand\bcStyleTitre[1]{\textbf{#1}}
\newcommand\bcexample{\centering \normalsize \faPaperclip}
\newcommand\bcremark{\centering \normalsize \faExclamationTriangle}



%
%
% Captions
%
%

\DeclareCaptionFormat{source}{\textbf{\textit{source#2}} #3}

%---------------------------------------------
% \NewDocumentCommand \hcancel { O{black} O{1pt} } {
% 	\setbox0=\hbox{$#3$}%
% 	\rlap{\raisebox{.45\ht0}{\textcolor{#1}{\rule{\wd0}{#2}}}} {#3}
% }

% \NewDocumentCommand \solution { s O{solution} g } {
% 	\IfBooleanTF {#1}
%   {
% 		\setboolean{display}{true}
%   }
%     {}
%   \begin{#2}
%   \end{#2}
% }

%% \underdash[color]{text}
%\newcommand\underdash[1][black]{% <- règle la couleur du texte
%  \bgroup
%  \ifdim\ULdepth=\maxdimen\settodepth\ULdepth{(j}\advance\ULdepth.4pt\fi
%  \markoverwith{\kern0.2em% <- règle l'espacement avant un pointillé
%    \vtop{
%      \kern0.5ex% <- règle l'altitude des pointillés
%      {\color{black}% <- règle la couleur des pointillés
%       \hrule width.4em% <- règle la largeur des pointillés
%      }
%    }
%    \kern0.2em% <- règle l'espacement après un pointillé
%  }
%  \color{#1}\ULon
%}
%---------------------------------------------



%
%
% Fonts
%
%

\newfontfamily\Annie[Ligatures=TeX]{Annie Use Your Telescope}
\newfontfamily\Architects[Ligatures=TeX]{Architects Daughter}
\newfontfamily\Bristol[Ligatures=TeX]{Bristol}
\newfontfamily\ChelseaMarket[Ligatures=TeX]{Chelsea Market}
\newfontfamily\Comic[Ligatures=TeX]{Comic Sans MS}
\newfontfamily\Delius[Ligatures=TeX]{Delius}
\newfontfamily\DeliusSC[Ligatures=TeX]{Delius Swash Caps}
\newfontfamily\FingerPaint[Ligatures=TeX]{Finger Paint}
\newfontfamily\Handlee[Ligatures=TeX]{Handlee}
\newfontfamily\Julee[Ligatures=TeX]{Julee}
\newfontfamily\Morse[Ligatures=TeX]{Morse}
\newfontfamily\NixieOne[Ligatures=TeX]{Nixie One}
\newfontfamily\PenguinAttack[Ligatures=TeX]{PenguinAttack}
\newfontfamily\PokemonHollow[Ligatures=TeX]{Pokemon Hollow}
\newfontfamily\PokemonSolid[Ligatures=TeX]{Pokemon Solid}
\newfontfamily\ScratchedLetters[Ligatures=TeX]{Scratched Letters}
% \newfontfamily\TrebuchetMS[Ligatures=TeX]{Trebuchet MS}

%--------------------------------------------------------
% Intent for a more general command.
% \NewDocumentCommand \setFont { O{\familydefault} O{\encodingdefault} }{%
% 	\fontencoding{#2}%
% 	\fontfamily{#1}%
% 	\selectfont
% }
%--------------------------------------------------------



%
%
% Colors
%
%

% \newColorCommand{color}
% Create a macro which can be accessed with the name "\color".
% This macro make the following text to be colored in color.
\newcommand\newColorCommand[1]{%
\expandafter\newcommand\csname #1\endcsname{\color{#1}}}

% Create some color commands
\newColorCommand{red}
\newColorCommand{black}
\newColorCommand{white}
\newColorCommand{gray}
\newColorCommand{lapislazuli}



%
%
% Maths
%
%

\newcommand\OPoval[3]{%
	\dimen1=#2\opcolumnwidth
	\ovalnode{#1}
		{\kern\dimen1 #3\kern\dimen1}}



\makeatother
