%%%%%%%%%%%%%%%%%%%%%%%%%%% -*- Mode: Latex -*- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% seminar.bg3 --- Corrections for compatibility problems and new bugs
%%                 found in the Seminar package, and few new additions
%%                 to help overlays management for PDF output files.
%%                 (see also the seminar.bug file in Seminar distribution)
%%
%%                 Disclaimer: this file is mine and doesn't engage TVZ!
%%
%% Note: insert it after \usepackage{graphicx} if you use `graphicx'
%%       and after \usepackage{longtable} if you use `longtable'
%%
%% Author          : Denis GIROU (CNRS/IDRIS - France) <Denis.Girou@idris.fr>
%% Created the     : 1995
%% Last mod. by    : Patrice MEGRET (FPMs - Belgium) <patrice.megret@fpms.ac.be>
%% Last mod. the   : Sunday February 29 2004
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\FileVersion{2.3}
\def\FileDate{2014/05/12}
\typeout{seminar.bg3: various corrections for the Seminar document class^^J%
         added since seminar.bug and few add-ons for overlays^^J%
         (Version \FileVersion\space of <\FileDate> (P.M.))}

\edef\TheAtCode{\the\catcode`\@}
\catcode`\@=11

% PM modification begin PM December 6, 2003
% ce nouveau test permet de choisir entre un footer
% verticalement centré \footervcenter = true (default)
% ou non \footervcenter = false
\newif\iffootervcenter \footervcentertrue
% PM modification end December 6, 2003


% 1 - To correct a bug in the note environment
%     (reported by Denis Girou (CNRS/IDRIS) <Denis.Girou@idris.fr> - 1995)
\@savsf=1


% 2 - To correct several bugs to generate a list of slides with subsection
%     entries
%     (reported by Denis Girou (CNRS/IDRIS) <Denis.Girou@idris.fr> - Jul. 18, 1995)
%   - To clear the subheading when a new heading is defined
%     (reported by Axel Thimm - <thimm@physik.fu-berlin.de> - June 5, 1997)
%   - To assure coherence between heading and subheading when used
%     in header/footer, for article mode
%     (reported by Axel Thimm - <thimm@physik.fu-berlin.de> - June 5, 1997)
%   - Improvements (\refstepcounter and \@addtoreset) by Jeremy Gibbons
%     <jgibbons@brookes.ac.uk> - Sep. 30, 1997

% Used by the \slide@subheading macro but undefined
\def\theslidesubsection{\theslidesection.\arabic{slidesubsection}}

\def\slide@heading[#1]#2{%
  \refstepcounter{slidesection}%
  \@addtoreset{slidesubsection}{slidesection}
  \addtocontents{los}{\protect\l@slide
    {\the\c@slidesection}{\ignorespaces#1}{\@SCTR}}%
  \def\@tempa{#2}%
  \ifx\@tempa\@empty\else
    {\edef\@currentlabel{\csname p@slidesection\endcsname\theslidesection}%
      \makeslideheading{#2}}%
  \fi
  \gdef\theslideheading{#1}%
  \gdef\theslidesubheading{}%
}

\def\slide@subheading[#1]#2{%
  \refstepcounter{slidesubsection}%
  \addtocontents{los}{\protect\l@subslide
    {\the\c@slidesubsection}{\ignorespaces#1}{\@SCTR}}%
  \def\@tempa{#2}%
  \ifx\@tempa\@empty\else
    {\edef\@currentlabel{\csname p@slidesubsection\endcsname
      \theslidesubsection}\makeslidesubheading{#2}}%
  \fi
  \gdef\theslidesubheading{#1}%
}


% 3 - To correct a bug in the \slidecontents macro
%     (reported by Denis Roegel (LORIA) <Denis.Roegel@loria.fr> - Sep. 22, 1996)

\long\def\@gobblethree #1#2#3{}

\def\slide@contents{%
  \def\l@slide##1##2##3{%
    \slide@cline{\slidenumberline{##1}{##2}}{##3}}%
  \let\l@subslide\@gobblethree
  \@startlos}


% 4 - To solve incompatibility between the `graphicx' package and Seminar.
%     The \espfslidesize Seminar macro work only with the old version of
%     the `epsfig' package, so with \includegraphics the PostScript files are
%     always scaled without the possibility to leave them to there natural
%     size. And also these files are not correctly scaled when we switch
%     from normal to article mode under Seminar. So, we must redefined the
%     \epsfslidesize macro of Seminar and modify few internal macros of
%     `graphicx'.
%     (Note: I consider only the `graphicX' package, not the 'graphicS' one)
%     (reported by Karl Tombre  (LORIA) <Karl.Tombre@loria.fr> and
%                  Denis Roegel (LORIA) <Denis.Roegel@loria.fr> - Jan. 16, 1997)

\def\GraphicsNotScaled{%
\ifx\Gin@viewport\undefined
\else                           % Graphicx package detected
\def\Gin@i{%
 \def\Gin@req@sizes{%
   \Gin@nat@height=\inverseslidesmag\Gin@nat@height
   \Gin@nat@width=\inverseslidesmag\Gin@nat@width
   \Gin@req@height\Gin@nat@height
   \Gin@req@width\Gin@nat@width}%
 \@ifnextchar[\Gin@ii{\Gin@ii[]}}
\define@key{Gin}{width}{%
\@tempdima=##1\@tempdima=\inverseslidesmag\@tempdima\def\Gin@ewidth{\@tempdima}}
\define@key{Gin}{height}{%
\@tempdima=##1\@tempdima=\inverseslidesmag\@tempdima\def\Gin@eheight{\@tempdima}}
\define@key{Gin}{totalheight}{%
\def\Gin@eresize{\totalheight}%
\@tempdima=##1\@tempdima=\inverseslidesmag\@tempdima\def\Gin@eheight{\@tempdima}}
\fi}

\def\epsfslidesize{%
\let\epsfsize\slide@epsfsize
\GraphicsNotScaled}


% 5 - To solve incompatibily between the LongTable package and Seminar
%     (reported by Bhaskar Manda (UIUC) <bhaskar@or4.me.uiuc.edu> - May 7, 1997)
%   - Problem in article format seen later
%     (reported by Axel Thimm <thimm@physik.fu-berlin.de> - June 5, 1997)

% From seminar.cls
\def\slide@outputLT{% (from \slide@output)
  \@makeslide
  \@testfalse
  \ifnotesonly\else
    \iflandscape
      \ifnum\@landscapeonly>-1 \os@test\fi
    \else
      \ifnum\@landscapeonly<1 \os@test\fi
    \fi
  \fi
  \if@test
    \reset@slideoutput
    \@@makeslideLT
    \process@slide
  \fi
  \refstepcounter{slide}}
\def\@@makeslideLT{% (from \@@makeslide)
  \overfullslide@warning
  \setbox\@slidebox\hbox{%
    \vfuzz=\slidefuzz\relax
    \vbox to\slide@vsize{%
    \box\@outputbox
    \ifcenterslides\vskip\z@ plus .0001fil \fi
    \unvbox\@slidebox
    \vskip\z@ plus .0001fil}%
    \the\after@slidepage}%
  \wd\@slidebox\textwidth}

% From LongTable
\def\LT@output{%
  \ifnum\outputpenalty <-\@Mi
    \ifnum\outputpenalty > -\LT@end@pen
      \LT@err{floats and marginpars not allowed in a longtable}\@ehc
    \else
      \setbox\z@\vbox{\unvbox\@cclv}%
      \ifdim \ht\LT@lastfoot>\ht\LT@foot
        \dimen@\pagegoal
        \advance\dimen@-\ht\LT@lastfoot
        \ifdim\dimen@<\ht\z@
          \setbox\@cclv\vbox{\unvbox\z@\copy\LT@foot\vss}%
          \@makecol
          \slide@outputLT
          \setbox\z@\vbox{\box\LT@head}%
        \fi
      \fi
      \global\@colroom\@colht
      \global\vsize\@colht
      \vbox
        {\unvbox\z@\box\ifvoid\LT@lastfoot\LT@foot\else\LT@lastfoot\fi}%
    \fi
  \else
    \setbox\@cclv\vbox{\unvbox\@cclv\copy\LT@foot\vss}%
    \@makecol
    \slide@outputLT
    \copy\LT@head
  \fi}

% We must adjust \textheight. Sometimes, you must increase it a little by
% something like \addtolength{\textheight}{5mm}
% But if you use slides like \begin{slide*}[15cm,10cm]
% you must define locally \textheight=15cm
\addtolength{\textheight}{-\headheight}


% 6 - To allow automatic changes of language dependent labels,
%     for instance by loading the `french' package after Seminar
%     (suggested by Bernard Gaulle (IDRIS) <gaulle@idris.fr> - Nov. 20, 1997)
% From seminar.cls
\def\slidename{Slide}
\def\slidelabel{\bf\slidename{} \theslide}
% From slidesec.sty
\def\listslidename{List of Slides}%
\def\listofslides{\section*{\listslidename%
\@mkboth{\expandafter\MakeUppercase\listslidename}%
        {\expandafter\MakeUppercase\listslidename}}%
  \def\l@slide##1##2##3{%
    \slide@undottedcline{\slidenumberline{##3}{##2}}{}}%
  \let\l@subslide\l@slide
  \@startlos}


% 7 - There were several problems when doing a global change of color
%     outside the "slide"environment (using the \color{ColorName} macro
%     of the `color' package) if this change was not done globally
%     (that is to say before the "\begin{document}") but inside the document,
%     for a part of the slides.
%     These problems can be seen specially for screen presentations,
%     when we want to use a dark background, so a light foreground color
%     for the text.
%     First, the header (defining for instance with the `fancyhdr' package)
%     changed of color one slide later and was restored one slide later too
%     if the change of the color was mas inside a group for some slides,
%     and second, the black color was forced by the footer.
%     We solve the first problem by usage of the same technique than the one
%     used by Seminar for global changes based on \special macros and made
%     before the "\begin{document}". We save the \specials in the
%     \saved@specials box and insert it at the beginning of the \@slidebox box
%     with the \insert@specials macro, as for the first slide.
%     And we solve the second problem by suppression of the command in the
%     hook which force the black color (defined in the `semcolor' package).
%     (reported by Denis Girou (CNRS/IDRIS) <Denis.Girou@idris.fr> - 1999-2002)

% Built from \save@srlidespecials (for all slides excepted the first one)
\def\save@slidespecials@ii{%
  \begingroup
    \output{%
      \global\setbox\saved@specials=\box\@cclv
      \global\wd\saved@specials=\z@
      \global\dp\saved@specials=\z@
      \global\ht\saved@specials=\z@}%
    \hbox{}\penalty-\@M
  \endgroup}%

% The first slide is already managed, so we will define \save@slidespecials@i
% started to the second one only...
\def\save@slidespecials@i{}%

\ifarticle\else
  \def\insert@specials{%
    \ifvoid\saved@specials\else
      \setbox\@slidebox\hbox{\box\saved@specials\box\@slidebox}%
    \fi
    \global\let\save@slidespecials@i\save@slidespecials@ii}
\fi

\addto@hook{\before@newslide}{\save@slidespecials@i}

\after@slidepage={}


% 7 - To vertically correctly center the footer, if defined
%     (this is mainly visible when using the `fancyhdr' package, and specially
%     when a footer rule line is defined)
%     (reported by Denis Girou (CNRS/IDRIS) - <Denis.Girou@idris.fr> - April 1998)

% 8 - Add-on to allow "full screen" backgrounds.
%     Seminar originally support only partial backgrounds, which doesn't cover
%     the full page but only the place of the text. It cannot be easily
%     modified, as there are dependancies between the header and the text.
%     So, we choose to define new macros \SeminarNewSlideFrameBackground
%     and \SeminarSlideFrameBackground to manage the full screen backgrounds,
%     designed on the model of the \newslideframe and \slideframe ones.
%     (added by Denis Girou (CNRS/IDRIS) <Denis.Girou@idris.fr> - Jun. 30, 1999)

\newbox\Seminar@SlideBoxBackground
\ifarticle
\else
  \def\output@slide{%
    \begingroup
      \hoffset=-\inverseslidesmag in
      \voffset=-\inverseslidesmag in
      \setslidelength\@tempdima{%
        \ifportrait\paperwidth\else\paperheight\fi}%
      \setslidelength\@tempdimb{%
        \ifportrait\paperheight\else\paperwidth\fi}%
      \ifrotateheaders
        \@ifrotateslide{%
          \dimen@=\@tempdima
          \@tempdima=\@tempdimb
          \@tempdimb=\dimen@}
      \fi
      % \oddsidemargin, \evensidemargin, \headheight, \footheight
      % used for scratch:
      % Some page styles like to know \textwidth:
      \setslidelength\headheight\slidetopmargin
      \setslidelength\footheight\slidebottommargin
      \ifautoslidemargins
        \textwidth=\wd\@slidebox
        \oddsidemargin=\@tempdima
        \advance\oddsidemargin-\textwidth
        \divide\oddsidemargin 2
      \else
        \setslidelength\oddsidemargin\slideleftmargin
        \setslidelength\evensidemargin\sliderightmargin
        \textwidth=\@tempdima
        \advance\textwidth-\oddsidemargin
        \advance\textwidth-\evensidemargin
      \fi
      \setbox\@slidebox=\hbox to \@tempdima{%
        \box\Seminar@SlideBoxBackground
        \kern\oddsidemargin
        \vbox to\@tempdimb{%
          \ifnum\fancyput@flag>-1
            \hbox{\kern-\oddsidemargin\do@fancyput}%
          \fi
          \let\label\@gobble
          \let\index\@gobble
          \let\glossary\@gobble
          \vbox to\headheight{%
            \vfill
            \hbox{%
              \slideheadfont\relax\strut
              \hbox to\textwidth{\@oddhead}}%
            \kern\z@}%
          \vfill
          \hbox to\textwidth{\hss\box\@slidebox\hss}%
          \vfill
          \vbox to\footheight{%
	  \iffootervcenter
            \vfill
	  \fi
            \hbox{%
              \slidefootfont\relax\strut
              \hbox to\textwidth{\@oddfoot}}%
            \vfill}}%
        \hss}%
      \ifrotateheaders\@ifrotateslide\rotate@slide\fi
      \insert@specials
      \let\protect\noexpand
      \shipout\box\@slidebox
    \endgroup
    \let\firstmark\botmark}
  \@ifundefined{fancyput@flag}{\def\fancyput@flag{-1}}{}
\fi


\def\finish@slide{%
  \theSlideFrameBackground
  \theslideframe
  \add@slidelabel\slidelabel}


\def\SeminarNewSlideFrameBackground#1{%
  \@ifnextchar[{\@SeminarNewSlideFrameBackground{#1}}%
               {\@SeminarNewSlideFrameBackground{#1}[]}}
\def\@SeminarNewSlideFrameBackground#1[#2]{%
  \@namedef{semsfbops@#1}{#2}%
  \@namedef{semsfb@#1}##1}

\def\SeminarSlideFrameBackground{\Seminar@SlideFrameBackground{Slide}}
\def\Seminar@SlideFrameBackground#1{%
  \@ifstar{\@testtrue\Seminar@@SlideFrameBackground{#1}}%
          {\@testfalse\Seminar@@SlideFrameBackground{#1}}}
\def\Seminar@@SlideFrameBackground#1{%
  \@ifnextchar[{\Seminar@@@SlideFrameBackground{#1}}%
               {\Seminar@@@SlideFrameBackground{#1}[]}}
\def\Seminar@@@SlideFrameBackground#1[#2]#3{%
  \def\@tempa{none}%
  \def\@tempb{#3}%
  \ifx\@tempa\@tempb
    \@namedef{the#1FrameBackground}{\relax}%
  \else
    \ifx\@tempb\@empty
      \@namedef{the#1FrameBackground}{}%
    \else
      \@ifundefined{semsfb@#3}%
        {\@seminarerr{Background slide frame `#3' undefined}\@eha}%
        {\if@test
          \Seminar@@@@SlideFrameBackground{#1}[#2]{#3}%
        \else
          \@namedef{the#1FrameBackground}{%
            \setbox\Seminar@SlideBoxBackground=\hbox{{%
              \@nameuse{semsfbops@#3}#2%
                \@nameuse{semsfb@#3}{\box\Seminar@SlideBoxBackground}}}}%
        \fi}%
     \fi
   \fi}
\def\Seminar@@@@SlideFrameBackground#1[#2]#3{%
  \expandafter\let\expandafter\@tempa\csname the#1FrameBackground\endcsname
  \edef\next{%
    \noexpand\def\expandafter\noexpand\csname the#1FrameBackground\endcsname}%
  \expandafter\next\expandafter{\@tempa
    \setbox\Seminar@SlideBoxBackground=\hbox{{%
      \@nameuse{semsfbops@#3}%
      #2%
      \@nameuse{semsfb@#3}{\box\Seminar@SlideBoxBackground}}}}}%

\SeminarSlideFrameBackground{none}


% 9 - For screen presentations, and specially animated graphics,
%     we need more than 10 overlays. We increase the limit to 676 (26^2).
%     (added by Denis Girou (CNRS/IDRIS) <Denis.Girou@idris.fr> - Dec.  5, 2001)

\def\overlay#1{%
  \ifoverlays\ifx\@overlay\relax\nooverlays@err\fi\fi
  \ifslide
    \@tempcnta=#1
    \@testfalse
    \ifnum\@tempcnta>-2 \ifnum\@tempcnta<677 \@testtrue\fi\fi
    \if@test
      \c@overlay=\@tempcnta
      \ifnum\c@overlay=0
        \advance\c@slide by -1
        \refstepcounter{slide}%
      \else
        \advance\c@overlay by -1
        \refstepcounter{overlay}%
        \ifoverlays
          \xdef\overlay@list{\overlay@list,\the\c@overlay}%
        \fi
      \fi
      \ifoverlays
        \@overlay{\the\c@overlay}%
      \fi
    \else
      \@seminarerr{\string\overlay\space argument must be
        an integer between 0 and 676}\@eha
    \fi
  \else
    \@seminarerr{\string\overlay\space can only be used
      in slide environments}\@eha
  \fi
  \ignorespaces}

\def\overlay@loop{%
  \begingroup
    \overlay@prep
    \c@overlay=1
    \@whilenum\c@overlay<677
      \do{%
        \test@member{\the\c@overlay}{\overlay@list}%
        \if@test
          \make@overlay{\the\c@overlay}%
          \finish@slide
          \output@slide
        \fi
        \layer@loop{\the\c@overlay}%
        \advance\c@overlay by 1}%
  \endgroup}

\def\theoverlay{{%
\ifnum\c@overlay>26
  \@tempcnta=\c@overlay
  \advance\@tempcnta\m@ne
  \divide\@tempcnta by 26
  \multiply\@tempcnta by 26
  \@tempcntb=\c@overlay
  \advance\@tempcntb-\@tempcnta
  \@tempcnta=\c@overlay
  \advance\@tempcnta\m@ne
  \divide\@tempcnta by 26
  \theslide-\@alph{\@tempcnta}\@alph{\@tempcntb}%
\else
  \theslide-\alph{overlay}%
\fi}}


% 10 - Addition for management of cumulative and progressive overlays.
%      Due to PSTricks, Seminar had since the beginning the required
%      capabilities to manage overlays in various ways. The only thing
%      to do is to redefine the PSTricks \pst@initoverlay macro in the
%      relevant way.
%      (added by Denis Girou (CNRS/IDRIS) <Denis.Girou@idris.fr> - 1999-2001)

% From `semcolor'
\def\make@overlay#1{%
  \setbox\@slidebox=\hbox{%
    \pst@initoverlay{#1}%
    \pst@Verb{0 \tx@BOL }%
    \copy\@@slidebox
    \pst@Verb{-1 \tx@BOL }}}

\iffalse
% We must redefine too the /BeginOL macro form pstricks.pro, as "all" is now -1
\def\pst@initoverlay#1{%
\pst@Verb{%
/BeginOL {%
  dup -1 eq exch TheOL eq or
    {IfVisible not
      {Visible /IfVisible true def}
     if}
    {IfVisible
      {Invisible /IfVisible false def}
     if}
  ifelse} def
\tx@InitOL end
/TheOL #1 def}}

\def\pst@overlay#1{%
\edef\curr@overlay{#1}%
\pst@Verb{#1 \tx@BOL }%
\aftergroup\pst@endoverlay}
\def\pst@endoverlay{%
\pst@Verb{\curr@overlay\space \tx@BOL }}
\fi

% Cumulative overlays
% ===================

% Cumulative overlays, to force to print all preceding ones
\def\SeminarCumulativeOverlays{%
\def\pst@initoverlay##1{%
\pst@Verb{%
/BeginOL {%
  dup -1 eq exch TheOL le or
    {IfVisible not
      {Visible /IfVisible true def}
     if}
    {IfVisible
      {Invisible /IfVisible false def}
     if}
  ifelse} def
\tx@InitOL end 
/TheOL ##1 def}}}

% Alternative method for same goal (needed when PSTricks nodes are used)
\def\SeminarAltCumulativeOverlays{%
\def\pst@initoverlay##1{%
\pst@Verb{%
/BeginOL {%
  dup -1 eq exch TheOL le or
    {IfVisible not
      {Visible /IfVisible true def}
     if}
    {IfVisible
      {Invisible /IfVisible false def}
     if}
  ifelse} def
\tx@InitOL end
/Visible {initclip} def
/Invisible {CP newpath OLUnit itransform moveto clip newpath moveto} def
/TheOL ##1 def}}}

% Progressive overlays
% ====================

% Progressive overlays (at step i, only overlays 0 and i are shown)
\def\SeminarProgressiveOverlays{%
\def\pst@initoverlay##1{%
\pst@Verb{%
/BeginOL {%
  /NumOL ED
  NumOL -1 eq NumOL 0 eq NumOL TheOL eq or or
    {IfVisible not
      {Visible /IfVisible true def}
     if}
    {IfVisible
      {Invisible /IfVisible false def}
     if}
  ifelse} def
\tx@InitOL end
/TheOL ##1 def}}}

% Alternative method for the same goal (needed when PSTricks nodes are used)
\def\SeminarAltProgressiveOverlays{%
\def\pst@initoverlay##1{%
\pst@Verb{%
/BeginOL {%
  /NumOL ED
  NumOL -1 eq NumOL 0 eq NumOL TheOL eq or or
    {IfVisible not
      {Visible /IfVisible true def}
     if}
    {IfVisible
      {Invisible /IfVisible false def}
     if}
  ifelse} def
\tx@InitOL end 
/Visible {initclip} def
/Invisible {CP newpath OLUnit itransform moveto clip newpath moveto} def
/TheOL ##1 def}}}

% Generation of the next overlay (minor add-on)
% =============================================
% (it increment automatically the number of the current overlay)
\newcommand{\SeminarNextOverlay}[1]{%
\addtocounter{overlay}{1}%
\begin{overlay}{\the\c@overlay}#1\end{overlay}}

% To force all items in the various list environments to appear
% in their own overlay (minor add-on)
% ==================================
\let\itemORIG\item

\def\SeminarItemInOverlay{%
\def\item{%
\addtocounter{overlay}{1}%
\overlay{\the\c@overlay}%
\itemORIG}}

\catcode`\@=\TheAtCode\relax
\endinput
%% END seminar.bg3
