summaryrefslogtreecommitdiff
path: root/macros/latex209/contrib/misc/settosize.sty
blob: 66267c6c0e7cd3bf05f585b555395f87679a54ba (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
%%% The user needs to be able to specify the width for text, and
%%% use the largest point size necessary to fill that width.
%%%
%%% After macros by Phil Taylor January 1993; 
%%% converted to LaTeX style file (needs NFSS) and changed syntax 
%%% by Sebastian Rahtz, February 1993.

%%% \Fontname: like \fontname, but voids any size specifier
%%%  Usage:   \Fontname \font {} %%% don't omit {} !!!

\edef \Fontname 
     {\noexpand \expandafter \noexpand \stripsize \noexpand \fontname \space}
\def \stripsize #1 #2#{#1}

\newcount \pts@f@r
\newdimen \set@width

\def\massage@fontname#1 #2:{\def\curr@fontname{#1}}

\def \scaletowidth#1#2{%
    \set@width #1 
    \edef\f@name{\fontname\font\space:}%
    \expandafter\massage@fontname\f@name
    \pts@f@r \f@size
    \setbox 0 = \hbox{#2}%
     \ifdim \wd 0 < \set@width
	\def\@increment{1}%
	\def\@test{<}%
     \else
	\def\@increment{-1}%
	\def\@test{>}%
     \fi
     \loop
       \font\temp@font=\curr@fontname\space at \the\pts@f@r pt
	\setbox 0 = \hbox{{\temp@font #2}}%
        \message {\curr@fontname->\the \pts@f@r...}%
        \ifdim \wd 0 \@test \set@width
           \advance \pts@f@r by \@increment
     \repeat
     \advance \pts@f@r by -\@increment
     \message {The calculated font size is \the \pts@f@r pt}%
     \font\temp@font=\curr@fontname\space at \the\pts@f@r pt
     \hbox to \set@width {\hss{\temp@font #2}\hss}%
    }
\endinput


Example:

\scaletowidth{50cm}{Now is the time for the Party}