Debian Codegraph @

texmf-dist/tex/latex/fitbox/fitbox.sty

raw
1 %%
2 %% This is file `fitbox.sty',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% fitbox.dtx (with options: `style')
8 %%
9 %% IMPORTANT NOTICE:
10 %%
11 %% For the copyright see the source file.
12 %%
13 %% Any modified versions of this file must be renamed
14 %% with new filenames distinct from fitbox.sty.
15 %%
16 %% For distribution of the original source see the terms
17 %% for copying and modification in the file fitbox.dtx.
18 %%
19 %% This generated file may be distributed as long as the
20 %% original source files, as listed above, are part of the
21 %% same distribution. (The sources need not necessarily be
22 %% in the same archive or directory.)
23 %% Copyright 2015-2019, Boris Veytsman <[email protected]
24 %% This work may be distributed and/or modified under the
25 %% conditions of the LaTeX Project Public License, either
26 %% version 1.3 of this license or (at your option) any
27 %% later version.
28 %% The latest version of the license is in
29 %% http://www.latex-project.org/lppl.txt
30 %% and version 1.3 or later is part of all distributions of
31 %% LaTeX version 2003/06/01 or later.
32 %%
33 %% This work has the LPPL maintenance status `maintained'.
34 %%
35 %% The Current Maintainer of this work is Boris Veytsman
36 %%
37 \NeedsTeXFormat{LaTeX2e}
38 \ProvidesPackage{fitbox}
39 [2019/02/20 v1.02 Fitting boxes on a page]
40 \newdimen\fitboxnatheight
41 \newdimen\fitboxnatwidth
42 \RequirePackage{xkeyval}
43 \define@cmdkeys{FTBX}{maxheight, minheight, maxwidth, minwidth,
44 belowboxspace, maxenlargepage, colsep, maincapheight,
45 subcapheight}
46 \define@key{FTBX}{colsepexpr}{%
47 \setbox\@tempboxa=\hbox{#1}%
48 \edef\cmdKV@FTBX@colsep{\wd\@tempboxa}}
49 \define@key{FTBX}{maincaplines}{%
50 \@tempdima=\z@
51 \advance\@tempdima by #1\baselineskip\relax
52 \ifnum#1>0\relax
53 \advance\@tempdima by \parskip
54 \fi
55 \advance\@tempdima by \abovecaptionskip
56 \advance\@tempdima by \belowcaptionskip
57 \edef\cmdKV@FTBX@maincapheight{\the\@tempdima}}
58 \define@key{FTBX}{subcaplines}{%
59 \@tempdima=\z@
60 \advance\@tempdima by #1\baselineskip\relax
61 \ifnum#1>0\relax
62 \advance\@tempdima by \parskip
63 \fi
64 \advance\@tempdima by \abovecaptionskip
65 \advance\@tempdima by \belowcaptionskip
66 \edef\cmdKV@FTBX@subcapheight{\the\@tempdima}}
67 \def\fitboxset#1{\setkeys{FTBX}{#1}}
68 \fitboxset{maxheight=\textheight, minheight=\fitboxnatheight,
69 maxwidth=\hsize, minwidth=\fitboxnatwidth,
70 belowboxspace=0pt, maxenlargepage=0pt, colsepexpr={aaa},
71 maincaplines=1, subcaplines=0}
72 \newbox\FTBX@box
73 \newdimen\FTBX@desired@maxheight
74 \newdimen\FTBX@desired@minheight
75 \newdimen\FTBX@available@height
76 \def\fitbox{\@ifstar\@@fitbox\@fitbox}
77 \newcommand\@fitbox[2][]{\noindent
78 \fitboxset{#1}%
79 \setbox\FTBX@box=\hbox{#2}%
80 \fitboxnatwidth=\wd\FTBX@box\relax
81 \fitboxnatheight=\ht\FTBX@box\relax
82 \advance\fitboxnatheight by \dp\FTBX@box\relax
83 % Checking the sizes
84 \expandafter\ifdim\cmdKV@FTBX@minwidth>\columnwidth\relax
85 \PackageWarning{fitbox}{Minimal width is too large. Consider
86 changing it to \the\hsize}%
87 \fi
88 \expandafter\ifdim\cmdKV@FTBX@maxwidth>\hsize\relax
89 \PackageWarning{fitbox}{Desired width is too large. Consider
90 changing it to \the\hsize}%
91 \fi
92 \expandafter\ifdim\cmdKV@FTBX@minheight>\textheight\relax
93 \PackageWarning{fitbox}{Minimal height is too large.
94 Consider changing it to \the\textheight}%
95 \fi
96 \expandafter\ifdim\cmdKV@FTBX@maxheight>\textheight\relax
97 \PackageWarning{fitbox}{Desired height is too large.
98 Consider changing it to \the\textheight}%
99 \fi
100 % Calculating the minimal and maximal height
101 \Gscale@div{\@FTBX@tempa}{\cmdKV@FTBX@maxwidth}{\fitboxnatwidth}%
102 \FTBX@desired@maxheight=\@FTBX@tempa\fitboxnatheight\relax
103 \expandafter\ifdim\cmdKV@FTBX@maxheight<\FTBX@desired@maxheight\relax
104 \expandafter\FTBX@desired@maxheight=\cmdKV@FTBX@maxheight\relax
105 \fi
106 \Gscale@div{\@FTBX@tempa}{\cmdKV@FTBX@minwidth}{\fitboxnatwidth}%
107 \FTBX@desired@minheight=\@FTBX@tempa\fitboxnatheight\relax
108 \expandafter\ifdim\cmdKV@FTBX@minheight>\FTBX@desired@minheight\relax
109 \expandafter\FTBX@desired@minheight=\cmdKV@FTBX@minheight\relax
110 \fi
111 \ifdim\FTBX@desired@minheight>\FTBX@desired@maxheight\relax
112 \PackageWarning{fitbox}{Desired min scale exceeds desired max
113 scale.}%
114 \fi
115 \FTBX@available@height=\pagegoal\relax
116 \ifdim\FTBX@available@height>\vsize\relax
117 \FTBX@available@height=\vsize
118 \fi
119 \advance\FTBX@available@height by -\pagetotal\relax
120 \advance\FTBX@available@height by -\cmdKV@FTBX@belowboxspace\relax
121 \advance\FTBX@available@height by -\baselineskip\relax
122 \ifdim\FTBX@desired@maxheight>\FTBX@available@height\relax
123 \ifdim\FTBX@available@height<\FTBX@desired@minheight\relax
124 \@tempdima=\FTBX@desired@minheight\relax
125 \advance\@tempdima by
126 -\FTBX@available@height\relax
127 \expandafter\ifdim\cmdKV@FTBX@maxenlargepage<\@tempdima\relax
128 \newpage
129 \resizebox*{!}{\FTBX@desired@maxheight}{\box\FTBX@box}%
130 \else
131 \enlargethispage{\@tempdima}%
132 \resizebox*{!}{\FTBX@desired@minheight}{\box\FTBX@box}%
133 \fi
134 \else
135 \resizebox*{!}{\FTBX@available@height}{\box\FTBX@box}%
136 \fi
137 \else
138 \resizebox*{!}{\FTBX@desired@maxheight}{\box\FTBX@box}%
139 \fi
140 }
141 \newcommand\@@fitbox[2][]{\noindent
142 \fitboxset{#1}%
143 \setbox\FTBX@box=\hbox{#2}%
144 \fitboxnatwidth=\wd\FTBX@box\relax
145 \fitboxnatheight=\ht\FTBX@box\relax
146 \advance\fitboxnatheight by \dp\FTBX@box\relax
147 % Checking the sizes
148 \expandafter\ifdim\cmdKV@FTBX@minwidth>\columnwidth\relax
149 \PackageWarning{fitbox}{Minimal width is too large. Consider
150 changing it to \the\hsize}%
151 \fi
152 \expandafter\ifdim\cmdKV@FTBX@maxwidth>\hsize\relax
153 \PackageWarning{fitbox}{Desired width is too large. Consider
154 changing it to \the\hsize}%
155 \fi
156 \expandafter\ifdim\cmdKV@FTBX@minheight>\textheight\relax
157 \PackageWarning{fitbox}{Minimal height is too large.
158 Consider changing it to \the\textheight}%
159 \fi
160 \expandafter\ifdim\cmdKV@FTBX@maxheight>\textheight\relax
161 \PackageWarning{fitbox}{Desired height is too large.
162 Consider changing it to \the\textheight}%
163 \fi
164 % Calculating the minimal and maximal height
165 \Gscale@div{\@FTBX@tempa}{\cmdKV@FTBX@maxwidth}{\fitboxnatwidth}%
166 \FTBX@desired@maxheight=\@FTBX@tempa\fitboxnatheight\relax
167 \expandafter\ifdim\cmdKV@FTBX@maxheight<\FTBX@desired@maxheight\relax
168 \expandafter\FTBX@desired@maxheight=\cmdKV@FTBX@maxheight\relax
169 \fi
170 \Gscale@div{\@FTBX@tempa}{\cmdKV@FTBX@minwidth}{\fitboxnatwidth}%
171 \FTBX@desired@minheight=\@FTBX@tempa\fitboxnatheight\relax
172 \expandafter\ifdim\cmdKV@FTBX@minheight>\FTBX@desired@minheight\relax
173 \expandafter\FTBX@desired@minheight=\cmdKV@FTBX@minheight\relax
174 \fi
175 \ifdim\FTBX@desired@minheight>\FTBX@desired@maxheight\relax
176 \PackageWarning{fitbox}{Desired min scale exceeds desired max
177 scale.}%
178 \fi
179 \resizebox*{!}{\FTBX@desired@maxheight}{\box\FTBX@box}%
180 }
181 \newcommand\SetFitboxLayout[3][]{%
182 \fitboxset{#1}%
183 \@tempdima=\textheight
184 \advance\@tempdima by -\cmdKV@FTBX@maincapheight\relax
185 \divide\@tempdima by #2\relax
186 \advance\@tempdima by -\cmdKV@FTBX@subcapheight\relax
187 \edef\cmdKV@FTBX@maxheight{\the\@tempdima}%
188 \@tempdima=\columnwidth
189 \@tempdimb=\cmdKV@FTBX@colsep\relax
190 \advance\@tempdima by -#3\@tempdimb\relax
191 \advance\@tempdima by \@tempdimb\relax
192 \divide\@tempdima by #3\relax
193 \edef\cmdKV@FTBX@maxwidth{\the\@tempdima}%
194 }
195 \endinput
196 %%
197 %% End of file `fitbox.sty'.