% LaTeX macros for figures
% \def\lastedit{2009-01-20 04:08:24 by stolfi}

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

  % Figures with manual placement (never floated):
  %   \jsfig{LABEL}{CONTENTS}{CAPTION}
  %   \jstab{LABEL}{CONTENTS}{CAPTION}
  % where CONTENTS is any hmode stuff.
  
  \newcommand{\jsfig}[3]{
    \begin{center}
      \botcaptionbox
        {\hbox to 0.9\textwidth{\hss #2\hss}}
        {figure}
        {#1}
        {#3}
    \end{center}
  }

  \newcommand{\jstab}[3]{
    \begin{center}
      \topcaptionbox
        {\hbox to 0.9\textwidth{\hss #2\hss}}
        {table}
        {#1}
        {#3}
    \end{center}
  }

  % Adjust width of figures to fit page width:
  \newcommand{\fullfigbox}[1]{\hbox to 0.900\textwidth{\hss #1 \hss}}
  \newcommand{\halffigbox}[1]{\hbox to 0.475\textwidth{\hss #1 \hss}}
  
  % Clients may want to redefine this
  \newcommand{\figbox}[1]{\fullfigbox{#1}}

  % Inset figures:
  %    \jsfigright{LABEL}{CONTENTS}{CAPTION}{FRACWD}{TEXT}
  %    \jstabright{LABEL}{CONTENTS}{CAPTION}{FRACWD}{TEXT}
  % where CONTENTS is any hmode stuff.
  % Start the caption with \cenering to get centered captions.

  \newcommand{\jsfigright}[5]{
    \noindent
    \hbox
      { \dimen2=\parindent
        \dimen0=\textwidth
        \advance\dimen0 by -#4\textwidth
        \advance\dimen0 by -0.05\textwidth
        \begin{minipage}[t]{\dimen0}
          \parindent=\dimen2 
          #5
          \hrule height 0pt depth 0pt
          \kern 2mm
          \hrule height 0pt depth 0pt
        \end{minipage}
        \vtop
          { \hrule height 0pt width 0pt
            \botcaptionbox
              {\hbox to #4\textwidth{\hss #2\hss}}
              {figure}
              {#1}
              {#3}
          }
      }
  }
  
  \newcommand{\jstabright}[5]{
    \noindent
    \hbox
      { \dimen2=\parindent
        \dimen0=\textwidth
        \advance\dimen0 by -#4\textwidth
        \advance\dimen0 by -0.05\textwidth
        \begin{minipage}[t]{\dimen0}
          \parindent=\dimen2 
          #5
          \hrule height 0pt depth 0pt
          \kern 2mm
          \hrule height 0pt depth 0pt
        \end{minipage}
        \vtop
          { \hrule height 0pt width 0pt
            \topcaptionbox
              {\hbox to #4\textwidth{\hss #2\hss}}
              {table}
              {#1}
              {#3}
          }
      }
  }

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