% Copyright 2007 Nathanaël COTTIN <www.ncottin.net>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 3.

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{polyout}[2009/03/21 version 0.12.8]

\RequirePackage[latin1]{inputenc}
\RequirePackage{ifthen}
\RequirePackage{fancyhdr}
\RequirePackage{ifpdf}
\RequirePackage{amsmath}
\RequirePackage{gnulicenses}
\RequirePackage{graphicx}

\provideboolean{@french}
\provideboolean{@sectoc}
\provideboolean{@pagenum}
\provideboolean{@tocpagesref}
\provideboolean{@scientific}
\provideboolean{@twoside}
\provideboolean{@twocolumnmode}
\provideboolean{@nonavigation}
\provideboolean{@restartsection}
\provideboolean{@fullscreen}
\@restartsectiontrue

\def\@extraoptions{}	% Beamer and article options

\def\outmode{presentation}	% Default mode

%\if@compatibility\else\fi
\DeclareOption{french}{\@frenchtrue}
\DeclareOption{article}{\def\outmode{article}}
\DeclareOption{printable}{\def\outmode{printable}}
\DeclareOption{sectiontoc}{\@sectoctrue}
\DeclareOption{pnum}{\@pagenumtrue}
\DeclareOption{compress}{\def\@extraoptions{, compress}}
\DeclareOption{tocpageref}{\@tocpagesreftrue}
\DeclareOption{twoside}{\@twosidetrue}
\DeclareOption{twocolumn}{\@twocolumnmodetrue}
\DeclareOption{nonavbar}{\@nonavigationtrue}
\DeclareOption{scientific}{\@scientifictrue}
\DeclareOption{nosecrestart}{\@restartsectionfalse}
\DeclareOption{fullscreen}{\@fullscreentrue}
\ProcessOptions\relax

\def\@theparttocdepth{1}
\def\parttocdepth#1{\def\@theparttocdepth{#1}}

\def\@thesectiontocdepth{2}
\def\sectiontocdepth#1{\def\@thesectiontocdepth{#1}}

\def\@polyoutsubtitle{}
\newcommand{\stitle}[1]{
	\def\@polyoutsubtitle{#1}}

\def\@polyoutversion{}
\newcommand{\version}[1]
	{\def\@polyoutversion{#1}}

\def\@polyoutcontact{}
\newcommand{\contact}[1]{
	\def\@polyoutcontact{#1}}

\def\@polyoutwebsite{}
\newcommand{\website}[1]{
	\def\@polyoutwebsite{#1}}

% This command should not be named 'logo'...
\def\@polyoutlogo{}
\newcommand{\titlelogo}[1]
	{\def\@polyoutlogo{#1}}

\def\@polyoutpagelogo{}
\newcommand{\pagelogo}[1]
	{\def\@polyoutpagelogo{#1}}

\def\@polyoutkeywords{} % Empty by default
\newcommand{\keywords}[1]{
	\def\@polyoutkeywords{#1}}

\def\@fancypagestyle{fancy}
\newcommand{\articlepagestyle}[1]{
	\def\@fancypagestyle{#1}}

\newlength{\@presentationlogoheight}
\setlength{\@presentationlogoheight}{1.7cm}
\newcommand{\presentationlogoheight}[1]
	{\ifthenelse
		{\equal{#1}{}}
		{}
		{\setlength{\@presentationlogoheight}{#1}}}

\newlength{\@articlelogoheight}
\setlength{\@articlelogoheight}{4cm}
\newcommand{\articlelogoheight}[1]
	{\ifthenelse
		{\equal{#1}{}}
		{}
		{\setlength{\@articlelogoheight}{#1}}}

\newlength{\@pagelogoheight}
\setlength{\@pagelogoheight}{7pt}
\newcommand{\pagelogoheight}[1]
	{\ifthenelse
		{\equal{#1}{}}
		{}
		{\setlength{\@pagelogoheight}{#1}}}

\newlength\@abstractspacer
\setlength\@abstractspacer{1pt}
\newcommand{\abstractspacer}[1]
	{\ifthenelse
		{\equal{#1}{}}
		{}
		{\setlength{\@abstractspacer}{#1}}}

\newcommand{\formatpar}[2]
	{\ifthenelse
		{\equal{#1}{}}
		{}
		{\setlength{\parskip}{#1}}
	\ifthenelse
		{\equal{#2}{}}
		{}
		{\setlength{\parindent}{#2}}}

\newcommand{\interline}[1]
	{\ifthenelse
		{\equal{#1}{}}
		{}
		{\renewcommand{\baselinestretch}{#1}}}

\newcommand{\presprintvfill}
	{\presprintonly{\vfill}}

\newcommand{\printpresvfill}
	{\presprintvfill}

\newcommand{\subtitlenewline}
	{\vskip1pt}

\newcommand{\setsize}
	{\if@french
		\RequirePackage{french}
		\changepapersize
	\else
		\if@twoside
			% Swap odd and even margins (to correct LaTeX reversed pagination!!!)
			\let\oddmarginOLD\oddsidemargin
			\let\oddsidemargin\evensidemargin
			\let\evensidemargin\oddmarginOLD
		\fi
	\fi}

\newcommand{\presonly}[1]
	{\ifthenelse
		{\equal{\outmode}{presentation}}
		{#1}
		{}}

\newcommand{\printonly}[1]
	{\ifthenelse
		{\equal{\outmode}{printable}}
		{#1}
		{}}

\newcommand{\articleonly}[1]
	{\ifthenelse
		{\equal{\outmode}{article}}
		{#1}
		{}}

\newcommand{\presprintonly}[1]
	{\presonly{#1}\printonly{#1}}

\newcommand{\presarticleonly}[1]
	{\presonly{#1}\articleonly{#1}}

\newcommand{\printarticleonly}[1]
	{\printonly{#1}\articleonly{#1}}

% Complementary commands to switch names
\newcommand{\printpresonly}[1]
	{\presprintonly{#1}}

\newcommand{\articlepresonly}[1]
	{\presarticleonly{#1}}

\newcommand{\articleprintonly}[1]
	{\printarticleonly{#1}}

% Caption displayed for article mode only
\newcommand{\acaption}[1]
	{\articleonly{\caption{#1}}}

\newcommand{\pcaption}[1]
	{\presprintonly{\caption{#1}}}

\newcommand{\includepolygraphics}[3][]
	{\articleonly{
		\ifthenelse
			{\equal{#1}{}}
			{\includegraphics[#2]{#3}}
			{\includegraphics[#1]{#3}}
		}
	\presprintonly{\includegraphics[#2]{#3}}}

\articleonly{
	\def\@pagination{oneside}
	\if@twoside
		\def\@pagination{twoside}
	\fi
	\def\@columns{onecolumn}
	\if@twocolumnmode
		\def\@columns{twocolumn}
	\fi
	\LoadClass[\@pagination, \@columns]{article}
	\RequirePackage{beamer article}
	\setsize
	\ifpdf
		\def\@ltp{}
		\if@tocpagesref
			\def\@ltp{, linktocpage}
		\fi
		\RequirePackage[plainpages=false, pdfpagelabels, pdfborder={0 0 0}\@ltp]{hyperref} % colorlinks=true, urlcolor=black, linkcolor=black
		\pdfcompresslevel=9
	\else
		\RequirePackage{hyperref}
	\fi
	
	\formatpar{5pt}{0pt}
	
	\if@restartsection
		\numberwithin{section}{part}
		\renewcommand{\thesection}
			{\arabic{section}}
	\fi}
		
%	\newcommand{\MakeEndOnEven}
%		{\ifthenelse
%			{\isodd{\thepage}}
%			{\newpage\thispagestyle{empty}~}
%			{}}
%	
%	\AtEndDocument{\MakeEndOnEven}}

\presonly{
	\LoadClass[ignorenonframetext\@extraoptions]{beamer}
	\RequirePackage{hyperref}
	\if@fullscreen
		\hypersetup{pdfpagemode=FullScreen}
	\fi
	\setbeamercovered{transparent}}

\printonly{
	\LoadClass[ignorenonframetext, trans\@extraoptions]{beamer}
	\RequirePackage{hyperref}}

\if@scientific
	\RequirePackage{helvet}
	\RequirePackage{courier}
\fi

\def\@polyouttitle{}
\let\titleOLD\title
\renewcommand{\title}[1]
	{\def\@polyouttitle{#1}
	\titleOLD{#1}}

\def\@polyoutauthor{}
\let\authorOLD\author
\renewcommand{\author}[1]
	{\def\@polyoutauthor{#1}
	\authorOLD{#1}}

\newcommand{\usecolorthemes}[2]	% Selects either presentation (#1) or printable (#2) beamer color theme
	{\ifthenelse
		{\equal{\outmode}{presentation}}
		{\ifthenelse
			{\equal{#1}{}}{}{\usecolortheme{#1}}}
		{\ifthenelse
			{\equal{#2}{}}{}{\usecolortheme{#2}}}}

\def\@kwords{Keywords:}
\def\@parttitle{Part}
\def\@polyoutpartname{}

\def\@partgotobtn{Display}
\def\@partreturnbtn{Outline}

\newcommand{\partgotoreference}[1]{
	\ifthenelse
		{\equal{#1}{}}
		{}
		{\def\@partgotobtn{#1}}
}

\newcommand{\partgobackreference}[1]{
	\ifthenelse
		{\equal{#1}{}}
		{}
		{\def\@partreturnbtn{#1}}
}

\if@french
	\RequirePackage{french}
	\def\@kwords{Mots-clés\,:}
	\def\@parttitle{Partie}
	\def\@partgotobtn{Afficher}
	\def\@partreturnbtn{Sommaire}
	\presprintonly{
		\addto\captionsfrench{\def\partname{\@parttitle}}}	% To avoid 'Partie 1 I', 'Partie 2 II', ...
\fi

\let\frametitleOLD\frametitle
\renewcommand{\frametitle}[1]
	{\presprintonly{\frametitleOLD{#1}}}

\newcommand{\prespart}[1]
	{\presonly{\part{#1}}%
	\printonly{\part*{#1}}%
	\articleonly{\part*{#1}}}

\newcommand{\printpart}[1]
	{\printonly{\part{#1}}%
	\presonly{\part*{#1}}%
	\articleonly{\part*{#1}}}

\newcommand{\articlepart}[1]
	{\articleonly{\part{#1}}%
	\presprintonly{\part*{#1}}}

\newcommand{\presprintpart}[1]
	{\presprintonly{\part{#1}}%
	\articleonly{\part*{#1}}}

\newcommand{\printarticlepart}[1]
	{\printarticleonly{\part{#1}}%
	\presonly{\part*{#1}}}

\newcommand{\presarticlepart}[1]
	{\presarticleonly{\part{#1}}%
	\printonly{\part*{#1}}}

% Complementary commands to switch names
\newcommand{\printprespart}[1]
	{\presprintpart{#1}}

\newcommand{\articleprintpart}[1]
	{\printarticlepart{#1}}

\newcommand{\articleprespart}[1]
	{\presarticlepart{#1}}


\newcommand{\pressection}[1]
	{\presonly{\section{#1}}%
	\printonly{\section*{#1}}%
	\articleonly{\section*{#1}}}

\newcommand{\printsection}[1]
	{\printonly{\section{#1}}%
	\presonly{\section*{#1}}%
	\articleonly{\section*{#1}}}

\newcommand{\articlesection}[1]
	{\articleonly{\section{#1}}%
	\presonly{\section*{#1}}}

\newcommand{\presprintsection}[1]
	{\presprintonly{\section{#1}}%
	\articleonly{\section*{#1}}}

\newcommand{\printarticlesection}[1]
	{\printarticleonly{\section{#1}}%
	\presonly{\section*{#1}}}

\newcommand{\presarticlesection}[1]
	{\presarticleonly{\section{#1}}%
	\printonly{\section*{#1}}}

% Complementary commands to switch names
\newcommand{\printpressection}[1]
	{\presprintsection{#1}}

\newcommand{\articleprintsection}[1]
	{\printarticlesection{#1}}

\newcommand{\articlepressection}[1]
	{\presarticlesection{#1}}


\newcommand{\pressubsection}[1]
	{\presonly{\subsection{#1}}%
	\printonly{\subsection*{#1}}%
	\articleonly{\subsection*{#1}}}

\newcommand{\printsubsection}[1]
	{\printonly{\subsection{#1}}%
	\presonly{\subsection*{#1}}%
	\articleonly{\subsection*{#1}}}

\newcommand{\articlesubsection}[1]
	{\articleonly{\subsection{#1}}%
	\presprintonly{\subsection*{#1}}}

\newcommand{\presprintsubsection}[1]
	{\presprintonly{\subsection{#1}}%
	\articleonly{\subsection*{#1}}}

\newcommand{\printarticlesubsection}[1]
	{\printarticleonly{\subsection{#1}}%
	\presonly{\subsection*{#1}}}

\newcommand{\presarticlesubsection}[1]
	{\presarticleonly{\subsection{#1}}%
	\printonly{\subsection*{#1}}}

% Complementary commands to switch names
\newcommand{\printpressubsection}[1]
	{\presprintsubsection{#1}}

\newcommand{\articleprintsubsection}[1]
	{\printarticlesubsection{#1}}

\newcommand{\articlepressubsection}[1]
	{\presarticlesubsection{#1}}


\newcommand{\pressubsubsection}[1]
	{\presonly{\subsubsection{#1}}%
	\printonly{\subsubsection*{#1}}%
	\articleonly{\subsubsection*{#1}}}

\newcommand{\printsubsubsection}[1]
	{\printonly{\subsubsection{#1}}%
	\presonly{\subsubsection*{#1}}%
	\articleonly{\subsubsection*{#1}}}

\newcommand{\articlesubsubsection}[1]
	{\articleonly{\subsubsection{#1}}%
	\presprintonly{\subsubsection*{#1}}}

\newcommand{\presprintsubsubsection}[1]
	{\presprintonly{\subsubsection{#1}}%
	\articleonly{\subsubsection*{#1}}}

\newcommand{\printarticlesubsubsection}[1]
	{\printarticleonly{\subsubsection{#1}}%
	\presonly{\subsubsection*{#1}}}

\newcommand{\presarticlesubsubsection}[1]
	{\presarticleonly{\subsubsection{#1}}%
	\printonly{\subsubsection*{#1}}}

% Complementary commands to switch names
\newcommand{\printpressubsubsection}[1]
	{\presprintsubsubsection{#1}}

\newcommand{\articleprintsubsubsection}[1]
	{\printarticlesubsubsection{#1}}

\newcommand{\articlepressubsubsection}[1]
	{\presarticlesubsubsection{#1}}


\newcommand{\articledot}
	{\articleonly{.}}

\newcommand{\presentationdot}
	{\presentationonly{.}}

\newcommand{\printdot}
	{\printonly{.}}


\def\@logodim{}
\newcommand{\definelogodim}
	{\ifthenelse
		{\equal{\outmode}{article}}
		{\def\@logodim{\@articlelogoheight}}
		{\def\@logodim{\@presentationlogoheight}}}	% Both presentation and printable

\newcommand{\initvalues}
	{\definelogodim
	\presprintonly{
		\subtitle{\vspace{1mm}\@polyoutsubtitle}}
	\institute{
		\ifthenelse
			{\equal{\@polyoutlogo}{}}
			{\vspace{1pt}}
			{\includegraphics[height=\@logodim]{\@polyoutlogo}}
		\newline
		{\texttt\@polyoutcontact}
		\newline
		\href{\@polyoutwebsite}{\texttt\@polyoutwebsite}}}

\provideboolean{@includedate}
\@includedatetrue
\newcommand{\nodate}
	{\@includedatefalse}

\provideboolean{@versionselected}
\@versionselectedtrue

\def\@dateversion{}
\newcommand{\dateandversion}
	{\ifthenelse
		{\equal{\@polyoutversion}{}}
		{\if@includedate
			\def\@dateversion{\@date}
		\else
			\def\@dateversion{}
		\fi
		\@versionselectedfalse}
		{\def\@dateversion{\@polyoutversion}
		\@versionselectedtrue}}

\newcommand{\makeonesideheader}
	{\lhead{}}

\newcommand{\makeonesidefooter}
	{\ifthenelse
		{\equal{\@polyoutpagelogo}{}}
		{\lfoot{\@polyoutauthor}}
		{\lfoot{\includegraphics[height=\@pagelogoheight]{\@polyoutpagelogo}~\@polyoutauthor}}
	\cfoot{\thepage}
	\rfoot{\@polyouttitle}
	\renewcommand{\footrulewidth}{0pt}
	\renewcommand{\headrulewidth}{0pt}}

\newcommand{\maketwosideheader}
	{\fancyhead[LE]{}
	\fancyhead[RO]{}}

\newcommand{\maketwosidefooter}
	{\def\@dateversionfooter{\@dateversion}
	\if@versionselected
		\def\@dateversionfooter{v\,\@dateversion}
	\fi
	\fancyfoot[RE]{\@dateversionfooter}
	\fancyfoot[CE]{\@polyouttitle}
	\ifthenelse
		{\equal{\@polyoutpagelogo}{}}
		{\lfoot{\@polyoutauthor}}
		{\fancyfoot[LO]{\includegraphics[height=\@pagelogoheight]{\@polyoutpagelogo}~\@polyoutauthor}}
	\fancyfoot[CO]{}
	\fancyfoot[LE, RO]{\thepage}
	\renewcommand{\footrulewidth}{0pt}
	\renewcommand{\headrulewidth}{0pt}}

\newcommand{\makepagestyle}
	{\headheight12.2pt
	\if@twoside
		\maketwosideheader
		\maketwosidefooter
	\else
		\makeonesideheader
		\makeonesidefooter
	\fi}

\newcommand{\partsoverview}[1]
	{\presprintonly{%
		\section*{}
		#1}}

\newcounter{@partno}
%\setcounter, \addtocounter

\newcommand{\parttitle}[2][]
	{\subsection*{\the@partno}
	\refstepcounter{@partno}% @partno ++
	\ifthenelse
		{\equal{#2}{}}
		{\ifthenelse
			{\equal{#1}{}}
			{\frametitle{\@parttitle\ \the@partno}}
			{\frametitle{\@parttitle\ \the@partno\hfill\hyperlink{#1}{\beamergotobutton{\@partgotobtn}}}}}
		{\ifthenelse
			{\equal{#1}{}}
			{\frametitle{\@parttitle\ \the@partno\ --\ #2}}
			{\frametitle{\@parttitle\ \the@partno\ --\ #2\hfill\hyperlink{#1}{\beamergotobutton{\@partgotobtn}}}}}
	\parttoc{\the@partno}}

\newcommand{\insertdateversiontitlepage}
	{\ifthenelse
		{\equal{\@dateversion}{}}
		{\articleonly
			{\vfill
			\vspace*{\stretch{2}}
			\quad}}
		{\vfill
		\vspace*{\stretch{2}}
		\Large
		\if@versionselected
			version
		\fi
		\@dateversion}}

\renewcommand{\maketitle}
	{\presprintonly{
		\if@versionselected
			\date{version~\@dateversion}
		\else
			\date{\@dateversion}
		\fi
		\titlepage}
	\articleonly{
		\if@twocolumnmode
			\onecolumn
		\fi
		\pagestyle{empty}
		\begin{center}
			\renewcommand{\newline}{\vskip1pt}
			\renewcommand{\\}{\vskip1pt}
			\hrule height 1.5pt
			\vskip5ex
			{\Huge\textbf{\@polyouttitle}\par}
			\vskip6ex
			\hrule height 1.5pt
			\vskip10ex
			{\Large\textbf{\@polyoutsubtitle}\par}
			\vfill
			\vspace*{\stretch{1}}
			{\Large\@polyoutauthor}
			\ifthenelse
				{\equal{\@polyoutlogo}{}}
				{}
				{\vskip6ex
				\includegraphics[height=\@articlelogoheight]{\@polyoutlogo}}
			\vfill
			\texttt{\@polyoutcontact}
			\newline
			\href{\@polyoutwebsite}{\texttt{\@polyoutwebsite}}
			\insertdateversiontitlepage
		\end{center}
		\pagestyle{\@fancypagestyle}}}

\newcommand{\makegnufdl}[1]	% Copyright date
	{\articleonly
		{\pagestyle{empty}}
	\cleardoublepage\vspace*{\stretch{2}}\gnufdl{#1}{\@polyoutauthor}
	\pagestyle{\@fancypagestyle}}

\let\tocOLD\tableofcontents
\def\tableofcontents{%
	\if@twocolumnmode
		\twocolumn
	\fi
	\setcounter{page}{1}
	\tocOLD
	\newpage
	\pagestyle{\@fancypagestyle}}

\newcommand{\parttoc}[1]
	{\tocOLD[part=#1]}

\newcommand{\inittitlepage}
	{\presprintonly{
		\setbeamertemplate{footline}{
			\leavevmode%
			\if@pagenum
				\newcommand{\boxproperties}{, ht=6pt, leftskip=2pt, rightskip=2pt, dp=2pt}% This comment is necessary to avoid small blank before first box
				\hbox{% This comment is necessary to avoid space between boxes...
					\begin{beamercolorbox}[wd=.45\paperwidth, ht=6pt, leftskip=2pt, rightskip=2pt, dp=2pt]{author in head/foot}%
						\@polyoutauthor%
					\end{beamercolorbox}% This comment is necessary to avoid space between boxes...
					\begin{beamercolorbox}[wd=.1\paperwidth, ht=6pt, leftskip=2pt, rightskip=2pt, dp=2pt]{date in head/foot}%
						\center\insertframenumber{}\,/\,\inserttotalframenumber%
					\end{beamercolorbox}% This comment is necessary to avoid space between boxes...
					\begin{beamercolorbox}[wd=.45\paperwidth, ht=6pt, leftskip=2pt, rightskip=2pt, dp=2pt]{title in head/foot}%
						\hfill\@polyouttitle%
					\end{beamercolorbox}
				}
			\else
				\hbox{% This comment is necessary to avoid space between boxes...
					\begin{beamercolorbox}[wd=.5\paperwidth, ht=6pt, leftskip=2pt, rightskip=2pt, dp=2pt]{author in head/foot}%
						\@polyoutauthor%
					\end{beamercolorbox}% This comment is necessary to skip space between boxes...
					\begin{beamercolorbox}[wd=.5\paperwidth, ht=6pt, leftskip=2pt, rightskip=2pt, dp=2pt]{title in head/foot}%
						\hfill\@polyouttitle%
					\end{beamercolorbox}
				}
			\fi
		}
		
		% Navigation bar is automatically removed in printable mode
		\if@nonavigation		
			\setbeamertemplate{navigation symbols}{}	% Removes navigation bar
		\fi
				
		\setcounter{tocdepth}{\@theparttocdepth}
		
		\AtBeginSection[]{%
			\if@sectoc
				\setcounter{tocdepth}{\@thesectiontocdepth}
				\frame{
					\tocOLD[currentsection, hideothersubsections]
				}
			\fi
		}
	}}

\newcommand{\goodgap}
	{\hspace{\subfigtopskip}
	\hspace{\subfigbottomskip}}

\def\@thepartimage{}
\def\@thepartimageposition{c}	% l|c|r

\newcommand{\partimageposition}[1]
	{\ifthenelse
		{\equal{#1}{}}
		{\def\@thepartimageposition{c}}
		{\def\@thepartimageposition{#1}}}

\newcommand{\partimage}[2][]	% #1 = l|c|r (position: left, center, right), #2 = image source
	{\ifthenelse
		{\equal{#1}{}}
		{}	% Do not change current part position
		{\def\@thepartimageposition{#1}}
	\def\@thepartimage{#2}}

\provideboolean{@partimagewidthinitialized}
\newlength{\@thepartimagewidth}
\newcommand{\partimagewidth}[1]
	{\ifthenelse
		{\equal{#1}{}}
		{}
		{\setlength{\@thepartimagewidth}{#1}
		\@partimagewidthinitializedtrue}}

\renewenvironment{abstract}
	{\articleonly{\pagestyle{empty}}
	\cleardoublepage\vspace*{\stretch{1}}\hfill\textbf{\abstractname}\hfill\vspace{\@abstractspacer}\newline}
	{\vspace*{\stretch{2}}\newline\textbf\@kwords\ \@polyoutkeywords\cleardoublepage}

\newenvironment{extrasection}[1][]
	{\pagestyle{empty}
	\cleardoublepage
	\ifthenelse
		{\equal{#1}{}}
		{}
		{{\Huge #1}\vspace{5pt}}}
	{\cleardoublepage}

\newcommand{\extrasubsection}[1]
	{\vspace{2pt}{\large\textbf #1}\vspace{5pt}}

\newcommand{\initpdf}
	{\ifpdf
		\hypersetup{%
			pdftitle={\@polyouttitle},
			pdfauthor={\@polyoutauthor},
			pdfkeywords={\@polyoutkeywords},
			pdfsubject={}} % Should be \@polyoutsubtitle, but does not appear in all modes
	\fi}

\let\vbtm\texttt

\newenvironment{vbtmenv}
	{}{}

\let\appendixOLD\appendix
\renewcommand{\appendix}{
	\articleonly{\appendixOLD}
}

\newcommand{\initparts}{
	\ifthenelse
		{\boolean{@partimagewidthinitialized}}
		{}
		{\setlength{\@thepartimagewidth}{.33\textwidth}}
	\renewcommand{\thepart}{\@Roman\c@part}	% To display 'Partie 1' and not 'Partie I'
	\let\partOLD\part
	\renewcommand{\part}[6][]	% #1 = short title, #2 = title, #3 = subtitle, #4 = part reference, #5 = outline reference
		{\frame[label=##4]{
			\presprintonly{
				\renewcommand{\newline}
					{\vskip1pt}
				\renewcommand{\\}
					{\vskip1pt}}
			\articleonly{
				\renewcommand{\newline}
					{\par}
				\renewcommand{\\}
					{\par}
				\cleardoublepage
				\if@twocolumnmode
					\onecolumn
				\fi
				\thispagestyle{empty}
				\vspace*{\stretch{1}}}
			\ifthenelse
				{\equal{##1}{}}
				{\partOLD[##2]{##2}\label{##4}}
				{\partOLD[##1]{##2}\label{##4}}
			\partpage
			\articleonly{\hrule \\ \vspace{20pt} \\}	% \\ not supported by presentation mode
			\presonly{
				\ifthenelse
				{\equal{##5}{}}
				{}
				{\par\hfill\hyperlink{##5}{\beamerreturnbutton{\@partreturnbtn}}}
			}
			\vspace{40pt}
			\ifthenelse
				{\equal{##3}{}}
				{\par ~}
				{\par ##3}}%
		\articleonly{
			\vspace*{\stretch{2}}
			\newline
			\ifthenelse
				{\equal{\@thepartimage}{}}
				{}
				{\ifthenelse
					{\equal{\@thepartimageposition}{c}}	% Centered
					{\begin{center}%
						\includegraphics[width=\@thepartimagewidth]{\@thepartimage}%
					\end{center}}
					{\ifthenelse
						{\equal{\@thepartimageposition}{r}}
						{\vspace{1pt}\hfill}	% Right aligned
						{}	% Left (default)
					\includegraphics[width=\@thepartimagewidth]{\@thepartimage}}}
			\if@twocolumnmode
				\twocolumn
			\fi
			\newpage
			\pagestyle{\@fancypagestyle}}}}

\AtBeginDocument{
	\initvalues
	\inittitlepage
	\dateandversion
	\articleonly
		{\makepagestyle
		\pagestyle{\@fancypagestyle}}
	\initpdf
	\initparts}

\endinput

