%%
%% This is file `kaupaper.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% kautools.dtx  (with options: `paper')
%% 
%% This is a generated file.
%% 
%% Copyright (c) 2011-2014 Stefan Berthold <stefan.berthold@kau.se>
%% 
%% This file is part of the kauthesis bundle.
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%% 
%% This work has the LPPL maintenance status `author-maintained'.
%% 
%% The Current Maintainer and author of this work is Stefan Berthold.
%% 
%% This work consists of all files listed in manifest.txt.
%% 
%% kautools.dtx
%% Copyright (c) 2011-2015 Stefan Berthold <stefan.berthold@kau.se>
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{kaupaper}
    [2014/10/22 v1.15 Karlstad University kautools bundle]
\RequirePackage{xkeyval}
\PassOptionsToPackage{hypertexnames=false}{hyperref}

\define@cmdkeys[kua]{paper}[kua@]{author,title,subtitle,refprefix,reference,refnote,email,refstr,vanity,subdelimiter,label,summary,limitations,participation}
\define@cmdkeys[kua]{paperlist}[kua@]{printparticipation,tocline}
\setkeys[kua]{paper}{refstr=\reprintedname}

\ProcessOptionsX[kua]<paper>

\RequirePackage{kauparts}
\RequirePackage{ifthen}
\RequirePackage{tikz}

\RequirePackage{ragged2e}
\RequirePackage{hyphenat}

\RequirePackage{kaulanguage}

\AtBeginDocument{%
  \setname{reprintedname}{Reprinted from}{Ursprungligen publicertad i}%
  \setname{appendedpapersname}{List of Appended Papers}{Bifogade publiceringar}%
  \setname{participationname}{Comments on my Participation}{Kommentarer p\aa{} min medverka}%
  \setname{papername}{Paper}{Publicering}%
}

\newcounter{kua@section}
\newcounter{kua@equation}
\newcounter{kua@figure}
\newcounter{kua@table}

\newcounter{kua@paper}

\providecommand\thepaper{}
\providecommand\thepapertitle{}

\newcommand\kua@warning\relax
\newcommand\kua@dowarn{\gdef\kua@warning{\@latex@warning@no@line{List data created from the kaupaper environment was outdated. Rerun to get the lists right}}}
\AtEndDocument{\kua@warning}

\newcommand\kua@listof[4]{%
  \IfFileExists{\jobname.#1}%
    {% check whether empty file
      \newread\reader%
      \openin\reader\jobname.#1%
      \read\reader to \readmacro%
      \ifeof\reader%
        \textcolor{red}{\ldots{} will be available after the next \LaTeX{} run.}%
        \@starttoc{#1}%
        %\AtEndDocument{\@latex@warning@no@line{Rerun to get the list of #2 right}}%
        \kua@dowarn%
      \else% file not empty -> create list
        #3\@starttoc{#1}#4%
      \fi%
    }%
    {% file does not exist
      \textcolor{red}{\ldots{} will be available after the next \LaTeX{} run.}%
      \@starttoc{#1}%
      %\AtEndDocument{\@latex@warning@no@line{Rerun to get the list of #2 right}}%
      \kua@dowarn%
    }%
}
\newcommand\listofpapers[1][]{%
  \setkeys[kua]{paperlist}{printparticipation=yes,tocline=yes,#1}
  \section*{\appendedpapersname}%
  \ifthenelse{\equal{\kua@tocline}{yes}}{%
    \addcontentsline{toc}{section}{\appendedpapersname}%
  }{}%
  \kua@listof{pap}{appended papers}{%
    \begin{enumerate}%
    \renewcommand\theenumi{\textbf{\Roman{enumi}}}%
  }{\end{enumerate}}%
  \ifthenelse{\equal{\kua@printparticipation}{yes}}{%
    \subsection*{\participationname}%
    \kua@listof{pcp}{participation in appended papers}{}{}%
  }{}%
}

\newcommand\l@paper[2]{%
  \item #1%
}

\newcommand\listofsummaries{%
  \kua@listof{sum}{paper summaries}{}{}%
}

\newcommand\l@summary[2]{%
  #1%
}

\newcommand\l@limit[2]{%
  %\paragraph{Limitations.}
  #1%
}

\newcommand\l@participation[2]{%
  #1%
}

\newcommand\papercover{%
  \begin{tikzpicture}[remember picture,overlay]%
    \path (current page.center)%
      node%
        [ node distance=\baselineskip%
        , text width=\textwidth%
        , text centered%
        ] (refstr) {\kua@refstr};%
      \ifthenelse{\equal{\kua@subtitle}{}}{%
        \node%
          [ node distance=1.5\baselineskip%
          , above=of refstr%
          , text width=\textwidth%
          , text centered%
          , font=\LARGE\bfseries%
          ] {\nohyphens{\kua@title}};%
      }{%
        \node%
          [ node distance=1.5\baselineskip%
          , above=of refstr%
          , text width=\textwidth%
          , text centered%
          , font=\large\bfseries%
          ] (sub) {\nohyphens{\kua@subtitle}};%
        \node%
          [ node distance=1pt%
          , above=of sub%
          , text width=\textwidth%
          , text centered%
          , font=\LARGE\bfseries%
          ] {\nohyphens{\kua@title}};%
      }%
      \node%
        [ node distance=\baselineskip%
        , below=of refstr%
        , text width=\textwidth%
        , text centered%
        , font=\large%
        ] {\nohyphens{\kua@reference}\ifthenelse{\equal{\kua@refnote}{}}{}{\mbox{}\\\medskip\nohyphens{\kua@refnote}}}%
    ;%
  \end{tikzpicture}%
}

\newenvironment{kaupaper}[1][]{%
  \setcounter{kua@section}{\value{section}}%
  \setcounter{kua@equation}{\value{equation}}%
  \setcounter{kua@figure}{\value{figure}}%
  \setcounter{kua@table}{\value{table}}%
  \setcounter{section}{0}%
  \setcounter{equation}{0}%
  \setcounter{figure}{0}%
  \setcounter{table}{0}%
  \setkeys[kua]{paper}{subtitle=,vanity=,subdelimiter={---},refprefix=,refnote=,label=,summary={\string\textcolor{red}{Use the \string\texttt{summary} key in the \string\texttt{kaupaper} environment to add a summary.}},participation={\string\textcolor{red}{Use the \string\texttt{participation} key in the \string\texttt{kaupaper} environment to add a comment.}},limitations={},#1}%
  \setcounter{kua@paper}{\value{kup@part}}\stepcounter{kua@paper}%
  \kaupart[tocentry=false,label=\kua@label,body=\papercover\kua@vanity]{\papername}%
  \ifthenelse{\equal{\kua@subtitle}{}}%
    {\ifthenelse{\equal{\kua@refnote}{}}%
      {\addcontentsline{pap}{paper}{\kua@author. \kua@title. \kua@refprefix\kua@reference.}}%
      {\addcontentsline{pap}{paper}{\kua@author. \kua@title. \kua@refprefix\kua@reference.\smallskip\\\kua@refnote}}%
     \addcontentsline{toc}{part}{\textsc{\papername} \Roman{kua@paper}: \\\kua@title}}%
    {\ifthenelse{\equal{\kua@refnote}{}}%
      {\addcontentsline{pap}{paper}{\kua@author. \kua@title\kua@subdelimiter\kua@subtitle. \kua@refprefix\kua@reference.}}%
      {\addcontentsline{pap}{paper}{\kua@author. \kua@title\kua@subdelimiter\kua@subtitle. \kua@refprefix\kua@reference.\smallskip\\\kua@refnote}}%
     \addcontentsline{toc}{part}{\textsc{\papername} \Roman{kua@paper}: \\\kua@title\kua@subdelimiter\kua@subtitle}}%
  \addcontentsline{sum}{summary}{\string\subsubsection*{\papername~\Roman{kua@paper} -- \kua@title}\kua@summary}%
  \ifthenelse{\equal{\kua@limitations}{}}{}{%
    \addcontentsline{sum}{limit}{\kua@limitations}}%
  \addcontentsline{pcp}{participation}{\string\paragraph{\papername~\Roman{kua@paper}}\kua@participation}%
  \renewcommand*\thepaper{\papername~\Roman{kua@paper}}%
  \renewcommand*\thepapertitle{\kua@title}%
  \renewcommand\maketitle{%
    \thispagestyle{plain}%
    \centering%
      \Large\bfseries%
      \vspace*{0.15\textheight}%
      \kua@title\par%
      \addvspace{1ex}%
      \ifthenelse{\equal{\kua@subtitle}{}}{}{\large\kua@subtitle}%
      \par\addvspace{\baselineskip}%
      \normalsize%
      \kua@author\\[0.25\baselineskip]%
      \normalfont%
    \par\addvspace{2\baselineskip}\justifying%
  }%
}{%
  \setcounter{section}{\value{kua@section}}%
  \setcounter{equation}{\value{kua@equation}}%
  \setcounter{figure}{\value{kua@figure}}%
  \setcounter{table}{\value{kua@table}}%
  \clearpage%
}
\endinput
%%
%% End of file `kaupaper.sty'.
