summaryrefslogtreecommitdiff
path: root/macros/latex209/contrib/textfit/textfit.dtx
blob: 1e59c3247b174d2f0f6e7e8d287fcf78f7c74556 (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
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
% \iffalse meta-comment
% File `textfit.dtx'.
%
% Copyright (C) 1994 by Sebastian Rahtz and Phil Taylor
% All rights reserved.
%
%  @LaTeX-style-file{
%     author          = "Sebastian Rahtz and Phil Taylor",
%     version         = "3",
%     date            = "10th January 1994",
%     filename        = "textfit.sty",
%     email           = "spqr@ftp.tex.ac.uk (Internet)",
%     keywords        = "LaTeX, scaling",
%     supported       = "yes",
%     docstring       = "
%
%     textfit.sty
%
% LaTeX style option for scaling up text to a desired size. Requires LaTeX2e
% "}
% You are not allowed to change this file.  You may however copy
% this file to a file with a different name and then change the copy.
% 
% \fi
\def\fileversion{3}
\def\filedate{1994/01/10}
\def\docdate{1994/01/10}
% \CheckSum{310}
%
% \iffalse        This is a META comment
%
% Copying of this file is authorized only if either
% (1) you make absolutely no changes to your copy, including name, or
% (2) if you do make changes, you name it something other than
%     textfit.dtx.
% Please send bug reports to:
%
% S Rahtz
% 12 Cygnet Street
% York Y02 1AG
% UK
% email: spqr@ftp.tex.ac.uk
% \fi                  
%
%
% \title{The \texttt{textfit.dtx} file\thanks
%         {This file has version number \fileversion, dated \filedate.
%                The documentation was last revised on \docdate}\\
%       }
% \author{Sebastian Rahtz and Phil Taylor}
%
% \MakeShortVerb{\|}
% \def\dst{{\csname mediumseries\endcsname\sc docstrip}}
% \setcounter{StandardModuleDepth}{1}
%
% \maketitle
%
% \section{Introduction}
%
% The user needs to be able to specify the width or height for text, and
% use the largest size necessary to fill that width or height. You
% can choose whether to have the size increased by simple points, or
% by using magsteps.
% Usage:
% \verb|\scaletowidth{3in}{This is the way of the world}|
% \verb|\scaletoheight{7mm}{This is the way of the world}|
% Details are controlled by two options: `magstep' will
% make the system use magsteps, not points, and `noisy'
% will produce useful messages.
% \changes{1}{5/2/93}{Worked out point size by trial and error, increasing
%   it in increments of 1pt until result reached desired size}
% \changes{2}{9/2/93}{Final point size calculated by comparison of size at
%    10pt. faster, and takes less TeX memory for intermediate fonts}
% \changes{3}{10/1/94}{Revised to make it a \LaTeXe\ package}
%
%Examples; note that the base font is taken from the current state when
%you enter the macros. so if you start off with a large font (eg
%cmr17), it will give a different result from that obtained by scaling
%up cmr5.
%
%\scaletowidth{1in}{This is the way of the world}
%
%{\Huge \scaletowidth{1in}{This is the way of the world}}
%
%{\Huge \scaletowidth{5in}{This is the way of the world}}
%
%\scaletowidth{5in}{This is the way of the world}
%
%{\Huge \scaletoheight{1.3in}{Cowabunga!} }
%
% \scaletowidth{5in}{Gloucestershire  Warwickshire Railway}
%
%\ScalebyMagstepstrue
%
%\scaletowidth{1in}{This is the way of the world}
%
%{\Huge \scaletowidth{1in}{This is the way of the world}}
%
%{\Huge \scaletowidth{5in}{This is the way of the world}}
%
%\scaletowidth{5in}{This is the way of the world}
%
%{\Huge \scaletoheight{1.3in}{Cowabunga!} }
% \StopEventually{}
%    \begin{macrocode}
%<*textfit>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{textfit}[\filedate]
\newif\ifScalebyMagsteps
\newif\ifNoisyFitting
\NoisyFittingfalse
\ScalebyMagstepsfalse
\DeclareOption{noisy}{\NoisyFittingtrue}
\DeclareOption{magstep}{\ScalebyMagstepstrue}
\ProcessOptions
\newcount \mags@f@r
\newdimen \desired@size
\newcount \r@mainder
\newcount \m@gstepcount
\newcount \m@gsteplimit
\newcount \m@gstepvalue
\newdimen \m@gstepdimen
%    \end{macrocode}
% Code for working out the right magstep (this is Phil's bit).
%    \begin{macrocode}
\def \magsteps {\afterassignment \m@gsteps \m@gsteplimit = }
\def \m@gsteps
    {\let \@r = \or
     \def \or {\noexpand \or}%
     \m@gstepdimen = 0.166667 \maxdimen
     \m@gstepvalue = 1000 
     \m@gstepcount = 0
     \def \magstep {}%
     \loop
     \ifnum     \m@gstepcount < \m@gsteplimit
                \advance \m@gstepcount by 1
                \ifnum \m@gstepvalue > \m@gstepdimen
                        \advance \m@gstepcount by -1
                        \message {Sorry --- integer overflow would occur if
                                        I went any further; stopped at 
                                                \the \m@gstepcount.}
                        \m@gsteplimit = \m@gstepcount 
                \else
                        \multiply \m@gstepvalue by 12
                        \multiply \r@mainder by 12
                        \divide \r@mainder by 10
                        \advance \m@gstepvalue by \r@mainder
                        \r@mainder = \m@gstepvalue
                        \divide \m@gstepvalue by 10
                        \multiply \m@gstepvalue by 10
                        \advance \r@mainder by -\m@gstepvalue
                        \divide \m@gstepvalue by 10
                        \ifnum \r@mainder < 5
                               \edef \magstep {\magstep \or \the \m@gstepvalue}%
                        \else
                               \advance \m@gstepvalue by 1
                               \edef \magstep {\magstep \or \the \m@gstepvalue}%
                               \advance \m@gstepvalue by -1
                        \fi
                \fi
     \repeat
     \edef \magstep ##1%
          {\noexpand \ifcase ##1
                        1000\magstep 
           \noexpand \else 0%
           \noexpand \message 
                {Sorry --- \string \magstep \space ##1
                                is not in range 0 .. \the \m@gsteplimit}%
           \noexpand \fi
           \noexpand \relax
          }%
     \let \or = \@r
    }
\magsteps 63
\def \Fontname #1{\expandafter \strip@size \fontname #1 }
\def \strip@size #1 #2#{#1\void@@@}
\def \void@@@ #1{}
\gdef\n@d#1.#2:{#1}
\def \@scaletofit[#1]#2#3{%
     \def\Hb@x{h}\def\H@rV{#1}%
     \ifx\H@rV\Hb@x\def\C@mpare{\wd}\else\def\C@mpare{\ht}\fi
     \desired@size #2 
     \def\curr@fontname{\Fontname \font {} }%
     \ifScalebyMagsteps
        \mags@f@r \z@
        \setbox 0 = \hbox{#3}%
        \def\@increment{1}%
	\def\@test{<}%
        \ifdim \C@mpare 0 > \desired@size
           \message{When scaling by Magsteps, you cannot go downwards!}%
        \fi
        \loop
        \font \temp@font = \curr@fontname  scaled \magstep \mags@f@r
	\setbox 0 = \hbox{{\temp@font #3}}%
        \ifNoisyFitting
          \message {Trying \noexpand \magstep \the \mags@f@r...}%
        \fi
        \ifdim \C@mpare 0 \@test \desired@size
           \advance \mags@f@r by \@increment
        \repeat
        \ifnum \mags@f@r=\z@
           \mags@f@r1
         \fi
         \advance \mags@f@r by -\@increment
     \else
        \font\temp@font=\curr@fontname at1pt
        \setbox 0 = \hbox{{\temp@font #3}}%
        \@tempdima\C@mpare0
        \multiply\@tempdima by 500 %\@m
        \def\foo@@{\expandafter\n@d\the\@tempdima:}%
        \@tempdimb\desired@size
        \divide\@tempdimb by \foo@@
        \multiply\@tempdimb by 500 %\@m
     \fi
     \ifNoisyFitting
     \ifScalebyMagsteps
        \message {The calculated font is \curr@fontname 
           scaled \noexpand \magstep \the \mags@f@r}%
           \font \temp@font = \curr@fontname scaled \magstep \mags@f@r
     \else
           \message {The calculated font is \curr@fontname ->\the\@tempdimb}%
           \font\temp@font=\curr@fontname at \the\@tempdimb
     \fi
     \fi
     \ifx\H@rV\Hb@x
        \hbox to \desired@size {\hss{\temp@font #3}\hss}%
     \else
        \hbox {{\temp@font #3}}%
     \fi     
    }
% user interface
\def\scaletowidth{\@scaletofit[h]}
\def\scaletoheight{\@scaletofit[v]}
%</textfit>
% \Finale
%    \end{macrocode}
% \section{A driver for this document}
%
% The next bit of code contains the documentation driver file for
% \TeX{}, i.e., the file that will produce the documentation you are
% currently reading. It will be extracted from this file by the 
% \dst{} program.
%    \begin{macrocode}
%<*driver>
\documentclass{article}
\usepackage{doc}
\usepackage[noisy]{textfit}
% dimensions from ltugboat.sty:
\setlength\textwidth{31pc} 
\setlength\textheight{54pc}
\setlength{\parindent}{0pt}
\setlength{\parskip}{2pt plus 1pt minus 1pt}
\setlength{\oddsidemargin}{8pc} 
\setlength{\marginparwidth}{8pc}
\setlength{\topmargin}{-2.5pc} 
\setlength{\headsep}{20pt}
\setlength{\columnsep}{1.5pc} 
\setlength{\columnwidth}{18.75pc}

\DisableCrossrefs

\CodelineIndex     % Index code by line number

%\OnlyDescription  % comment out for implementation details

\begin{document}
   \DocInput{textfit.dtx}
\end{document}
%</driver>
%    \end{macrocode}
%
%
%    The next line goes into all files and in addition prevents \dst{}
%    from adding any further code from the main source file (such as a
%    character table.
%    \begin{macrocode}
\endinput
%    \end{macrocode}
%
% \DeleteShortVerb{\|}
%
% \Finale
%
%% \CharacterTable
%%  {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
%%   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
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}