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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
%%
%% This is file `fitbox.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% fitbox.dtx (with options: `style')
%%
%% IMPORTANT NOTICE:
%%
%% For the copyright see the source file.
%%
%% Any modified versions of this file must be renamed
%% with new filenames distinct from fitbox.sty.
%%
%% For distribution of the original source see the terms
%% for copying and modification in the file fitbox.dtx.
%%
%% This generated file may be distributed as long as the
%% original source files, as listed above, are part of the
%% same distribution. (The sources need not necessarily be
%% in the same archive or directory.)
%% Copyright 2015-2019, Boris Veytsman <borisv@lk.net
%% 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 the 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/06/01 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% The Current Maintainer of this work is Boris Veytsman
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{fitbox}
[2019/02/20 v1.02 Fitting boxes on a page]
\newdimen\fitboxnatheight
\newdimen\fitboxnatwidth
\RequirePackage{xkeyval}
\define@cmdkeys{FTBX}{maxheight, minheight, maxwidth, minwidth,
belowboxspace, maxenlargepage, colsep, maincapheight,
subcapheight}
\define@key{FTBX}{colsepexpr}{%
\setbox\@tempboxa=\hbox{#1}%
\edef\cmdKV@FTBX@colsep{\wd\@tempboxa}}
\define@key{FTBX}{maincaplines}{%
\@tempdima=\z@
\advance\@tempdima by #1\baselineskip\relax
\ifnum#1>0\relax
\advance\@tempdima by \parskip
\fi
\advance\@tempdima by \abovecaptionskip
\advance\@tempdima by \belowcaptionskip
\edef\cmdKV@FTBX@maincapheight{\the\@tempdima}}
\define@key{FTBX}{subcaplines}{%
\@tempdima=\z@
\advance\@tempdima by #1\baselineskip\relax
\ifnum#1>0\relax
\advance\@tempdima by \parskip
\fi
\advance\@tempdima by \abovecaptionskip
\advance\@tempdima by \belowcaptionskip
\edef\cmdKV@FTBX@subcapheight{\the\@tempdima}}
\def\fitboxset#1{\setkeys{FTBX}{#1}}
\fitboxset{maxheight=\textheight, minheight=\fitboxnatheight,
maxwidth=\hsize, minwidth=\fitboxnatwidth,
belowboxspace=0pt, maxenlargepage=0pt, colsepexpr={aaa},
maincaplines=1, subcaplines=0}
\newbox\FTBX@box
\newdimen\FTBX@desired@maxheight
\newdimen\FTBX@desired@minheight
\newdimen\FTBX@available@height
\def\fitbox{\@ifstar\@@fitbox\@fitbox}
\newcommand\@fitbox[2][]{\noindent
\fitboxset{#1}%
\setbox\FTBX@box=\hbox{#2}%
\fitboxnatwidth=\wd\FTBX@box\relax
\fitboxnatheight=\ht\FTBX@box\relax
\advance\fitboxnatheight by \dp\FTBX@box\relax
% Checking the sizes
\expandafter\ifdim\cmdKV@FTBX@minwidth>\columnwidth\relax
\PackageWarning{fitbox}{Minimal width is too large. Consider
changing it to \the\hsize}%
\fi
\expandafter\ifdim\cmdKV@FTBX@maxwidth>\hsize\relax
\PackageWarning{fitbox}{Desired width is too large. Consider
changing it to \the\hsize}%
\fi
\expandafter\ifdim\cmdKV@FTBX@minheight>\textheight\relax
\PackageWarning{fitbox}{Minimal height is too large.
Consider changing it to \the\textheight}%
\fi
\expandafter\ifdim\cmdKV@FTBX@maxheight>\textheight\relax
\PackageWarning{fitbox}{Desired height is too large.
Consider changing it to \the\textheight}%
\fi
% Calculating the minimal and maximal height
\Gscale@div{\@FTBX@tempa}{\cmdKV@FTBX@maxwidth}{\fitboxnatwidth}%
\FTBX@desired@maxheight=\@FTBX@tempa\fitboxnatheight\relax
\expandafter\ifdim\cmdKV@FTBX@maxheight<\FTBX@desired@maxheight\relax
\expandafter\FTBX@desired@maxheight=\cmdKV@FTBX@maxheight\relax
\fi
\Gscale@div{\@FTBX@tempa}{\cmdKV@FTBX@minwidth}{\fitboxnatwidth}%
\FTBX@desired@minheight=\@FTBX@tempa\fitboxnatheight\relax
\expandafter\ifdim\cmdKV@FTBX@minheight>\FTBX@desired@minheight\relax
\expandafter\FTBX@desired@minheight=\cmdKV@FTBX@minheight\relax
\fi
\ifdim\FTBX@desired@minheight>\FTBX@desired@maxheight\relax
\PackageWarning{fitbox}{Desired min scale exceeds desired max
scale.}%
\fi
\FTBX@available@height=\pagegoal\relax
\ifdim\FTBX@available@height>\vsize\relax
\FTBX@available@height=\vsize
\fi
\advance\FTBX@available@height by -\pagetotal\relax
\advance\FTBX@available@height by -\cmdKV@FTBX@belowboxspace\relax
\advance\FTBX@available@height by -\baselineskip\relax
\ifdim\FTBX@desired@maxheight>\FTBX@available@height\relax
\ifdim\FTBX@available@height<\FTBX@desired@minheight\relax
\@tempdima=\FTBX@desired@minheight\relax
\advance\@tempdima by
-\FTBX@available@height\relax
\expandafter\ifdim\cmdKV@FTBX@maxenlargepage<\@tempdima\relax
\newpage
\resizebox*{!}{\FTBX@desired@maxheight}{\box\FTBX@box}%
\else
\enlargethispage{\@tempdima}%
\resizebox*{!}{\FTBX@desired@minheight}{\box\FTBX@box}%
\fi
\else
\resizebox*{!}{\FTBX@available@height}{\box\FTBX@box}%
\fi
\else
\resizebox*{!}{\FTBX@desired@maxheight}{\box\FTBX@box}%
\fi
}
\newcommand\@@fitbox[2][]{\noindent
\fitboxset{#1}%
\setbox\FTBX@box=\hbox{#2}%
\fitboxnatwidth=\wd\FTBX@box\relax
\fitboxnatheight=\ht\FTBX@box\relax
\advance\fitboxnatheight by \dp\FTBX@box\relax
% Checking the sizes
\expandafter\ifdim\cmdKV@FTBX@minwidth>\columnwidth\relax
\PackageWarning{fitbox}{Minimal width is too large. Consider
changing it to \the\hsize}%
\fi
\expandafter\ifdim\cmdKV@FTBX@maxwidth>\hsize\relax
\PackageWarning{fitbox}{Desired width is too large. Consider
changing it to \the\hsize}%
\fi
\expandafter\ifdim\cmdKV@FTBX@minheight>\textheight\relax
\PackageWarning{fitbox}{Minimal height is too large.
Consider changing it to \the\textheight}%
\fi
\expandafter\ifdim\cmdKV@FTBX@maxheight>\textheight\relax
\PackageWarning{fitbox}{Desired height is too large.
Consider changing it to \the\textheight}%
\fi
% Calculating the minimal and maximal height
\Gscale@div{\@FTBX@tempa}{\cmdKV@FTBX@maxwidth}{\fitboxnatwidth}%
\FTBX@desired@maxheight=\@FTBX@tempa\fitboxnatheight\relax
\expandafter\ifdim\cmdKV@FTBX@maxheight<\FTBX@desired@maxheight\relax
\expandafter\FTBX@desired@maxheight=\cmdKV@FTBX@maxheight\relax
\fi
\Gscale@div{\@FTBX@tempa}{\cmdKV@FTBX@minwidth}{\fitboxnatwidth}%
\FTBX@desired@minheight=\@FTBX@tempa\fitboxnatheight\relax
\expandafter\ifdim\cmdKV@FTBX@minheight>\FTBX@desired@minheight\relax
\expandafter\FTBX@desired@minheight=\cmdKV@FTBX@minheight\relax
\fi
\ifdim\FTBX@desired@minheight>\FTBX@desired@maxheight\relax
\PackageWarning{fitbox}{Desired min scale exceeds desired max
scale.}%
\fi
\resizebox*{!}{\FTBX@desired@maxheight}{\box\FTBX@box}%
}
\newcommand\SetFitboxLayout[3][]{%
\fitboxset{#1}%
\@tempdima=\textheight
\advance\@tempdima by -\cmdKV@FTBX@maincapheight\relax
\divide\@tempdima by #2\relax
\advance\@tempdima by -\cmdKV@FTBX@subcapheight\relax
\edef\cmdKV@FTBX@maxheight{\the\@tempdima}%
\@tempdima=\columnwidth
\@tempdimb=\cmdKV@FTBX@colsep\relax
\advance\@tempdima by -#3\@tempdimb\relax
\advance\@tempdima by \@tempdimb\relax
\divide\@tempdima by #3\relax
\edef\cmdKV@FTBX@maxwidth{\the\@tempdima}%
}
\endinput
%%
%% End of file `fitbox.sty'.
|