%%%  UP Project Style
%%%  Copyright (C) 2001 Vil\'em Vychodil, <vilem.vychodil@upol.cz>
%%% 
%%%  This style is free software; you can redistribute it and/or modify
%%%  it under the terms of the GNU General Public License as published by
%%%  the Free Software Foundation; either version 2 of the License, or
%%%  (at your option) any later version.
%%% 
%%%  This style is distributed in the hope that it will be useful,
%%%  but WITHOUT ANY WARRANTY; without even the implied warranty of
%%%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%%%  GNU General Public License for more details.
%%% 
%%%  You should have received a copy of the GNU General Public License
%%%  along with this file; if not, write to the Free Software
%%%  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

%% Poznamky
%% kveten 2009, Jan Outrata (JO)

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{uproject}[2001/06/22 UP Project Style]

%% style options
\def\@inspdf#1{#1}
\def\@print@lot{}
\def\@print@lof{}
\def\@lospace{\newpage}
\DeclareOption{joinlists}{\gdef\@lospace{}}
\DeclareOption{figures}{\gdef\@print@lof{\listoffigures{}}}
\DeclareOption{tables}{\gdef\@print@lot{\listoftables{}}}
\DeclareOption{nopdf}{\gdef\@inspdf#1{}}
\ProcessOptions

%% labels, references (must precede the style inclusion)
\let\@oldlabel=\label
\let\@oldref=\ref
\let\@oldpageref=\pageref
\let\@oldcite=\cite
\let\@oldbiblabel=\@biblabel
\let\@oldlbibitem=\@lbibitem
\let\@oldbibitem=\@bibitem

\def\label#1{\@pdfdest{lnk#1}\@oldlabel{#1}}
\def\ref#1{\@pdflink{\@oldref{#1}}{lnk#1}}
\def\pageref#1{\@pdflink{\@oldpageref{#1}}{lnk#1}}
\def\cite#1{\@pdflink{\@oldcite{#1}}{bib#1}}

\def\@lbibitem[#1]#2{\@pdfdest{bib#2}\@oldlbibitem[#1]{#2}}
\def\@bibitem#1{\@pdfdest{bib#1}\@oldbibitem{#1}}

%% ams styles
\usepackage{amsmath}
\usepackage{amsbsy}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{euscript}

%% localization, page layout
\usepackage{a4}
\usepackage{booktabs}
\usepackage{czech}
\usepackage{multicol}

%% figures, logos
\usepackage{epsfig}
\usepackage{mflogo}

%% disallow two-sided documents
\if@twoside
  \PackageError{uproject}
  {Two-sided document is not allowed}{}
\fi

%% abstract
\def\abstract#1{\gdef\@abstract{#1}}

%% group
\def\@group{}
\def\group#1{\gdef\@group{#1}}

%% subtitle
\def\@subtitle{}
\def\subtitle#1{\gdef\@subtitle{#1}}

%% title page
\def\ifdef#1{\ifx#1\undefined\null\else#1\fi}
%% JO: HNUSNY HACK pro sekvencni fyzicke cislovani stranek, protoze
%% napr. \tableofcontents cislovani resetuje
\let\oldsetcounter=\setcounter
\renewcommand\setcounter[2]{%
  \ifx\not{#1}{page}\oldsetcounter{#1}{#2}\fi}
%% JO: cislovani stran hned arabskymi cislicemi
\def\maketitle{%\pagenumbering{roman}%
  \begin{titlepage}%
    \let\footnotesize\small
    \let\footnoterule\relax
%% JO: cislovani stran od 1
    \setcounter{page}{1}%
    \begin{center}
      {\large P\v R\'IRODOV\v EDECK\'A FAKULTA UNIVERZITY PALACK\'EHO \par
        KATEDRA INFORMATIKY \par}
      \vskip 3cm
      {\LARGE\bfseries{RO\v CN\'IKOV\'Y PROJEKT} \\}
      \vskip 4cm
      {\LARGE \@title \ifx\@subtitle\undefined\null\else\\[1em]\@subtitle\fi}
      \vskip 4cm
      \centerline{\epsfbox{uplogo.eps}}
    \end{center}
    \vfill
    {\noindent \@date \hfill%
      \begin{tabular}{ll} 
        \ifdef{\@author} \\ \ifdef{\@group} \\ 
      \end{tabular}}
    \ifx\@@docauthor\undefined
    \@docinfo{\@author}{\@title}\else\@docinfo{\@@docauthor}{\@@doctitle}\fi
    \newpage
    \thispagestyle{empty}
    \ifx\@abstract\undefined
    \null\else\null\vfill
    \begin{center}
      \textbf{\abstractname}
    \end{center}
    {\rm \@abstract}
    \fi
    \vfill\null
    \newpage
  \end{titlepage}%
  \tableofcontents\@lospace\@print@lof\@lospace\@print@lot
  \newpage
  \pagestyle{plain}
%%  \pagenumbering{arabic}
  \setcounter{footnote}{0}}%

%% references, bibliography
\renewenvironment{thebibliography}[1]
{\insertoutline{1}{\refname}%
  \section*{\refname
    \@mkboth{\MakeUppercase\refname}{\MakeUppercase\refname}}%
  \addcontentsline{toc}{section}{\refname}
  \list{\@biblabel{\@arabic\c@enumiv}}%
  {\settowidth\labelwidth{\@biblabel{#1}}%
    \leftmargin\labelwidth
    \advance\leftmargin\labelsep
    \@openbib@code
    \usecounter{enumiv}%
    \let\p@enumiv\@empty
    \renewcommand\theenumiv{\@arabic\c@enumiv}}%
  \sloppy
  \clubpenalty4000
  \@clubpenalty \clubpenalty
  \widowpenalty4000%
  \sfcode`\.\@m}
{\def\@noitemerr
  {\@latex@warning{Empty `thebibliography' environment}}%
  \endlist}

%% section counters
\renewcommand\thepart         {\@Roman\c@part.}
\renewcommand\thesection      {\@arabic\c@section.}
\renewcommand\thesubsection   {\thesection\@arabic\c@subsection.}
\renewcommand\thesubsubsection{\thesubsection\@arabic\c@subsubsection.}
\renewcommand\theparagraph    {\thesubsubsection\@arabic\c@paragraph.}
\renewcommand\thesubparagraph {\theparagraph\@arabic\c@subparagraph.}

%% appendix counters
\renewcommand\appendix{\par
  \setcounter{section}{0}%
  \setcounter{subsection}{0}%
  \gdef\thesection{\@@appendix@Alph\c@section}}

\def\@@appendix@Alph#1{%
  \ifcase#1\or A\or B\or C\or D\or E\or F\or G\or H\or I\or J\or
   K\or L\or M\or N\or O\or P\or Q\or R\or S\or T\or U\or V\or W\or X\or
    Y\or Z\else\@ctrerr\fi.}

%% table / figure counters
\renewcommand\thetable{\@arabic\c@table.}
\renewcommand\thefigure{\@arabic\c@figure.}

%% czech caption style
\long\def\@makecaption#1#2{%
  \vskip\abovecaptionskip
  \sbox\@tempboxa{#1~#2}%
  \ifdim \wd\@tempboxa >\hsize
    #1~#2\par
  \else
    \global \@minipagefalse
    \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
  \fi
  \vskip\belowcaptionskip}

%% indent all paragraphs (czech typographical convention}
\def\@afterheading{}

%% colors, hyper links
\def\@pdfsetcolor#1#2{\@inspdf{\special{pdf:bc #1}}%
  #2\@inspdf{\special{pdf:ec}}}
\def\@@pdflinkcolor{[0.2 0.3 0.6]}

\def\@pdflink#1#2{\leavevmode%
  \@inspdf{%
    \special{pdf:bann << /Type /Annot /Subtype /Link /Border [ 0 0 0 ] /A
      << /S /GoTo /D (#2) >> >>}}%
  {\@pdfsetcolor{\@@pdflinkcolor}{#1}}\@inspdf{\special{pdf: eann}}\relax}

\def\@pdfuri#1#2{\leavevmode%
  \@inspdf{%
    \special{pdf:bann << /Type /Annot /Subtype /Link /Border [ 0 0 0 ] /A
      << /S /URI /URI (#2) >> >>}}%
  {\@pdfsetcolor{\@@pdflinkcolor}{#1}}\@inspdf{\special{pdf: eann}\relax}}

\def\@pdfdest#1{\@inspdf{\special{pdf:dest (#1) [ @thispage /FitH @ypos ]}}}

%% external hyperlinks
\def\@@ignorewhs#1{%
  \bgroup \catcode`\ =9 \catcode`\~=12 \catcode`\_=12 \catcode`\@=12
  #1}

\def\mail{\@@ignorewhs{\s@mail}}
\def\s@mail#1{\@pdfuri{\lowercase{\tt\char60#1\char62}}{mailto:#1}\egroup}

\def\url{\@@ignorewhs{\s@url}}
\def\s@url#1{\@pdfuri{\lowercase{\tt#1}}{#1}\egroup}

\def\link#1{\gdef\@linktxt{#1}\@@ignorewhs{\s@link}}
\def\s@link#1{\@pdfuri{\@linktxt}{#1}\egroup}

%% internal hyperlinks
\def\emphref#1{\gdef\@emphreftxt{#1}\@@ignorewhs{\s@emphref}}
\def\s@emphref#1{\@pdflink{\@emphreftxt}{lnk#1}\egroup}

\def\hyplabel#1{\@pdfdest{lnk#1}}

\def\emphref#1{\gdef\@emphreftxt{#1}\@@ignorewhs{\s@emphref}}
\def\s@emphref#1{\@pdflink{\@emphreftxt}{lnk#1}\egroup}

%% initialize outlines
\def\insertoutline#1#2{%
  \@inspdf{\special{pdf:outline #1 
      << /Title (#2) /Dest [ @thispage /FitH @ypos ] >>}}}

\def\nextoutline#1{\gdef\@@nextoutlinelabel{#1}}
\let\@oldsect=\@sect
\def\@sect#1#2#3#4#5#6[#7]#8{%
  \ifx\@@nextoutlinelabel\undefined\insertoutline{#2}{#7}%
  \else\insertoutline{#2}{\@@nextoutlinelabel}%
  \let\@@nextoutlinelabel=\undefined\fi%
  \@oldsect{#1}{#2}{#3}{#4}{#5}{#6}[#7]{#8}}

%% insert outlines manually
\def\outline{\insertoutline{1}}
\def\suboutline{\insertoutline{2}}
\def\subsuboutline{\insertoutline{3}}
\def\subsubsuboutline{\insertoutline{4}}

%% document initialization
\special{\@inspdf{pdf:docview <</PageMode /UseOutlines >>}}

%% document info
\def\@docinfo#1#2{\@inspdf{%
    \special{ pdf: docinfo << /Author (#1) /Creator (#1) /Title (#2) >> }}}

\def\docinfo#1#2{\gdef\@@docauthor{#1}\gdef\@@doctitle{#2}}

%% adjust page size
\sloppy
\addtolength{\oddsidemargin}{-1cm}
\addtolength{\textwidth}{2cm}
\addtolength{\topmargin}{-1cm}
\addtolength{\textheight}{1.5cm}

\endinput
