Debian Codegraph @

texmf-dist/source/latex/textfit/textfit.dtx

raw
1 \def\fileversion{5}
2 \def\filedate{1994/04/15}
3 \def\docdate{1994/04/15}
4 % \iffalse
5 %% File: textfit.dtx Copyright (C) 1994 Sebastian Rahtz and Phil Taylor
6 %
7 % This work may be distributed and/or modified under the
8 % conditions of the LaTeX Project Public License, either version 1.3
9 % of this license or (at your option) any later version.
10 % The latest version of this license is in
11 % http://www.latex-project.org/lppl.txt
12 % and version 1.3 or later is part of all distributions of LaTeX
13 % version 2005/12/01 or later.
14 %
15 % This work has the LPPL maintenance status `maintained'.
16 %
17 % The Current Maintainers of this work are Sebastian Rahtz and Phil Taylor.
18 %
19 % This work consists of all files listed in manifest.txt.
20 %
21 % This licence statement added 2010/11/26 by Clea F. Rees on behalf
22 % of Sebastian Rahtz and Phil Taylor.
23 %
24 %<*driver>
25 \documentclass{ltxdoc}
26 \usepackage{textfit}
27 \begin{document}
28 \title{The \textsf{textfit} package for
29 scaling up text to a desired size\thanks{This file
30 has version number \fileversion, last
31 revised \filedate.}}
32 \author{Sebastian Rahtz \and Phil Taylor}
33 \date{\filedate}
34 \maketitle
35 \tableofcontents
36 \DocInput{textfit.dtx}
37 \end{document}
38 %</driver>
39 % \fi
40 % \CheckSum{281}
41 %
42 % \section{Introduction}
43 %
44 % The user needs to be able to specify the width or height for text, and
45 % use the largest size necessary to fill that width or height. You
46 % can choose whether to have the size increased by simple points, or
47 % by using magsteps.
48 % Usage:
49 % \verb|\scaletowidth{3in}{This is the way of the world}|
50 % \verb|\scaletoheight{7mm}{This is the way of the world}|
51 % Details are controlled by two options: `magstep' will
52 % make the system use magsteps, not points, and `noisy'
53 % will produce useful messages.
54 % \changes{1}{5/2/93}{Worked out point size by trial and error, increasing
55 % it in increments of 1pt until result reached desired size}
56 % \changes{2}{9/2/93}{Final point size calculated by comparison of size at
57 % 10pt. faster, and takes less TeX memory for intermediate fonts}
58 % \changes{3}{10/1/94}{Revised to make it a \LaTeXe\ package}
59 % \changes{4}{6/2/94}{It only worked if `noisy' option was given ...}
60 % \changes{5}{15/4/94}{Checked again for \LaTeXe}
61 %
62 %Examples; note that the base font is taken from the current state when
63 %you enter the macros. so if you start off with a large font (eg
64 %cmr17), it will give a different result from that obtained by scaling
65 %up cmr5.
66 %
67 %\scaletowidth{1in}{This is the way of the world}
68 %
69 %{\Huge \scaletowidth{1in}{This is the way of the world}}
70 %
71 %{\Huge \scaletowidth{5in}{This is the way of the world}}
72 %
73 %\scaletowidth{5in}{This is the way of the world}
74 %
75 %{\Huge \scaletoheight{1.3in}{Cowabunga!} }
76 %
77 % \scaletowidth{5in}{Gloucestershire Warwickshire Railway}
78 %
79 %\ScalebyMagstepstrue
80 %
81 %\scaletowidth{1in}{This is the way of the world}
82 %
83 %{\Huge \scaletowidth{1in}{This is the way of the world}}
84 %
85 %{\Huge \scaletowidth{5in}{This is the way of the world}}
86 %
87 %\scaletowidth{5in}{This is the way of the world}
88 %
89 %{\Huge \scaletoheight{1.3in}{Cowabunga!} }
90 % \StopEventually{}
91 % \begin{macrocode}
92 %<*package>
93 \NeedsTeXFormat{LaTeX2e}
94 \ProvidesPackage{textfit}[\filedate]
95 \newif\ifScalebyMagsteps
96 \newif\ifNoisyFitting
97 \NoisyFittingfalse
98 \ScalebyMagstepsfalse
99 \DeclareOption{noisy}{\NoisyFittingtrue}
100 \DeclareOption{magstep}{\ScalebyMagstepstrue}
101 \ProcessOptions
102 \newcount \mags@f@r
103 \newdimen \desired@size
104 \newcount \r@mainder
105 \newcount \m@gstepcount
106 \newcount \m@gsteplimit
107 \newcount \m@gstepvalue
108 \newdimen \m@gstepdimen
109 % \end{macrocode}
110 % Code for working out the right magstep (this is Phil's bit).
111 % \begin{macrocode}
112 \def \magsteps {\afterassignment \m@gsteps \m@gsteplimit = }
113 \def \m@gsteps
114 {\let \@r = \or
115 \def \or {\noexpand \or}%
116 \m@gstepdimen = 0.166667 \maxdimen
117 \m@gstepvalue = 1000
118 \m@gstepcount = 0
119 \def \magstep {}%
120 \loop
121 \ifnum \m@gstepcount < \m@gsteplimit
122 \advance \m@gstepcount by 1
123 \ifnum \m@gstepvalue > \m@gstepdimen
124 \advance \m@gstepcount by -1
125 \message {Sorry --- integer overflow would occur if
126 I went any further; stopped at
127 \the \m@gstepcount.}
128 \m@gsteplimit = \m@gstepcount
129 \else
130 \multiply \m@gstepvalue by 12
131 \multiply \r@mainder by 12
132 \divide \r@mainder by 10
133 \advance \m@gstepvalue by \r@mainder
134 \r@mainder = \m@gstepvalue
135 \divide \m@gstepvalue by 10
136 \multiply \m@gstepvalue by 10
137 \advance \r@mainder by -\m@gstepvalue
138 \divide \m@gstepvalue by 10
139 \ifnum \r@mainder < 5
140 \edef \magstep {\magstep \or \the \m@gstepvalue}%
141 \else
142 \advance \m@gstepvalue by 1
143 \edef \magstep {\magstep \or \the \m@gstepvalue}%
144 \advance \m@gstepvalue by -1
145 \fi
146 \fi
147 \repeat
148 \edef \magstep ##1%
149 {\noexpand \ifcase ##1
150 1000\magstep
151 \noexpand \else 0%
152 \noexpand \message
153 {Sorry --- \string \magstep \space ##1
154 is not in range 0 .. \the \m@gsteplimit}%
155 \noexpand \fi
156 \noexpand \relax
157 }%
158 \let \or = \@r
159 }
160 \magsteps 63
161 \def \Fontname #1{\expandafter \strip@size \fontname #1 }
162 \def \strip@size #1 #2#{#1\void@@@}
163 \def \void@@@ #1{}
164 \gdef\n@d#1.#2:{#1}
165 \def \@scaletofit[#1]#2#3{%
166 \def\Hb@x{h}\def\H@rV{#1}%
167 \ifx\H@rV\Hb@x\def\C@mpare{\wd}\else\def\C@mpare{\ht}\fi
168 \desired@size #2
169 \def\curr@fontname{\Fontname \font {} }%
170 \ifScalebyMagsteps
171 \mags@f@r \z@
172 \setbox 0 = \hbox{#3}%
173 \def\@increment{1}%
174 \def\@test{<}%
175 \ifdim \C@mpare 0 > \desired@size
176 \message{When scaling by Magsteps, you cannot go downwards!}%
177 \fi
178 \loop
179 \font \temp@font = \curr@fontname scaled \magstep \mags@f@r
180 \setbox 0 = \hbox{{\temp@font #3}}%
181 \ifNoisyFitting
182 \message {Trying \noexpand \magstep \the \mags@f@r...}%
183 \fi
184 \ifdim \C@mpare 0 \@test \desired@size
185 \advance \mags@f@r by \@increment
186 \repeat
187 \ifnum \mags@f@r=\z@
188 \mags@f@r1
189 \fi
190 \advance \mags@f@r by -\@increment
191 \else
192 \font\temp@font=\curr@fontname at1pt
193 \setbox 0 = \hbox{{\temp@font #3}}%
194 \@tempdima\C@mpare0
195 \multiply\@tempdima by 500 %\@m
196 \def\foo@@{\expandafter\n@d\the\@tempdima:}%
197 \@tempdimb\desired@size
198 \divide\@tempdimb by \foo@@
199 \multiply\@tempdimb by 500 %\@m
200 \fi
201 \ifScalebyMagsteps
202 \ifNoisyFitting
203 \message {The calculated font is \curr@fontname
204 scaled \noexpand \magstep \the \mags@f@r}%
205 \fi
206 \font \temp@font = \curr@fontname scaled \magstep \mags@f@r
207 \else
208 \ifNoisyFitting
209 \message {The calculated font is \curr@fontname ->\the\@tempdimb}%
210 \fi
211 \font\temp@font=\curr@fontname at \the\@tempdimb
212 \fi
213 \ifx\H@rV\Hb@x
214 \hbox to \desired@size {\hss{\temp@font #3}\hss}%
215 \else
216 \hbox {{\temp@font #3}}%
217 \fi
218 }
219 % user interface
220 \def\scaletowidth{\@scaletofit[h]}
221 \def\scaletoheight{\@scaletofit[v]}
222 %</package>
223 % \end{macrocode}
224 % \Finale
225 \endinput
226 %
227 %% \CharacterTable
228 %% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
229 %% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
230 %% Digits \0\1\2\3\4\5\6\7\8\9
231 %% Exclamation \! Double quote \" Hash (number) \#
232 %% Dollar \$ Percent \% Ampersand \&
233 %% Acute accent \' Left paren \( Right paren \)
234 %% Asterisk \* Plus \+ Comma \,
235 %% Minus \- Point \. Solidus \/
236 %% Colon \: Semicolon \; Less than \<
237 %% Equals \= Greater than \> Question mark \?
238 %% Commercial at \@ Left bracket \[ Backslash \\
239 %% Right bracket \] Circumflex \^ Underscore \_
240 %% Grave accent \` Left brace \{ Vertical bar \|
241 %% Right brace \} Tilde \~}
242