% Crepbook Package -- version 0.1 for LaTeX2e
%
% This package is intend to use with the songbook package.
% It defines some layout for automatic songbook generation.
% See http://github.com/patacrep/songbook-core/

\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{crepbook}[2014/04/13 Crepbook Package, version 0.1]

\newif{\iffancycapo}
\DeclareOption{fancy-capo}{\fancycapotrue}
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{SongbookUtils}}

\ProcessOptions\relax

\RequirePackage{SongbookUtils}

\ifpictures
    \fancycapotrue
\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Multilanguage management

\AtBeginDocument{
    % Default names (english)
    \def\labelversionname{Version:}
    \def\labeldatename{Date:}
    \def\labelauthorname{aAuthors:}
    \def\labelwebname{Web:}
    \def\labelmailname{Email:}
    
    \IfStrEq{\mainlanguage}{french}{
        % French names
        \def\labelversionname{Version :}
        \def\labeldatename{Date :}
        \def\labelauthorname{Auteurs :}
        \def\labelwebname{Web :}
        \def\labelmailname{Mail :}
    }{}
}

\def\andname{and}
\def\lastandname{\unskip, and}


\def\lang#1{\def\mainlanguage{#1}}

% End of multilanguage management
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Title page
\long\def\subtitle#1{\long\def\@subtitle{#1}}
\def\version#1{\def\@version{#1}}
\def\web#1{\def\@web{#1}}
\def\mail#1{\def\@mail{#1}}
\def\email#1{\def\@email{#1}}
\def\picture#1{\def\@picture{#1}}
\def\picturecopyright#1{\def\@picturecopyright{#1}}
\def\footer#1{\def\@footer{#1}}

\def\clearheadinfo{
    \author{}%
    \title{No title}%
    \subtitle{}%
    \version{}%
    \web{}%
    \mail{}%
    \email{}%
    \picture{}%
    \picturecopyright{}%
}

\clearheadinfo

\def\maketitle{
    \@maketitle
    \clearheadinfo
}


\newcounter{@inst}
\newcounter{@auth}
\newcounter{auco}

\def\@titlefont{\Huge\bfseries\boldmath}
\def\@subtitlefont{\large\bfseries\boldmath}

\def\@maketitle{
    \begin{titlepage}
        \thispagestyle{empty}
        \begin{center}
            {\rule{\textwidth}{1mm}}
            {\@titlefont\@title\par}
            \if!\@subtitle!\else 
                {\hfil\@subtitlefont\@subtitle\par}
            \fi
            {\rule{\textwidth}{1mm}}
        \end{center}
        \vfil
        \begin{flushleft}
            \begin{tabular}{l l}
                \if!\@version!\else{\textbf{\labelversionname}} & \@version \\ \fi
                \if!\@date!\else{\textbf{\labeldatename}} & \@date \\ \fi
                \if!\@author!\else{\textbf{\labelauthorname}} & \begin{tabular}[t]{c}\@author\end{tabular} \\ \fi
                \if!\@web!\else{\textbf{\labelwebname}} &  \url{\@web} \\ \fi
                \if!\@mail!\else{\textbf{\labelmailname}} &  \url{\@mail} \\ \fi
            \end{tabular}
        \end{flushleft}
        \vfil
        \begin{center}
            \includegraphics[keepaspectratio=true, width=12cm, height=12cm]{\@picture}
            \vskip1em
            {\hfil\hbox{\small \@picturecopyright}}
        \end{center}
        \begin{flushright}
        \vfil
        {\hfil\rule{.4\textwidth}{.75pt}\par}
        \@footer
        \end{flushright}
    \end{titlepage}
}

% Fancy capo
\iffancycapo %
    \newlength{\capoheight}
    \setlength{\capoheight}{1.5cm}
    \renewcommand\capo[1]{%
        \iftranscapos%
            \transpose{#1}%
        \fi%
        \mbox{%
            \includegraphics[height=\capoheight]{capodastre}%
            \put(-22,8){\Large #1}
            }%
    }
\fi

% Fonts definitions
\def\chordfont#1{\gdef\@chordfont{#1}}
\def\@chordfont{\small\it}

\renewcommand{\idxtitlefont}{\sffamily\bfseries}
\renewcommand{\idxauthfont}{\sffamily\bfseries}
\renewcommand{\idxheadfont}{\sffamily\it\LARGE}
\renewcommand{\idxrefsfont}{\bfseries}


% Configuration of the songs package
\titleprefixword{}
\renewcommand{\stitlefont}{\LARGE\bf}
\renewcommand{\printchord}[1]{\@chordfont #1}
\renewcommand{\chorusfont}{\it}
\renewcommand{\lyricfont}{\normalfont\normalsize}
\renewcommand{\showauthors}{%
    \hbox{\normalsize\songauthors}%
}

\endinput
