% \iffalse meta-comment
%
% Copyright (C) 2011 by Rapha��l Pinson <raphink@gmail.com>
% ---------------------------------------------------------------------------
% 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 `maintained'.
%
% The Current Maintainer of this work is Rapha��l Pinson.
%
% This work consists of the files fancytabs.dtx and fancytabs.ins
% and the derived filebase fancytabs.sty.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{fancytabs.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{fancytabs}
%<*package>
   [2016/03/29 1.9 Fancy page border tabs with Tikz]
%</package>
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{fancytabs}
\usepackage{scrpage2}
\makeatletter
\global\let\tikz@ensure@dollar@catcode=\relax
\makeatother
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
 \DocInput{fancytabs.dtx}
 \PrintChanges
 \PrintIndex
\end{document}
%</driver>
% \fi
%
% \CheckSum{142}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%
% \changes{v1.9}{2016/03/29}{Add RTL support (thanks to Zvika Haramaty)}
% \changes{v1.8}{2012/09/17}{Use lengths were fit}
% \changes{v1.7}{2011/09/04}{Add Makefile}
% \changes{v1.6}{2011/09/03}{Bugfix: Fix babel for non-frenchb users (thanks to Marco Daniel)}
% \changes{v1.5}{2011/09/01}{Bugfix: Put rotate box around text only (thanks to Wolfgang Ulmer)}
% \changes{v1.4}{2011/04/20}{Protect internal macros. Display a fancytab in documentation. Make it babel-safe.}
% \changes{v1.3}{2011/04/18}{Add tabfloor and accessors}
% \changes{v1.2}{2011/04/17}{Add tabgap. Fix tabtop by adding tabheight/2}
% \changes{v1.1}{2011/04/16}{Add tabtextvpos and tabtexthpos macros}
% \changes{v1.0}{2011/04/14}{Initial version}

% \DoNotIndex{\newcommand,\newenvironment}
%
% \providecommand*{\url}{\texttt}
% \GetFileInfo{fancytabs.dtx}
% \title{The \textsf{fancytabs} package\thanks{This document
%  corresponds to \textsf{fancytabs}~\fileversion,
%  dated~\filedate.}}
% \author{Rapha\"el Pinson \\ \url{raphink@gmail.com}}
% \date{\fileversion~from \filedate}
%
% \fancytabsStyle{\small\scshape}
% \chead{\fancytab{The Fancytabs Manual}{1}}
% \pagestyle{scrheadings}
%
% \maketitle
%
% \thispagestyle{scrheadings}
% 
% \begin{abstract}
% The \textsf{fancytabs} package allows to insert tabs
% on the border of pages.
% \end{abstract}
%
% \section{Usage}
%
% \subsection{Adding a tab}
%
% \DescribeMacro{\fancytab}
% The |\fancytab| macro adds a new tab.
% It takes two mandatory arguments, and one optional:
% |\fancytab[<LEFT,RIGHT>]{<text>}{<position>}|
% and displays the text in the tab, on given vertical position,
% at LEFT or RIGHT horizontal position. Default is RIGHT.
%
% \subsection{Adding a tab to all odd pages with scrpage2}
%
% The following code adds a tab with the chapter name,
% positioned by chapter order, on each odd page.
%
% \begin{verbatim}
% \documentclass{scrbook}
% \usepackage{scrpage2}
% \usepackage{fancytabs}
% \usepackage{lipsum}
% 
% % Capture chapter head
% \let\oldchapter\chapter
% \newcommand\temphead{}
% \newcommand\chaphead{}
% \renewcommand\chapter[2][\temphead]{%
%    \renewcommand\temphead{#2}%
%    \renewcommand\chaphead{#2}%
%    \oldchapter[#1]{#2}}
%
% % Set central right header to display tab
% % for both scrplain and scrheadings
% \cohead[\fancytab{\chaphead}{\thechapter}]
%        {\fancytab{\chaphead}{\thechapter}}
% \renewcommand*{\chapterpagestyle}{scrplain}
% \pagestyle{scrheadings}
% 
% \begin{document}
% \chapter{A chapter}
% 
% \lipsum
% \lipsum
%
% \end{document}
% \end{verbatim}
%
% \subsection{Parameters}
%
% \DescribeMacro{\fancytabsStyle}
% The style of the text in the tab.
% Default is |\Large\scshape|.
%
% \DescribeMacro{\fancytabsHeight}
% Define the height of the tab.
% Default is |4cm|.
%
% \DescribeMacro{\fancytabsWidth}
% Define the height of the tab.
% Default is |1cm|.
%
% \DescribeMacro{\fancytabsCount}
% Define the maximum amount of tabs on a page.
% After |\tabcount| tabs are displayed,
% the next tab is displayed on top of the page again.
% Default is |6|.
%
% \DescribeMacro{\fancytabsLeftColor}
% Define the left color for the tab gradient.
% Default is |white|.
%
% \DescribeMacro{\fancytabsRightColor}
% Define the right color for the tab gradient.
% Default is |gray!50|.
%
% \DescribeMacro{\fancytabsTop}
% Define margin on top of the top tab.
% Default is |\tab@height|.
%
% \DescribeMacro{\fancytabsTextVPos}
% Define the relative vertical position
% of the text in the tab.
% Default is |0.5|.
%
% \DescribeMacro{\fancytabsTextHPos}
% Define the relative horizontal position
% of the text in the tab.
% Default is |\tab@textvpos|.
%
% \DescribeMacro{\fancytabsGap}
% Define the gap between two tabs.
% Default is |0in|.
%
% \DescribeMacro{\fancytabsFloor}
% Define the starting number for incrementation.
% This is useful if you want to pass for example
% |\arabic{chapter}| as counter but not put tabs
% for previous chapters.
% Default is |0|.
%
% \DescribeMacro{\fancytabsRotate}
% Define the text rotation.
% Default is |90|.
%
% \StopEventually{}
%
% \section{Implementation}
%
% \iffalse
%<*package>
% \fi
%
%    \begin{macrocode}
\ProvidesPackage{fancytabs}
\RequirePackage{tikz}
\RequirePackage{etoolbox}
%    \end{macrocode}
% 
% \begin{macro}{Variables}
%    \begin{macrocode}
\newcommand{\tab@style}{\Large\scshape}
\newlength{\tab@height}
\setlength{\tab@height}{4cm}
\newlength{\tab@width}
\setlength{\tab@width}{1cm}
\newcommand{\tab@count}{6}
\newcommand{\tab@leftcolor}{white}
\newcommand{\tab@rightcolor}{gray!50}
\newlength{\tab@top}
\setlength{\tab@top}{\the\tab@height}
\newcommand{\tab@textvpos}{0.5}
\newcommand{\tab@texthpos}{\tab@textvpos}
\newlength{\tab@gap}
\setlength{\tab@gap}{0in}
\newcommand{\tab@floor}{0}
\newcommand{\tab@rotate}{90}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{Accessors}
%    \begin{macrocode}
\newcommand{\fancytabsStyle}[1]{\renewcommand{\tab@style}{#1}}
\newcommand{\fancytabsHeight}[1]{\setlength{\tab@height}{#1}}
\newcommand{\fancytabsWidth}[1]{\setlength{\tab@width}{#1}}
\newcommand{\fancytabsCount}[1]{\renewcommand{\tab@count}{#1}}
\newcommand{\fancytabsLeftColor}[1]{\renewcommand{\tab@leftcolor}{#1}}
\newcommand{\fancytabsRightColor}[1]{\renewcommand{\tab@rightcolor}{#1}}
\newcommand{\fancytabsTop}[1]{\setlength{\tab@top}{#1}}
\newcommand{\fancytabsTextVPos}[1]{\renewcommand{\tab@textvpos}{#1}}
\newcommand{\fancytabsTextHPos}[1]{\renewcommand{\tab@texthpos}{#1}}
\newcommand{\fancytabsGap}[1]{\setlength{\tab@gap}{#1}}
\newcommand{\fancytabsFloor}[1]{\renewcommand{\tab@floor}{#1}}
\newcommand{\fancytabsRotate}[1]{\renewcommand{\tab@rotate}{#1}}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{Babel safety}
%
% Some |babel| packages (such as |frenchb|) handle semi-colons which
% is incompatible with |tikz|. This part disables semi-colon handling
% by babel locally.
%
%    \begin{macrocode}
\AtBeginDocument{\@ifpackageloaded{babel} 
  {\@ifundefined{active@char;}{}{% 
    \g@addto@macro\tikz@installcommands{% 
      \shorthandoff{;}}% 
      \g@addto@macro\tikz@uninstallcommands{% 
        \shorthandon{;}}% 
  }% 
  }{}% 
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fancytab}
% We define the |\fancytab| macro to generate a new tab.
%    \begin{macrocode}
\newcommand{\fancytab}[3][RIGHT]{%
  \ifstrequal{#1}{LEFT}
    {
      \newcommand{\eastwest}{west}
      \newcommand{\multiplier}{0.5}
    }
    { %else
      \newcommand{\eastwest}{east}
      \newcommand{\multiplier}{-0.5}
    }
  \begin{tikzpicture}[remember picture,overlay]%
    \node[yshift={-1*(\the\tab@top+\the\tab@height/2+
                 mod(#3-1-\tab@floor,\tab@count)*
                 (\the\tab@height+\the\tab@gap))},
                  xshift=\multiplier*\the\tab@width]
      at (current page.north \eastwest) {
      \tikz\shade[shading=axis,bottom color=\tab@leftcolor,
                  top color=\tab@rightcolor,shading angle=-90]
        (0,0) rectangle (\the\tab@width,\the\tab@height)
           node[rotate=0]
                  at (\tab@texthpos*\the\tab@width,\tab@textvpos*\the\tab@height)
                      {\rotatebox{\tab@rotate}{\tab@style#2}};%
    };%
  \end{tikzpicture}%
}
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%</package>
% \fi
%
% \Finale
\endinput