Debian Codegraph @

texmf-dist/doc/latex/fontscale/fontscale.tex

raw
1 \documentclass{beerydoc}
2
3
4 \begin{document}
5
6
7 \section*{\stepfontsize{1}The \pkg{fontscale} package}
8
9 A flexible interface for setting font sizes
10
11 Oliver Beery
12
13 Version 5.0.0\quad 17 February 2026
14
15
16 \section{Introduction}
17 \label{sec:intro}
18
19 \subsection{About}
20 \label{subsec:about}
21
22 \listheading
23 {The \pkg{fontscale} package provides the following functionalities:}
24 \begin{itemize}
25 \item
26 Set font sizes using a classic or musical typographic scale.
27 \item
28 Set arbitrary font sizes and font baselineskips for the standard \LaTeX{}
29 font size commands: \cs{tiny}, \cs{scriptsize}, \cs{footnotesize},
30 \cs{small}, \cs{normalsize}, \cs{large}, \cs{Large}, \cs{LARGE}, \cs{huge},
31 and \cs{Huge}.
32 \item
33 Defines lengths that store the current font size, font baselineskip, and the
34 font size of \cs{normalsize}.
35 \item
36 Set the font size relative to the current font size using more robust tools
37 than the \pkg{scalefnt} and \pkg{relsize} packages.
38 \item
39 Defines \pkg{expl3} variables that store the font size and font baselineskip
40 of each font size command from \cs{tiny} to \cs{Huge} and the current font
41 size and font baselineskip.
42 \end{itemize}
43
44 \subsection{Loading the package}
45 \label{subsec:loading}
46
47 \listheading{Requirements:}
48 \begin{itemize}
49 \item \LaTeXe{} version 2023-11-01 or newer
50 \item \pkg{l3kernel} version 2023-11-01 or newer
51 \end{itemize}
52
53 For historical reasons, the Computer Modern font is available only in a number
54 of discrete font sizes.
55 If you get a warning that Computer Modern is not available in the requested
56 size, you may need to add the following code before \cs{documentclass} to make
57 Computer Modern available at arbitrary font sizes:
58 \begin{verbatim}
59 \RequirePackage{fix-cm}
60 \end{verbatim}
61 Alternatively, you can use the Latin Modern font by loading the \pkg{lmodern}
62 package.
63
64 When loaded, this package uses \cs{normalsize} after declaring and initializing
65 the font size commands from \cs{tiny} to \cs{Huge}.
66
67 Many \LaTeX{} classes have a font size option (e.g. \key{10pt}, \key{11pt},
68 \key{12pt}) which not only changes the font sizes, but also modifies additional
69 settings such as the page layout and vertical spacing which were specifically
70 designed to work with those font sizes.
71 For this reason, you may want to set the class font size option close to the
72 font size of \cs{normalsize} set by this package.
73
74 \subsection{The font size commands from \cs{tiny} to \cs{Huge}}
75 \label{subsec:names}
76
77 \begin{code}
78 {
79 \tiny,
80 \scriptsize,
81 \footnotesize,
82 \small,
83 \normalsize,
84 \large,
85 \Large,
86 \LARGE,
87 \huge,
88 \Huge,
89 \@currsize
90 }
91 \listheading
92 {
93 The font size commands from \cs{tiny} to \cs{Huge} defined by this
94 package:
95 }
96 \begin{itemize}
97 \item
98 First set \cs{@currsize} to have the same meaning as the font size command.
99 This is needed only for backwards compatibility.
100 \item
101 Set the font size and font baselineskip using \cs{fontsize} and
102 \cs{selectfont}.
103 You can change the font sizes and font baselineskips that are set by the
104 font size commands by setting the \pkg{fontscale} package keys
105 (\S\ref{sec:keys}).
106 (The font baselineskip should not be confused with the paragraph
107 baselineskip
108 \cs{baselineskip}.)
109 \item
110 Cannot be used in math mode.
111 \item
112 Have no other functionality.
113 In particular, they do not change the vertical spacing for displayed math
114 and list structures.
115 This differs from the font size commands defined by many \LaTeX{} classes.
116 You can add arbitrary code to the font size commands using hooks, which are
117 documented in \pkg{lthooks} and \pkg{ltcmdhooks}.
118 \end{itemize}
119 \end{code}
120
121 \subsection{Syntax}
122 \label{subsec:syntax}
123
124 This documentation uses the syntaxes listed below.
125 The syntaxes on the left have the same meaning as the argument to the
126 corresponding command on the right.
127 The commands on the right are documented in \pkg{usrguide}.
128 \input{fontscale-syntax.tex}
129
130
131 \section{Keys}
132 \label{sec:keys}
133
134 This section documents the keys provided by the \pkg{fontscale} package.
135 Set the package keys using \cs{fontscalesetup} (\S\ref{subsec:setup}).
136
137 \subsection{The key \key{typographic-scale}}
138 \label{subsec:typographicscale}
139
140 The font sizes of the font size commands from \cs{tiny} to \cs{Huge} are
141 initially set by the key \key{typographic-scale}.
142
143 \begin{code}{typographic-scale}
144 \begin{syntax}
145 \key{typographic-scale=\choices{classic,musical}}
146 \end{syntax}
147 Choice key that sets the font size of each font size command from \cs{tiny}
148 to \cs{Huge} using a classic or musical typographic scale.
149 These are common methods of choosing a set of document font sizes.
150 The initial value is \key{=classic}.
151 \end{code}
152
153 \begin{code}{classic, musical}
154 Meta keys that set the key \key{typographic-scale} to the named value.
155 \end{code}
156
157 \subsubsection{The classic typographic scale}
158 \label{subsubsec:classictypographicscale}
159
160 \begin{code}{classic/base, classic/point}
161 \begin{syntax}
162 \key{classic/base=\choices{10,11,12}}
163 \key{classic/point=\choices{pt,bp,dd,nd}}
164 \end{syntax}
165 Setting the key \key{typographic-scale=classic} sets the font size of each
166 font size command from \cs{tiny} to \cs{Huge} using the classic typographic
167 scale.
168 The classic typographic scale consists of the traditional font sizes in units
169 of points:%
170 \footnote
171 {See \textit{The Elements of Typographic Style} by Robert Bringhurst.}
172 \input{fontscale-classic-list.tex}%
173 They have been used since the sixteenth century and are the default font
174 sizes on some computer software.
175
176 The choice key \key{classic/base} sets the base font size of the classic
177 typographic scale to the named value in units of points.
178 The base font size is the font size of \cs{normalsize}.
179 The font sizes of the other font size commands are the adjacent font sizes in
180 the classic typographic scale in units of points.
181 The initial value is \key{=10}.
182 The choice key \key{classic/point} sets which \enquote{point} is used.
183 The initial value is \key{=pt}.
184 Table \ref{table:classic} displays the font size of each font size command
185 from \cs{tiny} to \cs{Huge} when setting the key
186 \key{typographic-scale=classic}.
187 \end{code}
188
189 \input{./fontscale-table-classic.tex}
190
191 \subsubsection{The musical typographic scale}
192 \label{subsubsec:musicaltypographicscale}
193
194 \begin{code}{musical/base, musical/ratio, musical/notes}
195 \begin{syntax}
196 \key{musical/base=\meta{dimen}}
197 \key{musical/ratio=\meta{number}}
198 \key{musical/notes=\meta{integer}}
199 \end{syntax}
200 Setting the key \key{typographic-scale=musical} calculates the font size of
201 each font size command from \cs{tiny} to \cs{Huge} using the formula for the
202 musical typographic scale:%
203 \footnote
204 {%
205 I have referenced this article by Spencer Mortensen:
206 \newline
207 \url{https://spencermortensen.com/articles/typographic-scale/}%
208 }
209 \begin{equation*}
210 f_i = f_0 \times r ^ { i / n }
211 \end{equation*}
212 $f_i$ is the font size of the $i$th note.
213 $f_0$ is the base font size.
214 $n$ is the number of notes, the number of font sizes above $f_0$.
215 $r$ is the musical ratio, the ratio of the highest to the lowest note
216 $ f_n / f_0 $.
217
218 The key \key{musical/base} sets the base font size $f_0$ to \meta{dimen}.
219 The base font size is the font size of \cs{normalsize}.
220 The initial value is \qty{10}{pt}.
221 The key \key{musical/ratio} sets the musical ratio $r$ to \meta{number}.
222 The initial value is \num{2}.
223 The key \key{musical/notes} sets the number of notes $n$ to \meta{integer}.
224 The initial value is \num{5}.
225 Table \ref{table:musical} displays the font size of each font size command
226 from \cs{tiny} to \cs{Huge} when setting the key
227 \key{typographic-scale=musical}.
228 \end{code}
229
230 \input{./fontscale-table-musical.tex}
231
232 \subsection{The key \key{baselineskip-size-ratio}}
233 \label{subsec:baselineskipsizeratio}
234
235 The font baselineskips of the font size commands from \cs{tiny} to \cs{Huge}
236 are initially set by the key \key{baselineskip-size-ratio}.
237
238 \begin{code}{baselineskip-size-ratio}
239 \begin{syntax}
240 \key{baselineskip-size-ratio=\meta{number}}
241 \end{syntax}
242 Sets the font baselineskip of each font size command from \cs{tiny} to
243 \cs{Huge} equal to its font size \texttimes{} \meta{number}.
244 The initial value is \num{1.2}.
245 This key also affects the behavior of \cs{setfontsize}
246 (\S\ref{subsec:fontsize}).
247 \end{code}
248
249 \subsection{Overwriting the previous keys}
250 \label{subsec:overwriting}
251
252 This subsection documents keys for setting the font sizes and font
253 baselineskips of the font size commands from \cs{tiny} to \cs{Huge} in a more
254 direct manner.
255
256 When setting the font sizes, you should take care to ensure that their lengths
257 remain correctly ordered from \cs{tiny} to \cs{Huge}.
258 This is important for typographic and syntactic consistency.
259 If the font sizes are in the wrong order, then \cs{fontscalesetup} will issue a
260 warning and some package features may not work correctly.
261
262 \begin{code}
263 {
264 tiny/size-normalsize-ratio,
265 scriptsize/size-normalsize-ratio,
266 footnotesize/size-normalsize-ratio,
267 small/size-normalsize-ratio,
268 large/size-normalsize-ratio,
269 Large/size-normalsize-ratio,
270 LARGE/size-normalsize-ratio,
271 huge/size-normalsize-ratio,
272 Huge/size-normalsize-ratio
273 }
274 \begin{syntax}
275 \key{\meta{font size command}/size-normalsize-ratio=\meta{number}}
276 \end{syntax}
277 Sets the font size of \cs{\meta{font size command}} equal to the font size of
278 \cs{normalsize} \texttimes{} \meta{number}.
279 Overwrites the font size set by the key \key{typographic-scale}.
280 The initial value is \meta{not set}.
281 The key \key{normalsize/size-normalsize-ratio} is not defined.
282 \end{code}
283
284 \begin{code}
285 {
286 tiny/size,
287 scriptsize/size,
288 footnotesize/size,
289 small/size,
290 normalsize/size,
291 large/size,
292 Large/size,
293 LARGE/size,
294 huge/size,
295 Huge/size
296 }
297 \begin{syntax}
298 \key{\meta{font size command}/size=\meta{dimen}}
299 \end{syntax}
300 Sets the font size of \cs{\meta{font size command}} to \meta{dimen}.
301 Overwrites the font size set by the keys \key{typographic-scale} and
302 \key{\meta{font size command}/size-normalsize-ratio}.
303 The initial value is \meta{not set}.
304 \end{code}
305
306 \begin{code}
307 {
308 tiny,
309 scriptsize,
310 footnotesize,
311 small,
312 normalsize,
313 large,
314 Large,
315 LARGE,
316 huge,
317 Huge
318 }
319 \begin{syntax}
320 \key{\meta{font size command}=\meta{dimen}}
321 \end{syntax}
322 Meta keys that set the key \key{\meta{font size command}/size=\meta{dimen}}.
323 \end{code}
324
325 \begin{code}
326 {
327 tiny/baselineskip-size-ratio,
328 scriptsize/baselineskip-size-ratio,
329 footnotesize/baselineskip-size-ratio,
330 small/baselineskip-size-ratio,
331 normalsize/baselineskip-size-ratio,
332 large/baselineskip-size-ratio,
333 Large/baselineskip-size-ratio,
334 LARGE/baselineskip-size-ratio,
335 huge/baselineskip-size-ratio,
336 Huge/baselineskip-size-ratio
337 }
338 \begin{syntax}
339 \key{\meta{font size command}/baselineskip-size-ratio=\meta{number}}
340 \end{syntax}
341 Sets the font baselineskip of \cs{\meta{font size command}} equal to its font
342 size \texttimes{} \meta{number}.
343 Overwrites the font baselineskip set by the key
344 \key{baselineskip-size-ratio}.
345 The initial value is \meta{not set}.
346 \end{code}
347
348 \begin{code}
349 {
350 tiny/baselineskip,
351 scriptsize/baselineskip,
352 footnotesize/baselineskip,
353 small/baselineskip,
354 normalsize/baselineskip,
355 large/baselineskip,
356 Large/baselineskip,
357 LARGE/baselineskip,
358 huge/baselineskip,
359 Huge/baselineskip
360 }
361 \begin{syntax}
362 \key{\meta{font size command}/baselineskip=\meta{skip}}
363 \end{syntax}
364 Sets the font baselineskip of \cs{\meta{font size command}} to \meta{skip}.
365 Overwrites the font baselineskip set by the keys
366 \key{baselineskip-size-ratio} and
367 \key{\meta{font size command}/baselineskip-size-ratio}.
368 The initial value is \meta{not set}.
369 \end{code}
370
371
372 \section{Commands}
373 \label{sec:commands}
374
375 This section documents the commands provided by the \pkg{fontscale} package.
376
377 \subsection{Setting the keys}
378 \label{subsec:setup}
379
380 \begin{code}{\fontscalesetup}
381 \begin{syntax}
382 \cs{fontscalesetup} \sarg{} \marg{key-value list}
383 \end{syntax}
384 Sets and processes the \pkg{fontscale} package keys (\S\ref{sec:keys}) in
385 \meta{key-value list} and then uses \cs{normalsize}.
386 Adding the optional star first sets all the \pkg{fontscale} package keys to
387 their initial values.
388 All assignments made by \cs{fontscalesetup} are local to the current group.
389 Can be used mid-document.
390 Cannot be used in math mode.
391 \end{code}
392
393 \subsection{Lengths}
394 \label{subsec:lengths}
395
396 \begin{code}{\currentfontsize}
397 Dimen register (rigid length) that stores the current font size.
398 This is more convenient than using \cs{f@size}.
399 \end{code}
400
401 \begin{code}{\currentfontbaselineskip}
402 Skip register (rubber length) that stores the current font baselineskip.
403 This is more convenient than using \cs{f@baselineskip}.
404 (The font baselineskip should not be confused with the paragraph baselineskip
405 \cs{baselineskip}.)
406 \end{code}
407
408 \begin{code}{\currentnormalsize}
409 Dimen register (rigid length) that stores the current font size of
410 \cs{normalsize}.
411 \end{code}
412
413 \subsection{More font size commands}
414 \label{subsec:fontsize}
415
416 \begin{code}{\setfontsize}
417 \begin{syntax}
418 \cs{setfontsize} \oarg{skip} \marg{dimen}
419 \end{syntax}
420 Sets the font size to \meta{dimen}.
421 Sets the font baselineskip to \meta{skip} or, if the optional argument is
422 omitted, equal to the new font size \texttimes{} the value of the key
423 \key{baselineskip-size-ratio} (\S\ref{subsec:baselineskipsizeratio}).
424 Cannot be used in math mode.
425 This command is a more robust alternative to \cs{fontsize} + \cs{selectfont}.
426 \end{code}
427
428 \begin{code}{\stepfontsize}
429 \begin{syntax}
430 \cs{stepfontsize} \marg{integer}
431 \end{syntax}
432 Increases the font size by an \meta{integer} number of \enquote{steps}.
433 Changing the font size by one step means incrementing\slash decrementing from
434 a font size equal to the font size of a font size command from \cs{tiny} to
435 \cs{Huge} to the next larger\slash smaller \cs{\meta{font size command}} by
436 using \cs{\meta{font size command}}.
437 Changing the font size by more than one step does not use any intermediate
438 \cs{\meta{font size command}}.
439 If $\meta{integer}=\num{0}$ and the current font size equals the font size of
440 any \cs{\meta{font size command}}, then \cs{stepfontsize} uses
441 \cs{\meta{font size command}}.
442
443 \listheading{Some exceptions:}
444 \begin{itemize}
445 \item
446 Issues a warning if the current font size does not equal the font size of
447 any font size command from \cs{tiny} to \cs{Huge}.
448 \item
449 Issues an error if the font size would be changed by more than nine steps.
450 \item
451 Issues a warning and uses \cs{tiny} if the new font size would be smaller
452 than \cs{tiny}.
453 \item
454 Issues a warning and uses \cs{Huge} if the new font size would be larger
455 than \cs{Huge}.
456 \item
457 Cannot be used in math mode.
458 \end{itemize}
459 \end{code}
460
461 \subsection{Setting only the font baselineskip}
462 \label{subsec:fontbaselineskip}
463
464 \begin{code}{\setfontbaselineskip}
465 \begin{syntax}
466 \cs{setfontbaselineskip} \marg{skip}
467 \end{syntax}
468 Sets the font baselineskip to \meta{skip}.
469 Does not change the font size.
470 Cannot be used in math mode.
471 \end{code}
472
473 \subsection{Printing sample text}
474 \label{subsec:printsampletext}
475
476 \begin{code}{\printsampletext}
477 \begin{syntax}
478 \cs{printsampletext} \sarg{} \marg{text}
479 \end{syntax}
480 Prints \meta{text} in each font size ordered from \cs{tiny} to \cs{Huge} each
481 followed by \cs{par}.
482 \meta{text} can contain \cs{par} tokens.
483 Adding the optional star reverses the order of the font sizes.
484 \end{code}
485
486 \begin{code}{\printfontsizecommand}
487 Prints \cs{\meta{font size command}} if the current font size equals the font
488 size of any font size command from \cs{tiny} to \cs{Huge}.
489 Otherwise, prints \enquote{\ttfamily\string\undefined}.
490 The command name is printed in \cs{ttfamily}.
491 \end{code}
492
493
494 \section{Programming}
495 \label{sec:expl3}
496
497 This section documents the \pkg{expl3} programming support provided by the
498 \pkg{fontscale} package.
499
500 \subsection{Compatibility with \cs{text_purify:n}}
501 \label{subsec:textpurify}
502
503 This package uses \cs{text_declare_purify_equivalent:Nn} to make
504 \cs{text_purify:n} correctly remove the text formatting commands defined by
505 this package.
506
507 \subsection{Variables set by \cs{fontscalesetup}}
508 \label{subsec:varsetup}
509
510 \begin{code}
511 {
512 \l_fontscale_tiny_size_dim,
513 \l_fontscale_scriptsize_size_dim,
514 \l_fontscale_footnotesize_size_dim,
515 \l_fontscale_small_size_dim,
516 \l_fontscale_normalsize_size_dim,
517 \l_fontscale_large_size_dim,
518 \l_fontscale_Large_size_dim,
519 \l_fontscale_LARGE_size_dim,
520 \l_fontscale_huge_size_dim,
521 \l_fontscale_Huge_size_dim
522 }
523 \begin{syntax}
524 \cs{l_fontscale_\meta{font size command}_size_dim}
525 \end{syntax}
526 Stores the font size of \cs{\meta{font size command}}.
527 \cs{l_fontscale_normalsize_size_dim} is equivalent to \cs{currentnormalsize}
528 (\S\ref{subsec:lengths}).
529 \end{code}
530
531 \begin{code}
532 {
533 \l_fontscale_tiny_baselineskip_skip,
534 \l_fontscale_scriptsize_baselineskip_skip,
535 \l_fontscale_footnotesize_baselineskip_skip,
536 \l_fontscale_small_baselineskip_skip,
537 \l_fontscale_normalsize_baselineskip_skip,
538 \l_fontscale_large_baselineskip_skip,
539 \l_fontscale_Large_baselineskip_skip,
540 \l_fontscale_LARGE_baselineskip_skip,
541 \l_fontscale_huge_baselineskip_skip,
542 \l_fontscale_Huge_baselineskip_skip
543 }
544 \begin{syntax}
545 \cs{l_fontscale_\meta{font size command}_baselineskip_skip}
546 \end{syntax}
547 Stores the font baselineskip of \cs{\meta{font size command}}.
548 \end{code}
549
550 \subsection{Variables set in the \hook{selectfont} hook}
551 \label{subsec:varselectfont}
552
553 \begin{code}{\l_fontscale_size_dim}
554 Stores the current font size.
555 Equivalent to \cs{currentfontsize} (\S\ref{subsec:lengths}).
556 \end{code}
557
558 \begin{code}{\l_fontscale_baselineskip_skip}
559 Stores the current font baselineskip.
560 Equivalent to \cs{currentfontbaselineskip} (\S\ref{subsec:lengths}).
561 \end{code}
562
563
564 \end{document}