%% gretl.sty, originally written by Allin Cottrell, <2005/11/07>
%% To be used when generating the Gretl manuals from LaTeX source.

\RequirePackage{ae}
\RequirePackage{amsmath,xcolor,amssymb}
\ProvidesPackage{gretl}

\newcommand{\scriptname}{Listing}
\newcommand{\GCR}{\textit{Gretl Command Reference}{}}
\newcommand{\GUG}{the \textit{Gretl User's Guide}{}}
\newcommand{\PKGBOOK}{\textit{Gretl Function Package Guide}{}}

\newcommand{\gtitle}[1]{\vspace*{1in}
   {\Huge \sffamily #1}\par
   \vspace{.5in}
  \includegraphics{figures/gretl-logo} 
}

\newcommand{\htitle}[1]{\vspace*{1in}
   {\Huge \sffamily #1}\par
   \vspace{.5in}
  \includegraphics{figures/hansl-logo} 
}

\newcommand{\gsubtitle}[1]{%
   {\Large \sffamily #1}
   \vspace{.5in}
}

\newcommand{\guidechap}[1]{%
   \hypertarget{chap:#1}{}%
   \include{#1}
}

\ifcsname c@chapter\endcsname
  \setcounter{secnumdepth}{1}
  \setcounter{chapter}{-1}
\else
  \setcounter{secnumdepth}{2}
\fi

\newcommand{\app}[1]{\textsf{#1}}
\newcommand{\cmd}[1]{\texttt{#1}}
\newcommand{\dtk}[1]{\texttt{\detokenize{#1}}}
\newcommand{\varname}[1]{\texttt{#1}}
\newcommand{\option}[1]{\texttt{-{}-#1}}
\newcommand{\dollar}[1]{\texttt{\$#1}}
\newcommand{\package}[1]{\textsl{#1}}

\newcommand{\ttsl}[1]{\ttfamily{\textsl{#1}}\normalfont}

%% --- a few handy math additions ---------------------------------------

\DeclareMathOperator*{\argmin}{\mathrm{Argmin}}
\DeclareMathOperator*{\argmax}{\mathrm{Argmax}}
\newcommand{\LogLik}{\ensuremath\ell}
\newcommand{\stackunder}[2]{\ensuremath\mathrel{\mathop{#2}\limits_{#1}}}
\newcommand{\pder}[2]{\frac{\ensuremath\partial #1}{\partial #2}}
\newcommand{\convp}{\stackrel{\mathrm{p}}{\longrightarrow}}
\newcommand{\convd}{\stackrel{\mathrm{d}}{\longrightarrow}}
\renewcommand{\vec}[1]{{\rm vec}(#1)}

%% --- bibtex logo (avoid use of doc.sty for this) ----------------------

\def\BibTeX{{\rmfamily B\kern-.05em%
     \textsc{i\kern-.025em b}\kern-.08em%
     T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}

%% ----------------------------------------------------------------------

\newenvironment{textcode}{\par\small\ttfamily}
{\normalfont\normalsize\par}

%% basic inline code style
\DefineVerbatimEnvironment%
{code}{Verbatim}
{fontsize=\small, xleftmargin=1em}

%% style for the first, or only, piece of hansl code inside
%% a \script environment
\DefineVerbatimEnvironment%
{scode}{Verbatim}
{frame=lines, framesep=2ex, fontsize=\small,
 formatcom=\color{myteal}, rulecolor=\color{mygray}}

%% style for an incomplete piece of hansl code inside a
%% a \script environment (without any horizontal rules)
\DefineVerbatimEnvironment%
{scodebit}{Verbatim}
{fontsize=\small, formatcom=\color{myteal}}

%% style for output to accompany hansl code inside a
%% a \script environment
\DefineVerbatimEnvironment%
{outbit}{Verbatim}
{fontsize=\small, formatcom=\color{myteal}}

%% like scode above, but without the upper separator rule
\DefineVerbatimEnvironment%
{scodebot}{Verbatim}
{frame=bottomline, framesep=2ex, fontsize=\small,
 formatcom=\color{myteal}, rulecolor=\color{mygray}}

\renewcommand{\arraystretch}{1.2}

\definecolor{mygray}{rgb}{0.85,0.85,0.85} 
\definecolor{myteal}{rgb}{0.0,0.25,0.15}
\definecolor{steel}{rgb}{0.03,0.20,0.45} 

%% offset "tip" text
\newcommand{\tip}[1]{\par\vspace{4pt}
 \ding{43} {\small \sffamily #1}\par}

%% rule for use in bibliography
\newcommand{\bibliorule}{\rule[-.01in]{.5in}{.005in}}

%% floats
\renewcommand{\topfraction}{0.9}
\renewcommand{\bottomfraction}{0.8}
\renewcommand{\textfraction}{0.07}

%% add script as float ("Listing")
\ifcsname c@chapter\endcsname
 \newcounter{script}[chapter]
 \renewcommand \thescript
     {\ifnum \c@chapter>\z@ \thechapter.\fi \@arabic\c@script}
\else
 \newcounter{script}
 \renewcommand \thescript
     {\@arabic\c@script}
\fi
\def\fps@script{tbp}
\def\ftype@script{1}
\def\ext@script{los}
\def\fnum@script{\scriptname\nobreakspace\thescript}
\newenvironment{script}
               {\@float{script}}
               {\end@float}
\newenvironment{script*}
               {\@dblfloat{script}}
               {\end@dblfloat}
\ifcsname theHscript\endcsname%
   \ifcsname c@chapter\endcsname
   \renewcommand\theHscript{\thechapter.\arabic{script}}
   \else
   \renewcommand\theHscript{\arabic{script}}
   \fi
\else%
   \ifcsname c@chapter\endcsname
   \newcommand\theHscript{\thechapter.\arabic{script}}
   \else
   \newcommand\theHscript{\arabic{script}}
   \fi
\fi%

%% section headings

\renewcommand\section{\@startsection{section}{1}{\z@}%
                                   {-3ex \@plus -1ex \@minus -.2ex}%
                                   {.5ex \@plus .2ex}%
                                   {\normalfont\large\sffamily}}

\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
                                     {-2.5ex\@plus -1ex \@minus -.2ex}%
                                     {.2ex \@plus .5ex}%
                                     {\normalfont\bfseries}}

\renewcommand\subsubsection{\@startsection{subsubsection}{2}{\z@}%
                                     {-2ex\@plus -1ex \@minus -.2ex}%
                                     {.2ex \@plus .2ex}%
                                     {\normalfont\normalsize\itshape}}

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

%% The rest of the material below is specific to the book
%% document class

\ifcsname c@chapter\endcsname
\else
 \endinput
\fi

%% Make TOC match revised chapter style
\renewcommand\tableofcontents{%
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
    \chapter*{\contentsname
        \@mkboth{\contentsname}{\contentsname}}%
    \@starttoc{toc}%
    \if@restonecol\twocolumn\fi}

%% get the bibliography into the TOC
\renewenvironment{thebibliography}[1]
     {\chapter*{\bibname\@mkboth{\bibname}{\bibname}}
      \label{refs}
      \addcontentsline{toc}{chapter}{\bibname}
      \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}

%% custom page headings 
\if@twoside
  \def\ps@headings{%
      \let\@oddfoot\@empty\let\@evenfoot\@empty
      \def\@evenhead{\thepage\hfil\sffamily\leftmark}%
      \def\@oddhead{{\sffamily\rightmark}\hfil\sffamily\thepage}%
      \let\@mkboth\markboth
    \def\chaptermark##1{%
      \markboth {{%
        \ifnum \c@secnumdepth >\m@ne
          \if@mainmatter
            \@chapapp\ \thechapter. \ %
          \fi
        \fi
        ##1}}{}}%
    \def\sectionmark##1{%
      \markright {{%
        \ifnum \c@secnumdepth >\z@
          \thesection. \ %
        \fi
        ##1}}}}
\else
  \def\ps@headings{%
    \let\@oddfoot\@empty
    \def\@oddhead{{\sffamily\rightmark}\hfil\sffamily\thepage}%
    \let\@mkboth\markboth
    \def\chaptermark##1{%
      \markright {{%
        \ifnum \c@secnumdepth >\m@ne
          \if@mainmatter
            \@chapapp\ \thechapter. \ %
          \fi
        \fi
        ##1}}}}
\fi

\def\@makechapterhead#1{%
  \vspace*{10\p@}%
  {\parindent \z@ \centering \normalfont
    \ifnum \c@secnumdepth >\m@ne
        \Large\sffamily \@chapapp\space \thechapter
        \par\nobreak
        \vskip 5\p@
    \fi
    \interlinepenalty\@M
    \huge \sffamily #1\par\nobreak
    \vskip 30\p@
  }}

\def\@schapter#1{%
 \if@twocolumn \@topnewpage[\@makeschapterhead{#1}]
 \else \@makeschapterhead{#1} 
 \@afterheading\fi
  \refstepcounter{chapter}
  \if\pdfoutput=1 \@writetorep{#1}{chapter.\theHchapter}{0}\fi 
 }

\def\@makeschapterhead#1{%
  \vspace*{10\p@}%
  {\parindent \z@ \centering
    \normalfont
    \interlinepenalty\@M
    \Large \sffamily  #1\par\nobreak
    \vskip 30\p@
  }}

%% table of contents
\renewcommand{\l@chapter}[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{2em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
      \penalty\@highpenalty
    \endgroup
  \fi}

\renewcommand{\l@section}{\@dottedtocline{1}{1.5em}{2.8em}}
\renewcommand{\l@subsection}{\@dottedtocline{2}{4.3em}{3.2em}}

%% For downloadable example scripts which appear within \begin{script}
%% and \end{script}: the first argument serves as the basename of the
%% associated script file (".inp" will be added), and a \label{} is
%% automatically constructed out of "ex:" plus this argument. The
%% second argument is the caption text for the script.
\newcommand{\scriptinfo}[2]{%
  \def\@inpname{#1.inp}
  \caption{#2 %
  \href{http://gretl.sourceforge.net/guidefiles/\@inpname}%
  {[Download $\blacktriangledown$]}}
  \label{ex:#1}
}

\endinput
%% end of gretl.sty
