% LaTeX macros for captioning boxes
% \newcommand{\lastedit}{2014-06-25 15:04:40 by stolfilocal}
% Extracted 93-12-02 by Jorge Stolfi 
%   from eps-macros.tex of 12 Oct 90 by Jack Snoeyink 
%   w/ ideas from John Hershberger and code from Tom Rokicki 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% SUMMARY
%
%   The most important macros defined by this file are:
% 
%     \botcaptionbox{BOX}{STYLE}{LABEL}{CAPTION}
%     \topcaptionbox{BOX}{STYLE}{LABEL}{CAPTION}
%     \captionbox{BOX}{STYLE}{LABEL}{CAPTION}
%       Adds a numbered caption to the given box, defines the
%       given label to be its number, and returns a box
%       containing everything.  Here:
%
%         BOX
%           is a box containing a figure or table.
%         
%         STYLE
%           is the caption style {figure}, {figure*}, {table}, or {table*}.
%         
%         LABEL
%           is the label to be assigned to the figure. If empty, the figure
%           will not be labeled.
%         
%         CAPTION
%           is of the form {} or {Caption}.
%           If empty, the figure will not be captioned or labeled.
% 
%       The \captionbox macro is intended for use
%       in \begin{figure}, \begin{table}, etc., which decide the
%       placement according to the STYLE; while \topcationbox and
%       \botcaptionbox are for hand-assembly of figure-like things.
%
% OPTIONS
%
%   The following macros affect the operation of \captionbox,
%   and may be redefined by the user:
%
%     \botcaptionstyle
%     \topcaptionstyle
%       Macros executed before typesetting the text of \topcaptionbox
%       or \botcaptionbox, respectively.
%
%     \captionstyle
%       A macro executed before typesetting the text of \captionbox.
%
% 
%     \botcaptionskip
%       Spacing above \botcaptionbox.
% 
%     \topcaptionskip
%       Spacing below \botcaptionbox or below \topcaptionbox.
%
%     \abovecaptionskip
%     \belowcaptionskip
%       Spacing above and below \captionbox.
%
%  For non-english versions, or to add other types of floats, the
%  macro \definefnum should be changed.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\catcode`@=11 \endlinechar=-1   % Use LaTeX internals, igore line breaks

% Default options
%
\def\captionstyle{}
\def\botcaptionstyle{\raggedright}
\def\topcaptionstyle{\centering}

\newdimen{\topcaptionskip}
\setlength{\topcaptionskip}{5pt}
\newdimen{\botcaptionskip}
\setlength{\botcaptionskip}{5pt}

\newbox\@captionee

\long\def\botcaptionbox#1#2#3#4{
  \setbox\@captionee\hbox{#1}
  \parbox[t]{\wd\@captionee}{
    \box\@captionee
    \let\@captionstyle=\botcaptionstyle
    \abovecaptionskip=\botcaptionskip
    \belowcaptionskip=0pt
    \@captionandlabel{#2}{#3}{#4}
  }
}

\long\def\topcaptionbox#1#2#3#4{
  \setbox\@captionee\hbox{#1}
  \parbox[t]{\wd\@captionee}{
    \let\@captionstyle=\topcaptionstyle
    \abovecaptionskip=0pt
    \belowcaptionskip=\topcaptionskip
    \@captionandlabel{#2}{#3}{#4}
    \box\@captionee
  }
}

\long\def\captionbox#1#2#3#4{
  \setbox\@captionee\hbox{#1}
  \parbox[t]{\wd\@captionee}{
    \box\@captionee
    \let\@captionstyle=\captionstyle
    \@captionandlabel{#2}{#3}{#4}
  }
}

\def\@captionandlabel#1#2#3{ % {style} {label} {caption}
  \def\testit{#3}
  \ifx\testit
    \empty
  \else
    % remove optional stars
    \@captypeunstarred#1*.
    % format the caption:
    \caption[#3]{
      \def\baselinestretch{1}
      \Large\normalsize\rm\@captionstyle
      \ignorespaces
      #3
    }
    % check for empty label:
    \def\testit{#2}
    \ifx\testit
      \empty
    \else
      \label{#2}
    \fi
  \fi
}

% remove two-column star from style:
%
\def\@captypeunstarred#1*#2.{
  \def\@captype{#1}
}

% Parse the caption (without the [short caption] option)

\def\getc@ption#1\endc@ption{
  
}

% Ugly latex hacking to get the right figure/table name:
%
\def\definefnumPt#1{
  \def\fnum@figure{\textbf{Figura \ref{#1}}}
  \def\fnum@table{\textbf{Tabela \ref{#1}}}
  \def\fnum@code{\textbf{Algoritmo \ref{#1}}}
}
\def\definefnumEn#1{
  \def\fnum@figure{\textbf{Figure \ref{#1}}}
  \def\fnum@table{\textbf{Table \ref{#1}}}
  \def\fnum@code{\textbf{Algorithm \ref{#1}}}
}
\def\definefnum#1{\definefnumEn{#1}}

\catcode`@=12 \endlinechar=`\^^M

