summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/widetable/widetable.sty
blob: 499f033ccdc749375b84e123aba4ac60f4f55613 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
%%
%% This is file `widetable.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% widetable.dtx  (with options: `package')
%% 
%% Copyright 2009 Claudio Beccari
%% 
%%  This package is distributed in the hope that it will be useful,
%%  but WITHOUT ANY WARRANTY; without even the implied warranty of
%%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
%% 
%%  This work may be distributed and/or modified under the
%%  conditions of the LaTeX Project Public License, either version 1.3
%%  of this license or (at your option) any later version.
%%  The latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%%  and version 1.3 or later is part of all distributions of LaTeX
%%  version 2003/12/01 or later.
%% 
%%  This work has the LPPL maintenance status "maintained".
%% 
%%  The Current Maintainer of this work is Claudio Beccari
%% 
\NeedsTeXFormat{LaTeX2e}[2005/12/01]
\ProvidesPackage{widetable}%
   [2009/10/26 v.1.1 Package for typesetting specified width tables]
\dimendef\wt@Numer=2
\dimendef\wt@Denom=4
\countdef\wt@Num=2
\countdef\wt@Den=4
\countdef\wt@I=6
\def\wt@segno{}

\newif\ifm@mifetex
  \m@mifetexfalse
\IfFileExists{ifetex.sty}{\RequirePackage{ifetex}\relax}{%
  \PackageWarningNoLine{widetable}{%
    If there is an `ifetex' package then it is not installed.\MessageBreak
    The package is being emulated}%
\m@mifetextrue
\newif\ifetex
  \etexfalse
\ifx\eTeXversion\undefined
\else
  \ifx\eTeXversion\@undefined
  \else
    \ifx\eTeXversion\relax
    \else
      \ifnum\eTeXversion>0\relax
        \etextrue
      \fi
    \fi
  \fi
\fi
%%\EmulatedPackage{ifetex}[2008/07/23]% from memoir.cls
}

\def\dividi#1\per#2\in#3{%
  \begingroup
  \wt@Numer #1\relax \wt@Denom #2\relax
  \ifdim\wt@Denom<\z@ \wt@Denom -\wt@Denom \wt@Numer -\wt@Numer\fi
  \ifdim\wt@Numer<\z@ \def\wt@segno{-}\wt@Numer -\wt@Numer\fi
  \ifdim\wt@Denom=\z@
    \edef\wt@Q{\ifdim\wt@Numer<\z@-\fi\strip@pt\maxdimen}%
  \else
    \wt@Num=\wt@Numer \wt@Den=\wt@Denom \divide\wt@Num\wt@Den
    \edef\wt@Q{\number\wt@Num.}%
    \advance\wt@Numer -\wt@Q\wt@Denom \wt@I=6
    \@whilenum \wt@I>\z@ \do{\wt@dividiDec\advance\wt@I\m@ne}%
  \fi
  \edef\x{\noexpand\endgroup\noexpand\def\noexpand#3{\wt@segno\wt@Q}}
  \x
}

\def\wt@dividiDec{%
  \wt@Numer=10\wt@Numer \wt@Num=\wt@Numer \divide\wt@Num\wt@Den
  \edef\wt@q{\number\wt@Num}\edef\wt@Q{\wt@Q\wt@q}%
  \advance\wt@Numer -\wt@q\wt@Denom}

\def\scala#1\per#2\diviso#3\in#4{\begingroup
\wt@Num #2\relax \wt@Den #3\relax
\ifnum\wt@Den<\z@ \wt@Den -\wt@Den \wt@Num -\wt@Num \fi
\ifnum\wt@Den=\z@
  \@tempdima\ifnum\wt@Num<0-\fi\maxdimen
\else
  \@tempdima\dimexpr#1*\wt@Num/\wt@Den\relax
\fi
\edef\x{\noexpand\endgroup\noexpand\def\noexpand#4{\the\@tempdima}}%
\x}

\newdimen\wt@width

\def\wt@starttabular{\expandafter\tabular\expandafter{\wt@preamble}}

\def\widetable#1#2{%
  \def\@tempC{widetable}\setlength{\wt@width}{#1}%
  \def\wt@preamble{#2}\wt@getTable}

\newif\ifwt@scartare\wt@scartarefalse

\def\endwidetable{%
  \ifwt@scartare
    \noindent\null
  \else
    \tabcolsep=\z@
    \setbox\z@=\hbox{\wt@starttabular\the\toks@\endtabular}%
    \tabcolsep=1cm\relax
    \setbox\tw@=\hbox{\wt@starttabular\the\toks@\endtabular}%
    \advance\wt@width-\wd\z@
    \@tempdimb=\wd\tw@
    \advance\@tempdimb-\wd\z@
    \ifetex
      \scala\tabcolsep\per\wt@width\diviso\@tempdimb\in\tabcolsep\relax
    \else
      \dividi\wt@width\per\@tempdimb\in\@tempA
      \tabcolsep=\@tempA\tabcolsep
    \fi
    \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
}

\endinput
%%
%% End of file `widetable.sty'.