-
-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathfitbox2.sty
42 lines (37 loc) · 1.39 KB
/
fitbox2.sty
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
%=================================================================
% From https://tex.stackexchange.com/questions/26002/fit-text-into-given-box-by-adjusting-the-fontsize
% \RequirePackage{fp}
\RequirePackage{pbox}
\providecommand*{\DivideLengths}[2]{%
\strip@pt\dimexpr\number\numexpr\number\dimexpr#1\relax*65536/\number\dimexpr#2\relax\relax sp\relax
}
\newsavebox{\@fbbox}
\newcommand{\fitboxratio}[4]{%
% #1 = ratio
% #2 = width
% #3 = height
% #4 = text
\@tempdima=\dimexpr#2\relax%
\savebox{\@fbbox}{\pbox{\paperwidth}{#4}}%
\ifdim\wd\@fbbox=0pt\relax
\PackageError{fitbox2}{Invalid text width 0pt for text: “#4”}
\fi
\typeout{FITBOX boxwidth=\the\@tempdima\space textwidth=\the\wd\@fbbox\space}%
\edef\@hratio{\DivideLengths{\@tempdima}{\wd\@fbbox}}%
\typeout{FITBOX boxwidth=\the\@tempdima\space textwidth=\the\wd\@fbbox\space hratio=\@hratio}%
\@tempdima=\dimexpr#3\relax%
\typeout{FITBOX height=\the\@tempdima}%
\@tempdimb=\dimexpr\ht\@fbbox+\dp\@fbbox\relax%
\edef\@vratio{\DivideLengths{\@tempdima}{\@tempdimb}}%
\typeout{FITBOX boxheight=\the\@tempdima\space textheight=\the\@tempdimb\space ratio=\@vratio}%
\pgfmathparse{min(\@hratio,\@vratio)}%
\typeout{\pgfmathresult}
% \PAUSETHIS
\csedef{#1}{\pgfmathresult}%
}
\newcommand{\fitboxmin}[2]{%
% #1 = minimum (out)
% #2 = list (in)
\pgfmathparse{min(\expanded{#2})}%
\csedef{#1}{\pgfmathresult}%
}