%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Contents: Special Commands for the LShort2e Introduction
% $Id: lshort.sty,v 1.2 2003/03/19 20:57:45 oetiker Exp $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% By Tobias Oetiker
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\errorcontextlines=10

%save pageref an label
\let\lsspageref\pageref
\ProvidesPackage{lshort}
\RequirePackage{etex}
\RequirePackage[autolanguage]{numprint}
\RequirePackage[english,francais,german,greek,estonian]{babel}
\RequirePackage{mflogo}
\RequirePackage{hologo} % for \XeTeX logo *ak*
\RequirePackage{verbatim}
\RequirePackage{fancyheadings}
\RequirePackage{calc}
\RequirePackage{lastpage}
\RequirePackage{amsmath,latexsym,amsthm}
\RequirePackage[retainorgcmds]{IEEEtrantools}
\RequirePackage[psamsfonts]{amssymb}
\RequirePackage{cmmib57}% Use blueSky cmmib5 cmmib7 cmsy
\RequirePackage[all]{xy}
\RequirePackage[T1]{fontenc}
\RequirePackage[utf8]{inputenc}
\RequirePackage{lmodern}
\RequirePackage[babel=true,kerning=true]{microtype}
%\RequirePackage{textcomp}
%\RequirePackage{type1cm}% remove size restrictions
%\RequirePackage{aeguill}
% some packages which draw a euro
\RequirePackage{textcomp}
% need some magic here to keep the original definition of rightarrow
\newcommand{\org@Rightarrow}{}
\let\org@Rightarrow\Rightarrow
\usepackage{marvosym}
\let\MVRightarrow\Rightarrow
\let\Rightarrow\org@Rightarrow
%%%%
\RequirePackage[gen]{eurosym} % redefines \EUR
% \RequirePackage{eurosans}
% \let\EUROSANS\euro
% marvosym defines \EUR, \EURtm, \EURhv and \EURcr (with \def), while europs
% uses \providecommand to define them :-( so let's first undefine them:
\let\EURtm\undefined
\let\EURhv\undefined
\let\EURcr\undefined
% \RequirePackage{europs}
%\RequirePackage[mathcal]{euscript}
%\IfFileExists{eucal.sty}
%  {\RequirePackage[psamsfonts]{eucal}}
%  {\IfFileExists{euscript.sty}
%  {\RequirePackage[mathcal]{euscript}}{}}

\RequirePackage{url}
% Lets have some nice headings
%
\pagestyle{fancyplain}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection{} #1}}
\lhead[\fancyplain{}{\bfseries\thepage}]
    {\fancyplain{}{\bfseries\rightmark}}
\rhead[\fancyplain{}{\bfseries\leftmark}]
    {\fancyplain{}{\bfseries\thepage}}
\cfoot[]{}
\RequirePackage{pgfbaseplot}
\RequirePackage{tikz}
\usetikzlibrary{%
  arrows,%
  calc,%
  fit,%
  patterns,%
  plotmarks,%
  shapes.geometric,%
  shapes.misc,%
  shapes.symbols,%
  shapes.arrows,%
  shapes.callouts,%
  shapes.multipart,%
  shapes.gates.logic.US,%
  shapes.gates.logic.IEC,%
  er,%
  automata,%
  backgrounds,%
  chains,%
  topaths,%
  trees,%
  petri,%
  mindmap,%
  matrix,%
  calendar,%
  folding,%
  fadings,%
  through,%
  positioning,%
  scopes,%
  decorations.fractals,%
  decorations.shapes,%
  decorations.text,%
  decorations.pathmorphing,%
  decorations.pathreplacing,%
  decorations.footprints,%
  decorations.markings,%
  shadows}
\addtolength{\headheight}{1.6pt}
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Adapted from TeX FAQ
\renewcommand{\Email}{\begingroup \def\UrlLeft{<}\def\UrlRight{>} \urlstyle{tt}\Url}     % email address
\def\mailto|#1|{\href{mailto:#1}{\Email|#1|}}        % url to mail somewhere
%\newcommand{\CTANref}{\begingroup \urlstyle{tt}\Url}     %
\newcommand{\CTANref}{\begingroup \urlstyle{tt}\Url}     %
\def\CTAN|#1|{\href{http://www.ctan.org/#1}{\CTANref|CTAN://#1|}}
\newcommand\Newsgroup{\begingroup \urlstyle{tt}\Url} % newsgroup
\let\URL\url                                         % just a URL

\newcommand{\PSi}{\textsc{PostScript}\index{PostScript@\textsc{PostScript}}}
\newcommand{\EPSi}{Kapseldatud \textsc{Post\-Script}%
\index{kapseldatud PostScript@kapseldatud \textsc{PostScript}}%
\index{PostScript@\textsc{PostScript}!kapseldatud}}
\newcommand{\ePSi}{kapseldatud \textsc{Post\-Script}%
\index{kapseldatud PostScript@kapseldatud \textsc{PostScript}}%
\index{PostScript@\textsc{PostScript}!kapseldatud}}

% Earlier paragraphs were separated by some space
%
%\setlength{\parindent}{0pt}
%\setlength{\parskip}{1.5ex plus 0.7ex minus 0.6ex}

\newcommand{\manual}{\glqq\LaTeX{} Manual\grqq~\cite{manual}}
\newcommand{\companion}{\glqq The \LaTeX{} Companion\grqq~\cite{companion}}
\newcommand{\guide}{\glqq Kohalik juhend\grqq~\cite{local}}
\newcommand{\contrib}[3]{#1\quad\mailto|#2|{\small\\\quad\textit{#3}}\\[1ex]}
%
% Some commands for helping with INDEX creation
%
%\newcommand{\bs}{\symbol{'134}}%Print backslash
\newcommand\bs{\char '134 }
%\newcommand{\bs}{\ensuremath{\mathtt{\backslash}}}%Print backslash
% Index entry for a command (\cih for hidden command index
\newcommand{\eei}[1]{%
% \index{laiendid!\texttt{#1}}\texttt{#1}
\index{#1@\texttt{\hspace*{-1.2ex}.#1}}\texttt{.#1}}
% probably add handling of period like handling of \ in \ci
\newcommand{\fni}[1]{%
% \index{kiri!#1@\texttt{\bs#1}}%
\index{#1@\texttt{\hspace*{-1.2ex}\bs #1}}\texttt{\bs #1}}
\newcommand{\cih}[1]{%
% \index{käsud!#1@\texttt{\bs#1}}%
\index{#1@\texttt{\hspace*{-1.2ex}\bs #1}}}
\newcommand{\ci}[1]{\cih{#1}\texttt{\bs #1}}
%Package
\newcommand{\paih}[1]{%
% \index{paketid!#1@\textsf{#1}}%
\index{#1@\textsf{#1}}}
\newcommand{\pai}[1]{%
\paih{#1}\textsf{#1}}
% Index entry for an environment
\newcommand{\ei}[1]{%
% \index{keskkonnad!\texttt{#1}}%
\index{#1@\texttt{#1}}%
\texttt{#1}}
% Indexentry for a word (Word inserted into the text)
\newcommand{\wi}[1]{\index{#1}#1}
%
% Typesetting Commands
%
\newenvironment{lscommand}%
    {\nopagebreak\par\small\addvspace{3.2ex plus 0.8ex minus 0.2ex}%
     \vskip -\parskip
     \noindent%
     \begin{tabular}{|l|}\hline\rule{0pt}{1em}\ignorespaces}%
    {\\\hline\end{tabular}\par\nopagebreak\addvspace{3.2ex plus 0.8ex
        minus 0.2ex}%
     \vskip -\parskip}
%
% Type setting Code Fragments
%
\newenvironment{code}{\begin{quote}}{\end{quote}}
%
% Intro Environment
\newenvironment{intro}{\sffamily}{\vspace*{2ex minus 1.5ex}}
%
\newcommand{\secby}[2]{\nopagebreak\par\addvspace{-1.5ex}%
     \vskip -\parskip\noindent{\tiny Autor #1 \mailto|#2|}\par\nopagebreak%
     \addvspace{1ex plus 0.8ex minus 0.2ex}%
     \vskip -\parskip\noindent\ignorespaces}
%
% propper bookmark entries in pdftex

\ifx\hypersetup\undefined\else
\pdfstringdefDisableCommands{\edef\ci{\textbackslash}}%
\pdfstringdefDisableCommands{\edef\sim{\textasciitilde}}%
\pdfstringdefDisableCommands{\edef\circ{\textdegree}}%
\pdfstringdefDisableCommands{\edef\ldots{... }}%
\fi

%\noindent\addvspace{1ex}\small #1 <\texttt{#2}>\par\addvspace{2ex}\noindnet\ignorespaces}
%
%
% Symbol Entry for Math Symbol Tables
%
\newcommand{\X}[1]{$#1$&\texttt{\string#1}\hspace*{1ex}}
% normal text ....
\newcommand{\SC}[1]{#1&\texttt{\string#1}\hspace*{1ex}}
% for accents in text mode
\newcommand{\A}[1]{#1&\texttt{\string#1}\hspace*{1ex}}
\newcommand{\B}[2]{#1#2&\texttt{\string#1{} #2}\hspace*{1ex}}

\newcommand{\W}[2]{$#1{#2}$&
  \texttt{\string#1}\texttt{\string{\string#2\string}}\hspace*{1ex}}
\newcommand{\Y}[1]{$\big#1$ &\texttt{\string#1}}  %
% Mathsymbol Table
\newsavebox{\symbbox}
\newenvironment{symbols}[1]%
{\par\vspace*{2ex}
\renewcommand{\arraystretch}{1.1}
\begin{lrbox}{\symbbox}
\hspace*{4ex}\begin{tabular}{@{}#1@{}}}%
{\end{tabular}\end{lrbox}\makebox[\linewidth]{\usebox{\symbbox}}\par\medskip}
%
% Special Prep for AMS Symbols Printout
% Should work if AMS is not available
%

%% we have no PS versions of the rsfs fonts ... so this is a nogo for pdf
%\ifx\HyPsd@pageref\undefined
\RequirePackage{mathrsfs}
%\fi
\RequirePackage{latexsym}
\RequirePackage[mathcal]{euscript}
%
% Print |--| to show a distance
%
\newcommand{\demowidth}[1]{\rule{0.3pt}{1.3ex}\rule{#1}{0.3pt}\rule{0.3pt}{1.3ex}}
%
%
% --- example ----
% This is an environment to set LaTeX examples.
% On the left side the source text and on the
% right side the typeset text.
%
% \begin{example}
% \Large This is Large
% \end{example}
% This Part is stolen from the verbaim.sty by FMi
%
\newwrite\example@out
\newcounter{exacnt}
\setcounter{exacnt}{1}
\newlength{\savefboxrule}
\newlength{\savefboxsep}
\newlength{\outdent}
\setlength{\outdent}{1cm}
\addtolength{\headwidth}{\outdent}
\newenvironment{example}%
{\begingroup% Lets Keep the Changes Local
  \@bsphack
  \immediate\openout \example@out \jobname.exa
  \let\do\@makeother\dospecials\catcode`\^^M\active
  \def\verbatim@processline{%
    \immediate\write\example@out{\the\verbatim@line}}%
  \verbatim@start}%
{\immediate\closeout\example@out\@esphack\endgroup%
                                %
                                % And here comes my part. :-
                                %
  \stepcounter{exacnt}%
  \setlength{\parindent}{0pt}%
  \par\addvspace{3.0ex plus 0.8ex minus 0.5ex}\vskip -\parskip
%  Page \lsspageref{exa:\theexacnt}
\expandafter\ifx\csname r@exa\theexacnt\endcsname\relax\else
%\ifx\pdfoutput\undefined % We're not running pdftex
%  \ifodd\lsspageref{exa\theexacnt}\hspace*{0pt}\else\hspace*{-\outdent}\fi%
%\else
%% HyPsd@pageref internal hyperref command v6.69c
  \ifodd\HyPsd@pageref{exa\theexacnt}\hspace*{0pt}\else\hspace*{-\outdent}\fi%
%\fi
\fi
\makebox[\linewidth][l]{%
%\raisebox{-\height}[0pt][\totalheight]{%
  \begin{minipage}[c]{0.5\outdent+0.46\linewidth-3mm}%
    \small\verbatiminput{\jobname.exa}
  \end{minipage}%
                                %}%
  \hspace{5mm}%
  \setlength{\savefboxrule}{\fboxrule}%
  \setlength{\fboxrule}{0.1pt}%
  \setlength{\savefboxsep}{\fboxsep}%
  \setlength{\fboxsep}{3mm}%
                                %  \raisebox{-\height}[0pt][\totalheight]{%
  \fbox{%
    \begin{minipage}{0.5\outdent+0.54\linewidth-3.5mm-2\fboxrule-2\fboxsep}%
      \setlength{\fboxrule}{\savefboxrule}%
      \setlength{\fboxsep}{\savefboxsep}%
      \setlength{\fboxrule}{0.5pt}%
      \setlength{\parskip}{1ex plus 0.4ex minus 0.2ex}%
      \begin{trivlist}\item\small\input{\jobname.exa}
      \end{trivlist}
    \end{minipage}
    }%
%  }%
}\label{exa\theexacnt}%
\par\addvspace{3ex plus 0.8ex minus 0.5ex}\vskip -\parskip
}

\newenvironment{lined}[1]%
 {\begin{center}\begin{minipage}{#1}\hrule\medskip}
 {\vspace{-1ex}\hrule \end{minipage}\end{center}}
% I want no headers on pages created by clearpage

\renewcommand{\cleardoublepage}
    {\clearpage\if@twoside \ifodd\c@page\else
    \hbox{}\thispagestyle{empty}\newpage\if@twocolumn\hbox{}\newpage\fi\fi\fi}


% section titles should be raggright ... since
% this is not a trivial change I have to repeat the definitions here ...
% taken from book.cls

\renewcommand\section{\@startsection {section}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\raggedright\normalfont\Large\bfseries}}
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\raggedright\normalfont\large\bfseries}}
\renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\raggedright\normalfont\normalsize\bfseries}}

\addto\extrasestonian{\bbl@deactivate{~}}

\RequirePackage{multicol}
\renewenvironment{theindex}{%
  \chapter*{\indexname}%
  \@mkboth{\MakeUppercase\indexname}{\MakeUppercase\indexname}%
  \parskip\z@ \@plus .3\p@\relax
  \columnsep 9pt
  \rightskip0pt plus4em \pretolerance10001
  \let\item\@idxitem
  \vspace{-\baselineskip}\begin{multicols}{3}\small
}{\end{multicols}}
\renewcommand\@idxitem{\par\hangindent 12\p@\noindent}%%
\renewcommand\subitem{\@idxitem \hspace*{8\p@}}%%
\renewcommand\indexspace{\par \vskip 6pt plus 5pt minus 3pt\relax}%
