\usepackage[top=100pt, bottom=75pt, left=75pt, right=75pt]{geometry}
\setlength{\headsep}{15pt}
\setlength{\footskip}{45pt}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% packages

\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{amsmath, amssymb, amsthm}
% \counterwithout{equation}{section}
\usepackage{euscript}  % Euler Script alphabet, designed by Hermann Zapf
\usepackage{enumitem}
\usepackage{systeme}
\usepackage{array}
\usepackage{fancyhdr}
\usepackage{ifthen}
\usepackage{tikz}  % includes xcolor package
\usetikzlibrary{math, calc, cd}
\usetikzlibrary{arrows.meta, matrix, intersections}


% comments:
% 
\usepackage{caption}
% % The caption package provides a width parameter than can be set for
% % each figure individually.
% % The width can be set with the option \captionsetup{width=<len>} globally.
\captionsetup{width=.926\textwidth}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% title and author

\def\beforetitle{1.25}
\renewcommand{\title}[1]{
  \vspace*{\beforetitle\baselineskip}  
  \begin{center}
    \LARGE\textbf{#1}
  \end{center}\ignorespaces
  \addvspace{1.5\baselineskip}}

\renewcommand{\author}[1]{
  \addvspace{-1\baselineskip}  
  \begin{center}
    \large\textsc{#1}
  \end{center}\ignorespaces
  \addvspace{2\baselineskip}}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% sections and subsections
\usepackage{titlesec}

\titlelabel{\thetitle.\hspace{0.8em}}
\titlespacing*{\section}{0pt}{*9}{*3}  % the unit is the ex
\titlespacing*{\subsection}{0pt}{*5}{*1.5}
\titlespacing*{\subsubsection}{0pt}{*3}{*1}
\titlespacing*{\paragraph}{0pt}{*1}{0pt}

\titleformat{\section}{%
  \normalfont\bfseries\Large}{\thesection.}{0.5em}{} %[{\color{B}\titlerule[0.8pt]}]
\titleformat{\subsection}{%
  \normalfont\bfseries\slshape\large}{\thesubsection.}{0.5em}{}
  %\normalfont\bfseries\large}{\thesubsection.}{0.5em}{}
\titleformat{\subsubsection}[runin]{%
  \vspace{-1ex}
  \normalfont\bfseries}{\thesubsubsection.}{.3em}{}[ -- ]
\titleformat{\paragraph}[runin]{%
  \normalfont\scshape}{}{}{}[.\phantom{a}]


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% page style global
\newcommand{\headcol}{K}
\def\footrulewidth{0pt}                           
\def\headrulewidth{0pt}  %{0.3pt}
\pagestyle{fancy}
\renewcommand{\sectionmark}[1]{%
  \markboth{\color{\headcol}\footnotesize{\thesection. #1}}{}
}
\lhead{}
\chead{}  
\rhead{\fancyplain{}{\leftmark}}
\lfoot{\fancyplain{}{}}
\cfoot{\fancyplain{}{\small\thepage}}
\rfoot{\fancyplain{}{}}
\setlength{\headheight}{14pt}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% environments
\newlength{\thmsep}
\setlength{\thmsep}{1\baselineskip}
%\setlength{\thmsep}{2ex}

% modify the space before and after theorems and such
\makeatletter
\def\thm@space@setup{%
  \thm@preskip=1.1\thmsep plus .5ex minus .2ex
  \thm@postskip=1.1\thmsep plus .5ex minus .1ex % \thm@preskip
}
\makeatother


%%% theorem like
\newtheorem{thm}{\theoname}[section]
\newtheorem{lem}[thm]{\lemmaname}
\newtheorem{pro}[thm]{\propositionname}
\newtheorem{cor}[thm]{\corollaryname}
\newtheorem*{thm*}{\theoname}
\newtheorem*{lem*}{\lemmaname}
\newtheorem*{pro*}{\propositionname}
\newtheorem*{cor*}{\corollaryname}

\newcommand{\thistheoremname}{}
\newtheorem{genericthm}[thm]{\thistheoremname}
\newenvironment{likethm}[1]{%
  \renewcommand{\thistheoremname}{#1}\begin{genericthm}%
  }{\end{genericthm}}

\newtheorem*{genericthm*}{\thistheoremname}
\newenvironment{likethm*}[1]{%
  \renewcommand{\thistheoremname}{#1}\begin{genericthm*}%
  }{\end{genericthm*}}

%%% definition like
\theoremstyle{definition}
\newtheorem{definition}[thm]{\definitionname}
\newtheorem{definitions}[thm]{\definitionsname}
\newtheorem{exa}[thm]{\examplename}
\newtheorem{examples}[thm]{\examplesname}
\newtheorem{rem}[thm]{\remarkname}
\newtheorem{remarks}[thm]{\remarksname}
\newtheorem*{definition*}{\definitionname}
\newtheorem*{definitions*}{\definitionsname}
\newtheorem*{exa*}{\examplename}
\newtheorem*{examples*}{\examplesname}
\newtheorem*{rem*}{\remarkname}
\newtheorem*{remarks*}{\remarksname}

%%% exercise (depneds on the presence of sections and subsections
\newcounter{cntNo}
\newcounter{cntSubno}
\newtheorem{exerciseAlone}{\exercisename}
\newtheorem{exerciseSection}{\exercisename}[section]
\newtheorem{exerciseInText}[thm]{\exercisename}
\newtheorem*{exerciseAst}{\exercisename}

\newcounter{labelForNo}
\newcommand{\labelForNo}[1]{\refstepcounter{labelForNo}\label{#1}}

\newenvironment{exe}{%\ignorespaces\vspace{-1\baselineskip}%
  \setcounter{cntNo}{0}\setcounter{labelForNo}{0}%
  \ifthenelse{\thesection=0}{\begin{exerciseAlone}}{\begin{exerciseSection}}%
  %\phantom{}
}{%
  \ifthenelse{\thesection=0}{\end{exerciseAlone}}{\end{exerciseSection}}
}

\newenvironment{Exe}{\setcounter{cntNo}{0}%
  \begin{exerciseInText}}{\end{exerciseInText}}
\newenvironment{exe*}{\setcounter{cntNo}{0}%
  \begin{exerciseAst}}{\end{exerciseAst}}



\newcommand{\solution}{\setcounter{cntNo}{0}%
  \par\removelastskip\vskip.5\baselineskip%   
  \noindent{\textbf{\textit{Solution.}}}\\
}

%%% needed in the exercises
% the optional argument in \no is used when vertical space is needed
% with respect to the precedeing paragraph
%
%
\newcommand{\no}[1][]{\stepcounter{cntNo}\setcounter{cntSubno}{0}%
  \ifmmode \tikz{%
    \path[R, use as bounding box] (0, 0) rectangle (2\parindent, 1ex);
    \node[scale=.7, anchor=east, inner sep=0.]
    at (2.7em, 0.55ex) {(\roman{cntNo})};
  }
  \else%
  \leavevmode\par%
  \ifthenelse{\equal{#1}{}}{\vspace{.13\baselineskip}}{\vspace{#1}}\noindent
  \tikz{%
    \path[use as bounding box] (0,0) rectangle (1.3\parindent, 2ex);
    \node[scale=.85, anchor=east, inner sep=0.]
    at (1.1\parindent, 0.5ex) {\thecntNo)};
  }%
  \labelForNo{labelNo:\thecntNo}
  \fi%
}
\newcommand{\noAst}{\stepcounter{cntNo}\setcounter{cntSubno}{0}%
  \leavevmode\par%
  \vspace{.13\baselineskip}\noindent
  \tikz{%
    \path[use as bounding box] (0,0) rectangle (1.3\parindent, 2ex);
    \node[scale=.85, anchor=east, inner sep=0.]
    at (1.1\parindent, 0.5ex) {\thecntNo$^\ast$)};
  }%
  \labelForNo{labelNo:\thecntNo}
}
\newcommand{\tno}{\stepcounter{cntNo}\setcounter{cntSubno}{0}%
  \tikz{%
    \path[use as bounding box] (0, 0) rectangle (1.8em, 1ex);
    \path (1em, 0.55ex) node[scale=.8, left, inner sep=0]
    {(\roman{cntNo})};
  }
}
\newcommand{\subno}[1][]{%
  \stepcounter{cntSubno}%
  \leavevmode\par%
  \vspace{.13\baselineskip}
  \ifthenelse{\equal{#1}{}}{}{\vspace{#1}}\noindent
  \tikz{%
    \path[R, use as bounding box] (0,0) rectangle (2\parindent, 2ex);
    \node[scale=.85, anchor=east, inner sep=0.]
    at (1.8\parindent, 0.5ex) {\alph{cntSubno})};
  }%
}

%%% like remark
\theoremstyle{remark}
\newtheorem*{notation}{\notationname}


%%% proof and end of proof
% They are granted by amsthm; the definition of qed is changed to
% deal with the problem of a proof ending with a displayed formula.
\renewcommand{\qed}{%
  {% set up
    \ifdim\lastskip<.5pt%  % previously, a display
    \par%  % to pass in the vertical mode
    %\vspace{-\belowdisplayskip}%  % pushing the halmos upward
    \vspace{-\belowdisplayshortskip}%  % pushing the halmos upward
    \vspace{-1ex}
    \widowpenalty=10000%  % so we dont break the page before \square
    \displaywidowpenalty=10000%  % ditto
    \else%
    \parfillskip=0pt%  % so \par doesnt push \square to left
    \widowpenalty=10000%  % so we dont break the page before \square
    \displaywidowpenalty=10000%  % ditto
    \finalhyphendemerits=0%  % TeXbook exercise 14.32
    % 
    % horizontal
    \leavevmode%  % \nobreak means lines not pages
    \unskip%  % remove previous space or glue
    \nobreak%  % don’t break lines
    \hfil%  % ragged right if we spill over
    \penalty20%  % discouragement to do so
    \hskip.75em%  % ensure some space
    \null%  % anchor following \hfill
    \fi%
    \hfill%  % push \square to right
    \raisebox{-.33pt}{$\square$}%  % the end-of-proof mark
    % \ifthenelse{\equal{#1}{}}{}{\vspace{#1}}%  % build paragraph after halmos
    \par%  % build paragraph
  }%
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% path to local style files
\def\pathToLaTeXMacros{.}
%%% fonts and other commands
\usepackage{\pathToLaTeXMacros/fontsAndSuch}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% hyperref
% the first use of \ref should not be \eqref since it leads to an
% error when compiling pdflatex
\usepackage[linktoc=all]{hyperref}
% \usepackage{hyperref}
\hypersetup{%
  colorlinks=true,
  citecolor=DarkR!70!RK,
  linkcolor=blue!55!BK,
  urlcolor=VB
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% column headers in table environments

\newcolumntype{L}[1]{>{\raggedright\arraybackslash}m{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}m{#1}}
\newcolumntype{N}{@{}m{0pt}@{}}
% Example: L{.25\linewidth}
% this last type is to be used as a last empty column if
% a vertical space control is needed after \\, i.e. \tabularnewline

%% Other commands:
% \renewcommand{\arraystretch}{1.35}
% % which controls the space between rows (default 1)
% \multicolumn{number_of_columns}{alignment}{content}
% \hline

%%% for coloring cells in table environments
% \usepackage{colortbl}
