%%
%% This is file `widetable.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% widetable.dtx  (with options: `package')
%%   ______________________________________________________
%%   The WIDETABLE bundle
%%   Copyright (C) 2009-2017 Claudio Beccari
%%   All rights reserved
%% 
%%   License information appended
%% 

\NeedsTeXFormat{LaTeX2e}[2016/01/01]
\ProvidesPackage{widetable}%
   [2017/09/09 v.1.4 Package for typesetting specified width tables]

\ProvidesPackage{widetable}[2017/09/05 v.1.2 A simpler way to produce
     tables of specified width]
\dimendef\wt@Numer=2
\dimendef\wt@Denom=4
\countdef\wt@Num=2
\countdef\wt@Den=4
\usepackage{xparse}
\newcommand\WT@scale[4]{\begingroup
\wt@Num #2\relax \wt@Den #3\relax
\ifnum#3=\z@
  \@tempdima\ifnum#2<0-\fi\maxdimen
\else
  \@tempdima\dimexpr#1*#2/#3\relax
\fi
\edef\x{\noexpand\endgroup\noexpand\setlength{#4}{\the\@tempdima}}%
\x}
\newdimen\wt@width
\newif\ifwt@scartare\wt@scartarefalse

\DeclareDocumentCommand\widetable{m O{c} m}
{% OPENING WIDETABLE
  \def\@tempC{widetable}%
  \setlength{\wt@width}{#1}%
  \def\wt@preamble{#3}%
  \def\wt@starttabular{\tabular[#2]{#3}}%
  \wt@getTable}%
\def\endwidetable{% CLOSING WIDETABLE
  \ifwt@scartare
    \noindent\null
  \else
    \tabcolsep=\z@
    \setbox\z@=\hbox{\wt@starttabular\the\toks@\endtabular}%
    \tabcolsep=6pt\relax
    \setbox\tw@=\hbox{\wt@starttabular\the\toks@\endtabular}%
    \ifdim\wt@width<\wd\z@
       \@tempdimb=\dimexpr\wd\tw@-\wd\z@\relax
       \PackageWorning{widetable}{%
       The natural width `\the\wd\z@' of the tabular
       material\MessageBreak
       is larger than the specified width
       `\the\wt@width'\MessageBreak\null\space \MessageBreak
       The table is typeset with the default column spacing}%
    \else
       \@tempdimb=\dimexpr\wt@width-\wd\z@\relax
    \fi
    \@tempdimc=\dimexpr\wd\tw@-\wd\z@\relax
      \WT@scale{\tabcolsep}{\@tempdimb}{\@tempdimc}{\tabcolsep}\relax
    \wt@starttabular\the\toks@\endtabular
  \fi
  \ignorespacesafterend
}

\def\wt@finetabella{\end{widetable}}%

\def\wt@getTable#1\end#2{\def\@tempB{#2}%
  \ifx\@tempB\@tempC
    \toks@={#1}%
    \expandafter\wt@finetabella
  \else
    \PackageWarning{widetable}{%
      The table contains environment `\@tempB' %
      \MessageBreak
      not enclosed in braces. This is expressly forbidden!%
      \MessageBreak
      The table is not typeset  and is substituted%
      \MessageBreak
      with a framed box}%
      \advance\wt@width-2\fboxsep
    \noindent\fbox{\parbox{\wt@width}{The table was not typeset
     because it contains a visible \texttt{\char`\\end} in one
     or more cells.}}\par
    \expandafter\wt@finishTable
  \fi
}

\def\wt@finishTable#1\end#2{%
  \def\@tempB{#2}%
  \ifx\@tempB\@tempC
    \wt@scartaretrue\expandafter\wt@finetabella
  \else
    \expandafter\wt@finishTable
  \fi
}

%% 
%% Copyright 2009-2017 Claudio Beccari
%% 
%% Distributable under the LaTeX Project Public License,
%% version 1.3c or higher (your choice). The latest version of
%% this license is at: http://www.latex-project.org/lppl.txt
%% 
%% This work is "author-maintained"
%% 
%% This work consists of this file widetable.dtx, a README file
%% the manifest.txt file, and the derived files:
%%     widetable.sty and widetable.pdf.
%% 
%% 
%% By running pdflatex on widetable.dtx the user gets the sty
%% file and the English documentation file in
%% PDF format.
%% 
%%
%% End of file `widetable.sty'.
