From ea6dc95d491201abe5f09dd2ce16ccc4bd9a9f69 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Thu, 19 Nov 2009 18:36:45 +0000 Subject: widetable 1.1 (26oct09) git-svn-id: svn://tug.org/texlive/trunk@16082 c570f23f-e606-0410-a88d-b1316a301751 --- .../source/latex/widetable/widetable.dtx | 167 ++++++++++++++++++--- 1 file changed, 149 insertions(+), 18 deletions(-) (limited to 'Master/texmf-dist/source/latex/widetable') diff --git a/Master/texmf-dist/source/latex/widetable/widetable.dtx b/Master/texmf-dist/source/latex/widetable/widetable.dtx index f2560db3f9f..282ead13f02 100644 --- a/Master/texmf-dist/source/latex/widetable/widetable.dtx +++ b/Master/texmf-dist/source/latex/widetable/widetable.dtx @@ -5,7 +5,7 @@ %\NeedsTeXFormat{LaTeX2e}[2005/12/01] %\ProvidesPackage{widetable}% %<*package> - [2009/07/21 v.1.0 Package for typesetting specified width tables] + [2009/10/26 v.1.1 Package for typesetting specified width tables] % %<*driver> \documentclass{ltxdoc} @@ -31,7 +31,7 @@ \end{document} % % \fi -% \CheckSum{222} +% \CheckSum{314} % \begin{abstract} % This package allows to typeset tables of specified width, provided they fit in one % page. Instead of introducing an infinite stretching glue, which has an @@ -51,7 +51,7 @@ % 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". +% This work has the LPPL maintenance status ``maintained''. % % The Current Maintainer of this work is Claudio Beccari % @@ -59,7 +59,7 @@ % given in the file `manifest.txt'. % % The list of derived (unpacked) files belonging to the distribution -% and covered by LPPL is defined by the unpacking scripts (with +% and covered by the LPPL is defined by the unpacking scripts (with % extension .ins) which are part of the distribution. % %\section{Introduction} @@ -67,12 +67,12 @@ % a specified width, it is necessary to introduce in the delimiter declaration |@{...}| % of (possibly) the first cell of the model row a declaration such as % \begin{verbatim} -% \extraclosep{\fill} +% \extracolsep{\fill} % \end{verbatim} % in addition to other possible printable delimiters, such as vertical lines, and % other fixed spacing commands. The effect is that the extra stretchable glue % operates only on the left of each cell \emph{after} (to the \emph{right} of) -% the cell that received the declaration; the first cell will never get larger +% the cell that received the declaration; the first cell will never get larger % in spite of the presence of this glue. % % Another package, |tabularX|, normally distributed by the \LaTeX\,3 Team with @@ -80,7 +80,7 @@ % provided they contain only text. These expandable cells are identified with the % column identifier |X|; this identifier defines a paragraph-like cell, the width of % which gets determined after some runs of the typesetter on the same source -% tabular material, so as to find out the correct width of the textual columns. +% tabular material, so as to find out the correct width of the textual columns. % % The approach here is a little bit different: the cell contents need not be textual % and no cell width is determined in one or more runs of the typesetter; instead the @@ -176,11 +176,30 @@ % % Of course there is no limit to a better solution; nevertheless the one I % implemented never crashed in any real world situation I tested. +% +% \section{Using the \boldmath$\varepsilon$-\TeX\ facilies} +% On the other side if the |etex| facilies are available a different approach may +% be taken; |etex| natively performs several calculations connected by mathematical +% operations. In particular the scaling operation such as a dimension multiplied by +% a number ad immediately divided by another number is performed by storing the +% intermediate result into a 64-bit register, so that no overflow takes place if the +% operands represent lengths or the scaled-point numbers equivalent to these lengths. +% If the |etex| facilties are available, other calculations are more easily performed +% in order to determine directly the scaled length it is necessary to determine. % +% Therefore this package works equally well with old engines that do not have the +% |etex| functionality and with modern engines that possess this functionality; +% of course modern engines work much better and faster. +% % \section{Acknowledgements} % I must deeply thank Enrico Gregorio for the revision of this package macros and % for his wise suggestions about the correct programming style. If some glitch still % remains in the programming style, that is just my fault. +% +% I also thank very much Peter R.~Wilson who wrote the excellent class |memoir.cls| +% and its formidable decumentation. I copied from his code the necessary lines for +% testing the |etex| functionality of the engine that is processing this file. +% % \StopEventually{} % % \section{Implementation} @@ -213,6 +232,44 @@ \countdef\wt@Den=4 \countdef\wt@I=6 \def\wt@segno{} + +% \end{macrocode} +% +% We copy from |memoir.cls| the relevant lines and modify them in order to make +% them suitable for this |widetable| package. The relevant point is that a new |\if| +% is defined, |\ifetex|, and is immediately set to |true| or |false| depending on the +% fact that the engine being used has the |etex| functionalities. Actually all modern +% engines have these functionalites, but they might have been disabled; old engines +% lack these functionalites. May be, if a real \textsf{ifetex.sty} package existed, it +% would not be necessary to do any testing and to emulate its inner workings. May be +% this package could more efficiently detect it the current engine might be conforming +% to the |etex| specifications, but the latter have been disabled. In any case if the +% package existed, its macros would be used instead of the emulated ones. +% \begin{macrocode} +\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 +} + % \end{macrocode} % % We then start the definition of the division algorithm; the name of the macro and @@ -238,7 +295,9 @@ % we need just use this name, instead of assigning strange numerical values; the % only thing we must pay attention to is to strip the ``pt'' information from this % ``infinite'' dimension, since the quotient must be a dimensionless signed -% fractional decimal number. +% fractional decimal number. Notice that in this apllication the denominator never +% vanishes, so that actually some of the tests are useless; nevertheless if the macro +% is copied and used in other packages they might turn up to be essential. % % Otherwise we load the operands in similarly named counter registers, effectively % transferring the dimension integer number of scaled points to integer variables @@ -282,6 +341,7 @@ \edef\x{\noexpand\endgroup\noexpand\def\noexpand#3{\wt@segno\wt@Q}} \x } + % \end{macrocode} % % The cycle for the long division consists in multiplying the remainder in @@ -297,17 +357,52 @@ \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} + % \end{macrocode} % +% On the other hand for exploiting the facilites of the |etex| engine we define +% a new command |\scala| (`` imperative of the verb to scale'') that performs +% the scaling oepration by executing first a multiplication and then a division, +% while accumulating the intermediate result into a 64-bit register so as not to +% loose precision. Therefore this new command receives four arguments: the first +% is the length to be scaled, the second and the third are two lengths the ratio +% of which forms the scaling factore, and the foruth is the resulting scaled +% dimension. The numerator and the denominator lengths whose ratio defines the +% scaling factor are stored into two numerical registers as scaled points; +% therefore the length to be scaled is first multiplied by the numerator integer +% number of scaled points, and immediately divided by the denominator integer number +% of scaled points; the result is assigned to a temmporary dimension that on exit +% will be assigned to the fourth macro argument. in order to preserve all the +% variable and register contents, everything is done within a group and the final +% result is thrown out of the group by means of the usual trick already used in the +% |\dividi| macro above. +% \begin{macrocode} +\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} + +% \end{macrocode} +% At this point it will be the |widetable| environment responsibility to call |\scala| +% or |\dividi| according to the availaility of the |etex| facilities specified by the +% status of the |\ifetex| test. +% % Now we define the dimension register that is to contain the desired table width. -% We further define the start of the tabular typesetting that will be useful in a while. -% Actually the table preamble is being saved into a macro, so that when the +% We further define the start of the tabular typesetting that will be useful in +% a while. Actually the table preamble is being saved into a macro, so that when the % \meta{width} and the \meta{column descriptors} are given to the opening % environment statement, these saved quantities can be used again and again. -% % \begin{macrocode} \newdimen\wt@width + \def\wt@starttabular{\expandafter\tabular\expandafter{\wt@preamble}} + % \end{macrocode} % % The environment opening as well as the environment closing are defined by @@ -321,6 +416,7 @@ \def\widetable#1#2{% \def\@tempC{widetable}\setlength{\wt@width}{#1}% \def\wt@preamble{#2}\wt@getTable} + % \end{macrocode} % % A new boolean, |wt@scartare|, is defined; this boolean variable will be set true in @@ -332,6 +428,7 @@ % delimited by a pair of matching braces. % \begin{macrocode} \newif\ifwt@scartare\wt@scartarefalse + % \end{macrocode} % % The closing statement will acttually do the greatest part of the job. First of all if @@ -348,8 +445,10 @@ % The arbitrary constant of 1\,cm is $t_1$, and the specified width $l$ is the % dimension saved into |\wt@width|. The subtractions are operated directly on the % dimension registers |\wt@width| (the numerator) and on the auxiliary register -% |\@tempdimenb|; the |\dividi| command is executed in order to get the quotient -% in |\@tempA|, and the final definitive value of |\tabcolsep| is eventually computed. +% |\@tempdimenb|; the |\dividi| or the |\scala| command, depending on the |\ifetex| +% status, is executed in order to get the scaling ratio in |\@tempA|, if the |etex| +% facilites are not available, and, in any case, the final definitive value of +% |\tabcolsep| is eventually computed. % The table is finally typeset without using boxes, while the contents of box zero % and two are restored upon exiting the environment to any value they might have % contained before entering |widetable|. @@ -365,12 +464,17 @@ \advance\wt@width-\wd\z@ \@tempdimb=\wd\tw@ \advance\@tempdimb-\wd\z@ - \dividi\wt@width\per\@tempdimb\in\@tempA - \tabcolsep=\@tempA\tabcolsep + \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 } + % \end{macrocode} % % Of course other actions must be performed before executing the closing @@ -378,6 +482,7 @@ % the ending environment statement. % \begin{macrocode} \def\wt@finetabella{\end{widetable}}% + % \end{macrocode} % % We finally can define the all important macro that gets the table body; it requires @@ -414,12 +519,14 @@ \MessageBreak The table is not typeset and is substituted% \MessageBreak - with a framed box} - \noindent\framebox[\wt@width]{The table was not typeset because - it contains a visible \texttt{\char`\\end} in one or more cells.}\par + 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 } + % \end{macrocode} % % In order to avoid a complete mess, we have to iteratively gobble the rest of the @@ -437,6 +544,30 @@ \expandafter\wt@finishTable \fi } +% \end{macrocode} +% \section{Conclusion} +% Tables should always have their natural width, but\dots\ The default value of +%|\tabcolsep| is fixed by the document class, it is not prescribed by a supreme law: +% therefore what does it mean ``natural width''. Probably the one determined by the +% class default value of |\tabcolsep| so all tables have the same general look. +% +% Nevertheless sometimes a table is slightly wider than the current measure; why not +% shrink the table by shrinking |\tabcolsep| by the right ammount in order to fit the +% measure? The result might be a table where only the interculomn spaces are shrunk, +% not the whole table, fonts, drawings, and figures included, a result easily +% obtainable with a |\resizebox| command available throught th \textsf{graphicx.sty} +% package. Nobody forbids to follow this technique, of course, but the |widetable| +% route might yield a better result. +% +% The same is true when a natural width table is slightly shorter than the measure; +% enlarging it by retouching the |\tabcolsep| intercolumn space might be the right +% solution in order to avoid a multitude of slightly different indents or left margins. +% +% This package might be useful also for copying some macros so as to avoid some +% programming in other packages; this use is certainly permitted by the LaTeX Project +% Public License, which sets the observance of very light obbligations. +% \begin{macrocode} + \endinput % \end{macrocode} % -- cgit v1.2.3