% !TEX TS-program = XeLaTeX
% !TeX root = presentation.tex
%
% این فایل بر اساس پیشنهاد پرسش و پاسخ زیر برای رفع مشکل هایپررف در ۲۰۱۵ اصلاح شده است.
% http://qa.parsilatex.com/9325/
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% This is 'saahel.sty' the 'Saahel' Style for bidipresentation. v0.3
%% By: S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% This is based on `sidebarbidipres.sty',
%% by: AR Hashemi, <Nekoomehr@gmail.com>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{saahel}%
[2012/12/21 Saahel Style with sidebar for using with bidipresentation class]
\usepackage[RL]{flowfram}
\usepackage{eso-pic}
\usepackage{graphicx}
\usepackage{zref-lastpage,zref-user}
\geometry{paperwidth=225mm,paperheight=180mm,rmargin=40mm,top=10mm,bottom=10mm}

% to have access to the total number of sections
\usepackage{totcount}                       % http://ctan.org/pkg/totcount
\regtotcounter{section}

%% auxiliary lengths for the height of the frame and the width of each tab
\newlength\frameheight
\newlength\avgtabwidth

% remove TOC's title
\let\oldTOC\tableofcontents
\renewcommand{\tableofcontents}{\renewcommand{\contentsname}{}\oldTOC}


%% some definitions
%% redefinition of titlepage environment %\thispagestyle{empty}
\let\oldTitePage\titlepage
\renewenvironment{titlepage}{\begin{oldTitePage}\begin{rawslide}\setcounter{page}{0}}%
{\end{rawslide}\end{oldTitePage}}

% blocks
\tikzstyle{blockStyle} = [draw=themeColor!80, fill=themeColor!9, very thick,
    rectangle, rounded corners=3mm, inner sep=30pt, inner ysep=15pt]
\tikzstyle{blockTitleStyle} =[fill=themeColor!80, rectangle, rounded corners=2mm, text=white
, inner sep=10pt, inner ysep=7pt, left=10pt]

% \newcommand{\wblock}[3]{
%\begin{tikzpicture}\node [blockStyle]  (box) {\setRTL\begin{minipage}{#1}
%{\vspace{15pt}#3}
%  \end{minipage}};\node[blockTitleStyle] at (box.north east) {\hboxR{{\Large{#2}}}};
%\end{tikzpicture}
%}
% \newcommand{\block}[2]{
%\wblock{0.95\textwidth}{#1}{#2}
%}

\newenvironment{wblock}[2]{%
  \def\blockTitle{\hboxR{{\Large{#2}}}}%
  \begin{tikzpicture}
    \node [blockStyle] (box)
    \bgroup\setRTL\minipage{#1}\vspace{15pt}%
}{%
    \endminipage%
    \egroup;
    \node[blockTitleStyle] at (box.north east) {\blockTitle};
  \end{tikzpicture}%
}
\newenvironment{block}[1]{%
  \begin{wblock}{160mm}{#1}%
}{
  \end{wblock}%
}

\newenvironment{wpblock}[1]{%
  \begin{tikzpicture}
    \node [blockStyle] (box)
    \bgroup\setRTL\minipage{#1}\vspace{15pt}\centering%
}{%
    \endminipage%
    \egroup;
  \end{tikzpicture}%
}
\newenvironment{pblock}{%
  \begin{wblock}{160mm}{}%
}{
  \end{wblock}%
}


\tikzstyle{alertblock} = [draw=red!80, fill=red!12, very thick,
    rectangle, rounded corners=3mm, inner sep=10pt, inner ysep=20pt]
\tikzstyle{alertTitle} =[fill=red!80, rectangle, rounded corners=2mm, text=white
, inner sep=10pt, inner ysep=7pt, left=10pt]
% \newcommand{\alertblock}[2]{
%\begin{tikzpicture}\node [alertblock] (box){\setRTL\begin{minipage}{0.95\textwidth}
%{#2}
%  \end{minipage}};\node[alertTitle, left=10pt] at (box.north east) {\hboxR{{\Large{#1}}}};
%\end{tikzpicture} 
%}
\newenvironment{alertblock}[1]{%
  \def\blockTitle{\hboxR{{\Large{#1}}}}%
  \begin{tikzpicture}
    \node [alertblock] (box)
    \bgroup\setRTL\minipage{0.95\textwidth}\vspace{10pt}%
}{
    \endminipage%
    \egroup;
    \node[alertTitle] at (box.north east) {\blockTitle};
  \end{tikzpicture}%
}
%%%%%%%%%%%%%%%%%%
% Some tweaks about section's title
% re-new section command %% I like bigger title
\makeatletter
\renewcommand\section{\@startsection {section}{1}{\z@}%
    {-1ex \@plus -1ex \@minus -.2ex}%
    {1ex \@plus.2ex}%
    {\titr\scalebox{2}}}%
\makeatother
%
\tikzstyle{titleStyle} = [draw=lightgray!15, fill=lightgray!40, very thick,
    rectangle, rounded corners=10mm, inner sep=10pt, inner ysep=20pt]
 \newcommand{\titlePage}[1]{
\begin{tikzpicture}\node [titleStyle] (box) {\setRTL\begin{minipage}{0.65\textwidth}
{\vspace{0.15\paperheight}%
\begin{center}#1\end{center}%
\vspace{0.15\paperheight}}%
  \end{minipage}};\end{tikzpicture}
}

% section start's slide  
\makeatletter
\newcommand{\SecSlide}{\@dblarg\@SecSlide}
\def\@SecSlide[#1]#2{
\begin{plainslide}%
	\begin{center}%
	\markright{#1}
	\titlePage{\section[#1]{#2}\label{sec:\thesection}}%
	\end{center}%
\end{plainslide}%
}
\makeatother
%

%%رنگ ها
\def\setThemeColor#1#2{\definecolor{themeColor}{#1}{#2}
\linktc{#1}{#2}
\lbotbarc{#1}{#2}
}

\usepackage{etoolbox}

\newcommand{\selectThemeColor}[1]{%
\ifstrequal{#1}{blue}{\setThemeColor{RGB}{45, 47, 146}}%
{%
\ifstrequal{#1}{NavyBlue}{\setThemeColor{RGB}{0, 110, 184}}%
{%
\ifstrequal{#1}{golden}{\setThemeColor{RGB}{255, 223, 66}}%
{%
\ifstrequal{#1}{red}{\setThemeColor{RGB}{237, 27, 35}}%
{%
\ifstrequal{#1}{green}{\setThemeColor{RGB}{0, 166, 79}}%
{%
\ifstrequal{#1}{LimeGreen}{\setThemeColor{RGB}{141, 199, 62}}%
{%
\ifstrequal{#1}{purple}{\setThemeColor{RGB}{153, 71, 155}}%
{%
\ifstrequal{#1}{sepia}{\setThemeColor{RGB}{103, 24, 0}}%
{%
\ifstrequal{#1}{cyan}{\setThemeColor{RGB}{0, 174, 239}}%
{%
\ifstrequal{#1}{orange}{\setThemeColor{RGB}{245, 129, 55}}%
{%
\ifstrequal{#1}{gray}{\setThemeColor{RGB}{148,150,152}}%
{%
\ifstrequal{#1}{JungleGreen}{\setThemeColor{RGB}{0,169,154}}%
{%
\ifstrequal{#1}{Bittersweet}{\setThemeColor{RGB}{192, 79, 23}}%
{%
\ifstrequal{#1}{brown}{\setThemeColor{RGB}{121, 37,0}}%
{}%%default %\setThemeColor{RGB}{0,0,1}
}}}}}}}}}}}}}
}

%
%\def\greenText{green}
%\def\blueText{blue}
%\def\redText{red}
%\newcommand{\selectThemeColor}[1]{%
%  \begingroup
%    \def\tmp{#1}%
%    \ifthenelse{\equal{\tmp}{\redText}}{\setThemeColor{rgb}{0,0.8,0}}{\setThemeColor{rgb}{0.7,0,0}}
%%%    \ifx\tmp\infotext%
%%%      ---%
%%%    \else
%%    \ifx\tmp\greenText%
%%        \setThemeColor{rgb}{0,0.8,0}%
%%      \else\ifx\tmp\redText%
%%        \setThemeColor{rgb}{0.7,0,0}%
%%    \else%
%%        \setThemeColor{rgb}{1,0,0}%
%%    \fi\fi
%  \endgroup}
\def\linktc#1#2{\definecolor{link-text}{#1}{#2}}
\def\sidebartc#1#2{\definecolor{sidebar-text}{#1}{#2}}
\def\rtopbarc#1#2{\definecolor{topbar1-color}{#1}{#2}}
\def\ltopbarc#1#2{\definecolor{topbar2-color}{#1}{#2}}
\def\ltopbartc#1#2{\definecolor{topbar2-text}{#1}{#2}}
\def\rbotbarc#1#2{\definecolor{botbar1-color}{#1}{#2}}
\def\lbotbarc#1#2{\definecolor{botbar2-color}{#1}{#2}}
\def\lbotbartc#1#2{\definecolor{botbar2-text}{#1}{#2}}
% default colors
\selectThemeColor{NavyBlue}
%\setThemeColor{RGB}{50,50,200}
\sidebartc{cmyk}{0,0,0,1}
\linktc{rgb}{0,0,1}
\rtopbarc{cmyk}{0.94,0.54,0,0}
\ltopbarc{cmyk}{0.15,0.15,0,0}
\ltopbartc{cmyk}{0,0,0,1}
\rbotbarc{cmyk}{0.15,0.15,0,0}
%\lbotbarc{cmyk}{0.94,0.54,0,0}
\lbotbarc{rgb}{0,0,1}
\lbotbartc{cmyk}{0,0,0,0}

% http://qa.parsilatex.com/9325/
\usepackage{hyperref}%
\hypersetup{urlcolor=link-text,colorlinks=true,linkcolor=link-text,setpagesize=false,pdfpagemode=FullScreen,
    pdftitle={\theTitle},
    pdfauthor={\theAuthor, \theAuthorUrl},
}

%\usepackage[urlcolor=link-text,colorlinks=true,linkcolor=link-text,setpagesize=false,pdfpagemode=FullScreen]{hyperref}%
%\hypersetup{
%    pdftitle={\theTitle},
%    pdfauthor={\theAuthor, \theAuthorUrl},
%}
%\makeatletter
%\renewcommand{\rotateframe}[2]{\if@ttb@rotate
%\rotatebox{#1}{\if@RTL\beginL\fi#2\if@RTL\endL\fi}%
%\else
%#2\relax
%\fi}
%\makeatother

\renewcommand{\sectionmark}[1]{\markright{#1}{}} %%استخراج عنوان خالص سكشن

%%نوار بالا
%\vtwotonetop{1cm}{0.6\paperwidth}{[cmyk]{0.65,0.13,0,0}}{topleft}%
%{0.4\paperwidth}{[cmyk]{0.94,0.54,0,0}}{topright}
\newdynamicframe[1,>1]{65mm}{1.1cm}{123mm}{160mm}[topbar1]
\setdynamicframe*{topbar1}{valign=c,backcolor=botbar2-color,textcolor=botbar2-text}%topbar1-color}
\newdynamicframe[1,>1]{128mm}{8mm}{-5mm}{162mm}[topbar2]
\setdynamicframe*{topbar2}{valign=c,textcolor=topbar2-text,backcolor=topbar2-color}
%\newstaticframe[2,>1]{66mm}{1.3cm}{123mm}{159mm}[topbar1]
%\setstaticframe*{topbar1}{backcolor=topbar1-color}
%\newdynamicframe[2,>1]{128mm}{1.3cm}{-5mm}{159mm}[topbar2]
%\setdynamicframe*{topbar2}{valign=c,textcolor=topbar2-text,backcolor=topbar2-color}
%%محتویات نواربالا


%%نوار پایین
%\newstaticframe[2,>1]{99mm}{9mm}{90mm}{-10mm}[botbar1]
%\setstaticframe*{botbar1}{backcolor=botbar1-color}
%\newdynamicframe[2,>1]{95mm}{9mm}{-5mm}{-10mm}[botbar2]
%\setdynamicframe*{botbar2}{valign=c,textcolor=botbar2-text,backcolor=botbar2-color}
\newdynamicframe[1,>1]{183mm}{8mm}{5mm}{-10mm}[botbar1]
\setdynamicframe*{botbar1}{valign=c,backcolor=botbar1-color}
\newdynamicframe[1,>1]{17.8mm}{1.1cm}{-5mm}{-10mm}[botbar2]
\setdynamicframe*{botbar2}{valign=c,textcolor=botbar2-text,backcolor=botbar2-color}
%%محتویات نوارپایین
%


%%عكس زمینه سایدبار
%\AddToShipoutPicture{%
%%\hspace{-60mm}
%%\put(33,512){
%\put(-137,512){
%\reflectbox{
%\includegraphics[keepaspectratio=false,height=-\paperheight ,width=31mm]{side.jpg}
%}}}
%%خودسایدبار
%\newstaticframe[2,>2]{30mm}{\paperheight}{190mm}{-10mm}[sidebar]
%\setstaticframe*{sidebar}{valign=b}%{backcolor=[cmyk]{0.15,0.15,0,0}}
\newdynamicframe[1,>1]{35mm}{\paperheight}{187mm}{-10mm}[sidebar]
\setdynamicframe*{sidebar}{valign=t}%{backcolor=[cmyk]{0.15,0.15,0,0}}
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%محتویات سایدبار
\begin{dynamiccontents*}{sidebar}
\linespread{1}
\AddToShipoutPicture{%
%\tikz[remember picture, overlay]\shade[top color=themeColor!15, bottom color=themeColor!80] (current page.north east) rectangle +(-3.2,-18);
\put(-128,0){%
\begin{tikzpicture}
\fill [themeColor!80] (current page.north east) rectangle +(-3.2,-18);
\end{tikzpicture}
}
}
\vspace{.3cm}
\begin{center}
{\includegraphics[width=2cm]{\Logo}}
\end{center}
\vspace{.5cm}
% style for the section tabs
\tikzset{tab/.style={
    text width=35mm,anchor=south,
    draw=gray,thick,rectangle,rounded corners=12pt,%rotate=270,
    align=center,text height=20pt,
    text depth=25pt,inner sep=0pt,fill=gray!20,% yshift=-18pt,
    font=\sffamily\LARGE}}
% style for the current section tab
\tikzset{selectedtab/.style={tab,color=white,fill=gray!90}}
    % calculation of the width for each tab
    \setlength\frameheight{\dimexpr\textheight+2cm\relax}
    \ifnum\totvalue{section}>0
        \setlength\avgtabwidth{30mm}%\dimexpr\frameheight/\totvalue{section}\relax}
    \fi
                    \tikzstyle{sec} = [draw=white, fill=white, very thick,
                     rounded rectangle, rounded rectangle west arc=none,  inner xsep=-5pt, inner ysep=10pt]
\begin{small}
\ifnum\the\numexpr\totvalue{section}>0
            \foreach \valsection in {0,...,\numexpr\totvalue{section}-1\relax} {
               \ifnum\thesection<\numexpr\valsection+1 
\begin{center}
\nameref{sec:\the\numexpr\valsection+1\relax}
\end{center}
               \relax
                        \else \ifnum\thesection>\numexpr\valsection+1
\begin{center}
\nameref{sec:\the\numexpr\valsection+1\relax}
\end{center}
                         \relax
                        \else
    
\begin{tikzpicture}
 \node [sec] {\setRTL
             	       \begin{minipage}{30mm}{
            		        \begin{center}
\nameref{sec:\the\numexpr\valsection+1\relax}
\end{center}}
\end{minipage}};
\end{tikzpicture}

                        \fi\fi
            }
\fi % end of if the total sections > 0
\end{small}
\end{dynamiccontents*}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\setTextTR#1{
\begin{dynamiccontents*}{topbar1}\linespread{1}
#1
\end{dynamiccontents*}
}
%
\setTextTR{{\footnotesize \centerline{\bfseries{\rightmark}}}}
%%%
\def\setTextTL#1{
\begin{dynamiccontents*}{topbar2}\linespread{1}
	\begin{center}
		\begin{footnotesize}
			#1
		 \end{footnotesize}
	\end{center}	
\end{dynamiccontents*}
}
\def\setTextBR#1{
\begin{dynamiccontents*}{botbar1}\linespread{1}
{\color{sidebar-text}
		\begin{footnotesize}
\hspace{5mm}#1%\hspace{3mm}
%		\rm\makeatletter\@author\makeatother
		\end{footnotesize}
	}
\end{dynamiccontents*}
}
\def\setTextBL#1{
\begin{dynamiccontents*}{botbar2}\linespread{1}
	%\begin{flushleft}
	%	\footnotesize{
\begin{center}
#1
\end{center}	
%	}
	%\end{flushleft}
\end{dynamiccontents*}
}
%
\setTextBL{\bfseries{\thepage}
از
\zpageref{LastPage}%
}

%%
%% End of file `saahel.sty'.