\documentclass[13pt,t]{beamer}
%\usepackage[french]{babel} 
%\usepackage{polyglossia}
%\setdefaultlanguage{french}
\usepackage[french=guillemets*]{csquotes} 
\MakeOuterQuote{"} 
\frenchspacing
%\frenchbsetup{AutoSpacePunctuation=false}
\usepackage{ragged2e}
\justifying

%\usepackage[style=authoryear,abbreviate=true,backend=biber]{biblatex}       
%\usepackage{natbib}
%\renewcommand{\bibfont}{\footnotesize}

%\hyphenation{éven-tuel-les,repré-sen-ta-tion,re-la-tives}

\usepackage{makeidx}
%\usepackage{dcolumn}  % for apsrtable
\usepackage{multicol}
%\setlength{\columnsep}{5pt}
% Maybe I should go for imakeidx which allows to split \theindex in 
% several columns.

\newenvironment{theindex}{%
  \let\item\par   % definitions for subitem etc
 \begin{multicols}{4}\scriptsize
}{\end{multicols}}
\newcommand\indexspace{}

\usepackage{multirow}
\usepackage{amsmath}
\usepackage{textpos}
\usepackage{pdfpages}

\usepackage{fontspec,xltxtra,xunicode}
\defaultfontfeatures{Scale=MatchLowercase}
\setromanfont[Mapping=tex-text]{Fertigo Pro} 
\setsansfont[Mapping=tex-text]{Fontin Sans} 
\setmonofont[Scale=0.91]{Inconsolata}
\definecolor{grey30}{rgb}{.3,.3,.3}
\definecolor{grey70}{rgb}{.7,.7,.7}
\definecolor{mybrown}{rgb}{.5,.4,.3}
\definecolor{myred}{rgb}{.75,.19,.19}
\definecolor{myred2}{rgb}{.87,.38,.38}
\definecolor{myred3}{rgb}{.65,.38,.38}
%\definecolor{myred4}{rgb}{.83,.64,.64}
\colorlet{myred4}{myred2!30}

\usepackage[formats]{listings}
\lstdefineformat{tilde}{\~=\textcolor{myred3}{$$\sim$$}}

\lstloadlanguages{R} 
\lstdefinelanguage{Renhanced}[]{R}{% 
   morekeywords={probs,within,fun,read.table,read.csv,str,%
                 header,dec,sep,na.strings,as.factor,is.factor,%
		 data.frame,as.numeric,each,letters,LETTERS,%
		 in,head,is.na,:,rfs,bwplot,histogram,na.rm,%
		 panel,breaks,panel.bpplot,groups,qqmath,paired,%
		 auto.key,columns,type,count,t.test,var.equal,%
		 model.tables,with,plot.design,read.dta,tmd,%
		 help.search,expand.grid,set.wd,densityplot,%
		 bw.nrd0,loess,droplevels,as.matrix,describe,%
		 marginal.plot,prop.table,xtabs,xyplot,trim,%
		 method,lab,units,overall,jitter.data,amount,%
		 aspect,digits,dist,cex,summary.formula,skewness,%
		 barchart,plot.points,prmsd,FUN,shingle,equal.count,%
		 panel.xyplot,panel.abline,h,lty,pch,horiz,alpha,%
		 is.numeric,decreasing,nrow,byrow,ties.method,%
		 wilcox.test,chisq.test,oddsratio,margin.table,%
		 mcnemar.test,binom.test,untable,kappa2,fisher.test,%
		 alternative,correct,cor.test,to.data.frame,read.spss,%
		 kruskal.test,sm.ancova,ref,summary.lm,acast,%
                 margins,value.var,cterms,bartlett.test,g,cut2,%
		 model.matrix,.Last.value,influence.measures,%
                 contr.treatment,contr.sum,contr.helmert,random,%
		 intervals,lme,interval,xYplot,id.vars,Error,%
		 complete.cases,as.formula,scope,test,addterm,%
                 direction,collapse,mmplot,mmps,residual.plots,%
		 confint,lower.tail,lrm,datadist,Predict,conf.type}, 
   deletekeywords={csv,*,integer,double,or}}
\lstset{language=Renhanced,
	format=tilde,
	keepspaces=true,
	%escapeinside={\%*}{*)},
	extendedchars=true, 
	alsoletter={.},
	upquote=true,
	basicstyle=\small\ttfamily, 
   	commentstyle=\color{myred4}, 
   	keywordstyle=\color{myred3}, 
   	showstringspaces=false, 
   	index=[1][keywords], 
   	indexstyle=\indexfoo} 

\newcommand{\indexfoo}[1]{\index{#1@{\tt #1}}} 
\makeatletter
\lst@AddToHook{TextStyle}{\let\lst@basicstyle\normalsize\ttfamily}
\makeatother
\renewcommand{\texttt}[1]{\lstinline{#1}}
\newcommand*{\addon}[1]{\hfill\textcolor{myred}{\small #1}}

% \lstset{language=R, basicstyle=\small\ttfamily, 
%         keywordstyle=\color{myred3},
% 	commentstyle=\color{myred4}}


%% \setlength{\parindent}{0pt}
%% \setlength{\parskip}{6pt plus 2pt minus 1pt}

$if(verbatim-in-note)$
\usepackage{fancyvrb}
$endif$
$if(fancy-enums)$
\usepackage{enumerate}
$endif$
$if(tables)$
\usepackage{array}
\usepackage{ctable}
% This is needed because raggedright in table elements redefines \\:
\newcommand{\PreserveBackslash}[1]{\let\temp=\\#1\let\\=\temp}
\let\PBS=\PreserveBackslash
$endif$
$if(strikeout)$
\usepackage[normalem]{ulem}
$endif$
$if(subscript)$
\newcommand{\textsubscr}[1]{\ensuremath{_{\scriptsize\textrm{#1}}}}
$endif$
$if(links)$
\usepackage[breaklinks=true]{hyperref}
$endif$
$if(url)$
\usepackage{url}
$endif$
$if(graphics)$
\usepackage{graphicx}
$endif$
$if(numbersections)$
$else$
%% \setcounter{secnumdepth}{0}
$endif$
$if(verbatim-in-note)$
\VerbatimFootnotes % allows verbatim text in footnotes
$endif$
$for(header-includes)$
$header-includes$
$endfor$
$if(title)$
\title{\rm $title$}
$endif$
\author{Introduction à \textsf{R} pour la recherche biomédicale}
\institute{\footnotesize{\url{http://www.aliquote.org/cours/2012_biomed}}}
$if(date)$
\date{$date$}
$else$
\date{}
$endif$

% remove navigation bar
\setbeamertemplate{navigation symbols}{}
%\setbeamertemplate{footline}[page number]

% transparent overlays
\setbeamercovered{transparent}

% for natbib
\def\newblock{}


\setbeamercolor{background canvas}{bg=mybrown}
\setbeamercolor{structure}{fg=myred}
\defbeamertemplate*{background}{perso}
{\hskip.025\paperwidth
\leavevmode
\vbox{
\begin{beamercolorbox}[wd=.95\paperwidth,ht=.0175\paperheight]{headlining}
\end{beamercolorbox}
\begin{beamercolorbox}[wd=.95\paperwidth,ht=.9275\paperheight,rounded=true]{bkg}
\end{beamercolorbox}}
}
\setbeamercolor{bkg}{bg=white} 
\setbeamercolor{headlining}{bg=mybrown} 
\setbeamertemplate{frametitle}[default][center]
%\setbeamerfont{frametitle}{series=\bfseries} 
\renewcommand{\textbf}{\alert}
\setbeamercolor{alerted text}{fg=myred2}
\setbeamercolor{block title}{bg=myred2, fg=white}
\setbeamercolor{block body}{bg=myred4, fg=black}
\setbeamertemplate{frametitle continuation}[from second][(\dots)]

\graphicspath{{figs/}}
\setkeys{Gin}{width=.8\textwidth}
\newcommand{\img}[1]{\centerline{\includegraphics{#1}}}
\newcommand{\simg}[2]{\centerline{\includegraphics[page={#1},height=2in,keepaspectratio]{#2}}}

\makeindex

\begin{document}

$if(title)$
\begin{frame}{}
  \titlepage
$endif$

$body$

\end{document}
