%!TeX root=simple.tex
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% License:
% CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%----------------------------------------------------------------------------------------
%	PAGE LAYOUT
%----------------------------------------------------------------------------------------

\RequirePackage[
paper=a4paper	,  
inner=15mm,
outer=15mm, 
top=20.0mm,
bottom=25.0mm,
%	headsep=1.0\baselineskip, 
%   headheight=1.0\baselineskip ,
%	textheight=49\baselineskip, 
]{geometry} 
\savegeometry{widelayout}
\AtBeginDocument{\loadgeometry{widelayout}}
 
%----------------------------------------------------------------------------------------
%	USEFUL PACKAGES AND COMMANDS
%----------------------------------------------------------------------------------------

% \RequirePackage[l2tabu,orthodox]{nag} % turn on warnings because of bad style
\usepackage{etoolbox} % Easy programming to modify TeX stuff
\usepackage{calc} % Make calculations, used for spacing the index letter headings correctly
\usepackage{xifthen,ifxetex,ifluatex} % Easy conditionals
\usepackage{xkeyval} % Manage class options
\usepackage{xparse} % Parse arguments for macros
\usepackage{xpatch} % Patch LaTeX code in external packages
\usepackage{xstring} % Parse strings
\usepackage{afterpage} % Run commands after specific pages
\usepackage{ccicons}                % Creative Commons icons
\usepackage{kantlipsum} 			% random text  
\usepackage{blindtext}		% Load packages for testing
%\usepackage{showlabels}             % Show labels

%----------------------------------------------------------------------------------------
% Hyphenation
%----------------------------------------------------------------------------------------

\usepackage[shorthands=off,english, main=french]{babel}  % English language/hyphenation
\frenchbsetup{AutoSpacePunctuation=false}  

%----------------------------------------------------------------------------------------
%	PARAGRAPH FORMATTING
%----------------------------------------------------------------------------------------

%\usepackage{ragged2e} % Required to achieve better ragged paragraphs
\usepackage{setspace} % Required to easily set the space between lines
%\usepackage{hyphenat} % Hyphenation for special fonts
%\usepackage{microtype} % Improves character and word spacing
%\usepackage{needspace} % Required to prevent page break right after a sectioning command
%\usepackage{xspace} % Better print trailing whitespace
\usepackage{xcolor} % Colours [usenames,svgnames,table]


\definecolor{blueperso}{HTML}{06386e}
%\definecolor{blueperso}{RGB}{2,22,43}
\def\basecolor{blueperso} 

%----------------------------------------------------------------------------------------
% Setspace options
%----------------------------------------------------------------------------------------

% \doublespacing 			%set the leading document-wide
% \singlespacing \onehalfspacing \doublespacing 
% \setstretch{ value of baselinestretch}
% for changing line specific in section:
% \begin{spacing}{value} ... \end{spacing}
\tolerance 1414
\hbadness 1414
\emergencystretch 1.5em
\hfuzz 0.3pt
\widowpenalty=10000
\vfuzz \hfuzz
\raggedbottom   

\AfterTOCHead{\singlespacing}

%----------------------------------------------------------------------------------------
% MATHS
%----------------------------------------------------------------------------------------

\usepackage{amsmath} % For math equations, theorems, symbols, etc
\usepackage{amsbsy}   
\usepackage{amssymb }  
\usepackage{mathrsfs}
\usepackage{amsfonts} 
\usepackage{mathtools}   % More math symbols and environments
\everymath{\displaystyle}	

\usepackage{siunitx}
\usepackage[autolanguage]{numprint} % écrituredes virgules  
\sisetup{%
	output-decimal-marker = {,},
	per-mode=symbol,
	scientific-notation=engineering,
	zero-decimal-to-integer,
	round-mode=places,
	%exponent-product = \cdot,
	%inter-unit-product = \ensuremath{{}\cdot{}}
}
%\DeclareSIPostPower\tothefourth{4}
\usepackage{eurosym} 
\usepackage{physics}	% better commands
\usepackage{esvect}		% better vector symbols
\usepackage{interval}
	\intervalconfig{scaled  , separator symbol={;}}

\usepackage{witharrows}
\usepackage{venndiagram}

\usepackage{scratch3}
	\setdefaultscratch{
		%		print
		%		, fill blocks
		%		, fill gray=0.95
		%, text color=white
		%, flag gray=0.66
	}
 

%----------------------------------------------------------------------------------------
%	FONTS  
%----------------------------------------------------------------------------------------


\usepackage{lmodern}   
% issue with mathspec amsmath and glossaries  https://tex.stackexchange.com/questions/85696/what-causes-this-strange-interaction-between-glossaries-and-amsmath
%\usepackage{unicode-math} %\usepackage{mathspec} for xetex, use \usepackage{unicode-math} for luatex and pdflatex
%\makeatletter % undo the wrong changes made by mathspec
%\let\RequirePackage\original@RequirePackage
%\let\usepackage\RequirePackage
%\makeatother 
\usepackage[T1]{fontenc} % Use 8-bit encoding that has 256 glyphs  
%\usepackage{textcomp}
\usepackage{fontawesome5}
\usepackage{fontawesome}
\usepackage{pifont}	 
\everymath{\displaystyle}	 


%----------------------------------------------------------------------------------------
%	TikZ , Tkz
%----------------------------------------------------------------------------------------

\usepackage{tikz,tikz-dependency} % Required for drawing custom shapes 
%	\expandafter\def\csname ver@etex.sty\endcsname{3000/12/31}
% Uncomment the line starting with 
% if you also want to get rid of the warning about etex.
\usepackage{pgfplots}
\usepgfplotslibrary{statistics, ternary}
\pgfplotsset{compat=newest}

\usetikzlibrary{ shapes %shapes to be placed as part of a flowchart
	, arrows
	, quotes
	, angles
	, cd	% drawing commutative diagrams. 
	, patterns
	, decorations
	, decorations.markings % for arrows 	
	, decorations.shapes 
	, decorations.pathmorphing 
	, calc
	, math
	, intersections 
	, arrows.meta
	, chains
	, positioning
	,petri 
	,shadows
	,matrix
	,automata
	,backgrounds
	%	,fi
}
\makeatletter
\tikzset{reset join/.code={\def\tikz@after@path{}}}
\makeatother			
\usepackage{tkz-fct}	
\usepackage{tkz-base
	, tkz-euclide 
	, tkz-tab	 
}



%----------------------------------------------------------------------------------------
%	FIGURES, TABLES AND CAPTIONS
%----------------------------------------------------------------------------------------
\RequirePackage[
font={footnotesize,sf}, % Set figure legends and captions to be smaller sized sans serif font 
hypcap=true 	% Correctly placed anchors for hyperlinks
]{caption} 		% beter compatibility with hyperref than subfig (subfig > subfigure)


\usepackage{graphicx,grffile} % Include figures
\DeclareGraphicsExtensions{.pdf,.png,.jpg,.jpeg,.mps, .tif}
\graphicspath{{images/}} % Specifies the directory where pictures are stored
\setkeys{Gin}{width=\linewidth,totalheight=\textheight,keepaspectratio} % Improves figure scaling


\usepackage{multirow} % Cells occupying multiple rows in tables
\usepackage{multicol} % Multiple columns in dictionary
\usepackage{booktabs} % Required for nicer horizontal rules in tables
\usepackage{longtable} % Nicer tables
%\usepackage{floatrow} % Set up captions of floats
%\usepackage{float} 
%\floatplacement{figure}{H} % set default placement for figures to H
\usepackage{array}  
\usepackage{tabularx}
	\newcolumntype{?}{!{\vrule width 2pt}}
	\renewcommand{\tabularxcolumn}[1]{p{#1}}
	\renewcommand{\tabularxcolumn}[1]{m{#1}}
\usepackage{makecell}
	\setlength\columnseprule{.4pt} 


\usepackage{xlop}
\opset{decimalsepsymbol={,},
	divsymbol={$\divisionsymbol$}
}

%----------------------------------------------------------------------------------------
%	Packages
%----------------------------------------------------------------------------------------

% Productivity
\RequirePackage{pdfpages} % Insert PDF pages
\RequirePackage{subfiles} % Adopt a modular structure

% Special gliphs 
\usepackage{metalogo} % XeTeX logo
\usepackage{ccicons}                % Creative Commons icons 


\usepackage[normalem]{ulem} % various ways to underline

\usepackage{enumitem} % Customize lists
	\setlist{nolistsep} % Reduce spacing between bullet points and numbered lists 

\usepackage{xfp}
\FPseed=12345
\ExplSyntaxOn
\sys_gset_rand_seed:n {12345}
\ExplSyntaxOff
%----------------------------------------------------------------------------------------
%	LISTINGS
%----------------------------------------------------------------------------------------

% Listings code
\usepackage{listings} % Code 
%\usepackage{morewrites}

\captionsetup[lstlisting]{
	labelfont={bf},
	textfont=sf,
	labelsep=endash, % none, colon, period, space, newline, endash
	format=plain, % hang, plain,  
	justification=justified, %  
	singlelinecheck=no,
	%	belowskip=-0.3cm ,
	indention=0pt, % Suppress indentation
	parindent=0pt, % Suppress space between paragraphs
	aboveskip=6pt, % Increase the space between the figure and the caption
	belowskip=6pt, % Increase the space between the caption and the table
}

\renewcommand{\lstlistingname}{Script}
%\renewcommand{\lstlistingnamestyle}{\bfseries}

\lstdefinestyle{python-code}{ 
	language=python,
	aboveskip=0.7\topskip,
	belowskip=0.1\topskip,
	basicstyle=\small\ttfamily,
	commentstyle=\color{Teal}\itshape,
	keywordstyle=\color{OliveGreen}\bfseries,
	numberstyle=\scriptsize\color{Black}\ttfamily,
	stringstyle=\color{Red},
	identifierstyle=\color{Blue},
	backgroundcolor=\color{AntiqueWhite},
	breakatwhitespace=false,
	breaklines=true,
	captionpos=t,
	keepspaces=true,
	showspaces=false,
	showstringspaces=false,
	showtabs=false,
	numbers=left,
	numbersep=1em,
	%frame=lines,
	frame=l,
	framerule=.7pt,
	tabsize=4,  
	mathescape = true,
	inputpath=questionnaires/scripts,
}

\lstdefinestyle{plain}{
	language=bash,                   % the language
	aboveskip=0.6\topskip,
	belowskip=-0.1\topskip,
	backgroundcolor=\color{WhiteSmoke}, 
	keywordstyle=\color{Purple}\bfseries,       % core keywords
	keywordstyle={[2]\color{Purple}\bfseries}, % built-ins
	stringstyle=\color{Teal},
	commentstyle=\color{Red}\itshape,
	numberstyle=\scriptsize\color{Black}\ttfamily, 
	identifierstyle=\color{Maroon}, 
	breakatwhitespace=false,
	breaklines=true,
	captionpos=b,
	keepspaces=true,
	showspaces=false,
	showstringspaces=false,
	showtabs=false,
	numbers=none,
	frame=none,
	tabsize=2,
	defaultdialect=[LaTeX]Tex,
}
\lstset{style=python-code}
 
%----------------------------------------------------------------------------------------
%	Pythontex
%----------------------------------------------------------------------------------------


%\usepackage{minted} 		% doit être charge après  auto multiple choice 
\usepackage[]{pythontex} 
%\setpythontexlistingenv{pylisting} 
%%\newenvironment{code}{\captionsetup{type=pylisting}}{}
%\SetupFloatingEnvironment{pylisting}{name=Code}


\begin{pycode}
import numpy
import math
import string
import random 
random.seed(12345)
numpy.random.seed(12345)

lower_upper_alphabet = string.ascii_letters
lower_alphabet = string.ascii_lowercase
upper_alphabet = string.ascii_uppercase

from re import sub
import sympy as sp
from sympy.core.sympify import kernS

x, y, z, t = sp.symbols('x y z t', real=True)
k, m, n = sp.symbols('k m n', integer=True)
f, g, h = sp.symbols('f g h', cls=sp.Function)	
\end{pycode}

% https://tex.stackexchange.com/questions/396862/how-can-i-pass-a-pythontex-variable-to-latex
\def\pyvar#1{\csname pythonvar@#1\endcsname} 
\begin{pycode}
from numbers import Number
def exposeNumericGlobals():
	res = r'\makeatletter '
		
	d = globals()
	for key in d.keys():
		val = d[key]
		if isinstance(val, Number):
			res = res + (r'\gdef\pythonvar@%s{%s} ' % (key, val))
	
	res = res + r'\makeatother'
	return res
\end{pycode}
%\AtBeginDocument{\py{exposeNumericGlobals()}} 
%----------------------------------------------------------------------------------------
%
%----------------------------------------------------------------------------------------
% Special KOMA-Script package - I added it because I also use the float package in this template, see: 
% http://tex.stackexchange.com/questions/51867/koma-warning-about-toc
% CTAN: http://www.ctan.org/tex-archive/macros/latex/contrib/koma-script/doc
\usepackage{scrhack}

%----------------------------------------------------------------------------------------
%
%----------------------------------------------------------------------------------------

 